Commit 85e1545f authored by Clément Haëck's avatar Clément Haëck
Browse files

Up various

parent 27b1fb1a
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
import tol_colors as tc
import lib
import lib.data.hists
fixes = dict(
Y=2007,
# Y=2007,
number=2,
coef=0,
scale=30,
......@@ -24,27 +24,14 @@ ds = ds.squeeze()
# For SOM variables
# ds['hist'] = ds['hist'].where(ds.nbins != 0, 0.)
ds['hist'] = ds['hist'].sum('time')
ds.load()
lib.data.hists.normalize_hist(ds)
fig, ax = plt.subplots(figsize=(5, 5))
fig.subplots_adjust(left=0.05, bottom=0.15, right=0.98, top=0.98)
cset = tc.tol_cset('vibrant')
s = datetime(2007, 4, 1)
H = ds.sel(time=slice(s, s+timedelta(days=8))).sum('time')
# H = lib.data.hists.normalize_hist(ds.sum('time'))
H = H.coarsen(nbins=12, boundary='pad').sum()
H = H.coarsen(nbins_p=12, boundary='pad').min()
# H['hist'] = H.hist.where(H.nbins < 250/3., 0)
H = lib.data.hists.normalize_hist(H)
cs = H.hist.cumsum('nbins')
ax.plot(H.bins[:-1], H.hist.sel(mask='bkg'), color='b', ls='--')
ax.plot(H.bins[:-1], H.hist.sel(mask='frt'), color='r', ls='-')
ax = ax.twinx()
ax.plot(H.bins[:-1], cs.sel(mask='bkg'), color='b', ls='--')
ax.plot(H.bins[:-1], cs.sel(mask='frt'), color='r', ls='-')
ax.set_xlabel(variable)
med = lib.data.hists.get_percentile(H, .5)
ax.axvline(med.sel(mask='bkg').values, color='b')
ax.axvline(med.sel(mask='frt').values, color='r')
bins = ds.bins[:-1]
ax.plot(bins, ds.hist.sel(mask='bkg'), color=cset.teal)
ax.plot(bins, ds.hist.sel(mask='frt'), color=cset.orange)
"""Plots histograms for CHL and SST over both zones."""
from os import path
import matplotlib.pyplot as plt
import numpy as np
import tol_colors as tc
import lib
import lib.data.hists
args = lib.get_args(['region', 'days'])
fixes = dict(
scale=30.,
number=2,
coef=0
)
cset = tc.tol_cset('vibrant')
month = 11
def plot(ax, variable, zone, threshold):
fixes.update(dict(zone=zone, threshold=threshold))
ds = lib.data.hists.get_data(args, fixes=fixes)
ds = ds.sel(variable=variable)
ds = ds.squeeze()
mth_idx = ds.groupby('time.month').groups[month]
ds = ds.isel(time=mth_idx)
ds['hist'] = ds['hist'].sum('time')
ds.load()
if variable == 'analysed_sst':
n_coarsen = 20
ds = ds.coarsen(nbins=n_coarsen, boundary='pad').mean()
ds = ds.coarsen(nbins_p=n_coarsen, boundary='pad').mean()
lib.data.hists.normalize_hist(ds)
ds['hist'] /= ds.hist.max()
bins = ds.bins[:-1]
ax.plot(bins, ds.hist.sel(mask='bkg'), color=cset.teal)
ax.plot(bins, ds.hist.sel(mask='frt'), color=cset.orange)
fig, axes = plt.subplots(2, 2, figsize=(10, 8))
fig.subplots_adjust(left=0.10, bottom=0.05, right=0.97, top=0.95,
wspace=0.3, hspace=0.2)
for i, var in enumerate(['CHL', 'analysed_sst']):
axes[i, 0].set_ylabel(var)
for j, (zone, threshold) in enumerate([('GS_S', 6.0), ('GS_N', 15.0)]):
ax = axes[i, j]
plot(ax, var, zone, threshold)
axes[0, 0].set_title('South')
axes[0, 1].set_title('North')
fig.canvas.draw()
fig.savefig(path.join(lib.root_plot, 'Hists', 'total_month',
'month_{:02d}.png'.format(month)),
dpi=150)
"""Plot front presence probability on a month."""
from cmocean import cm
import matplotlib.pyplot as plt
import numpy as np
import lib
import lib.data.ostia
import lib.data.front_probability
import lib.data.SN_separation
args = lib.get_args(['period', 'fixes'])
thr = lib.data.SN_separation.get_data(args)
thr = lib.data.SN_separation.smooth(thr, time_step=8)
thr = thr.isel(time=0)
# thr = thr.mean('time')
sst = lib.data.ostia.get_data(args)['analysed_sst']
sst = sst.mean('time')
p_frt = lib.data.front_probability.get_data(args)['p_frt']
p_frt = p_frt.mean('time')
fig, axes = plt.subplots(1, 2, figsize=(10, 5))
fig.subplots_adjust(left=0.05, bottom=0.05, right=0.98, top=0.98)
ax1, ax2 = axes
sst.plot.imshow(ax=ax1, cmap=cm.thermal, center=False)
cmap = plt.cm.get_cmap('gray_r').copy()
# cmap.set_bad('w')
cmap.set_under('w')
cmap.set_over('w')
p_frt.plot.imshow(ax=ax2, cmap=cmap,
norm=plt.Normalize(clip=False, vmin=1e-3))
for ax in axes:
sst.plot.contour(ax=ax, colors='k', add_colorbar=False,
levels=[thr.values])
np.isfinite(sst).plot.contour(ax=ax, add_colorbar=False,
colors='k', linewidths=0.5)
ax.set_aspect('equal')
"""Plot frontal presence probability over all data."""
import numpy as np
import matplotlib.pyplot as plt
import tol_colors as tc
import lib
import lib.data.front_probability
import Plots.util as plot_util
args = dict(period='total')
ds = lib.data.front_probability.get_data(args)
fig, ax = plt.subplots(figsize=(6, 5))
fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.98)
cax = plot_util.add_cax(ax)
ds.p_frt.plot.imshow(ax=ax, cmap="gray_r", cbar_ax=cax,
norm=plt.cm.colors.LogNorm(vmin=1e-2, vmax=1))
np.isfinite(ds.p_frt).plot.contour(
ax=ax, colors='k', linewidths=0.5,
levels=[0.5],
add_labels=False, add_colorbar=False)
cset = tc.tol_cset('vibrant')
levels = [5e-3, 1e-2, 2e-2, 5e-2]
ds.p_frt.plot.contour(ax=ax, linewidths=0.7, add_labels=False, levels=levels,
colors=cset)
for i, lvl in enumerate(levels):
cax.axhline(lvl, color=cset[i])
ax.set_aspect('equal')
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