Skip to content

Commit

Permalink
Added CMORizer for MOBO-DIC2004-2019 (#3297)
Browse files Browse the repository at this point in the history
  • Loading branch information
schlunma authored Nov 3, 2023
1 parent 29b20e7 commit 89153c1
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 7 deletions.
2 changes: 2 additions & 0 deletions doc/sphinx/source/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ A list of the datasets for which a CMORizers is available is provided in the fol
+------------------------------+------------------------------------------------------------------------------------------------------+------+-----------------+
| MOBO-DIC_MPIM | dissic (Omon) | 2 | Python |
+------------------------------+------------------------------------------------------------------------------------------------------+------+-----------------+
| MOBO-DIC2004-2019 | dissic (Omon) | 2 | Python |
+------------------------------+------------------------------------------------------------------------------------------------------+------+-----------------+
| MODIS | cliwi, clt, clwvi, iwpStderr, lwpStderr (Amon), od550aer (aero) | 3 | NCL |
+------------------------------+------------------------------------------------------------------------------------------------------+------+-----------------+
| MSWEP [#note1]_ | pr | 3 | n/a |
Expand Down
19 changes: 19 additions & 0 deletions esmvaltool/cmorizers/data/cmor_config/MOBO-DIC2004-2019.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
# Common global attributes for Cmorizer output
attributes:
dataset_id: MOBO-DIC2004-2019
version: '2.3'
tier: 2
modeling_realm: reanaly
project_id: OBS6
source: 'https://www.nodc.noaa.gov/archive/arc0211/0277099/2.3/data/0-data/'
reference: 'mobo_dic2004_2019'

# Variables to cmorize
variables:
dissic:
filename: MPI_MOBO-DIC_2004-2019_v2.nc
mip: Omon
raw_name: DIC
raw_units: '1e-6 mol kg-1'
comment: 'The original units of this variable are mumol/kg. To convert to the CMOR units mol/m3, we assume a constant sea water density of 1032 kg/m3, which is approximately the sea water density for T=4°C, salinity=35PSU, and p=100bar according to the UNESCO formula (UNESCO, 1981, Tenth report of the joint panel on oceanographic tables and standards, UNESCO Technical Papers in Marine Science, see https://www.wkcgroup.com/tools-room/seawater-density-calculator/ and https://link.springer.com/content/pdf/bbm:978-3-319-18908-6/1.pdf).'
9 changes: 8 additions & 1 deletion esmvaltool/cmorizers/data/datasets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,13 @@ datasets:
info: |
Download the file MOBO-DIC_MPIM_monthly_clim.nc
MOBO-DIC2004-2019:
tier: 2
source: https://www.nodc.noaa.gov/archive/arc0211/0277099/2.3/data/0-data/
last_access: 2023-10-09
info: |
Download the file MPI_MOBO-DIC_2004-2019_v2.nc
MODIS:
tier: 3
source: https://ladsweb.modaps.eosdis.nasa.gov/search/order
Expand Down Expand Up @@ -1015,7 +1022,7 @@ datasets:
miscSI-MO/pr_wtr.eatm.mon.mean.nc
prsSI-MO/shum.mon.mean.nc
miscMO/tcdc.eatm.mon.mean.nc
ntatFlxSI-MO/ulwrf.ntat.mon.mean.nc
ntatFlxSI-MO/ulwrf.ntat.mon.mean.nc
ntatFlxSI-MO/uswrf.ntat.mon.mean.nc
ntatFlxSI-MO/csulf.ntat.mon.mean.nc
ntatFlxSI-MO/csusf.ntat.mon.mean.nc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Script to download MOBO-DIC2004-2019."""
import logging

from esmvaltool.cmorizers.data.downloaders.wget import WGetDownloader

logger = logging.getLogger(__name__)


def download_dataset(config, dataset, dataset_info, start_date, end_date,
overwrite):
"""Download dataset.
Parameters
----------
config : dict
ESMValTool's user configuration
dataset : str
Name of the dataset
dataset_info : dict
Dataset information from the datasets.yml file
start_date : datetime
Start of the interval to download
end_date : datetime
End of the interval to download
overwrite : bool
Overwrite already downloaded files
"""
downloader = WGetDownloader(
config=config,
dataset=dataset,
dataset_info=dataset_info,
overwrite=overwrite,
)

downloader.download_file(
"https://www.nodc.noaa.gov/archive/arc0211/0277099/2.3/data/0-data/"
"MPI_MOBO-DIC_2004-2019_v2.nc",
wget_options=[],
)
17 changes: 17 additions & 0 deletions esmvaltool/cmorizers/data/formatters/datasets/mobo_dic2004_2019.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""ESMValTool CMORizer for MOBO-DIC2004-2019 data.
Tier
Tier 2: other freely-available dataset.
Source
https://www.nodc.noaa.gov/archive/arc0211/0277099/2.3/data/0-data/
Last access
20231009
Download and processing instructions
Download the file MPI_MOBO-DIC_2004-2019_v2.nc
"""

from .mobo_dic_mpim import cmorization # noqa
60 changes: 54 additions & 6 deletions esmvaltool/cmorizers/data/formatters/datasets/mobo_dic_mpim.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from pathlib import Path

import iris
import numpy as np
from cf_units import Unit
from dask import array as da
from iris import NameConstraint
Expand All @@ -30,6 +31,9 @@
logger = logging.getLogger(__name__)


TIME_UNITS = Unit('days since 1950-01-01 00:00:00', calendar='standard')


def _callback_fix_missing_value(cube, field, _):
"""Create masked array from missing_value."""
if hasattr(field.cf_data, 'missing_value'):
Expand All @@ -40,20 +44,18 @@ def _callback_fix_missing_value(cube, field, _):

def _fix_climatological_time(cube):
"""Fix climatology coordinate."""
time_units = Unit('days since 1950-01-01 00:00:00', calendar='standard')

# Following the doc the covered time period of the climatology is
# January 2004 to December 2017 (Use 2011 as the "mean" year). See
# https://www.ncei.noaa.gov/access/metadata/landing-page/bin/
# iso?id=gov.noaa.nodc%3A0221526
time_points = time_units.date2num(
time_points = TIME_UNITS.date2num(
[datetime(2011, m, 15) for m in range(1, 13)]
)
time_bounds = [
[datetime(2004, m, 1), datetime(2017, m + 1, 1)] for m in range(1, 12)
]
time_bounds.append([datetime(2004, 12, 1), datetime(2018, 1, 1)])
time_bounds = time_units.date2num(time_bounds)
time_bounds = TIME_UNITS.date2num(time_bounds)

# Add new time coordinate to cube
time_coord = DimCoord(
Expand All @@ -62,7 +64,7 @@ def _fix_climatological_time(cube):
standard_name='time',
long_name='time',
var_name='time',
units=time_units,
units=TIME_UNITS,
climatological=True,
)
cube.remove_coord('month of the year')
Expand All @@ -73,6 +75,49 @@ def _fix_climatological_time(cube):
cube.add_cell_method(CellMethod('mean over years', coords=time_coord))


def _fix_time(cube):
"""Fix time coordinate."""
julian_day_coord = cube.coord('Julian Day')

# Calculate bounds of new time coordinate
# print(str(julian_day_coord.units))
datetime_base = datetime.strptime(
str(julian_day_coord.units).partition(' since ')[2],
'%Y-%m-%d %H:%M:%S',
)
base_year = datetime_base.year
base_month = datetime_base.month
all_months = list(julian_day_coord.points.astype(int)) + [
julian_day_coord.points.astype(int).max() + 1 # 1 more month for bnds
]
bounds_datetimes = [
datetime(base_year + (m - 1) // 12, base_month + (m - 1) % 12, 1)
for m in all_months
]
time_bounds = np.stack(
(
TIME_UNITS.date2num(bounds_datetimes[:-1]),
TIME_UNITS.date2num(bounds_datetimes[1:]),
),
axis=-1,
)

# Calculate time points as mean of bounds
time_points = np.mean(time_bounds, axis=1)

# Add new time coordinate to cube
time_coord = DimCoord(
time_points,
bounds=time_bounds,
standard_name='time',
long_name='time',
var_name='time',
units=TIME_UNITS,
)
cube.remove_coord('Julian Day')
cube.add_dim_coord(time_coord, 0)


def _fix_var_metadata(var_info, cmor_info, cube):
"""Fix variable metadata.
Expand Down Expand Up @@ -121,7 +166,10 @@ def _extract_variable(var_info, cmor_info, attrs, filepath, out_dir):
_fix_var_metadata(var_info, cmor_info, cube)

# Fix coordinates
_fix_climatological_time(cube)
if cube.coords('month of the year'): # MOBO-DIC_MPIM
_fix_climatological_time(cube)
elif cube.coords('Julian Day'): # MOBO-DIC2004-2019
_fix_time(cube)
cube.coord('depth').units = 'm'
utils.fix_coords(cube, overwrite_time_bounds=False)

Expand Down
10 changes: 10 additions & 0 deletions esmvaltool/recipes/examples/recipe_check_obs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,16 @@ diagnostics:
scripts: null


MOBO-DIC2004-2019:
description: MOBO-DIC2004-2019 check
variables:
dissic:
additional_datasets:
- {dataset: MOBO-DIC2004-2019, project: OBS6, mip: Omon, tier: 2,
type: reanaly, version: '2.3', start_year: 2004, end_year: 2019}
scripts: null


NCEP-NCAR-R1:
description: NCEP-NCAR-R1 check
variables:
Expand Down
12 changes: 12 additions & 0 deletions esmvaltool/references/mobo_dic2004_2019.bibtex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@article{mobo_dic2004_2019,
doi = {10.1029/2022gb007677},
url = {https://doi.org/10.1029/2022gb007677},
year = {2023},
month = may,
publisher = {American Geophysical Union ({AGU})},
volume = {37},
number = {5},
author = {L. Keppler and P. Landschützer and S. K. Lauvset and N. Gruber},
title = {Recent Trends and Variability in the Oceanic Storage of Dissolved Inorganic Carbon},
journal = {Global Biogeochemical Cycles}
}

0 comments on commit 89153c1

Please sign in to comment.