Ocean iron concentration#

%load_ext autoreload
%autoreload 2
import xarray as xr

from dask.distributed import Client

import catalog
import util

xr.set_options(keep_attrs=True)
/glade/work/kristenk/miniconda/envs/cesm-exp/lib/python3.7/site-packages/dask_jobqueue/core.py:20: FutureWarning: tmpfile is deprecated and will be removed in a future release. Please use dask.utils.tmpfile instead.
  from distributed.utils import tmpfile
<xarray.core.options.set_options at 0x2b47246ffb50>
import matplotlib.pyplot as plt
import cartopy
import cartopy.crs as ccrs
import pop_tools
import pandas as pd
import tools
import plot
import matt_utils
import matplotlib.gridspec as gridspec
import numpy as np
from itertools import product
import cmocean
import matplotlib.colors as colors
ds_grid = pop_tools.get_grid('POP_gx1v7')
lons = ds_grid.TLONG
lats = ds_grid.TLAT
depths = ds_grid.z_t * 0.01

Parameters#

casename = 'g.e22a06.G1850ECOIAF_JRA_PHYS_DEV.TL319_g17.scope_v1'
component = 'pop'
stream = 'h'

cluster_scheduler_address = None
# Parameters
casename = "g.e22a06.G1850ECOIAF_JRA_PHYS_DEV.TL319_g17.scope_v1"
component = "pop"
stream = "h"
cluster_scheduler_address = "tcp://10.12.206.26:40301"
assert component in ['pop']
assert stream in ['h', 'h.ecosys.nday1']

Connect to cluster#

if cluster_scheduler_address is None:
    cluster, client = util.get_ClusterClient()
    cluster.scale(12)
else:
    client = Client(cluster_scheduler_address)
client

Client

Client-744b8e5c-0c3e-11ed-84f9-3cecef1b11d4

Connection method: Direct
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/36768/status

Scheduler Info

Scheduler

Scheduler-59153102-2d90-4250-b1d9-5b9f28512082

Comm: tcp://10.12.206.26:40301 Workers: 32
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/36768/status Total threads: 32
Started: 28 minutes ago Total memory: 744.96 GiB

Workers

Worker: PBSCluster-0

Comm: tcp://10.12.206.25:41180 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/42193/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.25:34568
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-smli87lm
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 526.57 MiB Spilled bytes: 0 B
Read bytes: 112.90 MiB Write bytes: 92.27 MiB

Worker: PBSCluster-1

Comm: tcp://10.12.206.23:35055 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/39970/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.23:39298
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-pajhhimy
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 608.65 MiB Spilled bytes: 0 B
Read bytes: 368.93 MiB Write bytes: 157.59 kiB

Worker: PBSCluster-10

Comm: tcp://10.12.206.18:39960 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/40058/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.18:33787
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-frtdc9f5
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 451.69 MiB Spilled bytes: 0 B
Read bytes: 328.19 MiB Write bytes: 48.62 MiB

Worker: PBSCluster-11

Comm: tcp://10.12.206.18:35287 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/39615/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.18:36732
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-mmo_bs6s
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 0.0% Last seen: Just now
Memory usage: 506.16 MiB Spilled bytes: 0 B
Read bytes: 323.72 MiB Write bytes: 48.54 MiB

Worker: PBSCluster-12

Comm: tcp://10.12.206.8:33729 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/35711/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.8:43143
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-svc02rvq
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 630.78 MiB Spilled bytes: 0 B
Read bytes: 145.23 MiB Write bytes: 80.74 MiB

Worker: PBSCluster-13

Comm: tcp://10.12.206.8:37550 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/38907/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.8:40235
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-lys_uzzv
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 521.56 MiB Spilled bytes: 0 B
Read bytes: 129.10 MiB Write bytes: 32.32 MiB

Worker: PBSCluster-14

Comm: tcp://10.12.206.25:44992 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/44154/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.25:43428
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-76two5nt
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 0.0% Last seen: Just now
Memory usage: 573.06 MiB Spilled bytes: 0 B
Read bytes: 113.05 MiB Write bytes: 92.39 MiB

Worker: PBSCluster-15

Comm: tcp://10.12.206.15:43062 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/32926/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.15:39144
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-jy38onqp
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 838.79 MiB Spilled bytes: 0 B
Read bytes: 128.83 MiB Write bytes: 16.15 MiB

Worker: PBSCluster-16

Comm: tcp://10.12.206.8:43565 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/41710/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.8:45391
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-_7ilj7sa
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 725.06 MiB Spilled bytes: 0 B
Read bytes: 128.98 MiB Write bytes: 32.29 MiB

