OCEAN file with DMS and CHLO

I ran the Notebook on Google Colab with ocean.txt as an input (after using ncgen) and it worked fine.

Steps

To make this work on Google Colab, you need to upload your ocean file, which I will assume is called “OCEANFile_AIRPACT_04km_fixed.nc”

  1. Follow this link to open on google colab

  2. Drag and drop your ocean file to the file browser.

  3. Add these three cells to the top and run them.

%%writefile requirements.txt
setuptools >= 58.0
importlib_metadata >= 4.6
numpy >= 1.19.5,<2
pandas >= 1.1.5
netCDF4 >= 1.5.8
matplotlib >= 3.3.4
pycno >= 0.2.0
pyproj >= 2.6.1
pseudonetcdf >= 3.2.0
cdo == 1.5.3
!python -m pip install -r requirements.txt
!apt install netcdf-bin
!wget -N https://forum.cmascenter.org/uploads/short-url/unjiMkCmgd6FBTWw3U0SZJ0f6AR.txt
!ncgen -o OCEANFile_AIRPACT_04km_fixed.nc unjiMkCmgd6FBTWw3U0SZJ0f6AR.txt
  1. After running those cells, restart the notebook (Runtime - Restart session)

  2. Update the user specifications

dom = 'AIRPACT_04km'

and

ocnintmpl = '/content/OCEANFile_AIRPACT_04km_fixed.nc'
  1. And, in install prerequisites, set installcdo = True

  2. Run the notebook and download results.

  3. To make a figure like the one I attached, run the code below. The exact result will depend on which file you visualize.

import matplotlib.pyplot as plt
import matplotlib.colors as mc
import pycno  # pip install pycno

tmpf = pnc.pncopen(ocnoutpath, format='ioapi')
cno = pycno.cno(tmpf.getproj(withgrid=True))
fig, axx = plt.subplots(1, 2, figsize=(12, 4))
for ax, key, norm in zip(axx, 'DMS CHLO'.split(), [None, mc.TwoSlopeNorm(4, 0)]):
  Z = tmpf[key]
  qm = ax.pcolormesh(Z[0, 0], norm=norm)
  fig.colorbar(qm, label=f'{Z.long_name} [{Z.units}]'.replace('  ', ''))
cno.drawstates(ax=axx)

p.s., the units on your ocean file are non-ascii characters – not ideal, but not a problem for the notebook.

3 Likes