Skip to content

Commit f815661

Browse files
committed
Fixes for soil moisture monthly / 10-day requests
Addresses Issue #48. Several soil moisture tests currently failing -- they will have to be updated for compatibility with the changed request format.
1 parent b2ad10c commit f815661

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ of use for any datasets you want to acccess.
3434

3535
#### Obtain a CDS API key
3636

37-
3837
You can obtain the UID and API key as follows:
3938

4039
1. Create a user account on the

test/test_soil_moisture.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,25 @@ def test_soil_moisture_volumetric_minimal_params(self):
5555
dataset.attrs['time_coverage_end'])
5656
description = store.describe_data(data_id)
5757
self.assertCountEqual(description.data_vars.keys(),
58-
map(str, dataset.data_vars))
58+
map(str, dataset.data_vars))
59+
60+
def test_soil_moisture_volumetric_monthly_2_years(self):
61+
store = CDSDataStore()
62+
data_id = 'satellite-soil-moisture:volumetric:monthly'
63+
dataset = store.open_data(
64+
data_id,
65+
time_range=['2015-01-01', '2016-12-31'],
66+
type_of_record='cdr'
67+
)
68+
self.assertTrue('sm' in dataset.variables)
69+
self.assertEqual(2, len(dataset.variables['time']))
70+
self.assertEqual('2014-12-31T12:00:00Z',
71+
dataset.attrs['time_coverage_start'])
72+
self.assertEqual('2017-01-01T12:00:00Z',
73+
dataset.attrs['time_coverage_end'])
74+
description = store.describe_data(data_id)
75+
self.assertCountEqual(description.data_vars.keys(),
76+
map(str, dataset.data_vars))
5977

6078
def test_soil_moisture_saturation_daily(self):
6179
store = CDSDataStore(client_class=CDSClientMock,

xcube_cds/datasets/reanalysis_era5.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,12 @@ def _read_dataset_info(self):
9898
# (issue #6) and sometimes with non-increasing time (issue #5), so
9999
# for now they are blacklisted.
100100
blacklist = frozenset([
101-
'reanalysis-era5-land-monthly-means:monthly_averaged_reanalysis_by_hour_of_day',
102-
'reanalysis-era5-single-levels-monthly-means:monthly_averaged_ensemble_members_by_hour_of_day',
103-
'reanalysis-era5-single-levels-monthly-means:monthly_averaged_reanalysis_by_hour_of_day'
101+
'reanalysis-era5-land-monthly-means:'
102+
'monthly_averaged_reanalysis_by_hour_of_day',
103+
'reanalysis-era5-single-levels-monthly-means:'
104+
'monthly_averaged_ensemble_members_by_hour_of_day',
105+
'reanalysis-era5-single-levels-monthly-means:'
106+
'monthly_averaged_reanalysis_by_hour_of_day'
104107
])
105108

106109
# We use a list rather than a set, since we want to preserve ordering

xcube_cds/datasets/satellite_soil_moisture.py

+7
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ def transform_params(self, opener_params, data_id: str) -> \
115115

116116
time_selectors = self.transform_time_params(
117117
self.convert_time_range(opener_params['time_range']))
118+
time_selectors.pop('time', None)
119+
if aggregation == 'monthly':
120+
time_selectors['day'] = '01'
121+
if aggregation == '10-day':
122+
time_selectors['day'] =\
123+
sorted(set(time_selectors['day'])
124+
.intersection({'01', '11', '21'}))
118125
cds_params.update(time_selectors)
119126

120127
# Transform singleton list values into their single members, as

xcube_cds/store.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,9 @@ def get_data_ids(self, type_specifier: Optional[str] = None,
770770
for data_id, handler in self._handler_registry.items():
771771
if return_tuples:
772772
if include_titles:
773-
yield data_id, {'title': handler.get_human_readable_data_id(data_id)}
773+
yield data_id,\
774+
{'title':
775+
handler.get_human_readable_data_id(data_id)}
774776
else:
775777
yield data_id, {}
776778
else:

0 commit comments

Comments
 (0)