Skip to content

Commit

Permalink
WCS fixes. (cherry pick of PR #1027 to 1.9 branch) (#1028)
Browse files Browse the repository at this point in the history
* WCS fixes. (#1027)

* Check for error after retrieving ranges.

* Use correct dtype when writing out empty data in WCS1 (not required in WCS2).

* Update issue template.

* Ensure correct default behaviour when output and subsetting CRSs match.

* Pin datacube<1.9

* Add (very simple) test.

(cherry picked from commit 79b796f)

* Plug up some permissions management gaps.

* Fix old style ranges accessors in the WCS2 Scaler.

* Update WCS Scaler tests to use new format ranges.
  • Loading branch information
SpacemanPaul authored Jun 12, 2024
1 parent f827516 commit 131242c
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 46 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ assignees: ''
4.

## Context (Environment)
### `datacube-ows` version (datacube-ows --version):
<!-- Run command datacube-ows --versiion -->
### `datacube-ows` version (datacube-ows-update --version):
<!-- Run command datacube-ows-update --version -->

### `ows_config.py` file (link, sample code)
<!-- Porvide a link to config or paste the config code below -->
<!-- Provide a link to config or paste the config code below -->

### datacube product metadata (datacube product show product_name)
<!-- If issue is related to a specific layer, run `datacube product show <product_name>` to get the product metadata and provide below -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Granting select on layer ranges table to {role}

GRANT SELECT ON ows.layer_ranges TO {role};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Granting agdc_user role to {role}

GRANT agdc_user to {role};
2 changes: 1 addition & 1 deletion datacube_ows/templates/wms_capabilities.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
{% endif %}
{%- endmacro %}
{% macro render_named_layer(lyr, depth=0) -%}
{% if not lyr.hide %}
{% set lyr_ranges = lyr.ranges %}
{% if not lyr.hide %}
<Layer queryable="1">
<Name>{{ lyr.name }}</Name>
<Title>{{ lyr.title }}</Title>
Expand Down
6 changes: 4 additions & 2 deletions datacube_ows/wcs1_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,17 @@ def get_coverage_data(req, qprof):
nparrays = {
band: (("time", yname, xname),
numpy.full((len(req.times), len(yvals), len(xvals)),
req.layer.band_idx.nodata_val(band))
req.layer.band_idx.nodata_val(band),
dtype=req.layer.band_idx.dtype_val(band))
)
for band in req.bands
}
else:
nparrays = {
band: (("time", xname, yname),
numpy.full((len(req.times), len(xvals), len(yvals)),
req.layer.band_idx.nodata_val(band))
req.layer.band_idx.nodata_val(band),
dtype=req.layer.band_idx.dtype_val(band))
)
for band in req.bands
}
Expand Down
49 changes: 24 additions & 25 deletions datacube_ows/wcs_scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,26 @@ def to_crs(self, new_crs):
grid = self.layer.grids[new_crs]
skip_x_xform = False
skip_y_xform = False
if self.crs != new_crs:
if not self.subsetted.x and not self.subsetted.y:
# Neither axis subsetted
self.min.x = self.layer.ranges["bboxes"][new_crs]["left"]
self.max.x = self.layer.ranges["bboxes"][new_crs]["right"]
self.min.y = self.layer.ranges["bboxes"][new_crs]["bottom"]
self.max.y = self.layer.ranges["bboxes"][new_crs]["top"]
self.crs = new_crs
elif not self.subsetted.x or not self.subsetted.y:
# One axis subsetted
if self.subsetted.x:
self.min.y = self.layer.ranges["bboxes"][self.crs]["bottom"]
self.max.y = self.layer.ranges["bboxes"][self.crs]["top"]
skip_y_xform = True
if self.subsetted.y:
self.min.x = self.layer.ranges["bboxes"][self.crs]["left"]
self.max.x = self.layer.ranges["bboxes"][self.crs]["right"]
skip_x_xform = True
else:
# Both axes subsetted
pass
if not self.subsetted.x and not self.subsetted.y:
# Neither axis subsetted
self.min.x = self.layer.ranges.bboxes[new_crs]["left"]
self.max.x = self.layer.ranges.bboxes[new_crs]["right"]
self.min.y = self.layer.ranges.bboxes[new_crs]["bottom"]
self.max.y = self.layer.ranges.bboxes[new_crs]["top"]
self.crs = new_crs
elif not self.subsetted.x or not self.subsetted.y:
# One axis subsetted
if self.subsetted.x:
self.min.y = self.layer.ranges.bboxes[self.crs]["bottom"]
self.max.y = self.layer.ranges.bboxes[self.crs]["top"]
skip_y_xform = True
if self.subsetted.y:
self.min.x = self.layer.ranges.bboxes[self.crs]["left"]
self.max.x = self.layer.ranges.bboxes[self.crs]["right"]
skip_x_xform = True
else:
# Both axes subsetted
pass

