Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.


Overview

The availability of several macronutrients controls production in most of the ocean: nitrate, phosphate, and silicate. Here we take a look at maps and depth profiles of these nutrients, and compare them to an observational dataset.

  1. General setup

  2. Subsetting

  3. Processing - means in time and space

  4. Compare to World Ocean Atlas data

  5. Make depth profiles

Prerequisites

ConceptsImportanceNotes
MatplotlibNecessary
Intro to CartopyNecessary
Dask CookbookHelpful
Intro to XarrayHelpful
  • Time to learn: 30 min


Imports

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 7
      3 import numpy as np
      4 import matplotlib.pyplot as plt
      5 import cartopy
      6 import cartopy.crs as ccrs
----> 7 import pop_tools
      8 from dask.distributed import LocalCluster
      9 import s3fs
     10 

File ~/micromamba/envs/ocean-bgc-cookbook-dev/lib/python3.14/site-packages/pop_tools/__init__.py:4
      1 """Top-level module for pop_tools"""
----> 4 from pkg_resources import DistributionNotFound, get_distribution
      6 from .calc import cfc11sol, cfc12sol
      7 from .datasets import DATASETS

ModuleNotFoundError: No module named 'pkg_resources'

General setup (see intro notebooks for explanations)

Connect to cluster

Bring in POP grid utilities

Load the data

Subsetting

Make our dataset smaller so it has just a couple of macronutrient variables we’re interested in.

Let’s take a quick look at nitrate to make sure that things look okay...

Transforming from monthly to annual data

We can’t just use xarray’s regular mean() function because months have different numbers of days in them, so we have to weight by that to ensure the annual mean is accurate. See this ESDS blog post for a more detailed explanation with examples!

Note that our time coordinate is now called year instead, and has only years now. We can select specific years to plot:

Let’s make a nicer-looking map

Compare long-term mean to World Ocean Atlas 2018

We’ve already regridded the WOA data to be on the same grid as the CESM data, so we don’t need to worry about that step. However, if you wanted to compare to a dataset that’s on a different grid, you’d need to go through the regridding process, which is beyond the scope of this cookbook.

This dataset has also already had a time mean taken, so there’s no time coordinate.

You might notice that there are three coordinates: z_t, z_w, and z_w_bot. Each of these are different versions of the same vertical coordinate - z_t represents the midpoint of a depth layer, z_w the top, and z_w_bot the bottom. We use z_t in this demonstration.

Now that we’re doing more involved calculations, we’re going to just take a mean over a couple years (2010-2011) to make the computational load a bit lighter. For a more accurate analysis, we’d want to include more years than this.

Surface comparison

We choose to set up a dictionary with some parameters for each plot we want to make, to cut down on repetition in the actual plotting code block. This could be condensed even further, but there’s a tradeoff between conciseness and readability! We specify the variables we want to plot (in this case different nutrients) and things like the colormaps and normalization. In addition to plotting each nutrient from the modeled data and observations, we also plot the bias, which is the difference between the two datasets. This helps us see how the model differs from observations.

Here we pull from the above dictionary to actually make the plots.

Comparison at 100m

Similar to above, but at a depth of 100m rather than at the surface.

Global mean macronutrient profiles

Let’s write a function to take a global mean of the variables we’re interested in, so that we can look at some depth profiles rather than maps. Also remember that we already took a mean over the whole time range (and the WOA dataset already had this mean taken), so this is a mean in time as well. Like the above maps, we also plot a bias panel to directly compare the difference between the datasets.

Rather than setting up a dictionary of parameters, here we choose to make the plots inline since there aren’t as many.

And close the Dask cluster we spun up at the beginning.


Summary

You’ve learned how to plot and evaluate the distribution of some key ocean nutrients in CESM output.

References
  1. (2013). In Ocean Biogeochemical Dynamics (pp. 102–172). Princeton University Press. 10.2307/j.ctt3fgxqx.7