- S3
- Sentry Shoal
- Central Node
- JDF
import pandas as pd
import netCDF4 as nc
import datetime as dt
import subprocess
import requests
import matplotlib.pyplot as plt
import cmocean
import numpy as np
import os
import re
import dateutil as dutil
from salishsea_tools import viz_tools, places
import glob
import pickle
import matplotlib.dates as mdates
import matplotlib as mpl
mpl.rc('xtick', labelsize=14)
mpl.rc('ytick', labelsize=16)
mpl.rc('legend', fontsize=16)
mpl.rc('axes', titlesize=16)
mpl.rc('figure', titlesize=16)
mpl.rc('axes', labelsize=16)
mpl.rc('font', size=16)
mpl.rcParams['font.size'] = 16
mpl.rcParams['axes.titlesize'] = 16
mpl.rcParams['legend.numpoints'] = 1
%matplotlib inline
plist=['Sentry Shoal','S3','Central node','Central SJDF']
flist=['search4979680/BritishColumbiaFerries_Tsawwassen-DukePoint_Turbidity-ChlorophyllandFluorescence_20170217T003041Z_20170315T031911Z-clean.csv',
'search4979680/BritishColumbiaFerries_Tsawwassen-DukePoint_Turbidity-ChlorophyllandFluorescence_20170315T031912Z_20170404T195130Z-clean.csv',
'search4979680/BritishColumbiaFerries_Tsawwassen-DukePoint_Turbidity-ChlorophyllandFluorescence_20170404T195131Z_20170426T173215Z-clean.csv',
'search4979680/BritishColumbiaFerries_Tsawwassen-DukePoint_Turbidity-ChlorophyllandFluorescence_20170426T173216Z_20170522T011843Z-clean.csv',
'search4979680/BritishColumbiaFerries_Tsawwassen-DukePoint_Turbidity-ChlorophyllandFluorescence_20170522T011844Z_20170611T234016Z-clean.csv',
'search4979680/BritishColumbiaFerries_Tsawwassen-DukePoint_Turbidity-ChlorophyllandFluorescence_20170611T234017Z_20170702T172228Z-clean.csv']
dfs=list()
for ii in range(0,len(flist)):
dfs.append(pd.read_csv('/ocean/eolson/MEOPAR/obs/ONC/turbidity/nearSurface/'+flist[ii],
skiprows=67,header=None,usecols=[0,1,2,3,4,5,6,7,8,9,10],
names=('TimeUTC','CDOM','CDOMQC','Chlorophyll_ug','ChlQC','Turbidity_NTU','TurbQC','Lat','LatQC','Lon','LongQC')))
/home/eolson/anaconda3/envs/python36/lib/python3.6/site-packages/IPython/core/interactiveshell.py:2698: DtypeWarning: Columns (7,9) have mixed types. Specify dtype option on import or set low_memory=False. interactivity=interactivity, compiler=compiler, result=result) /home/eolson/anaconda3/envs/python36/lib/python3.6/site-packages/IPython/core/interactiveshell.py:2698: DtypeWarning: Columns (3,5,7,9) have mixed types. Specify dtype option on import or set low_memory=False. interactivity=interactivity, compiler=compiler, result=result) /home/eolson/anaconda3/envs/python36/lib/python3.6/site-packages/IPython/core/interactiveshell.py:2698: DtypeWarning: Columns (1,3,5,7,9) have mixed types. Specify dtype option on import or set low_memory=False. interactivity=interactivity, compiler=compiler, result=result) /home/eolson/anaconda3/envs/python36/lib/python3.6/site-packages/IPython/core/interactiveshell.py:2698: DtypeWarning: Columns (1) have mixed types. Specify dtype option on import or set low_memory=False. interactivity=interactivity, compiler=compiler, result=result)
df=pd.concat(dfs,ignore_index=True)
dts=[dt.datetime(int(r[0:4]),int(r[5:7]),int(r[8:10]),int(r[11:13]),int(r[14:16]),int(r[17:19])) for r in df['TimeUTC']]
df=df.assign(dts=dts)
df['Lat']=pd.to_numeric(df['Lat'],errors='coerce')
df['Lon']=pd.to_numeric(df['Lon'],errors='coerce')
df.head()
TimeUTC | CDOM | CDOMQC | Chlorophyll_ug | ChlQC | Turbidity_NTU | TurbQC | Lat | LatQC | Lon | LongQC | dts | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2017-02-17T00:30:42.369Z | 14.37 | 1 | 2.0178 | 1 | 25.0716 | 1 | 49.177814 | 8 | -123.641612 | 8 | 2017-02-17 00:30:42 |
1 | 2017-02-17T00:30:43.444Z | 13.9868 | 1 | 1.9352 | 1 | 23.664 | 1 | 49.177854 | 8 | -123.641739 | 8 | 2017-02-17 00:30:43 |
2 | 2017-02-17T00:30:44.518Z | 13.9868 | 1 | 1.9352 | 1 | 23.7864 | 1 | 49.177895 | 8 | -123.641867 | 8 | 2017-02-17 00:30:44 |
3 | 2017-02-17T00:30:45.593Z | 13.9868 | 1 | 1.9116 | 1 | 23.4396 | 1 | 49.177935 | 8 | -123.641994 | 8 | 2017-02-17 00:30:45 |
4 | 2017-02-17T00:30:46.667Z | 14.0826 | 1 | 1.9352 | 1 | 23.358 | 1 | 49.177975 | 8 | -123.642122 | 8 | 2017-02-17 00:30:46 |
df['Lon'][0]
-123.64161193
places.PLACES['S3']
{'GEM2.5 grid ji': (138, 144), 'NEMO grid ji': (450, 258), 'lon lat': (-123.558, 49.125)}
111*.0226
2.5086
llon=places.PLACES['S3']['lon lat'][0]-.01
ulon=places.PLACES['S3']['lon lat'][0]+.01
llat=places.PLACES['S3']['lon lat'][1]-.01
ulat=places.PLACES['S3']['lon lat'][1]+.01
iidfnd=(df.Lon>llon)&(df.Lon<ulon)&(df.Lat>llat)&(df.Lat<ulat)
fig,ax=plt.subplots(1,1,figsize=(20,4))
ax.plot(df.loc[iidfnd,['dts']],df.loc[iidfnd,['Chlorophyll_ug']],'k*')
#ax.set_xlim(dt.datetime(2015,1,1),dt.datetime(2015,5,1))
#dt.datetime(2014,12,31)+dt.timedelta(days=65),dt.datetime(2014,12,31)+dt.timedelta(days=75)
[<matplotlib.lines.Line2D at 0x7fabd44b6668>]
with nc.Dataset('/ocean/eolson/MEOPAR/NEMO-forcing/grid/mesh_mask201702_noLPE.nc') as fm:
tmask=np.copy(fm.variables['tmask'])
umask=np.copy(fm.variables['umask'])
vmask=np.copy(fm.variables['vmask'])
navlon=np.copy(fm.variables['nav_lon'])
navlat=np.copy(fm.variables['nav_lat'])
e3t_0=np.copy(fm.variables['e3t_0'])
e3u_0=np.copy(fm.variables['e3u_0'])
e3v_0=np.copy(fm.variables['e3v_0'])
e1t=np.copy(fm.variables['e1t'])
e2t=np.copy(fm.variables['e2t'])
e1v=np.copy(fm.variables['e1v'])
e2u=np.copy(fm.variables['e2u'])
A=fm.variables['e1t'][0,:,:]*fm.variables['e2t'][0,:,:]*tmask[0,0,:,:]
t0=dt.datetime(2015,2,6)
fdur=10 # length of each results file in days
fnum=18 # number of results files per run
runlen=fdur*fnum # length of run in days
#stm=np.shape(tmask)
saveloc='/data/eolson/MEOPAR/SS36runs/calcFiles/comparePhytoN/'
baseloc='/data/eolson/MEOPAR/SS36runs/CedarRuns/'
dirname1='hindcast2017'
dirnames=(dirname1,)
#dirnames=('spring2015_NewSink','spring2015_slowPP','spring2015_KhT','spring2015_diatHS')
varNameDict={'Sentry Shoal':'SentryShoal', 'S3':'S3', 'Central node':'CentralNode', 'Central SJDF':'CentralSJDF'}
with open('/ocean/eolson/MEOPAR/analysis-elise/notebooks/bioTuning/spathsMaster.txt') as f:
spaths = dict(x.strip().split() for x in f)
#spaths={'spring2015_NewSink':'/data/eolson/results/MEOPAR/SS36runs/CedarRuns/spring2015_NewSink/',
# 'spring2015_KhT':'/data/eolson/results/MEOPAR/SS36runs/CedarRuns/spring2015_KhT/',
# 'spring2015_uzoo':'/data/eolson/results/MEOPAR/SS36runs/CedarRuns/spring2015_uzoo/',
# 'spring2015_uzoo2':'/data/eolson/results/MEOPAR/SS36runs/CedarRuns/spring2015_uzoo2/',
# 'spring2015_slowPP':'/data/eolson/results/MEOPAR/SS36runs/OrcinusRuns/spring2015_slowPP/',
# 'spring2015_lowMuNano':'/data/eolson/results/MEOPAR/SS36runs/CedarRuns/spring2015_lowMuNano/',
# 'spring2015_SMELTBFastSink':'/data/eolson/results/MEOPAR/SS36runs/OrcinusRuns/spring2015_SMELTBFastSink/',
# 'spring2015_uzPref':'/data/eolson/results/MEOPAR/SS36runs/CedarRuns/spring2015_uzPref/',
# 'spring2015_hiNH':'/data/eolson/results/MEOPAR/SS36runs/CedarRuns/spring2015_hiNH/'}
ff=dict()
for idir in dirnames:
ff[idir]=dict()
for pl in plist:
print(spaths[idir]+'ts_'+idir+'_'+varNameDict[pl]+'.nc')
ff[idir][pl]=nc.Dataset(spaths[idir]+'ts_'+idir+'_'+varNameDict[pl]+'.nc')
#try:
# pl='Total'
# ff[idir][pl]=nc.Dataset(spaths[idir]+'ts_'+idir+'_'+varNameDict[pl]+'.nc')
#except:
# pass
/data/eolson/results/MEOPAR/SS36runs/calcFiles/comparePhytoN/ts_hindcast2017_SentryShoal.nc /data/eolson/results/MEOPAR/SS36runs/calcFiles/comparePhytoN/ts_hindcast2017_S3.nc /data/eolson/results/MEOPAR/SS36runs/calcFiles/comparePhytoN/ts_hindcast2017_CentralNode.nc /data/eolson/results/MEOPAR/SS36runs/calcFiles/comparePhytoN/ts_hindcast2017_CentralSJDF.nc
spaths[idir]+'ts_'+idir+'_'+varNameDict[pl]+'.nc'
'/data/eolson/results/MEOPAR/SS36runs/calcFiles/comparePhytoN/ts_hindcast2017_CentralSJDF.nc'
times=dict()
for idir in dirnames:
f=ff[idir]['S3']
torig=dt.datetime.strptime(f.variables['time_centered'].time_origin,'%Y-%m-%d %H:%M:%S')
print(torig)
times[idir]=np.array([torig + dt.timedelta(seconds=ii) for ii in f.variables['time_centered'][:]])
1900-01-01 00:00:00
lcol={dirname1:{'diatoms':'darkgreen','flagellates':'mediumblue','ciliates':'maroon','nitrate':'darkorange','silicon':'indigo'}}
lsty={dirname1:'-',}
tmins=list()
tmaxs=list()
for idir in dirnames:
tmins.append(times[idir][0])
tmaxs.append(times[idir][-1])
xl=(np.min(np.array(tmins)),np.max(np.array(tmaxs)))
xl=(dt.datetime(2017,1,1),dt.datetime(2017,12,31))
sumVarTr={'diatoms':'diatSum','flagellates':'flagSum','ciliates':'myriSum'}
yearsFmt = mdates.DateFormatter('%b %d')
fig,ax=plt.subplots(len(plist),1,figsize=(12,3*(len(plist))))
pp=dict()
for ii in range(0,len(plist)):
pl=plist[ii]
if pl=='S3':
ax[ii].plot(df.loc[iidfnd,['dts']],[float(ik[0]) for ik in df.loc[iidfnd,['Chlorophyll_ug']].values],'.',color='lightgray',alpha=.5)
pp[ii]=dict()
for idir in dirnames:
f=ff[idir][pl]
for var in ('diatoms','flagellates','ciliates'):
try:
pp[ii][var]=ax[ii].plot(times[idir],2.0*np.sum(f.variables[var][:,:3,0,0]*f.variables['e3t'][:,:3,0,0],1)/np.sum(f.variables['e3t'][:,:3,0,0],1),
linestyle=lsty[idir],color=lcol[idir][var],alpha=.5,label=idir+' '+var)
except:
pp[ii][var]=ax[ii].plot(times[idir],2.0*np.sum(f.variables[var][:,:3,0,0]*np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1)/np.sum(np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1),
linestyle=lsty[idir],color=lcol[idir][var],alpha=.5,label=idir+' '+var)
try:
pp[ii]['tot']=ax[ii].plot(times[idir],2.0*np.sum((f.variables['diatoms'][:,:3,0,0]+f.variables['flagellates'][:,:3,0,0]+f.variables['ciliates'][:,:3,0,0])*f.variables['e3t'][:,:3,0,0],1)/np.sum(f.variables['e3t'][:,:3,0,0],1),
linestyle=lsty[idir],color='k',alpha=.6,label=idir+' '+'total')
except:
pp[ii]['tot']=ax[ii].plot(times[idir],2.0*np.sum((f.variables['diatoms'][:,:3,0,0]+f.variables['flagellates'][:,:3,0,0]+f.variables['ciliates'][:,:3,0,0])*np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1)/np.sum(np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1),
linestyle=lsty[idir],color='k',alpha=.6,label=idir+' '+'total')
ax[ii].set_title(pl)
ax[ii].set_ylabel('chl ($\mu$g/L)')
ax[ii].xaxis.set_major_formatter(yearsFmt)
ax[ii].set_xlim(xl)
ax[ii].set_ylim(0,40)
if ii==0:
ax[0].legend(bbox_to_anchor=(1,1),fontsize=12)
plt.tight_layout()
ax[1].plot(dt.datetime(2017,3,21),5,'r*')
[<matplotlib.lines.Line2D at 0x7fabfd4e4198>]
yearsFmt = mdates.DateFormatter('%b %d')
fig,ax=plt.subplots(len(plist),1,figsize=(12,3*(len(plist))))
pp=dict()
for ii in range(0,len(plist)):
pl=plist[ii]
if pl=='S3':
ax[ii].plot(df.loc[iidfnd,['dts']],[float(ik[0]) for ik in df.loc[iidfnd,['Chlorophyll_ug']].values],'.',color='lightgray',alpha=.5)
pp[ii]=dict()
for idir in dirnames:
f=ff[idir][pl]
for var in ('diatoms',):#,'flagellates','ciliates'):
try:
pp[ii][var]=ax[ii].plot(times[idir],2.0*np.sum(f.variables[var][:,:3,0,0]*f.variables['e3t'][:,:3,0,0],1)/np.sum(f.variables['e3t'][:,:3,0,0],1),
linestyle=lsty[idir],color=lcol[idir][var],alpha=.5,label=idir+' '+var)
except:
pp[ii][var]=ax[ii].plot(times[idir],2.0*np.sum(f.variables[var][:,:3,0,0]*np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1)/np.sum(np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1),
linestyle=lsty[idir],color=lcol[idir][var],alpha=.5,label=idir+' '+var)
#try:
# pp[ii]['tot']=ax[ii].plot(times[idir],2.0*np.sum((f.variables['diatoms'][:,:3,0,0]+f.variables['flagellates'][:,:3,0,0]+f.variables['ciliates'][:,:3,0,0])*f.variables['e3t'][:,:3,0,0],1)/np.sum(f.variables['e3t'][:,:3,0,0],1),
# linestyle=lsty[idir],color='k',alpha=.6,label=idir+' '+'total')
#except:
# pp[ii]['tot']=ax[ii].plot(times[idir],2.0*np.sum((f.variables['diatoms'][:,:3,0,0]+f.variables['flagellates'][:,:3,0,0]+f.variables['ciliates'][:,:3,0,0])*np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1)/np.sum(np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1),
# linestyle=lsty[idir],color='k',alpha=.6,label=idir+' '+'total')
ax[ii].set_title(pl)
ax[ii].set_ylabel('chl ($\mu$g/L)')
ax[ii].xaxis.set_major_formatter(yearsFmt)
ax[ii].set_xlim(xl)
ax[ii].set_ylim(0,40)
if ii==0:
ax[0].legend(bbox_to_anchor=(1,1),fontsize=12)
plt.tight_layout()
yearsFmt = mdates.DateFormatter('%b %d')
fig,ax=plt.subplots(len(plist),1,figsize=(12,3*(len(plist))))
pp=dict()
for ii in range(0,len(plist)):
pl=plist[ii]
if pl=='S3':
ax[ii].plot(df.loc[iidfnd,['dts']],[float(ik[0]) for ik in df.loc[iidfnd,['Chlorophyll_ug']].values],'.',color='lightgray',alpha=.5)
pp[ii]=dict()
for idir in dirnames:
f=ff[idir][pl]
for var in ('flagellates',):#,'flagellates','ciliates'):
try:
pp[ii][var]=ax[ii].plot(times[idir],2.0*np.sum(f.variables[var][:,:3,0,0]*f.variables['e3t'][:,:3,0,0],1)/np.sum(f.variables['e3t'][:,:3,0,0],1),
linestyle=lsty[idir],color=lcol[idir][var],alpha=.5,label=idir+' '+var)
except:
pp[ii][var]=ax[ii].plot(times[idir],2.0*np.sum(f.variables[var][:,:3,0,0]*np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1)/np.sum(np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1),
linestyle=lsty[idir],color=lcol[idir][var],alpha=.5,label=idir+' '+var)
#try:
# pp[ii]['tot']=ax[ii].plot(times[idir],2.0*np.sum((f.variables['diatoms'][:,:3,0,0]+f.variables['flagellates'][:,:3,0,0]+f.variables['ciliates'][:,:3,0,0])*f.variables['e3t'][:,:3,0,0],1)/np.sum(f.variables['e3t'][:,:3,0,0],1),
# linestyle=lsty[idir],color='k',alpha=.6,label=idir+' '+'total')
#except:
# pp[ii]['tot']=ax[ii].plot(times[idir],2.0*np.sum((f.variables['diatoms'][:,:3,0,0]+f.variables['flagellates'][:,:3,0,0]+f.variables['ciliates'][:,:3,0,0])*np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1)/np.sum(np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1),
# linestyle=lsty[idir],color='k',alpha=.6,label=idir+' '+'total')
ax[ii].set_title(pl)
ax[ii].set_ylabel('chl ($\mu$g/L)')
ax[ii].xaxis.set_major_formatter(yearsFmt)
ax[ii].set_xlim(xl)
ax[ii].set_ylim(0,40)
if ii==0:
ax[0].legend(bbox_to_anchor=(1,1),fontsize=12)
plt.tight_layout()
yearsFmt = mdates.DateFormatter('%b %d')
fig,ax=plt.subplots(len(plist),1,figsize=(12,3*(len(plist))))
pp=dict()
for ii in range(0,len(plist)):
pl=plist[ii]
if pl=='S3':
ax[ii].plot(df.loc[iidfnd,['dts']],[float(ik[0]) for ik in df.loc[iidfnd,['Chlorophyll_ug']].values],'.',color='lightgray',alpha=.5)
pp[ii]=dict()
for idir in dirnames:
f=ff[idir][pl]
for var in ('ciliates',):#,'flagellates','ciliates'):
try:
pp[ii][var]=ax[ii].plot(times[idir],2.0*np.sum(f.variables[var][:,:3,0,0]*f.variables['e3t'][:,:3,0,0],1)/np.sum(f.variables['e3t'][:,:3,0,0],1),
linestyle=lsty[idir],color=lcol[idir][var],alpha=.5,label=idir+' '+var)
except:
pp[ii][var]=ax[ii].plot(times[idir],2.0*np.sum(f.variables[var][:,:3,0,0]*np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1)/np.sum(np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1),
linestyle=lsty[idir],color=lcol[idir][var],alpha=.5,label=idir+' '+var)
#try:
# pp[ii]['tot']=ax[ii].plot(times[idir],2.0*np.sum((f.variables['diatoms'][:,:3,0,0]+f.variables['flagellates'][:,:3,0,0]+f.variables['ciliates'][:,:3,0,0])*f.variables['e3t'][:,:3,0,0],1)/np.sum(f.variables['e3t'][:,:3,0,0],1),
# linestyle=lsty[idir],color='k',alpha=.6,label=idir+' '+'total')
#except:
# pp[ii]['tot']=ax[ii].plot(times[idir],2.0*np.sum((f.variables['diatoms'][:,:3,0,0]+f.variables['flagellates'][:,:3,0,0]+f.variables['ciliates'][:,:3,0,0])*np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1)/np.sum(np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1),
# linestyle=lsty[idir],color='k',alpha=.6,label=idir+' '+'total')
ax[ii].set_title(pl)
ax[ii].set_ylabel('chl ($\mu$g/L)')
ax[ii].xaxis.set_major_formatter(yearsFmt)
ax[ii].set_xlim(xl)
ax[ii].set_ylim(0,40)
if ii==0:
ax[0].legend(bbox_to_anchor=(1,1),fontsize=12)
plt.tight_layout()
# one at a time
yearsFmt = mdates.DateFormatter('%b %d')
for idir in dirnames:
fig,ax=plt.subplots(len(plist),1,figsize=(12,3*(len(plist))))
pp=dict()
for ii in range(0,len(plist)):
pl=plist[ii]
if pl=='S3':
ax[ii].plot(df.loc[iidfnd,['dts']],[(1/2.0)*float(ik[0]) for ik in df.loc[iidfnd,['Chlorophyll_ug']].values],'.',color='lightgray',alpha=.5)
pp[ii]=dict()
f=ff[idir][pl]
for var in ('diatoms','flagellates','ciliates'):
try:
pp[ii][var]=ax[ii].plot(times[idir],np.sum(f.variables[var][:,:3,0,0]*f.variables['e3t'][:,:3,0,0],1)/np.sum(f.variables['e3t'][:,:3,0,0],1),
linestyle=lsty[idir],color=lcol[idir][var],alpha=.6,label=idir+' '+var)
except:
pp[ii][var]=ax[ii].plot(times[idir],np.sum(f.variables[var][:,:3,0,0]*np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1)/np.sum(np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1),
linestyle=lsty[idir],color=lcol[idir][var],alpha=.6,label=idir+' '+var)
ax[ii].set_title(pl)
ax[ii].set_ylabel('N (mmol m$^{-2}$)')
ax[ii].xaxis.set_major_formatter(yearsFmt)
ax[ii].set_xlim(xl)
if ii==0:
ax[0].legend(bbox_to_anchor=(1.25,1),fontsize=12)
fig.suptitle(idir)
plt.tight_layout()
mfac={'nitrate':.8,'silicon':.8/1.3}
yearsFmt = mdates.DateFormatter('%b %d')
fig,ax=plt.subplots(len(plist),1,figsize=(12,3*(len(plist))))
pp=dict()
for ii in range(0,len(plist)):
pl=plist[ii]
if pl=='S3':
ax[ii].plot(df.loc[iidfnd,['dts']],[float(ik[0]) for ik in df.loc[iidfnd,['Chlorophyll_ug']].values],'.',color='lightgray',alpha=.5)
pp[ii]=dict()
for idir in dirnames:
f=ff[idir][pl]
for var in ('nitrate','silicon',):
try:
pp[ii][var]=ax[ii].plot(times[idir],mfac[var]*np.sum(f.variables[var][:,:3,0,0]*f.variables['e3t'][:,:3,0,0],1)/np.sum(f.variables['e3t'][:,:3,0,0],1),
linestyle=lsty[idir],color=lcol[idir][var],alpha=.5,label=idir+' '+var)
except:
pp[ii][var]=ax[ii].plot(times[idir],mfac[var]*np.sum(f.variables[var][:,:3,0,0]*np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1)/np.sum(np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1),
linestyle=lsty[idir],color=lcol[idir][var],alpha=.5,label=idir+' '+var)
try:
pp[ii]['tot']=ax[ii].plot(times[idir],2.0*np.sum((f.variables['diatoms'][:,:3,0,0]+f.variables['flagellates'][:,:3,0,0]+f.variables['ciliates'][:,:3,0,0])*f.variables['e3t'][:,:3,0,0],1)/np.sum(f.variables['e3t'][:,:3,0,0],1),
linestyle=lsty[idir],color='k',alpha=.6,label=idir+' '+'total')
except:
pp[ii]['tot']=ax[ii].plot(times[idir],2.0*np.sum((f.variables['diatoms'][:,:3,0,0]+f.variables['flagellates'][:,:3,0,0]+f.variables['ciliates'][:,:3,0,0])*np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1)/np.sum(np.tile(e3t_0[:,:3,0,0],(len(times[idir]),1)),1),
linestyle=lsty[idir],color='k',alpha=.6,label=idir+' '+'total')
ax[ii].set_title(pl)
ax[ii].set_ylabel('chl ($\mu$g/L)')
ax[ii].xaxis.set_major_formatter(yearsFmt)
ax[ii].set_xlim(xl)
ax[ii].set_ylim(0,40)
if ii==0:
ax[0].legend(bbox_to_anchor=(1,1),fontsize=12)
plt.tight_layout()
ax[1].plot(dt.datetime(2015,3,21),5,'r*')
[<matplotlib.lines.Line2D at 0x7fabfb7680f0>]