#!/usr/bin/env python # coding: utf-8 # In[1]: import numpy as np import matplotlib.pyplot as plt import netCDF4 as nc import datetime as dt import os import glob import cmocean from salishsea_tools import viz_tools, places, visualisations get_ipython().run_line_magic('matplotlib', 'inline') # In[2]: x=np.arange(0,10) print('x:',x) y=x[4:8] print('y:',y) print('last element:', x[-1]) print('all of x:',x[:]) # In[3]: places.PLACES['S3'] # ### Load a file from the 201812 hindcast # In[4]: f=nc.Dataset('/results/SalishSea/nowcast-green.201812/01apr15/SalishSea_1h_20150401_20150401_ptrc_T.nc') # In[5]: print(f.variables.keys()) # In[6]: fe3t=nc.Dataset('/results/SalishSea/nowcast-green.201812/01apr15/SalishSea_1h_20150401_20150401_carp_T.nc') # In[7]: print(fe3t.variables.keys()) # In[8]: fe3t.variables['time_centered'] # In[9]: # return times as datetime objects: torig=dt.datetime.strptime(f.variables['time_centered'].time_origin,'%Y-%m-%d %H:%M:%S') # In[10]: torig # In[11]: f.variables['time_centered'][:] # In[12]: times=np.array([torig+dt.timedelta(seconds=ii) for ii in \ f.variables['time_centered'][:]]) # In[13]: times # In[14]: # load model mesh with nc.Dataset('/data/eolson/results/MEOPAR/NEMO-forcing-new/grid/mesh_mask201702.nc') as fm: print(fm.variables.keys()) tmask=fm.variables['tmask'][:,:,:,:] navlon=fm.variables['nav_lon'][:,:] navlat=fm.variables['nav_lat'][:,:] # ### Dept Profile # In[17]: fig,ax=plt.subplots(1,2,figsize=(6,6)) fig.subplots_adjust(wspace=.5) # space the axes out more il=12 # use location 'S3' ij,ii=places.PLACES['S3']['NEMO grid ji'] ax[0].plot(np.ma.masked_where(tmask[0,:,ij,ii]==0, f.variables['microzooplankton'][il,:,ij,ii]), f.variables['deptht'][:],'b-x',label='microzo') ax[0].plot(np.ma.masked_where(tmask[0,:,ij,ii]==0,f.variables['diatoms'][il,:,ij,ii]),f.variables['deptht'][:],'g-x',label='diatoms') ax[0].set_ylim(300,0) ax[0].legend() ax[0].set_xlabel('Concentration ($\mu$M)') ax[0].set_ylabel('Depth (m)') ax[1].plot(np.ma.masked_where(tmask[0,:,ij,ii]==0,f.variables['nitrate'][il,:,ij,ii]),f.variables['deptht'][:],'-x',color='orange',label='NO$_3$') ax[1].plot(np.ma.masked_where(tmask[0,:,ij,ii]==0,f.variables['silicon'][il,:,ij,ii]),f.variables['deptht'][:],'-x',color='r',label='dissolved Si') ax[1].set_ylim(300,0) ax[1].set_ylabel('Depth (m)') ax[1].legend() ax[1].set_xlabel('Concentration ($\mu$M)') # In[ ]: