In [1]:
import numpy as np
import netCDF4 as nc
import f90nml
import os
import matplotlib.pyplot as plt
from salishsea_tools import bio_tools as bio
import visualisations
from matplotlib.colors import LinearSegmentedColormap
%matplotlib inline
In [2]:
bathy = nc.Dataset('/data/vdo/MEOPAR/NEMO-forcing/grid/bathymetry_201702.nc')
mesh = nc.Dataset('/data/vdo/MEOPAR/NEMO-forcing/grid/mesh_mask201702.nc')
In [3]:
vmax = 5.0
cmap = LinearSegmentedColormap.from_list('mycmap', [(0 / vmax, 'green'),
                                                    (1 / vmax, 'white'),
                                                    (1.99 / vmax, 'white'),
                                                    (2 / vmax, 'orange'),
                                                    (3 / vmax, 'white'),
                                                    (3.99 / vmax, 'white'),
                                                    (4 / vmax, 'purple'),
                                                    (5 / vmax, 'white')]
                                        )
fig, ax = plt.subplots()
mesh1 = ax.pcolormesh(np.random.randint(0,6, size=(20,20)), cmap = cmap)
ticks = [0,1,2,3,4,5]
cbar1 = fig.colorbar(mesh1, ax=ax)
cbar1.set_ticks([0,1,2,3,4,5])
cbar1.set_ticklabels(['0.0 I', '1.0 I', '0.0 N', '1.0 N', '0.0 Si', '1.0 Si'])
ax.set_title('$Example$', fontsize =15)
cbar1.ax.tick_params(labelsize = 12)
In [5]:
def limit_along_thalweg(path, diafile, ptrcfile, phytoplankton):
    resDir=path
    nampisprod=bio.load_nml_bio(resDir,'nampisprod',
                            namRefDir='/data/vdo/MEOPAR/NEMO-3.6-code/NEMOGCM/CONFIG/SMELT/EXP00/')
    fdia=nc.Dataset(os.path.join(resDir,diafile))
    fptc=nc.Dataset(os.path.join(resDir,ptrcfile))
    with nc.Dataset('/ocean/eolson/MEOPAR/NEMO-forcing/grid/mesh_mask201702.nc') as m:
        tmask=m.variables['tmask'][:,:,:,:]
    I=fdia.variables['PAR'][9,:,:,:]
    NO= (fptc.variables['nitrate'][19,:,:,:] + fptc.variables['nitrate'][18,:,:,:]) * 0.5
    NH= (fptc.variables['ammonium'][19,:,:,:] + fptc.variables['ammonium'][18,:,:,:]) * 0.5
    Si= (fptc.variables['silicon'][19,:,:,:] + fptc.variables['silicon'][18,:,:,:]) * 0.5
    D,M,N = bio.calc_p_limiters(I,NO,NH,Si,tmask[0,:,:,:],nampisprod)
    fig, ax = plt.subplots(2,1,figsize = (14,6))
    if phytoplankton == 'dia':
        cbar1 = visualisations.contour_thalweg(ax[0], D['limiter'], bathy, mesh, 
                                               np.arange(-2, 4.5, 2), cmap = cmap)
        cbar2 = visualisations.contour_thalweg(ax[1], D['limval'], bathy, mesh,
                                               np.arange(0,5.1,0.25), cmap = cmap)
        ax[0].set_title('Limiting Variable for Diatoms', fontsize = 15)
        ax[1].set_title('Rate Limitation Factor for Diatoms', fontsize = 15)
    elif phytoplankton == 'meso':
        cbar1 = visualisations.contour_thalweg(ax[0], M['limiter'], bathy, mesh,
                                               np.arange(-2,4.5,2), cmap = cmap)
        cbar2 = visualisations.contour_thalweg(ax[1], M['limval'], bathy, mesh,
                                               np.arange(0,5.1,0.25), cmap = cmap)
        ax[0].set_title('Limiting Variable for $Mesodinium$', fontsize = 15)
        ax[1].set_title('Rate Limitation Factor for $Mesodinium$', fontsize = 15)
    elif phytoplankton == 'flag':
        cbar1 = visualisations.contour_thalweg(ax[0], N['limiter'], bathy, mesh,
                                               np.arange(-2,4.5,2), cmap = cmap)
        cbar2 = visualisations.contour_thalweg(ax[1], N['limval'], bathy, mesh,
                                              np.arange(0,5.1,0.25), cmap = cmap)
        ax[0].set_title('Limiting Variable for Flagellates', fontsize = 15)
        ax[1].set_title('Rate Limitation Factor for Flagellates', fontsize = 15)
    cbar1.set_ticks([-1,1,3])
    cbar1.set_ticklabels(['I', 'N', 'Si'])
    cbar1.ax.tick_params(labelsize=12)
    cbar2.set_ticks([0,1,2,3,4,5])
    cbar2.set_ticklabels(['0.0 I','1.0 I','0.0 N','1.0 N','0.0 Si','1.0 Si'])
    cbar2.ax.tick_params(labelsize=12)
    for ax in ax:
        ax.set_ylim(35,0)
    plt.tight_layout()

January 2015

