#!/usr/bin/env python # coding: utf-8 # In[1]: import datetime as dt import numpy as np import xarray as xr import matplotlib.pyplot as plt from matplotlib.colors import LogNorm get_ipython().run_line_magic('matplotlib', 'inline') # In[2]: f=xr.open_dataset('https://salishsea.eos.ubc.ca/erddap/griddap/ubcSSg3DBiologyFields1hV19-05') f # In[3]: i0=130;i1=350 j0=330;j1=750 fig,ax=plt.subplots(1,1,figsize=(3,5)) ax.pcolormesh(f.variables['nitrate'][0,0,:,:]) ax.plot((i0,i1,i1,i0,i0),(j0,j0,j1,j1,j0),'r-') f.close() # In[4]: fig,ax=plt.subplots(10,2,figsize=(14,30)) fig.subplots_adjust(hspace=.4,wspace=.3) ax=ax.flatten() time=dt.datetime(2017,7,1,0,30) with xr.open_dataset('https://salishsea.eos.ubc.ca/erddap/griddap/ubcSSg3DBiologyFields1hV19-05') as f: with xr.open_dataset('https://salishsea.eos.ubc.ca/erddap/griddap/ubcSSg3DTracerFields1hV19-05') as fT: for k in range(0,20): sal=np.array(fT.salinity.sel(time=dt.datetime(2017,7,1,0,30)).\ isel(depth=k,gridY=slice(j0,j1),gridX=slice(i0,i1)).values).flatten() no3=np.array(f.nitrate.sel(time=time).\ isel(depth=k,gridY=slice(j0,j1),gridX=slice(i0,i1)).values).flatten() counts, xedges, yedges, m1=ax[k].hist2d(sal[~np.isnan(sal)&~np.isnan(no3)], no3[~np.isnan(sal)&~np.isnan(no3)], bins=36*3,norm=LogNorm()) cb=fig.colorbar(m1,ax=ax[k]) cb.set_label('Count') ax[k].set_title('level k='+str(k)) ax[k].set_xlabel('S (g/kg)') ax[k].set_ylabel('NO3 ($\mu$M)') print('July 1') # In[5]: fig,ax=plt.subplots(10,2,figsize=(14,30)) fig.subplots_adjust(hspace=.4,wspace=.3) ax=ax.flatten() time=dt.datetime(2017,3,1,0,30) with xr.open_dataset('https://salishsea.eos.ubc.ca/erddap/griddap/ubcSSg3DBiologyFields1hV19-05') as f: with xr.open_dataset('https://salishsea.eos.ubc.ca/erddap/griddap/ubcSSg3DTracerFields1hV19-05') as fT: for k in range(0,20): sal=np.array(fT.salinity.sel(time=dt.datetime(2017,7,1,0,30)).\ isel(depth=k,gridY=slice(j0,j1),gridX=slice(i0,i1)).values).flatten() no3=np.array(f.nitrate.sel(time=time).\ isel(depth=k,gridY=slice(j0,j1),gridX=slice(i0,i1)).values).flatten() counts, xedges, yedges, m1=ax[k].hist2d(sal[~np.isnan(sal)&~np.isnan(no3)], no3[~np.isnan(sal)&~np.isnan(no3)], bins=36*3,norm=LogNorm()) cb=fig.colorbar(m1,ax=ax[k]) cb.set_label('Count') ax[k].set_title('level k='+str(k)) ax[k].set_xlabel('S (g/kg)') ax[k].set_ylabel('NO3 ($\mu$M)') print('March 1') # In[ ]: