Skip to content

Commit

Permalink
Merge branch 'EDR-time-axis-values'
Browse files Browse the repository at this point in the history
  • Loading branch information
pzaborowski committed Oct 23, 2024
2 parents 1431963 + c38ad33 commit e6436eb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
14 changes: 9 additions & 5 deletions pygeoapi/provider/xarray_.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def __init__(self, provider_def):
self.axes = [self._coverage_properties['x_axis_label'],
self._coverage_properties['y_axis_label'],
self._coverage_properties['time_axis_label']]
self.time_axis_covjson = provider_def.get('time_axis_covjson') or self.time_field
self.time_axis_covjson = provider_def.get('time_axis_covjson') \
or self.time_field

self.get_fields()
except Exception as err:
Expand Down Expand Up @@ -308,7 +309,11 @@ def gen_covjson(self, metadata, data, fields):
'num': metadata['height']
},
self.time_axis_covjson: {
'values': [str(i) for i in data.coords[self.time_field].values]
'values': [str(i) for i in
data.coords[self.time_field].values],
#'start': mint,

Check failure on line 314 in pygeoapi/provider/xarray_.py

View workflow job for this annotation

GitHub Actions / flake8_py3

pygeoapi/provider/xarray_.py#L314

[E265] block comment should start with
#'stop': maxt,

Check failure on line 315 in pygeoapi/provider/xarray_.py

View workflow job for this annotation

GitHub Actions / flake8_py3

pygeoapi/provider/xarray_.py#L315

[E265] block comment should start with
#'num': metadata['time_steps']

Check failure on line 316 in pygeoapi/provider/xarray_.py

View workflow job for this annotation

GitHub Actions / flake8_py3

pygeoapi/provider/xarray_.py#L316

[E265] block comment should start with
}
},
'referencing': [{
Expand All @@ -334,7 +339,7 @@ def gen_covjson(self, metadata, data, fields):
for key, value in selected_fields.items():
parameter = {
'type': 'Parameter',
'description': {'en':value['title']},
'description': {'en': value['title']},
'unit': {
'symbol': value['x-ogc-unit']
},
Expand All @@ -356,7 +361,7 @@ def gen_covjson(self, metadata, data, fields):
'type': 'NdArray',
'dataType': value['type'],
'axisNames': [
self.time_axis_covjson,'y', 'x'
self.time_axis_covjson, 'y', 'x'
],
'shape': [metadata['time_steps'],
metadata['height'],
Expand Down Expand Up @@ -404,7 +409,6 @@ def _get_coverage_properties(self):
if self.time_field is None:
self.time_field = time_var


# It would be preferable to use CF attributes to get width
# resolution etc but for now a generic approach is used to assess
# all of the attributes based on lat lon vars
Expand Down
38 changes: 24 additions & 14 deletions tests/api/test_environmental_data_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_get_collection_edr_query(config, api_):
# bounded date range
req = mock_api_request({
'coords': 'POINT(11 11)',
'datetime': '2000-01-17/2000-06-16'
'datetime': '2000-01-17/2000-08-16'
})
rsp_headers, code, response = get_collection_edr_query(
api_, req, 'icoads-sst', None, 'position')
Expand All @@ -132,14 +132,17 @@ def test_get_collection_edr_query(config, api_):
data = json.loads(response)
time_dict = data['domain']['axes']['TIME']

assert time_dict['start'] == '2000-02-15T16:29:05.999999999'
assert time_dict['stop'] == '2000-06-16T10:25:30.000000000'
assert time_dict['num'] == 5
assert time_dict['values'] == ['2000-06-16T10:25:30.000000000',
'2000-07-16T20:54:36.000000000',
'2000-08-16T07:23:42.000000000']
# assert time_dict['start'] == '2000-06-16T10:25:30.000000000'
# assert time_dict['stop'] == '2000-08-16T07:23:42.000000000'
# assert time_dict['num'] == 3

# unbounded date range - start
req = mock_api_request({
'coords': 'POINT(11 11)',
'datetime': '../2000-06-16'
'datetime': '../2000-08-16'
})
rsp_headers, code, response = get_collection_edr_query(
api_, req, 'icoads-sst', None, 'position')
Expand All @@ -148,29 +151,36 @@ def test_get_collection_edr_query(config, api_):
data = json.loads(response)
time_dict = data['domain']['axes']['TIME']

assert time_dict['start'] == '2000-01-16T06:00:00.000000000'
assert time_dict['stop'] == '2000-06-16T10:25:30.000000000'
assert time_dict['num'] == 6
assert time_dict['values'] == ['2000-06-16T10:25:30.000000000',
'2000-07-16T20:54:36.000000000',
'2000-08-16T07:23:42.000000000']
# assert time_dict['start'] == '2000-06-16T10:25:30.000000000'
# assert time_dict['stop'] == '2000-08-16T07:23:42.000000000'
# assert time_dict['num'] == 3

# unbounded date range - end
req = mock_api_request({
'coords': 'POINT(11 11)',
'datetime': '2000-06-16/..'
'datetime': '2000-08-16/..'
})
rsp_headers, code, response = get_collection_edr_query(
api_, req, 'icoads-sst', None, 'position')
assert code == HTTPStatus.OK

data = json.loads(response)
time_dict = data['domain']['axes']['TIME']

assert time_dict['start'] == '2000-06-16T10:25:30.000000000'
assert time_dict['stop'] == '2000-12-16T01:20:05.999999996'
assert time_dict['num'] == 7
assert time_dict['values'] == ['2000-08-16T07:23:42.000000000',
'2000-09-15T17:52:48.000000000',
'2000-10-16T04:21:54.000000000',
'2000-11-15T14:51:00.000000000',
'2000-12-16T01:20:05.999999996']
# assert time_dict['start'] == '2000-08-16T07:23:42.000000000'
# assert time_dict['stop'] == '2000-12-16T01:20:05.999999996'
# assert time_dict['num'] == 7

# some data
req = mock_api_request({
'coords': 'POINT(11 11)', 'datetime': '2000-01-16'
'coords': 'POINT(11 11)', 'datetime': '2000-06-16'
})
rsp_headers, code, response = get_collection_edr_query(
api_, req, 'icoads-sst', None, 'position')
Expand Down

0 comments on commit e6436eb

Please sign in to comment.