Worker: PBSCluster-17

Comm: tcp://10.12.206.11:40919 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/45664/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.11:40649
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-o65npiy5
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 592.35 MiB Spilled bytes: 0 B
Read bytes: 745.00 MiB Write bytes: 299.14 kiB

Worker: PBSCluster-18

Comm: tcp://10.12.206.11:33891 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/38384/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.11:33328
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-nou8aprr
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 546.49 MiB Spilled bytes: 0 B
Read bytes: 741.80 MiB Write bytes: 294.55 kiB

Worker: PBSCluster-19

Comm: tcp://10.12.206.15:36904 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/35533/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.15:34961
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-r5hakwxw
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 464.66 MiB Spilled bytes: 0 B
Read bytes: 128.92 MiB Write bytes: 16.16 MiB

Worker: PBSCluster-2

Comm: tcp://10.12.206.15:43006 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/39124/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.15:43393
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-mmk9h6y4
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 0.0% Last seen: Just now
Memory usage: 455.24 MiB Spilled bytes: 0 B
Read bytes: 145.23 MiB Write bytes: 16.18 MiB

Worker: PBSCluster-20

Comm: tcp://10.12.206.18:45916 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/35027/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.18:43737
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-xa8tkihj
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 0.0% Last seen: Just now
Memory usage: 500.54 MiB Spilled bytes: 0 B
Read bytes: 323.06 MiB Write bytes: 48.63 MiB

Worker: PBSCluster-21

Comm: tcp://10.12.206.11:45334 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/46680/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.11:46761
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-t02yg0d0
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 4.0% Last seen: Just now
Memory usage: 631.21 MiB Spilled bytes: 0 B
Read bytes: 757.87 MiB Write bytes: 305.94 kiB

Worker: PBSCluster-22

Comm: tcp://10.12.206.18:34993 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/44524/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.18:46562
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-3e1h8ye1
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 465.18 MiB Spilled bytes: 0 B
Read bytes: 80.52 MiB Write bytes: 49.92 MiB

Worker: PBSCluster-23

Comm: tcp://10.12.206.15:39733 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/46168/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.15:41249
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-xyvrzxs3
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 476.00 MiB Spilled bytes: 0 B
Read bytes: 129.16 MiB Write bytes: 16.19 MiB

Worker: PBSCluster-24

Comm: tcp://10.12.206.25:44221 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/45234/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.25:40387
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-yfm951kg
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 0.0% Last seen: Just now
Memory usage: 512.43 MiB Spilled bytes: 0 B
Read bytes: 112.79 MiB Write bytes: 92.18 MiB

Worker: PBSCluster-25

Comm: tcp://10.12.206.18:33408 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/43488/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.18:41022
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-6df9eo6t
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 0.0% Last seen: Just now
Memory usage: 455.10 MiB Spilled bytes: 0 B
Read bytes: 325.06 MiB Write bytes: 48.57 MiB

Worker: PBSCluster-26

Comm: tcp://10.12.206.8:38884 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/39795/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.8:40143
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-sb74tso9
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 559.34 MiB Spilled bytes: 0 B
Read bytes: 128.97 MiB Write bytes: 32.29 MiB

Worker: PBSCluster-27

Comm: tcp://10.12.206.15:40873 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/45934/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.15:41861
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-2tgmhfdl
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 488.71 MiB Spilled bytes: 0 B
Read bytes: 129.18 MiB Write bytes: 16.19 MiB

Worker: PBSCluster-28

Comm: tcp://10.12.206.18:36750 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/42860/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.18:43661
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-6lr4z8hl
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 471.66 MiB Spilled bytes: 0 B
Read bytes: 322.88 MiB Write bytes: 48.60 MiB

Worker: PBSCluster-29

Comm: tcp://10.12.206.8:32978 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/46650/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.8:38238
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-ihw76ltj
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 0.0% Last seen: Just now
Memory usage: 685.27 MiB Spilled bytes: 0 B
Read bytes: 129.33 MiB Write bytes: 32.34 MiB

Worker: PBSCluster-3

Comm: tcp://10.12.206.18:34352 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/35771/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.18:32780
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-l8qf3wzg
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 502.95 MiB Spilled bytes: 0 B
Read bytes: 326.73 MiB Write bytes: 48.51 MiB

Worker: PBSCluster-30

Comm: tcp://10.12.206.8:39013 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/33562/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.8:40233
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-peochg10
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 496.60 MiB Spilled bytes: 0 B
Read bytes: 128.90 MiB Write bytes: 32.27 MiB

