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

Edr fixed axis #1811

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
48 changes: 19 additions & 29 deletions pygeoapi/provider/xarray_.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ 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.get_fields()
except Exception as err:
Expand All @@ -105,7 +106,7 @@ def get_fields(self):
LOGGER.debug('Adding variable')
dtype = value.dtype
if dtype.name.startswith('float'):
dtype = 'number'
dtype = 'float'

self._fields[key] = {
'type': dtype,
Expand Down Expand Up @@ -248,48 +249,35 @@ def gen_covjson(self, metadata, data, fields):
"""

LOGGER.debug('Creating CoverageJSON domain')
minx, miny, maxx, maxy = metadata['bbox']
startx, starty, stopx, stopy = metadata['bbox']
mint, maxt = metadata['time']

selected_fields = {
key: value for key, value in self.fields.items()
if key in fields
}

try:
tmp_min = data.coords[self.y_field].values[0]
except IndexError:
tmp_min = data.coords[self.y_field].values
try:
tmp_max = data.coords[self.y_field].values[-1]
except IndexError:
tmp_max = data.coords[self.y_field].values

if tmp_min > tmp_max:
LOGGER.debug(f'Reversing direction of {self.y_field}')
miny = tmp_max
maxy = tmp_min

cj = {
'type': 'Coverage',
'domain': {
'type': 'Domain',
'domainType': 'Grid',
'axes': {
'x': {
'start': minx,
'stop': maxx,
'start': startx,
'stop': stopx,
'num': metadata['width']
},
'y': {
'start': maxy,
'stop': miny,
'start': starty,
'stop': stopy,
'num': metadata['height']
},
self.time_field: {
'start': mint,
'stop': maxt,
'num': metadata['time_steps']
self.time_axis_covjson: {
'values': [str(i) for i in data.coords[self.time_field].values]
#'start': mint,
#'stop': maxt,
#'num': metadata['time_steps']
}
},
'referencing': [{
Expand All @@ -307,7 +295,7 @@ def gen_covjson(self, metadata, data, fields):
for key, value in selected_fields.items():
parameter = {
'type': 'Parameter',
'description': value['title'],
'description': {'en':value['title']},
'unit': {
'symbol': value['x-ogc-unit']
},
Expand All @@ -330,11 +318,12 @@ def gen_covjson(self, metadata, data, fields):
'type': 'NdArray',
'dataType': value['type'],
'axisNames': [
'y', 'x', self._coverage_properties['time_axis_label']
self.time_axis_covjson,'y', 'x'
],
'shape': [metadata['height'],
metadata['width'],
metadata['time_steps']]
'shape': [metadata['time_steps'],
metadata['height'],
metadata['width']
]
}
cj['ranges'][key]['values'] = data[key].values.flatten().tolist() # noqa
except IndexError as err:
Expand Down Expand Up @@ -370,6 +359,7 @@ def _get_coverage_properties(self):
self.y_field = y_var
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
Expand Down
2 changes: 1 addition & 1 deletion pygeoapi/templates/collections/edr/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
if (!firstLayer) {
firstLayer = layer;
layer.on('afterAdd', () => {
zoomToLayers([layers])
zoomToLayers([layer])
if (!cov.coverages) {
if (isVerticalProfile(cov) || isTimeSeries(cov)) {
layer.openPopup();
Expand Down
Binary file modified tests/data/coads_sst.nc
Binary file not shown.
Loading