Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmorize cru v4.04 & stn contraint #1981

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions esmvaltool/cmorizers/obs/cmor_config/CRU.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
---
# Filename (will be extended by variable name)
filename: 'cru_ts4.02.1901.2017.{raw_name}.dat.nc.gz'
filename: 'cru_ts4.04.1901.2019.{raw_name}.dat.nc.gz'

# Common global attributes for Cmorizer output
attributes:
dataset_id: CRU
version: 'TS4.02'
version: 'TS4.04'
tier: 2
modeling_realm: reanaly
project_id: OBS
source: 'https://crudata.uea.ac.uk/cru/data/hrg/cru_ts_4.02/cruts.1811131722.v4.02/'
source: 'https://crudata.uea.ac.uk/cru/data/hrg/cru_ts_4.04/cruts.2004151855.v4.04/'
reference: 'cru'
comment: ''

attributes_constraint:
dataset_id: CRU
version: 'TS4.04-stn1'
tier: 2
modeling_realm: reanaly
project_id: OBS
source: 'https://crudata.uea.ac.uk/cru/data/hrg/cru_ts_4.04/cruts.2004151855.v4.04/'
reference: 'cru'
comment: 'contrained on gridpoint values beeing based on at least 1 station'

# Variables to cmorize
variables:
tas:
mip: Amon
raw: tmp
raw_units: celsius
constraint: stn
pr:
mip: Amon
raw: pre
raw_units: kg m-2 month-1
constraint: stn
63 changes: 59 additions & 4 deletions esmvaltool/cmorizers/obs/cmorize_obs_cru.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@
Tier 2: other freely-available dataset.

Source
https://crudata.uea.ac.uk/cru/data/hrg/cru_ts_4.02/cruts.1811131722.v4.02/
https://crudata.uea.ac.uk/cru/data/hrg/cru_ts_4.04/cruts.2004151855.v4.04/

Last access
20190516
20210113

Download and processing instructions
Download the following files:
{raw_name}/cru_ts4.02.1901.2017.{raw_name}.dat.nc.gz
{raw_name}/cru_ts4.04.1901.2019.{raw_name}.dat.nc.gz
where {raw_name} is the name of the desired variable(s).

Two files are generated per variable, one with version (i.e. TS4.04),
one with version + -stn1 (i.e. TS4.04-stn1), which is constrained on holding
gridpoint values relying on data from at least one station (i.e. removing
gridpoints solely relying on climatological infilling).
"""

import gzip
import logging
import os
import shutil
import cftime

import numpy as np
from cf_units import Unit

import iris

Expand All @@ -45,13 +53,18 @@ def _extract_variable(short_name, var, cfg, filepath, out_dir):
cube.units = var['raw_units']
cmor_info = cfg['cmor_table'].get_variable(var['mip'], short_name)
cube.convert_units(cmor_info.units)
utils.convert_timeunits(cube, 1950)
# fix time units
cube.coord('time').convert_units(
Unit('days since 1950-1-1 00:00:00', calendar='gregorian'))

# Fix coordinates
utils.fix_coords(cube)
if 'height2m' in cmor_info.dimensions:
utils.add_height2m(cube)

# Fix time coordinate
_get_centered_timecoord(cube)

# Fix metadata
attrs = cfg['attributes']
attrs['mip'] = var['mip']
Expand All @@ -65,6 +78,48 @@ def _extract_variable(short_name, var, cfg, filepath, out_dir):
attrs,
unlimited_dimensions=['time'])

# build contrainted cube on stn < 1
constraint_var = var.get('constraint', short_name)
constr_cube = iris.load_cube(filepath,
utils.var_name_constraint(constraint_var))
utils.fix_coords(constr_cube)
cube.data = np.ma.masked_where(constr_cube.data < 1., cube.data)

# Save variable
attrs = cfg['attributes_constraint']
attrs['mip'] = var['mip']

utils.save_variable(cube,
short_name,
out_dir,
attrs,
unlimited_dimensions=['time'])


def _get_centered_timecoord(cube):
"""CRU timepoints are not in the center of the month.

Added bounds by utils.fix_coords are incorrect.
"""
time = cube.coord('time')
times = time.units.num2date(time.points)

# get bounds
starts = [
cftime.DatetimeNoLeap(c.year, c.month, 1)
for c in times
]
ends = [
cftime.DatetimeNoLeap(c.year, c.month + 1, 1) if c.month < 12
else cftime.DatetimeNoLeap(c.year + 1, 1, 1)
for c in times
]

time.bounds = time.units.date2num(np.stack([starts, ends], -1))

# get points
time.points = [np.mean((t1, t2)) for t1, t2 in time.bounds]

mwjury marked this conversation as resolved.
Show resolved Hide resolved

def _unzip(short_name, var, raw_filepath, out_dir):
"""Unzip `*.gz` file."""
Expand Down
4 changes: 3 additions & 1 deletion esmvaltool/recipes/examples/recipe_check_obs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ diagnostics:
pr:
additional_datasets:
- {dataset: CRU, project: OBS, mip: Amon, tier: 2,
type: reanaly, version: TS4.02, start_year: 1901, end_year: 2017}
type: reanaly, version: TS4.04, start_year: 1901, end_year: 2019}
- {dataset: CRU, project: OBS, mip: Amon, tier: 2,
remi-kazeroni marked this conversation as resolved.
Show resolved Hide resolved
type: reanaly, version: TS4.04-stn1, start_year: 1901, end_year: 2019}
scripts: null


Expand Down
22 changes: 11 additions & 11 deletions esmvaltool/references/cru.bibtex
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@article{cru,
doi = {10.1002/joc.3711},
url = {https://doi.org/10.1002%2Fjoc.3711},
year = 2013,
month = {may},
publisher = {Wiley},
volume = {34},
number = {3},
pages = {623--642},
author = {I. Harris and P.D. Jones and T.J. Osborn and D.H. Lister},
title = {Updated high-resolution grids of monthly climatic observations - the {CRU} {TS}3.10 Dataset},
journal = {International Journal of Climatology}
doi = {10.1038/s41597-020-0453-3},
issn = {2052-4463},
url = {http://www.nature.com/articles/s41597-020-0453-3},
year = 2020,
author = {Harris, Ian and Osborn, Timothy J. and Jones, Phil and Lister, David},
title = {Version 4 of the CRU TS monthly high-resolution gridded multivariate climate dataset},
journal = {Scientific Data},
month = {dec},
number = {1},
pages = {109},
volume = {7}
}