Worker: PBSCluster-31

Comm: tcp://10.12.206.25:43689 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/43012/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.25:43417
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-yfzy1i0u
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 584.56 MiB Spilled bytes: 0 B
Read bytes: 112.94 MiB Write bytes: 92.31 MiB

Worker: PBSCluster-4

Comm: tcp://10.12.206.13:33058 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/43170/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.13:39266
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-yy1kkjd5
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 482.78 MiB Spilled bytes: 0 B
Read bytes: 338.76 MiB Write bytes: 80.76 MiB

Worker: PBSCluster-5

Comm: tcp://10.12.206.23:36916 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/42702/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.23:45113
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-8th_y8dw
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 788.77 MiB Spilled bytes: 0 B
Read bytes: 277.14 MiB Write bytes: 184.85 kiB

Worker: PBSCluster-6

Comm: tcp://10.12.206.8:38424 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/46679/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.8:44217
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-ml7gmjn8
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 528.30 MiB Spilled bytes: 0 B
Read bytes: 129.11 MiB Write bytes: 32.28 MiB

Worker: PBSCluster-7

Comm: tcp://10.12.206.25:44991 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/42629/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.25:45710
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-ab599zkf
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 456.78 MiB Spilled bytes: 0 B
Read bytes: 113.05 MiB Write bytes: 92.39 MiB

Worker: PBSCluster-8

Comm: tcp://10.12.206.25:42326 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/44451/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.25:35373
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-3gi9oohh
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 617.67 MiB Spilled bytes: 0 B
Read bytes: 112.82 MiB Write bytes: 92.21 MiB

Worker: PBSCluster-9

Comm: tcp://10.12.206.15:35080 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/46851/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.15:39139
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-9ijbos11
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 478.12 MiB Spilled bytes: 0 B
Read bytes: 145.07 MiB Write bytes: 16.16 MiB

Load the data#

dsets = catalog.to_dataset_dict(
    case=casename,
    component=component,
    stream=stream,
)
dsets.keys()
dict_keys(['g.e22a06.G1850ECOIAF_JRA_PHYS_DEV.TL319_g17.scope_v1.pop.h'])

Compute long-term mean Fe concentration#

ds = dsets[f'{casename}.{component}.{stream}']
variables =['Fe']
keep_vars=['z_t','z_t_150m','dz','time_bound','TAREA','TLAT','TLONG'] + variables
ds = ds.drop([v for v in ds.variables if v not in keep_vars])
ds.Fe.isel(time=0,z_t=0).plot()
<matplotlib.collections.QuadMesh at 0x2b472ae72550>
_images/ocn-iron_17_1.png
dt_wgt = ds.time_bound.diff('d2').squeeze()
dt_wgt /= dt_wgt.sum()
#dt_wgt
ds = ds.weighted(dt_wgt).mean('time')
nmolcm3_to_nM = 1.e3
ds['Fe'] = ds['Fe'] * nmolcm3_to_nM
ds['Fe'].attrs['units'] = 'nM'

Compare to observational Fe database#

(need ref)

dFe_obs_file = '/glade/u/home/kristenk/cesm2-marbl/notebooks/discrete_obs/dFe-database-2021-05-20.csv'
df = pd.read_csv(dFe_obs_file, na_values=-999.).dropna(axis=0, how='all')
%%time
df.obs_stream.add_model_field(ds.Fe)
df
CPU times: user 17.5 s, sys: 157 ms, total: 17.7 s
Wall time: 4min 20s
lon lat depth dFe_obs Fe
0 210.010 -16.0018 20.0 0.540000 0.047255
1 210.010 -16.0018 35.0 0.440000 0.047110
2 210.010 -16.0019 50.0 0.480000 0.046569
3 210.010 -16.0019 80.0 0.400000 0.044805
4 210.010 -16.0020 100.0 0.390000 0.048094
... ... ... ... ... ...
27777 160.051 47.0032 3929.6 0.825681 0.466740
27778 160.051 47.0032 3929.8 0.902248 0.466748
27779 160.051 47.0032 4900.4 0.555630 NaN
27780 160.051 47.0032 4900.9 0.621851 NaN
27781 160.051 47.0032 5210.1 0.573220 NaN

27782 rows × 5 columns

