Commit 2e1ee8f6 authored by Clément Haëck's avatar Clément Haëck
Browse files

Up plots

parent 4670c41c
......@@ -9,20 +9,15 @@ import lib
import lib.data.hists as lh
def add_args(parser):
parser.add_argument('-thr_lo', type=float, default=5.)
parser.add_argument('-thr_hi', type=float, default=10.)
args = lib.get_args(['region', 'days', 'fixes'], add_args)
args['fixes']['thr_lo'] = args['thr_lo']
args['fixes']['thr_hi'] = args['thr_hi']
args = lib.get_args(['region', 'days', 'fixes'])
fixes = dict(
scale=30.,
number=2,
coef=0,
thr_lo=5.,
thr_hi=10.
thr_lo=6.,
thr_hi=10.,
Y=2007,
nomask=False
)
fixes.update(args['fixes'])
args['fixes'] = fixes
......
......@@ -15,8 +15,9 @@ fixes = dict(
scale=30.,
number=2,
coef=0,
thr_lo=5.,
thr_hi=10.
thr_lo=6.,
thr_hi=10.,
nomask=False
)
......
from os import path
import matplotlib.pyplot as plt
import tol_colors as tc
import xarray as xr
import lib
import lib.data.valid_pixels as lv
import lib.data.hists as lh
import Plots.util as plot_util
fixes = dict(
number=2,
scale=30.,
coef=0,
thr_lo=6.,
thr_hi=10.
)
ds = lh.get_data(fixes=fixes)
ds = ds.squeeze()
ds = lh.resample_8D_multiple_years(ds)
ds = ds.sum('zone')
pdf = lh.get_pdf(ds, variables='CHL')
med = lh.get_median(pdf).load()
fixes['nomask'] = True
ds = lh.get_data(fixes=fixes)
ds = ds.squeeze()
ds = lh.resample_8D_multiple_years(ds)
ds = ds.sum('zone')
T = lh.get_total(ds, variables='CHL')
N = lh.get_N(ds, variables='CHL')
T_f = T.sum('mask')
T_nf_mid = (T.sel(mask=['low', 'hi']).sum('mask')
+ med.sel(mask='low') * N.sel(mask='mid'))
T_nf_hi = (T.sel(mask=['low', 'mid']).sum('mask')
+ med.sel(mask='low') * N.sel(mask='hi'))
T_nf = xr.concat([T_nf_mid, T_nf_hi], dim=xr.DataArray(['mid', 'hi'],
dims=['mask']))
# T_nf = T.sel(mask='low') + med * N
surplus = (T_f-T_nf)/T_f * 100.
surplus = surplus.load()
# surplus = surplus.sel(mask=['mid', 'hi']).load()
clis = lh.get_climatology(surplus)
def plot(cli, cli_d1, cli_d9, ax, sel, color='k', ls='-'):
def get(ds):
return ds.sel(**sel)
ax.plot(cli.time, get(cli), color=color, ls=ls)
ax.fill_between(cli.time.values, get(cli_d1), get(cli_d9),
color=color, alpha=.3)
cset = tc.tol_cset('vibrant')
colors = dict(mid='blue', hi='teal')
colors = {m: getattr(cset, c) for m, c in colors.items()}
fig, ax = plt.subplots(figsize=(6.5, 4))
fig.subplots_adjust(left=0.10, bottom=0.06, right=0.99, top=0.90)
ax.xaxis.axis_date()
ax.xaxis.set_major_formatter(plot_util.MonthFormatter())
for m, c in colors.items():
plot(*clis, ax, dict(mask=m), color=c)
ax.set_ylabel('Surplus [%]')
ax.set_xlim(clis[0].time[[0, -1]].values)
ax.set_ylim(0, None)
labels = list(colors.keys())
handles = [plt.Line2D((), (), color=c) for c in colors.values()]
fig.legend(handles, labels, bbox_to_anchor=[0., 1.], loc='upper left',
ncol=2)
fig.savefig(path.join(lib.root_plot, 'Hists', 'surplus', 'article_surplus.png'),
dpi=150)
......@@ -14,6 +14,9 @@ fixes = dict(
scale=30.,
number=2,
coef=0,
thr_lo=6.,
thr_hi=10.,
nomask=True
)
fixes.update(args['fixes'])
args['fixes'] = fixes
......
from os import path
import matplotlib.pyplot as plt
import tol_colors as tc
import xarray as xr
import lib
import lib.data.valid_pixels as lv
import lib.data.hists as lh
import Plots.util as plot_util
fixes = dict(
number=2,
scale=30.,
coef=0,
thr_lo=6.,
thr_hi=10.
)
ds = lh.get_data(fixes=fixes)
ds = ds.squeeze()
ds = lh.resample_8D_multiple_years(ds)
pdf = lh.get_pdf(ds, variables='CHL')
med = lh.get_median(pdf).load()
fixes['nomask'] = True
ds = lh.get_data(fixes=fixes)
ds = ds.squeeze()
ds = lh.resample_8D_multiple_years(ds)
T = lh.get_total(ds, variables='CHL')
N = lh.get_N(ds, variables='CHL')
T_f = T.sum('mask')
T_nf_mid = (T.sel(mask=['low', 'hi']).sum('mask')
+ med.sel(mask='low') * N.sel(mask='mid'))
T_nf_hi = (T.sel(mask=['low', 'mid']).sum('mask')
+ med.sel(mask='low') * N.sel(mask='hi'))
T_nf = xr.concat([T_nf_mid, T_nf_hi], dim=xr.DataArray(['mid', 'hi'],
dims=['mask']))
# T_nf = T.sel(mask='low') + med * N
surplus = (T_f-T_nf)/T_f * 100.
surplus = surplus.load()
# surplus = surplus.sel(mask=['mid', 'hi']).load()
clis = lh.get_climatology(surplus)
def plot(cli, cli_d1, cli_d9, ax, sel, color='k', ls='-'):
def get(ds):
return ds.sel(**sel)
ax.plot(cli.time, get(cli), color=color, ls=ls)
ax.fill_between(cli.time.values, get(cli_d1), get(cli_d9),
color=color, alpha=.3)
cset = tc.tol_cset('vibrant')
colors = dict(mid='blue', hi='teal')
colors = {m: getattr(cset, c) for m, c in colors.items()}
zones = dict(S='South', I='Jet', N='North')
fig, axes = plt.subplots(1, 3, figsize=(10, 3.5), sharex=True)
fig.subplots_adjust(left=0.07, bottom=0.07, right=0.99, top=0.83)
for ax, (z, t) in zip(axes, zones.items()):
sel = dict(zone=f'GS3_{z}')
ax.xaxis.axis_date()
ax.xaxis.set_major_formatter(plot_util.MonthFormatter(interval=2))
for m, c in colors.items():
sel['mask'] = m
plot(*clis, ax, sel, color=c)
ax.set_xlim(clis[0].time[[0, -1]].values)
ax.set_ylim(0, 27)
ax.set_title(t)
axes[0].set_ylabel('Surplus [%]')
labels = list(colors.keys())
handles = [plt.Line2D((), (), color=c) for c in colors.values()]
fig.legend(handles, labels, bbox_to_anchor=[0., 1.], loc='upper left',
ncol=2)
fig.savefig(path.join(lib.root_plot, 'Hists', 'surplus', 'surplus_zones.png'),
dpi=150)
......@@ -102,8 +102,8 @@ gls = []
for i, ax in enumerate(axes.flat):
ax.coastlines(lw=0.7)
frt_filt.plot.contour(ax=ax, levels=[p_thr], colors='k', linewidths=0.7,
add_labels=False, add_colorbar=False)
# frt_filt.plot.contour(ax=ax, levels=[p_thr], colors='k', linewidths=0.7,
# add_labels=False, add_colorbar=False)
gl = ax.gridlines(lw=0.7, draw_labels=True)
gls.append(gl)
......
......@@ -10,6 +10,7 @@ from lib import root_plot
CHL_LABEL = r'Chl-\emph{a} [\(\si{\milli\gram\per\cubic\meter}\)]'
SST_LABEL = r'SST [\(\si{\degreeCelsius}\)]'
def set_style():
......
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