-
Notifications
You must be signed in to change notification settings - Fork 128
/
cowtanway.py
79 lines (62 loc) · 2.35 KB
/
cowtanway.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""ESMValTool CMORizer for CowtanWay.
Tier
Tier 2: other freely-available dataset.
Source
https://www-users.york.ac.uk/~kdc3/papers/coverage2013/series.html
Last access
20200226
Download and processing instructions
Download the following files:
'had4_krig_v1_0_0.nc.gz'
'had4_uah_v1_0_0.nc.gz'
'had4_short_krig_v2_0_0.nc.gz'
'had4_short_uah_v2_0_0.nc.gz'
'ghcn_short_krig_v2_0_0.nc.gz'
'ghcn_short_uah_v2_0_0.nc.gz'
'had4sst4_krig_v2_0_0.nc.gz'
'had4_krig_v2_0_0.nc.gz'
"""
import logging
import os
import iris
from iris import NameConstraint
from esmvaltool.cmorizers.data import utilities as utils
logger = logging.getLogger(__name__)
def _extract_variable(short_name, var, vkey, version, cfg, filepath, out_dir):
"""Extract variable."""
raw_var = var.get('raw', short_name)
cube = iris.load_cube(filepath, NameConstraint(var_name=raw_var))
# Fix units
cmor_info = cfg['cmor_table'].get_variable(var['mip'], short_name).copy()
cube.convert_units(cmor_info.units)
utils.convert_timeunits(cube, 1950)
# Fix coordinates
cube = utils.fix_coords(cube)
if 'height2m' in cmor_info.dimensions:
utils.add_height2m(cube)
# Fix metadata
attrs = cfg['attributes'].copy()
attrs['mip'] = var['mip']
attrs['version'] = version
baseline = cfg['attributes']['baseline'][vkey]
attrs['baseline'] = baseline
attrs['comment'] = attrs['comment'].format(baseline=baseline)
utils.fix_var_metadata(cube, cmor_info)
utils.set_global_atts(cube, attrs)
# Save variable
utils.save_variable(cube,
short_name,
out_dir,
attrs,
unlimited_dimensions=['time'])
def cmorization(in_dir, out_dir, cfg, cfg_user, start_date, end_date):
"""Cmorization func call."""
raw_filepath = os.path.join(in_dir, cfg['filename'])
# Run the cmorization
for (short_name, var) in cfg['variables'].items():
for (vkey, version) in cfg['attributes']['version'].items():
logger.info("CMORizing variable '%s' version '%s'", short_name,
version)
filepath = raw_filepath.format(version=version)
_extract_variable(short_name, var, vkey, version, cfg, filepath,
out_dir)