plt.plot(df.dFe_obs, df.Fe, '.')
plt.xlabel('CESM2 dFe [nM]')
plt.ylabel('Obs dFe [nM]')
plt.plot([0, 5], [0, 5], 'r-')
[<matplotlib.lines.Line2D at 0x2b473c1369d0>]
_images/ocn-iron_24_1.png
fig, axs = plot.canvas(3, 1, figsize=(6, 2.5), use_gridspec=True, hspace=0.06)

dx = 0.05
bin_edges = np.arange(0., 1.5+dx, dx)
bins = np.vstack((bin_edges[:-1], bin_edges[1:])).mean(axis=0)

depth_ranges = {
    '–100m < z': (0., 100.),
    '-500m < z < -100 m': (100., 500.),
    '   z < -500m': (500., 1e36),
}

for n, (key, depth_range) in enumerate(depth_ranges.items()):
    ax = axs[n, 0]
    df_sub = df.loc[(depth_range[0] <= df.depth) & (df.depth <= depth_range[1])]
    
    hist, _ = np.histogram(df_sub.dFe_obs.values, bin_edges)
    ax.bar(bins, hist, width=dx, alpha=0.7, label='Obs')
    
    hist, _ = np.histogram(df_sub.Fe.values, bin_edges)
    ax.bar(bins, hist, width=dx, alpha=0.6, label='CESM2-MARBL')
    
    if n == 0:
        ax.legend(loc='upper right', frameon=False)
    if n < 2:
        ax.set_xticklabels([])
    ylm = ax.get_ylim()
    ax.text(0.75, ylm[1] - 0.12 * np.diff(ylm), key, 
            fontweight='bold',
            fontsize=12,
            ha='center',
           )
    if n == 1:
        ax.set_ylabel('Number of samples')
    if n == 2:
        ax.set_xlabel('Dissolved iron concentration [nM]')
        
matt_utils.label_plots(fig, [ax for ax in axs.ravel()], xoff=-0.05, yoff=-0.02)
_images/ocn-iron_25_0.png
dsp = matt_utils.pop_add_cyclic(ds)
field = 'Fe'
levels = {'Fe': [0., 0.05, 0.1, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, 0.8, 1., 2.5, 5.0]}

fig = plt.figure(figsize=(10, 8))
prj = ccrs.Robinson(central_longitude=305.0)

nrow, ncol = 3, 2 
gs = gridspec.GridSpec(
    nrows=nrow, ncols=ncol+1, 
    width_ratios=(1, 1, 0.03),
    wspace=0.05, 
    hspace=0.2,
)

axs = np.empty((nrow, ncol)).astype(object)
caxs= np.empty((nrow, ncol)).astype(object)
for i, j in product(range(nrow), range(ncol)):    
    axs[i, j] = plt.subplot(gs[i, j], projection=prj)
cax = plt.subplot(gs[:, -1])

cmap_field = cmocean.cm.dense


for i, (key, depth_range) in enumerate(depth_ranges.items()):
    for j in range(2):
        ax = axs[i, j]
        if j == 0:
            zslice = slice(depth_range[0]*100., depth_range[1]*100.)

            cf = ax.contourf(
                dsp.TLONG,dsp.TLAT, dsp[field].sel(z_t=zslice).mean('z_t'),
                levels=levels[field],
                extend='max',
                cmap=cmap_field,
                norm=colors.BoundaryNorm(levels[field], ncolors=cmap_field.N),
                transform=ccrs.PlateCarree(),
            )
        else:
            df_sub = df.loc[(depth_range[0] <= df.depth) & (df.depth <= depth_range[1])]
            sc = ax.scatter(
                df_sub.lon, df_sub.lat, c=df_sub.dFe_obs.values,
                cmap=cmap_field,
                norm=colors.BoundaryNorm(levels[field], ncolors=cmap_field.N),
                s=6,
                transform=ccrs.PlateCarree(),
            )

        land = ax.add_feature(
            cartopy.feature.NaturalEarthFeature(
                'physical','land','110m',
                edgecolor='face',
                facecolor='gray'
            )
        )  

cb = plt.colorbar(cf, cax=cax, ticks=levels['Fe'])
if 'units' in dsp[field].attrs:
    cb.ax.set_title(dsp[field].attrs['units'])
    cb.ax.set_yticklabels([f'{f:g}' for f in levels['Fe']])

matt_utils.subplot_col_labels(axs[0, :], ['CESM2', 'Observations'])    
matt_utils.subplot_row_labels(axs[:, 0], depth_ranges.keys(), xoff=60)
    
matt_utils.label_plots(fig, [ax for ax in axs.ravel()], xoff=0.02, yoff=0) 
_images/ocn-iron_27_0.png