if self.crs != new_crs:
is_point = False
Expand Down Expand Up @@ -189,14 +188,14 @@ def to_crs(self, new_crs):
proj_geom = geom.to_crs(new_crs_obj)
bbox = proj_geom.boundingbox
if skip_x_xform:
self.min.x = self.layer.ranges["bboxes"][new_crs]["left"]
self.max.x = self.layer.ranges["bboxes"][new_crs]["right"]
self.min.x = self.layer.ranges.bboxes[new_crs]["left"]
self.max.x = self.layer.ranges.bboxes[new_crs]["right"]
else:
self.min.x = bbox.left
self.max.x = bbox.right
if skip_y_xform:
self.min.y = self.layer.ranges["bboxes"][new_crs]["bottom"]
self.max.y = self.layer.ranges["bboxes"][new_crs]["top"]
self.min.y = self.layer.ranges.bboxes[new_crs]["bottom"]
self.max.y = self.layer.ranges.bboxes[new_crs]["top"]
else:
self.min.y = bbox.bottom
self.max.y = bbox.top
Expand Down
7 changes: 7 additions & 0 deletions integration_tests/test_wcs_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,13 @@ def test_wcs20_getcoverage_geotiff_bigimage(ows_server):
scalesize="x(3000),y(3000)",
)
assert "too much data for a single request" in str(e.value)
# Test default request
with pytest.raises(ServiceException) as e:
output = wcs.getCoverage(
identifier=[layer.name],
format="application/x-netcdf",
)
assert "too much data for a single request" in str(e.value)


def test_wcs20_getcoverage_netcdf(ows_server):
Expand Down
22 changes: 7 additions & 15 deletions tests/test_wcs_scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from affine import Affine

from datacube_ows.ows_configuration import OWSConfig, OWSProductLayer
from datacube_ows.index.api import CoordRange, LayerExtent
from datacube_ows.wcs_scaler import (SpatialParameter, WCSScaler,
WCSScalerUnknownDimension)

Expand Down Expand Up @@ -124,20 +125,11 @@ def layer_crs_geom():
times = [datetime.date(2013, 1, 1), datetime.date(2014, 1, 1), datetime.date(2015, 1, 1),
datetime.date(2016, 1, 1), datetime.date(2017, 1, 1), datetime.date(2018, 1, 1)]
product_layer.dynamic = False
product_layer._ranges = {
'lat': {
'min': -34.5250413940276,
'max': -33.772472435988
},
'lon': {
'min': 150.330509919584,
'max': 151.258021405841
},
'times': times,
'start_time': datetime.date(2013, 1, 1),
'end_time': datetime.date(2018, 1, 1),
'time_set': set(times),
'bboxes': {
product_layer._ranges = LayerExtent(
lat=CoordRange(min=-34.5250413940276, max=-33.772472435988),
lon=CoordRange(min=150.330509919584, max=151.258021405841),
times=times,
bboxes={
'EPSG:3111': {
'top': 5725844.213533809, 'left': -1623290.9363678931,
'right': 3983581.449863785, 'bottom': 1042109.9920098772
Expand All @@ -155,7 +147,7 @@ def layer_crs_geom():
'right': 157.105656164263, 'bottom': -45.761684927317
}
}
}
)
return product_layer


Expand Down

0 comments on commit 131242c

Please sign in to comment.