In [8]:
limit_along_thalweg('/results/SalishSea/nowcast-green/28dec14', 
                    'SalishSea_2h_20141228_20150106_dia1_T.nc',
                   'SalishSea_1h_20141228_20141228_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/28dec14', 
                    'SalishSea_2h_20141228_20150106_dia1_T.nc',
                   'SalishSea_1h_20141228_20141228_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/28dec14', 
                    'SalishSea_2h_20141228_20150106_dia1_T.nc',
                   'SalishSea_1h_20141228_20141228_ptrc_T.nc', 'flag')

Febuary 2015

In [9]:
limit_along_thalweg('/results/SalishSea/nowcast-green/06feb15', 
                    'SalishSea_2h_20150206_20150215_dia1_T.nc',
                   'SalishSea_1h_20150206_20150206_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/06feb15', 
                    'SalishSea_2h_20150206_20150215_dia1_T.nc',
                   'SalishSea_1h_20150206_20150206_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/06feb15', 
                    'SalishSea_2h_20150206_20150215_dia1_T.nc',
                   'SalishSea_1h_20150206_20150206_ptrc_T.nc', 'flag')

March 2015

In [10]:
limit_along_thalweg('/results/SalishSea/nowcast-green/08mar15', 
                    'SalishSea_2h_20150308_20150317_dia1_T.nc',
                   'SalishSea_1h_20150308_20150308_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/08mar15', 
                    'SalishSea_2h_20150308_20150317_dia1_T.nc',
                   'SalishSea_1h_20150308_20150308_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/08mar15', 
                    'SalishSea_2h_20150308_20150317_dia1_T.nc',
                   'SalishSea_1h_20150308_20150308_ptrc_T.nc', 'flag')

April 2015

In [11]:
limit_along_thalweg('/results/SalishSea/nowcast-green/07apr15', 
                    'SalishSea_2h_20150407_20150416_dia1_T.nc',
                   'SalishSea_1h_20150407_20150407_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/07apr15', 
                    'SalishSea_2h_20150407_20150416_dia1_T.nc',
                   'SalishSea_1h_20150407_20150407_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/07apr15', 
                    'SalishSea_2h_20150407_20150416_dia1_T.nc',
                   'SalishSea_1h_20150407_20150407_ptrc_T.nc', 'flag')

May 2015

In [12]:
limit_along_thalweg('/results/SalishSea/nowcast-green/07may15', 
                    'SalishSea_2h_20150507_20150516_dia1_T.nc',
                   'SalishSea_1h_20150507_20150507_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/07may15', 
                    'SalishSea_2h_20150507_20150516_dia1_T.nc',
                   'SalishSea_1h_20150507_20150507_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/07may15', 
                    'SalishSea_2h_20150507_20150516_dia1_T.nc',
                   'SalishSea_1h_20150507_20150507_ptrc_T.nc', 'flag')

June 2015

In [13]:
limit_along_thalweg('/results/SalishSea/nowcast-green/06jun15', 
                    'SalishSea_2h_20150606_20150615_dia1_T.nc',
                    'SalishSea_1h_20150606_20150606_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/06jun15', 
                    'SalishSea_2h_20150606_20150615_dia1_T.nc',
                    'SalishSea_1h_20150606_20150606_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/06jun15', 
                    'SalishSea_2h_20150606_20150615_dia1_T.nc',
                    'SalishSea_1h_20150606_20150606_ptrc_T.nc', 'flag')

July 2015

In [14]:
limit_along_thalweg('/results/SalishSea/nowcast-green/06jul15', 
                    'SalishSea_2h_20150706_20150715_dia1_T.nc',
                    'SalishSea_1h_20150706_20150706_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/06jul15', 
                    'SalishSea_2h_20150706_20150715_dia1_T.nc',
                    'SalishSea_1h_20150706_20150706_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/06jul15', 
                    'SalishSea_2h_20150706_20150715_dia1_T.nc',
                    'SalishSea_1h_20150706_20150706_ptrc_T.nc', 'flag')

August 2015

In [15]:
limit_along_thalweg('/results/SalishSea/nowcast-green/05aug15', 
                    'SalishSea_2h_20150805_20150814_dia1_T.nc',
                    'SalishSea_1h_20150805_20150805_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/05aug15', 
                    'SalishSea_2h_20150805_20150814_dia1_T.nc',
                    'SalishSea_1h_20150805_20150805_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/05aug15', 
                    'SalishSea_2h_20150805_20150814_dia1_T.nc',
                    'SalishSea_1h_20150805_20150805_ptrc_T.nc', 'flag')

September 2015

In [16]:
limit_along_thalweg('/results/SalishSea/nowcast-green/04sep15', 
                    'SalishSea_2h_20150904_20150913_dia1_T.nc',
                    'SalishSea_1h_20150904_20150904_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/04sep15', 
                    'SalishSea_2h_20150904_20150913_dia1_T.nc',
                    'SalishSea_1h_20150904_20150904_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/04sep15', 
                    'SalishSea_2h_20150904_20150913_dia1_T.nc',
                    'SalishSea_1h_20150904_20150904_ptrc_T.nc', 'flag')