Skip to content

Commit bf4bae4

Browse files
authored
Cmorizer for the Wetland Area and Dynamics for Methane Modeling (WAD2M) dataset (#4110)
1 parent 9a73dc2 commit bf4bae4

7 files changed

Lines changed: 234 additions & 0 deletions

File tree

doc/sphinx/source/input.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ A list of the datasets for which a CMORizers is available is provided in the fol
479479
+------------------------------+------------------------------------------------------------------------------------------------------+------+-----------------+
480480
| UWisc* [#t3]_ | clwvi, lwpStderr (Amon) | 3 | NCL |
481481
+------------------------------+------------------------------------------------------------------------------------------------------+------+-----------------+
482+
| WAD2M | wetlandFrac (Emon) | 2 | Python |
483+
+------------------------------+------------------------------------------------------------------------------------------------------+------+-----------------+
482484
| WFDE5 | tas, pr (Amon, day) | 2 | Python |
483485
+------------------------------+------------------------------------------------------------------------------------------------------+------+-----------------+
484486
| WOA | thetao, so, tos, sos (Omon) | 2 | Python |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
# Filename
3+
filename: 'WAD2M_wetlands_2000-2020_025deg_Ver2.0.nc.zip'
4+
5+
# Common global attributes for Cmorizer output
6+
attributes:
7+
dataset_id: WAD2M
8+
version: '2.0'
9+
tier: 2
10+
modeling_realm: sat
11+
project_id: OBS6
12+
source: 'https://zenodo.org/record/5553187'
13+
reference: 'wad2m_zhang21essd'
14+
15+
# Variables to cmorize
16+
variables:
17+
wetlandFrac:
18+
mip: Emon
19+
raw_name: Fw
20+
raw_units: 1

esmvaltool/cmorizers/data/datasets.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,14 @@ datasets:
13451345
Contact Ralf Bennartz (Earth and Environmental Sciences, Vanderbilt
13461346
University, USA).
13471347
1348+
WAD2M:
1349+
tier: 2
1350+
source: https://doi.org/10.5281/zenodo.3998453
1351+
last_access: 2025-07-01
1352+
info: |
1353+
Use the automatic download to download the file:
1354+
WAD2M_wetlands_2000-2020_025deg_Ver2.0.nc
1355+
13481356
WFDE5:
13491357
tier: 2
13501358
source: https://doi.org/10.24381/cds.20d54e34
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Script to download Wetland Area and Dynamics for Methane Modeling (WAD2M)."""
2+
3+
import logging
4+
5+
from esmvaltool.cmorizers.data.downloaders.wget import WGetDownloader
6+
7+
logger = logging.getLogger(__name__)
8+
9+
10+
def download_dataset(
11+
config, dataset, dataset_info, start_date, end_date, overwrite
12+
):
13+
"""Download dataset.
14+
15+
Parameters
16+
----------
17+
config : dict
18+
ESMValTool's user configuration
19+
dataset : str
20+
Name of the dataset
21+
dataset_info : dict
22+
Dataset information from the datasets.yml file
23+
start_date : datetime
24+
Start of the interval to download
25+
end_date : datetime
26+
End of the interval to download
27+
overwrite : bool
28+
Overwrite already downloaded files
29+
"""
30+
downloader = WGetDownloader(
31+
config=config,
32+
dataset=dataset,
33+
dataset_info=dataset_info,
34+
overwrite=overwrite,
35+
)
36+
37+
downloader.download_file(
38+
"https://zenodo.org/record/5553187/files/"
39+
"WAD2M_wetlands_2000-2020_025deg_Ver2.0.nc.zip",
40+
wget_options=[],
41+
)
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
"""ESMValTool CMORizer for WAD2M data.
2+
3+
Tier
4+
Tier 2: other freely-available dataset.
5+
6+
Source
7+
https://zenodo.org/record/5553187
8+
9+
Last access
10+
20250701
11+
12+
Download and processing instructions
13+
Download the file WAD2M_wetlands_2000-2020_025deg_Ver2.0.nc.
14+
15+
"""
16+
17+
import logging
18+
import warnings
19+
import zipfile
20+
from datetime import datetime
21+
from pathlib import Path
22+
23+
import iris
24+
from cf_units import Unit
25+
from iris import NameConstraint
26+
from iris.coords import AuxCoord
27+
28+
from esmvaltool.cmorizers.data import utilities as utils
29+
from esmvaltool.diag_scripts.shared.iris_helpers import unify_time_coord
30+
31+
logger = logging.getLogger(__name__)
32+
33+
34+
def _fix_coords(cube, cmor_info):
35+
"""Fix coordinates."""
36+
# Dimensional coordinates
37+
if "time" in cmor_info.dimensions:
38+
unify_time_coord(cube, "days since 1950-01-01 00:00:00")
39+
40+
# Move time points to center of month
41+
time_coord = cube.coord("time")
42+
old_dates = time_coord.units.num2date(time_coord.points)
43+
new_dates = [datetime(t.year, t.month, 15) for t in old_dates]
44+
time_coord.points = time_coord.units.date2num(new_dates)
45+
46+
# Add typewetla coordinate
47+
typewetla_coord = AuxCoord(
48+
"wetland",
49+
var_name="typewetla",
50+
standard_name="area_type",
51+
long_name="Wetland",
52+
units=Unit("no unit"),
53+
)
54+
cube.add_aux_coord(typewetla_coord, ())
55+
56+
cube = utils.fix_coords(cube)
57+
58+
return cube
59+
60+
61+
def _fix_var_metadata(var_info, cmor_info, cube):
62+
"""Fix variable metadata."""
63+
if "raw_units" in var_info:
64+
cube.units = var_info["raw_units"]
65+
66+
# wetlandFrac:
67+
# Convert from fraction to percentage
68+
cube.convert_units("%")
69+
70+
utils.fix_var_metadata(cube, cmor_info)
71+
72+
73+
def _extract_variable(var_info, cmor_info, attrs, filepath, out_dir):
74+
"""Extract variable."""
75+
var = cmor_info.short_name
76+
raw_var = var_info.get("raw_name", var)
77+
78+
# Load data
79+
with warnings.catch_warnings():
80+
warnings.filterwarnings(
81+
action="ignore",
82+
message="Ignoring netCDF variable .* invalid units .*",
83+
category=UserWarning,
84+
module="iris",
85+
)
86+
cube = iris.load_cube(filepath, NameConstraint(var_name=raw_var))
87+
88+
# Fix variable metadata
89+
_fix_var_metadata(var_info, cmor_info, cube)
90+
91+
# Fix coordinates
92+
cube = _fix_coords(cube, cmor_info)
93+
94+
# Fix global metadata
95+
utils.set_global_atts(cube, attrs)
96+
97+
# Save variable
98+
utils.save_variable(
99+
cube,
100+
var,
101+
out_dir,
102+
attrs,
103+
unlimited_dimensions=["time"],
104+
)
105+
106+
107+
def _unzip(filepath, out_dir):
108+
"""Unzip `*.zip` file."""
109+
logger.info("Starting extraction of %s to %s", filepath, out_dir)
110+
with zipfile.ZipFile(filepath, "r") as zip_ref:
111+
zip_ref.extract(Path(filepath).stem, out_dir)
112+
extracted_file = Path(out_dir) / Path(filepath).stem
113+
logger.info("Succefully extracted file to %s", extracted_file)
114+
return extracted_file
115+
116+
117+
def cmorization(in_dir, out_dir, cfg, cfg_user, start_date, end_date):
118+
"""Cmorization func call."""
119+
cmor_table = cfg["cmor_table"]
120+
glob_attrs = cfg["attributes"]
121+
122+
# Run the cmorization
123+
for var, var_info in cfg["variables"].items():
124+
logger.info("CMORizing variable '%s'", var)
125+
glob_attrs["comment"] = var_info.get("comment", "")
126+
glob_attrs["mip"] = var_info["mip"]
127+
cmor_info = cmor_table.get_variable(var_info["mip"], var)
128+
129+
# Extract file from ZIP archive
130+
zip_file = Path(in_dir) / cfg["filename"]
131+
if not Path(zip_file).is_file():
132+
logger.debug("Skipping '%s', file '%s' not found", var, zip_file)
133+
continue
134+
logger.info("Found input file '%s'", zip_file)
135+
filepath = _unzip(zip_file, out_dir)
136+
137+
# Extract and save variable file
138+
_extract_variable(var_info, cmor_info, glob_attrs, filepath, out_dir)
139+
140+
# Remove extracted file
141+
Path(filepath).unlink()
142+
logger.info("Removed cached input file %s", filepath)

esmvaltool/recipes/examples/recipe_check_obs.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,3 +2130,12 @@ diagnostics:
21302130
- {dataset: UWisc, project: OBS, mip: Amon, tier: 3,
21312131
type: sat, version: v2, start_year: 1988, end_year: 2007}
21322132
scripts: null
2133+
2134+
WAD2M:
2135+
description: WAD2M check
2136+
variables:
2137+
wetlandFrac:
2138+
additional_datasets:
2139+
- {dataset: WAD2M, project: OBS6, mip: Emon, tier: 2,
2140+
type: sat, version: "2.0", start_year: 2000, end_year: 2020}
2141+
scripts: null
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@article{wad2m_zhang2021essd,
2+
author = {Zhang, Z. and Fluet-Chouinard, E. and Jensen, K. and McDonald, K. and Hugelius, G. and Gumbricht, T. and Carroll, M. and Prigent, C. and Bartsch, A. and Poulter, B.},
3+
title = {Development of the global dataset of Wetland Area and Dynamics for Methane
4+
Modeling (WAD2M)},
5+
journal = {Earth System Science Data},
6+
volume = {13},
7+
year = {2021},
8+
number = {5},
9+
pages = {2001--2023},
10+
url = {https://essd.copernicus.org/articles/13/2001/2021/},
11+
doi = {10.5194/essd-13-2001-2021}
12+
}

0 commit comments

Comments
 (0)