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 0x2b6a9fe72fd0>
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.e22.GOMIPECOIAF_JRA-1p4-2018.TL319_g17.4p2z.001branch"
component = "pop"
stream = "h"
cluster_scheduler_address = "tcp://10.12.206.3:35506"
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-77421e3a-935a-11ed-b3fa-3cecef1acc46

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

Scheduler Info

Scheduler

Scheduler-7b28f886-17c1-40f8-ae24-3360603786e8

Comm: tcp://10.12.206.3:35506 Workers: 32
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/8787/status Total threads: 32
Started: 39 minutes ago Total memory: 744.96 GiB

Workers

Worker: PBSCluster-0

Comm: tcp://10.12.206.60:40381 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/37473/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.60:43642
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-she593m8
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 511.20 MiB Spilled bytes: 0 B
Read bytes: 24.44 kiB Write bytes: 46.52 kiB

Worker: PBSCluster-1

Comm: tcp://10.12.206.57:34913 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/43168/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.57:40520
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-ais4w5nl
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 700.14 MiB Spilled bytes: 0 B
Read bytes: 35.85 MiB Write bytes: 22.34 kiB

Worker: PBSCluster-10

Comm: tcp://10.12.206.55:40610 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/41580/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.55:41770
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-24q12p4a
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 552.84 MiB Spilled bytes: 0 B
Read bytes: 18.43 kiB Write bytes: 15.79 kiB

Worker: PBSCluster-11

Comm: tcp://10.12.206.35:36760 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/34231/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.35:39163
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-tm589a2g
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 0.0% Last seen: Just now
Memory usage: 725.41 MiB Spilled bytes: 0 B
Read bytes: 14.53 kiB Write bytes: 8.68 kiB

Worker: PBSCluster-12

Comm: tcp://10.12.206.42:46667 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/44609/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.42:43503
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-63bl396p
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 523.46 MiB Spilled bytes: 0 B
Read bytes: 10.91 kiB Write bytes: 0.94 kiB

Worker: PBSCluster-13

Comm: tcp://10.12.206.55:34741 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/41987/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.55:39933
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-3taktpky
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 537.59 MiB Spilled bytes: 0 B
Read bytes: 18.44 kiB Write bytes: 19.03 kiB

Worker: PBSCluster-14

Comm: tcp://10.12.206.42:44723 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/38884/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.42:37139
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-btgwv71o
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 0.0% Last seen: Just now
Memory usage: 544.63 MiB Spilled bytes: 0 B
Read bytes: 11.39 kiB Write bytes: 4.17 kiB

Worker: PBSCluster-15

Comm: tcp://10.12.206.60:34840 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/36356/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.60:36517
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-s50upym9
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 553.09 MiB Spilled bytes: 0 B
Read bytes: 24.45 kiB Write bytes: 46.54 kiB

Worker: PBSCluster-16

Comm: tcp://10.12.206.55:33480 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/44604/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.55:34515
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-20gqvxq8
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 486.03 MiB Spilled bytes: 0 B
Read bytes: 18.96 kiB Write bytes: 484.39 kiB

Worker: PBSCluster-17

Comm: tcp://10.12.206.42:46005 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/44117/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.42:32947
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-18iilri4
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 597.78 MiB Spilled bytes: 0 B
Read bytes: 11.04 kiB Write bytes: 2.55 kiB

Worker: PBSCluster-18

Comm: tcp://10.12.206.60:33226 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/42773/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.60:46337
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-8qq6z3y3
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 520.46 MiB Spilled bytes: 0 B
Read bytes: 539.34 kiB Write bytes: 1.02 MiB

Worker: PBSCluster-19

Comm: tcp://10.12.206.36:36934 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/38605/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.36:40345
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-0wibvgh_
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 0.0% Last seen: Just now
Memory usage: 650.31 MiB Spilled bytes: 0 B
Read bytes: 100.41 kiB Write bytes: 44.00 kiB

Worker: PBSCluster-2

Comm: tcp://10.12.206.42:35532 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/37233/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.42:38029
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-tvn8qi89
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 487.30 MiB Spilled bytes: 0 B
Read bytes: 11.03 kiB Write bytes: 2.55 kiB

Worker: PBSCluster-20

Comm: tcp://10.12.206.57:44618 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/35828/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.57:39590
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-j87b3i6z
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 537.97 MiB Spilled bytes: 0 B
Read bytes: 10.25 MiB Write bytes: 16.49 kiB

Worker: PBSCluster-21

Comm: tcp://10.12.206.42:36146 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/42013/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.42:42567
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-te65hpsa
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 709.42 MiB Spilled bytes: 0 B
Read bytes: 11.98 kiB Write bytes: 6.59 kiB

Worker: PBSCluster-22

Comm: tcp://10.12.206.37:45266 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/41617/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.37:46778
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-6zjl_rf2
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 0.0% Last seen: Just now
Memory usage: 499.16 MiB Spilled bytes: 0 B
Read bytes: 92.72 kiB Write bytes: 147.30 kiB

Worker: PBSCluster-23

Comm: tcp://10.12.206.57:36646 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/33282/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.57:39220
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-tedt0oqb
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 602.02 MiB Spilled bytes: 0 B
Read bytes: 35.80 MiB Write bytes: 22.31 kiB

Worker: PBSCluster-24

Comm: tcp://10.12.206.35:43781 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/41280/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.35:41682
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-oenmf7ye
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 543.07 MiB Spilled bytes: 0 B
Read bytes: 15.30 kiB Write bytes: 10.53 kiB

