Skip to content

Commit

Permalink
STAC / OGC: exclude grid mapping vars from range
Browse files Browse the repository at this point in the history
The OGC / STAC / Coverages schema and rangetype endpoints were
including the 0-dimensional grid mapping variables in their
responses. These are now filtered out.
  • Loading branch information
pont-us committed Jan 5, 2024
1 parent a47a269 commit de5e27a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
11 changes: 8 additions & 3 deletions xcube/webapi/ows/coverages/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,14 +603,19 @@ def get_coverage_rangetype(
"""
ds = get_dataset(ctx, collection_id)
result = dict(type='DataRecord', field=[])
for var_name in ds.data_vars:
for var_name, variable in ds.data_vars.items():
if variable.dims == ():
# A 0-dimensional variable is probably a grid mapping variable;
# in any case, it doesn't have the dimensions of the cube, so
# isn't part of the range.
continue

Check warning on line 611 in xcube/webapi/ows/coverages/controllers.py

View check run for this annotation

Codecov / codecov/patch

xcube/webapi/ows/coverages/controllers.py#L611

Added line #L611 was not covered by tests
result['field'].append(
dict(
type='Quantity',
name=var_name,
description=get_dataarray_description(ds[var_name]),
description=get_dataarray_description(variable),
encodingInfo=dict(
dataType=dtype_to_opengis_datatype(ds[var_name].dtype)
dataType=dtype_to_opengis_datatype(variable.dtype)
),
)
)
Expand Down
11 changes: 7 additions & 4 deletions xcube/webapi/ows/stac/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,23 +396,26 @@ def get_collection_schema(
_assert_valid_collection(ctx, collection_id)

ml_dataset = ctx.get_ml_dataset(collection_id)
dataset = ml_dataset.base_dataset
ds = ml_dataset.base_dataset

def get_title(var_name: str) -> str:
attrs = dataset[var_name].attrs
attrs = ds[var_name].attrs
return attrs['long_name'] if 'long_name' in attrs else var_name

return {
'$schema': 'https://json-schema.org/draft/2020-12/schema',
'$id': f'{base_url}{PATH_PREFIX}/{collection_id}/schema',
'title': collection_id, # TODO use actual title, if defined
'title': ds.attrs['title'] if 'title' in ds.attrs else collection_id,
'type': 'object',
'properties': {
var_name: {
'title': get_title(var_name),
'type': 'number',
'x-ogc-property-seq': index + 1,
} for index, var_name in enumerate(dataset.data_vars.keys())
} for index, var_name in enumerate(
# Exclude 0-dimensional vars (usually grid mapping variables)
{k: v for k, v in ds.data_vars.items() if v.dims != ()}.keys()
)
}
}

Expand Down

0 comments on commit de5e27a

Please sign in to comment.