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

Up plot

parent 5c2fec8a
......@@ -10,67 +10,37 @@ import xarray as xr
import lib
import lib.data.frt_TS
import lib.data.HF_inv
cset = tc.tol_cset('vibrant')
args = lib.get_args(['region', 'grid_file', 'year', 'fixes',
'scale', 'number', 'coef', 'threshold',
'season'])
# Parse HF inversion dates
inv_file = path.join(lib.root_data, args['region'], 'HF',
args['grid_file'] + '_inversion_times_{}.txt'.format(
args['year']))
inv_times = {}
with open(inv_file, 'r') as infile:
for line in infile.readlines():
idx, date = line.split()
inv_times[idx] = date
args = lib.get_args(['region', 'grid_file', 'fixes', 'season'])
inv_times = lib.data.HF_inv.get_data(args, to_datetime=True)
# Load Chl TS data
args['zone'] = args['grid_file']
args['fixes']['Y'] = args['year']
args['days'] = 8
years = list(inv_times.keys())
chl = lib.data.frt_TS.get_data(args).sel(variable='CHL')
chl = chl.sel(time=slice(datetime(args['year'], 1, 1),
datetime(args['year'], 6, 30)))
dchl = chl.med.diff('time')
dchl = dchl.rename(zone='idx')
"""
idx = '0602'
inv_time = datetime.strptime(inv_times[idx], '%Y-%m-%d')
fig, axes = plt.subplots(1, 2, figsize=(10, 5))
fig.subplots_adjust(left=0.05, bottom=0.10, right=0.98, top=0.98)
ax1, ax2 = axes
dchl.sel(idx=idx, mask='bkg').plot.line(ax=ax1, color=cset.teal)
dchl.sel(idx=idx, mask='frt').plot.line(ax=ax1, color=cset.orange)
ax1.axvline(inv_time, color='r', ls='--')
lag = pd.to_datetime(dchl.time.values) - inv_time
dchl_lag = dchl.assign_coords(time=lag.days)
dchl_lag = dchl_lag.rename(time='lag')
dchl_lag.lag['units'] = 'days since {}'.format(inv_time.strftime('%F'))
dchl_lag.sel(idx=idx, mask='bkg').plot.line(ax=ax2, color=cset.teal)
dchl_lag.sel(idx=idx, mask='frt').plot.line(ax=ax2, color=cset.orange)
"""
idx_sel = ['0601', '0602', '0701', '0702']
idx_sel = ['0702']
# idx_sel = ['0601', '0602', '0701', '0702']
dchl_lag_sel = []
for idx in idx_sel:
inv_time = datetime.strptime(inv_times[idx], '%Y-%m-%d')
lag = pd.to_datetime(dchl.time.values) - inv_time
dchl_lag = dchl.sel(idx=[idx]).assign_coords(time=lag.days)
dchl_lag = dchl_lag.rename(time='lag')
dchl_lag.lag['units'] = 'days'
dchl_lag_sel.append(dchl_lag)
for year in years:
dchl_y = dchl.sel(time=slice(datetime(year, 1, 1), datetime(year, 6, 30)))
for idx in idx_sel:
inv_time = inv_times[year][idx]
lag = pd.to_datetime(dchl_y.time.values) - inv_time
dchl_lag = dchl_y.sel(idx=[idx]).assign_coords(time=lag.days)
dchl_lag = dchl_lag.rename(time='lag')
dchl_lag.lag['units'] = 'days'
dchl_lag_sel.append(dchl_lag)
s = xr.concat(dchl_lag_sel, dim='idx', join='outer', fill_value=np.nan)
......
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