#!/usr/bin/env python # coding: utf-8 # In[1]: import matplotlib.pyplot as plt import numpy as np import netCDF4 as nc import datetime as dt from salishsea_tools import evaltools as et, viz_tools, geo_tools from pandas.plotting import register_matplotlib_converters register_matplotlib_converters() get_ipython().run_line_magic('matplotlib', 'inline') # In[2]: df1=et.loadDFO() df1.head() # In[3]: fig,ax=plt.subplots(1,1,figsize=(24,4)) ax.hist(df1['dtUTC'].values) # In[4]: df1.loc[df1.Si>=0.0]['dtUTC'].max() # In[5]: dfam=df1.loc[(df1.Ammonium>=0)] dfam # In[6]: with nc.Dataset('/ocean/eolson/MEOPAR/NEMO-forcing/grid/mesh_mask201702_noLPE.nc') as mesh: navlon=mesh.variables['nav_lon'][:,:] navlat=mesh.variables['nav_lat'][:,:] tmask=mesh.variables['tmask'][0,:,:,:] # In[7]: m=plt.scatter(dfam.Lon,dfam.Lat,c=dfam.Ammonium) plt.contour(navlon,navlat,tmask[0,:,:],levels=[.5,]) plt.colorbar(m) plt.xlim((-124,-123)) plt.ylim(48,49.5) # In[8]: dfam2=dfam.loc[(dfam.Lat<49.2)] dfam3=dfam.loc[(dfam.Lat<49.2)&(dfam.dtUTC>dt.datetime(2003,1,1))] plt.scatter(dfam3.dtUTC,dfam3.Ammonium,c=dfam3.Lat) # In[9]: plt.scatter(dfam2.Ammonium,dfam2.Z,c=dfam2.Lat) # In[10]: np.unique(dfam2.loc[dfam2.Lat<49,['Lat','Lon']]) # In[11]: j,i=geo_tools.find_closest_model_point(-123.43666667, 48.391,navlon,navlat) # In[12]: j,i # In[13]: sourceloc='/results/SalishSea/hindcast.201905/' start=dt.datetime(2014,1,1) end=dt.datetime(2016,1,1) flist=et.index_model_files(start,end,sourceloc,'nowcast',1,'ptrc_T',1) # In[14]: data=list() for ind, row in flist.iterrows(): with nc.Dataset(row['paths']) as f: data.append(np.mean(f.variables['ammonium'][:,:,j,i],0,keepdims=True)) # In[15]: data=np.concatenate(data,axis=0) # In[16]: times=[start+dt.timedelta(days=ii) for ii in \ range(0,int((end-start).total_seconds()/(24*3600)+1))] # In[19]: fig,ax=plt.subplots(1,1,figsize=(16,3)) ax.plot(times,data); # In[ ]: