Commit 03dbb681 authored by Clément Haëck's avatar Clément Haëck
Browse files

Up plots

parent fb434274
from datetime import datetime
from os import path
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter
import pandas as pd
import tol_colors as tc
import lib.data.hists
import lib.data.frt_TS
variables = ['dtom', 'dinflg', None,
'galgae', 'prymnsio', None,
'prokrt', 'picoeuk', 'prchlcus']
names = ['Diatoms', 'Dinoflagellates', None,
'Green Algae', 'Prymnesiophytes', None,
'Prokaryotes', 'Pico-eukaryotes', 'Prochlorococcus']
variables = ['dtom', 'dinflg',
'galgae', 'prymnsio',
'prokrt', 'prchlcus']
names = ['Diatoms', 'Dinoflagellates',
'Green Algae', 'Prymnesiophytes',
'Prokaryotes', 'Prochlorococcus']
fixes = dict(
number=2,
coef=0,
scale=30,
threshold=6.0,
zone='GS_N_SOM'
zone='GS_N_SOM',
threshold=15.0,
)
ds = lib.data.hists.get_data(fixes=fixes)
ds = lib.data.frt_TS.get_data(days=8, fixes=fixes)
ds = ds.squeeze()
ds['med'] = ds.med.where(ds.n.sel(mask='frt') > 0)
def restore_time(ds):
ds = ds.rename(dayofyear='time')
ds = ds.assign_coords(time=pd.date_range(datetime(2000, 1, 1),
datetime(2000, 12, 31),
freq='8D'))
return ds
# Climatology
cli = ds['hist'].groupby("time.dayofyear").sum().to_dataset()
cli['bins'] = ds['bins']
cli = cli.rename(dayofyear='time')
cli = cli.assign_coords(time=pd.date_range(datetime(2000, 1, 1),
datetime(2000, 12, 31),
freq='8D'))
grp = ds.med.load().groupby("time.dayofyear")
cli = grp.mean()
cli_d1 = grp.quantile(0.1)
cli_d9 = grp.quantile(0.9)
cli = restore_time(cli)
cli_d1 = restore_time(cli_d1)
cli_d9 = restore_time(cli_d9)
cli = lib.data.hists.normalize_hist(cli)
cset = tc.tol_cset('vibrant')
med = lib.data.hists.get_percentile(cli, 0.5).persist()
def plot(cli, mask, var, color):
sel = dict(mask=mask, variable=var)
ax.plot(cli.time, cli.sel(sel), color=color)
ax.fill_between(cli.time, cli_d1.sel(sel), cli_d9.sel(sel),
color=color, alpha=0.4)
fig, axes = plt.subplots(3, 3, figsize=(10, 8), sharex=True)
fig.subplots_adjust(left=0.07, bottom=0.05, right=0.97, top=0.95,
fig, axes = plt.subplots(2, 3, figsize=(9, 4), sharex=True)
fig.subplots_adjust(left=0.05, bottom=0.06, right=0.97, top=0.93,
wspace=0.3, hspace=0.3)
for var, ax, name in zip(variables, axes.flat, names):
for var, ax, name in zip(variables, axes.T.flat, names):
if var is None:
fig.delaxes(ax)
continue
ax.plot(med.time, med.sel(mask='bkg', variable=var), color='b')
ax.plot(med.time, med.sel(mask='frt', variable=var), color='r')
plot(cli, 'bkg', var, cset.teal)
plot(cli, 'frt', var, cset.orange)
ax.xaxis.set_major_formatter(DateFormatter('%b'))
ax.set_title(name)
fig.canvas.draw()
fig.savefig(path.join(lib.root_plot, 'Hists', 'som_grid',
'fig_{}.png'.format(fixes['zone'])),
dpi=300)
......@@ -4,6 +4,7 @@ from os import path
from cmocean import cm
from matplotlib import pyplot as plt
from matplotlib.ticker import MultipleLocator
import numpy as np
import lib
import lib.data.ostia
......@@ -11,6 +12,7 @@ import lib.data.globcolour
import lib.data.hi
import Plots.util as plot_util
from Plots.Images.examples import examples
from lib.box import Box
plot_util.set_style()
plot_util.use_tex(True)
......@@ -23,9 +25,16 @@ args = dict(
coef=0
)
ex_id = 2
ex_id = 1
ex = examples[ex_id]
win_frac_bl = [0.3, 0.3]
win_bl = [ex.corner_bl[i] + (ex.corner_tr[i]-ex.corner_bl[i])
* win_frac_bl[i] for i in range(2)]
km_per_deg = 6.371*1e3 * np.pi / 180
win_tr = [bl + args['scale'] / km_per_deg for bl in win_bl]
win = Box.FromCorners(*win_bl, *win_tr)
fixes = dict(Y=ex.date.year, m=ex.date.month, d=ex.date.day)
oc = lib.data.globcolour.get_data(args, fixes=fixes)
st = lib.data.ostia.get_data(args, fixes=fixes)
......@@ -66,7 +75,6 @@ for ax, im, label in zip(axes.flat, images, labels):
fig.colorbar(im, cax=cax, ax=ax, orientation='horizontal', label=label,
ticklocation='top')
for ax in axes.flat:
ax.set_aspect('equal')
ax.set_xlim(*ex.lon_bounds)
......@@ -77,6 +85,8 @@ for ax in axes.flat:
ax.xaxis.set_major_formatter(plot_util.LonFormatter('.0f'))
ax.yaxis.set_major_formatter(plot_util.LatFormatter('.0f'))
for ax in axes[0, :2]:
win.add_to_plot(ax, ec='k', lw=0.7, fill=None, zorder=2.)
fig.canvas.draw()
fig.savefig(path.join(lib.root_plot, 'Images', 'article_example_zoom',
......
"""Middle-scale windows for plots."""
from datetime import datetime
from lib.box import Box
class Example(Box):
def __init__(self, lon_min, lon_max, lat_min, lat_max,
date):
super().__init__(lon_min, lon_max, lat_min, lat_max)
self.date = datetime(*date)
examples = [
Example(-64.81, -62.73, 39.38, 41.45, (2007, 4, 21)),
Example(-74.30, -72.23, 33.44, 35.52, (2007, 4, 22)),
Example(-73.56, -71.48, 25.94, 28.02, (2007, 4, 7))
]
......@@ -99,11 +99,11 @@ for ax in axes[:2]:
ax.xaxis.set_major_formatter(plot_util.LonFormatter('.0f'))
ax.yaxis.set_major_formatter(plot_util.LatFormatter('.0f'))
for i, ex in enumerate(examples):
ex.add_artist(ax, fill=None, ec='k', zorder=2.)
ax.annotate(str(i+1),
(ex.lon_bounds[1], ex.lat_bounds[0]), xycoords='data',
xytext=(2, -5), textcoords='offset points')
# for i, ex in enumerate(examples):
# ex.add_artist(ax, fill=None, ec='k', zorder=2.)
# ax.annotate(str(i+1),
# (ex.lon_bounds[1], ex.lat_bounds[0]), xycoords='data',
# xytext=(2, -5), textcoords='offset points')
hist = separation['hist']*6
......
"""Show HI-window and zoom window."""
from os import path
from cmocean import cm
import matplotlib.pyplot as plt
import tol_colors as tc
import lib
import lib.data.ostia
import Plots.util as plot_util
from Plots.Images.examples import examples
plot_util.set_style()
plot_util.use_tex(True)
args = dict(
region='GS',
days=1,
level='L3'
)
ex_id = 1
ex = examples[ex_id]
fixes = dict(
Y=ex.date.year,
m=ex.date.month,
d=ex.date.day
)
st = lib.data.ostia.get_data(args, fixes=fixes)
sst = st.analysed_sst.isel(time=0)
im_kw = dict(add_colorbar=False, add_labels=False)
cset = tc.tol_cset('bright')
sst_label = r'Sea Surface Temperature [\si{\degreeCelsius}]'
fig, ax = plt.subplots(figsize=(4, 4))
fig.subplots_adjust(left=0.08, bottom=0.10, right=0.98, top=0.95)
im = sst.plot.imshow(ax=ax, **im_kw, cmap=cm.thermal,
vmin=sst.min().values, vmax=sst.max().values)
cax = plot_util.add_cax(ax, "bottom", size=0.1, pad=0.05)
fig.colorbar(im, cax=cax, orientation="horizontal",
ticklocation="bottom", label=sst_label)
ax.set_aspect('equal')
ax.tick_params(bottom=False, top=True,
labelbottom=False, labeltop=True)
ax.xaxis.set_major_formatter(plot_util.LonFormatter('.0f'))
ax.yaxis.set_major_formatter(plot_util.LatFormatter('.0f'))
ex.add_to_plot(ax, fill=None, ec='k', zorder=2.)
fig.canvas.draw()
fig.savefig(path.join(lib.root_plot, 'comité_hi_description',
'fig.png'), dpi=300)
......@@ -28,12 +28,17 @@ chl = lib.data.frt_TS.get_data(args).sel(variable='CHL')
dchl = chl.med.diff('time')
dchl = dchl.rename(zone='idx')
idx_sel = ['0702']
# idx_sel = ['0601', '0602', '0701', '0702']
# idx_sel = ['0701']
idx_sel = ['0601', '0602', '0701', '0702']
dchl_lag_sel = []
dchl_lag_years = []
for year in years:
dchl_y = dchl.sel(time=slice(datetime(year, 1, 1), datetime(year, 6, 30)))
dchl_y = dchl_y.resample(time='D').interpolate(kind='linear')
# dchl_y = dchl_y.assign_coords(year=year).expand_dims('year')
dchl_y = dchl_y.assign_coords(year=year)
# dchl_y = dchl_y.expand_dims('year')
dchl_lag_sel = []
for idx in idx_sel:
inv_time = inv_times[year][idx]
lag = pd.to_datetime(dchl_y.time.values) - inv_time
......@@ -41,15 +46,28 @@ for year in years:
dchl_lag = dchl_lag.rename(time='lag')
dchl_lag.lag['units'] = 'days'
dchl_lag_sel.append(dchl_lag)
dchl_lag_years.append(xr.concat(dchl_lag_sel, dim='idx', join='outer'))
s = xr.concat(dchl_lag_sel, dim='idx', join='outer', fill_value=np.nan)
s = xr.concat(dchl_lag_years, dim='year', join='outer', fill_value=np.nan)
fig, ax = plt.subplots(figsize=(6, 5))
fig.subplots_adjust(left=0.15, bottom=0.10, right=0.98, top=0.98)
for ds in dchl_lag_sel:
ax.plot(ds.lag, ds.sel(mask='bkg'), lw=0.7)
fig, axes = plt.subplots(2, 2, figsize=(10, 8))
fig.subplots_adjust(left=0.10, bottom=0.10, right=0.98, top=0.95)
ax.plot(s.lag, s.sel(mask='bkg').mean('idx'), color='k')
mask = 'frt'
ax.set_xlabel('Jours depuis inversion flux chaleur')
ax.set_ylabel('dChl (background)')
for idx, ax in zip(s.idx.values, axes.T.flat):
ax.set_title(str(idx))
for year in s.year.values:
ax.plot(s.lag, s.sel(idx=idx, year=year, mask=mask), lw=0.7)
ax.plot(s.lag, s.sel(idx=idx, mask=mask).mean('year'), color='k')
axes[1, 0].set_xlabel('Jours depuis inversion flux chaleur')
axes[1, 0].set_ylabel('dChl (background)')
fig, ax = plt.subplots(figsize=(10, 5))
fig.subplots_adjust(left=0.05, bottom=0.05, right=0.98, top=0.98)
idx = '0702'
ax.plot(s.lag, s.sel(idx=idx, mask='bkg').mean('year'), color=cset.teal)
ax.plot(s.lag, s.sel(idx=idx, mask='frt').mean('year'), color=cset.orange)
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