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 [6]:
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 2017

In [5]:
limit_along_thalweg('/results/SalishSea/nowcast-green/06jan17', 
                    'SalishSea_2h_20170106_20170115_dia1_T.nc',
                   'SalishSea_1h_20170106_20170106_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/06jan17', 
                    'SalishSea_2h_20170106_20170115_dia1_T.nc',
                   'SalishSea_1h_20170106_20170106_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/06jan17', 
                    'SalishSea_2h_20170106_20170115_dia1_T.nc',
                   'SalishSea_1h_20170106_20170106_ptrc_T.nc', 'flag')

Febuary 2017

In [7]:
limit_along_thalweg('/results/SalishSea/nowcast-green/05feb17', 
                    'SalishSea_2h_20170205_20170214_dia1_T.nc',
                   'SalishSea_1h_20170205_20170205_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/05feb17', 
                    'SalishSea_2h_20170205_20170214_dia1_T.nc',
                   'SalishSea_1h_20170205_20170205_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/05feb17', 
                    'SalishSea_2h_20170205_20170214_dia1_T.nc',
                   'SalishSea_1h_20170205_20170205_ptrc_T.nc', 'flag')

March 2017

In [8]:
limit_along_thalweg('/results/SalishSea/nowcast-green/07mar17', 
                    'SalishSea_2h_20170307_20170316_dia1_T.nc',
                   'SalishSea_1h_20170307_20170307_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/07mar17', 
                    'SalishSea_2h_20170307_20170316_dia1_T.nc',
                   'SalishSea_1h_20170307_20170307_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/07mar17', 
                    'SalishSea_2h_20170307_20170316_dia1_T.nc',
                   'SalishSea_1h_20170307_20170307_ptrc_T.nc', 'flag')

April 2017

In [9]:
limit_along_thalweg('/results/SalishSea/nowcast-green/06apr17', 
                    'SalishSea_2h_20170406_20170415_dia1_T.nc',
                   'SalishSea_1h_20170406_20170406_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/06apr17', 
                    'SalishSea_2h_20170406_20170415_dia1_T.nc',
                   'SalishSea_1h_20170406_20170406_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/06apr17', 
                    'SalishSea_2h_20170406_20170415_dia1_T.nc',
                   'SalishSea_1h_20170406_20170406_ptrc_T.nc', 'flag')

May 2017

In [10]:
limit_along_thalweg('/results/SalishSea/nowcast-green/06may17', 
                    'SalishSea_2h_20170506_20170515_dia1_T.nc',
                   'SalishSea_1h_20170506_20170506_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/06may17', 
                    'SalishSea_2h_20170506_20170515_dia1_T.nc',
                   'SalishSea_1h_20170506_20170506_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/06may17', 
                    'SalishSea_2h_20170506_20170515_dia1_T.nc',
                   'SalishSea_1h_20170506_20170506_ptrc_T.nc', 'flag')

June 2017

In [11]:
limit_along_thalweg('/results/SalishSea/nowcast-green/05jun17', 
                    'SalishSea_2h_20170605_20170614_dia1_T.nc',
                    'SalishSea_1h_20170605_20170605_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/05jun17', 
                    'SalishSea_2h_20170605_20170614_dia1_T.nc',
                    'SalishSea_1h_20170605_20170605_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/05jun17', 
                    'SalishSea_2h_20170605_20170614_dia1_T.nc',
                    'SalishSea_1h_20170605_20170605_ptrc_T.nc', 'flag')

July 2017

In [12]:
limit_along_thalweg('/results/SalishSea/nowcast-green/05jul17', 
                    'SalishSea_2h_20170705_20170714_dia1_T.nc',
                    'SalishSea_1h_20170705_20170705_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/05jul17', 
                    'SalishSea_2h_20170705_20170714_dia1_T.nc',
                    'SalishSea_1h_20170705_20170705_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/05jul17', 
                    'SalishSea_2h_20170705_20170714_dia1_T.nc',
                    'SalishSea_1h_20170705_20170705_ptrc_T.nc', 'flag')

August 2017

In [13]:
limit_along_thalweg('/results/SalishSea/nowcast-green/01aug17', 
                    'SalishSea_2h_20170801_20170801_dia1_T.nc',
                    'SalishSea_1h_20170801_20170801_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/01aug17', 
                    'SalishSea_2h_20170801_20170801_dia1_T.nc',
                    'SalishSea_1h_20170801_20170801_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/01aug17', 
                    'SalishSea_2h_20170801_20170801_dia1_T.nc',
                    'SalishSea_1h_20170801_20170801_ptrc_T.nc', 'flag')

September 2017

In [14]:
limit_along_thalweg('/results/SalishSea/nowcast-green/01sep17', 
                    'SalishSea_2h_20170901_20170901_dia1_T.nc',
                    'SalishSea_1h_20170901_20170901_ptrc_T.nc', 'dia')
limit_along_thalweg('/results/SalishSea/nowcast-green/01sep17', 
                    'SalishSea_2h_20170901_20170901_dia1_T.nc',
                    'SalishSea_1h_20170901_20170901_ptrc_T.nc', 'meso')
limit_along_thalweg('/results/SalishSea/nowcast-green/01sep17', 
                    'SalishSea_2h_20170901_20170901_dia1_T.nc',
                    'SalishSea_1h_20170901_20170901_ptrc_T.nc', 'flag')