Worker: PBSCluster-25

Comm: tcp://10.12.206.42:38958 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/45762/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.42:41096
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-r999w54s
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 525.09 MiB Spilled bytes: 0 B
Read bytes: 11.26 kiB Write bytes: 4.16 kiB

Worker: PBSCluster-26

Comm: tcp://10.12.206.35:41019 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/46197/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.35:41093
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-n8z_ugpj
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 619.80 MiB Spilled bytes: 0 B
Read bytes: 15.29 kiB Write bytes: 10.53 kiB

Worker: PBSCluster-27

Comm: tcp://10.12.206.40:37756 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/34868/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.40:46061
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-ah4h4uwy
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.59 MiB Spilled bytes: 0 B
Read bytes: 15.28 kiB Write bytes: 6.48 kiB

Worker: PBSCluster-28

Comm: tcp://10.12.206.55:40536 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/40763/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.55:43688
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-mqh1_swd
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 499.59 MiB Spilled bytes: 0 B
Read bytes: 18.34 kiB Write bytes: 484.07 kiB

Worker: PBSCluster-29

Comm: tcp://10.12.206.35:43010 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/45869/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.35:38155
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-0zp2yifw
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 507.53 MiB Spilled bytes: 0 B
Read bytes: 14.42 kiB Write bytes: 7.88 kiB

Worker: PBSCluster-3

Comm: tcp://10.12.206.55:43243 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/45154/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.55:40506
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-d77lpe1m
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 0.0% Last seen: Just now
Memory usage: 483.93 MiB Spilled bytes: 0 B
Read bytes: 18.02 kiB Write bytes: 481.42 kiB

Worker: PBSCluster-30

Comm: tcp://10.12.206.42:40059 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/38562/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.42:35150
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-s1j98ibm
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 510.62 MiB Spilled bytes: 0 B
Read bytes: 10.91 kiB Write bytes: 0.94 kiB

Worker: PBSCluster-31

Comm: tcp://10.12.206.55:40509 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/46123/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.55:42505
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-0193oowl
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 539.46 MiB Spilled bytes: 0 B
Read bytes: 18.99 kiB Write bytes: 485.22 kiB

Worker: PBSCluster-4

Comm: tcp://10.12.206.60:33761 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/38547/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.60:43086
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-go_20xsh
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 611.59 MiB Spilled bytes: 0 B
Read bytes: 24.48 kiB Write bytes: 46.60 kiB

Worker: PBSCluster-5

Comm: tcp://10.12.206.56:36183 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/39960/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.56:36523
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-ak_et0qx
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 497.62 MiB Spilled bytes: 0 B
Read bytes: 291.00 MiB Write bytes: 28.29 MiB

Worker: PBSCluster-6

Comm: tcp://10.12.206.55:42418 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/43316/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.55:35755
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-w069mt42
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.81 MiB Spilled bytes: 0 B
Read bytes: 18.95 kiB Write bytes: 486.50 kiB

Worker: PBSCluster-7

Comm: tcp://10.12.206.42:38064 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/33959/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.42:37237
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-8g92ok8a
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 4.0% Last seen: Just now
Memory usage: 503.98 MiB Spilled bytes: 0 B
Read bytes: 11.74 kiB Write bytes: 5.78 kiB

Worker: PBSCluster-8

Comm: tcp://10.12.206.35:46716 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/38950/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.35:46823
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-t0bj5mka
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 490.59 MiB Spilled bytes: 0 B
Read bytes: 14.53 kiB Write bytes: 9.48 kiB

Worker: PBSCluster-9

Comm: tcp://10.12.206.55:36074 Total threads: 1
Dashboard: https://jupyterhub.hpc.ucar.edu/stable/user/kristenk/proxy/41381/status Memory: 23.28 GiB
Nanny: tcp://10.12.206.55:35112
Local directory: /glade/scratch/kristenk/dask-workers/dask-worker-space/worker-vzrt3wyj
Tasks executing: 0 Tasks in memory: 0
Tasks ready: 0 Tasks in flight: 0
CPU usage: 2.0% Last seen: Just now
Memory usage: 535.39 MiB Spilled bytes: 0 B
Read bytes: 18.01 kiB Write bytes: 481.24 kiB

Load the data#

dsets = catalog.to_dataset_dict(
    case=casename,
    component=component,
    stream=stream,
)
dsets.keys()
g.e22.GOMIPECOIAF_JRA-1p4-2018.TL319_g17.4p2z.001branch pop h /glade/scratch/kristenk/archive
dict_keys(['g.e22.GOMIPECOIAF_JRA-1p4-2018.TL319_g17.4p2z.001branch.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 0x2b6ada8d39d0>
_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 16.9 s, sys: 164 ms, total: 17 s
Wall time: 4min 13s
lon lat depth dFe_obs Fe
0 210.010 -16.0018 20.0 0.540000 0.095124
1 210.010 -16.0018 35.0 0.440000 0.094715
2 210.010 -16.0019 50.0 0.480000 0.093150
3 210.010 -16.0019 80.0 0.400000 0.087125
4 210.010 -16.0020 100.0 0.390000 0.090777
... ... ... ... ... ...
27777 160.051 47.0032 3929.6 0.825681 0.505122
27778 160.051 47.0032 3929.8 0.902248 0.505119
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 0x2b6adbbc93d0>]
_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