Commit 88a9da80 authored by Clément Haëck's avatar Clément Haëck
Browse files

Up plots

parent 502fbe62
......@@ -12,21 +12,21 @@ import Plots.util as plot_util
fixes = dict(
Y=2007
)
zone = 'GS3_S'
season = 'year'
ds = lh.get_data(fixes=fixes)
ds = ds.squeeze()
grp = ds.groupby('time.month')
ds = xr.combine_by_coords([grp[i] for i in [1, 2, 12]])
# hist = ds.groupby('time.season').sum().sel(season=season).hist
hist = ds.sum('time').hist
hist = ds.hist.sum('time')
hist.attrs['VAR'] = 'CHL'
pdf = lib.data.hists.get_pdf(hist)
pdf = lib.data.hists.get_pdf(hist).load()
pdf.attrs['VAR'] = 'CHL'
med = lib.data.hists.get_median(pdf)
q1 = lib.data.hists.get_quantile(pdf, q=0.25)
q3 = lib.data.hists.get_quantile(pdf, q=0.75)
fig, axes = plt.subplots(1, 3, figsize=(10, 3.8), sharex=True, sharey=True)
fig.subplots_adjust(left=0.07, bottom=0.13, right=0.94, top=0.92, wspace=0.08)
......@@ -47,19 +47,20 @@ for ax, z, t in zip(axes, 'SIN', ['South', 'Jet', 'North']):
add_labels=False,
add_colorbar=addcbar,
cbar_ax=cax)
# pdf.plot.contour(ax=ax, add_labels=False,
# colors='k', levels=np.geomspace(cmin, cmax, 10))
ax.plot(med.bins_HI, med.sel(zone=zone), color='k')
ax.plot(q1.bins_HI, q1.sel(zone=zone), color='k', linewidth=0.5)
ax.plot(q3.bins_HI, q3.sel(zone=zone), color='k', linewidth=0.5)
ax.set_title(t)
ax.set_xlabel('HI ')
ax.set_xlim(0, 19)
ax.set_ylim(0, 1.8)
ax.set_ylim(0, 1.)
axes[0].set_ylabel('CHL')
cax.set_ylabel('PDF (normalisée selon Chl)')
fig.savefig(path.join(lib.root_plot, 'Hists', '2D', 'fig.png'),
fig.savefig(path.join(lib.root_plot, 'Hists', '2D',
'fig_{}.png'.format(season)),
dpi=150)
......@@ -14,7 +14,8 @@ fixes = dict(
scale=30.,
number=2,
coef=0,
threshold=8.
thr_lo=5.,
thr_hi=10.
)
......@@ -23,16 +24,21 @@ ds = ds.squeeze()
ds = lh.resample_8D_multiple_years(ds)
ds = ds.load()
N = lh.get_N(ds)
frac = lh.get_surface_fraction(N.sel(var='CHL')) * 100.
# join = ['hi' if m == 'low' else 'low' for m in ds.mask]
# ds = xr.core.groupby.DatasetGroupBy(
# ds, xr.DataArray(join, dims=['mask'], name='mask')
# ).sum(keep_attrs=True)
N = lh.get_N(ds).sel(var='CHL').reset_coords(drop=True)
frac = N / N.sum('mask') * 100.
ds['frac'] = frac.reset_coords(drop=True)
pdf = lh.get_pdf(ds)
ds['med'] = lh.get_median(pdf).load()
T = lh.get_total(ds.hist_CHL)
T_img = (T.sel(mask='bkg') + ds.med.sel(mask='bkg', var='CHL')
* N.sel(mask='frt', var='CHL'))
ds['surplus'] = (T.sum('mask') - T_img) / T.sum('mask') * 100.
# T = lh.get_total(ds.hist_CHL)
# T_img = (T.sel(mask='bkg') + ds.med.sel(mask='bkg', var='CHL')
# * N.sel(mask='frt', var='CHL'))
# ds['surplus'] = (T.sum('mask') - T_img) / T.sum('mask') * 100.
ds = ds.drop_vars(['hist_CHL', 'hist_sst'])
......@@ -56,7 +62,7 @@ def plot(cli, cli_d1, cli_d9, ax, var, sel, color='k', ls='-'):
cset = tc.tol_cset('vibrant')
fig, axes = plt.subplots(4, 3, figsize=(10.8, 6), sharex=True)
fig, axes = plt.subplots(3, 3, figsize=(10.8, 6), sharex=True)
fig.subplots_adjust(left=0.06, bottom=0.05, right=0.98, top=0.95,
hspace=0.1, wspace=0.2)
......@@ -68,18 +74,20 @@ for ax in axes.flat:
for i, var in enumerate(['sst', 'CHL']):
for j, zone in enumerate(loop_zones()):
sel = dict(zone=zone, var=var)
sel['mask'] = 'bkg'
plot(*clis, axes[i, j], 'med', sel, color=cset.teal)
sel['mask'] = 'frt'
sel['mask'] = 'low'
plot(*clis, axes[i, j], 'med', sel, color=cset.cyan)
sel['mask'] = 'mid'
plot(*clis, axes[i, j], 'med', sel, color=cset.orange)
sel['mask'] = 'hi'
plot(*clis, axes[i, j], 'med', sel, color=cset.red)
for j, zone in enumerate(loop_zones()):
sel = dict(zone=zone)
plot(*clis, axes[2, j], 'frac', sel)
# plot(*clis, axes[3, j], 'est', sel, color=tc.tol_cset('bright').red)
plot(*clis, axes[3, j], 'surplus', sel, color=tc.tol_cset('bright').green)
# axes[2, j].set_ylim(0, None)
# axes[3, j].set_ylim(0, None)
sel['mask'] = 'mid'
plot(*clis, axes[2, j], 'frac', sel, color=cset.orange)
sel['mask'] = 'hi'
plot(*clis, axes[2, j], 'frac', sel, color=cset.red)
axes[2, j].set_ylim(0, 60)
axes[0, 0].set_xlim(*(clis[0].time[[0, -1]].values))
......@@ -87,8 +95,6 @@ axes[0, 0].set_xlim(*(clis[0].time[[0, -1]].values))
axes[0, 0].set_ylabel('SST [°C]')
axes[1, 0].set_ylabel('CHL [mg/m³]')
axes[2, 0].set_ylabel('Fronts surface [%]')
# axes[3, 0].set_ylabel('Ratio [%]')
axes[3, 0].set_ylabel('Surplus [%]')
axes[0, 0].set_title('SOUTH')
axes[0, 1].set_title('JET')
......
#!/usr/bin/env ipython
from os import path
import matplotlib.pyplot as plt
import lib
import lib.data.hists_2d
import lib.data.hists
import Plots.util as plot_util
plot_util.use_tex(True)
fixes = dict(
number=2,
scale=30.,
coef=0
)
ds = lib.data.hists_2d.get_data(fixes=fixes)
ds = ds.squeeze()
hist = ds.sum('time').hist
hist.attrs['VAR'] = 'CHL'
pdf = lib.data.hists.get_pdf(hist).load()
pdf.attrs['VAR'] = 'CHL'
stats = [lib.data.hists.get_quantile(pdf, q=q)
for q in [0.5, 0.25, 0.75, 0.05, 0.95]]
fig, axes = plt.subplots(1, 3, figsize=(10, 3.8), sharex=True, sharey=True)
fig.subplots_adjust(left=0.07, bottom=0.13, right=0.98, top=0.92, wspace=0.08)
for ax, z, t in zip(axes, 'SIN', ['South', 'Jet', 'North']):
zone = 'GS3_{}'.format(z)
S = [s.sel(zone=zone) for s in stats]
m = S[0]
qs = S[1:3]
ds = S[3:5]
bins = m.bins_HI
ax.fill_between(bins, *qs, color='grey', alpha=0.35)
ax.fill_between(bins, *ds, color='grey', alpha=0.20)
ax.plot(bins, m, ls='-', lw=1.5, color='k')
for q in qs:
ax.plot(bins, q, ls='--', lw=1., color='k')
for d in ds:
ax.plot(bins, d, ls=':', lw=1., color='k')
ax.set_title(t)
ax.set_xlim(0, 19)
ax.set_ylim(0, 1.)
axes[0].set_ylabel(plot_util.CHL_LABEL)
axes[1].set_xlabel('HI')
fig.savefig(path.join(lib.root_plot, 'Hists', 'article_2d',
'fig.png'),
dpi=150)
......@@ -9,6 +9,9 @@ import mpl_toolkits.axes_grid1 as axes_grid1
from lib import root_plot
CHL_LABEL = r'Chl-\emph{a} [\(\si{\milli\gram\per\cubic\meter}\)]'
def set_style():
plt.style.use(path.join(root_plot, 'Definitive', 'common.mplstyle'))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment