Skip to content

Commit df3e836

Browse files
authored
Merge pull request #1177 from xcube-dev/clarasb-xxx-xcube_viewer_add_zoom_box
WebAPI: Add resolutions and spatialUnits to mldataset
2 parents bcf42d7 + 73abdc4 commit df3e836

File tree

8 files changed

+44
-29
lines changed

8 files changed

+44
-29
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
`IPyPreloadDisplay` and the progress of the preload is shown as a HTML table. (#1184)
2020

2121

22+
* `xcube serve` now provides new metadata details of a multilevel dataset:
23+
- The spatial unit of the dataset is now given by property `spatialUnits`
24+
- The resolutions are now given by property `resolutions` and provide
25+
the average x,y resolutions for each level of the dataset given in
26+
the spatial units of the dataset's CRS.
27+
28+
2229
### Other changes
2330

2431
* Added two new versions of the xcube logo, one for dark and one for light themes,

test/cli/test_dump.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,20 @@ def test_dump_ds(self):
1313
with xr.set_options(display_width=80):
1414
result = self.invoke_cli(["dump", TEST_NC_FILE])
1515

16-
# Use a regex to accommodate the differing output formats produced by
17-
# various xarray versions.
18-
output_regex = r"""<xarray.Dataset>( Size: 8MB)?
19-
Dimensions:\s+\((?=.*lon: 360)(?=.*lat: 180)(?=.*time: 5)(?=.*bnds: 2).*?\)
20-
Coordinates:
21-
\* lon \(lon\) float64 (3kB )?-179\.5 -178\.5 -177\.5 \.\.\. 177\.5 178\.5 179\.5
22-
\* lat \(lat\) float64 (1kB )?-89\.5 -88\.5 -87\.5 -86\.5 \.\.\. (86\.5 )?87\.5 88\.5 89\.5
23-
\* time \(time\) datetime64\[ns\] (40B )?2010-01-01T12:00:00 \.\.\. 2010-01-(05T1)?\.\.\.
24-
lon_bnds \(lon, bnds\) float64 (6kB )?\.\.\.
25-
lat_bnds \(lat, bnds\) float64 (3kB )?\.\.\.
26-
time_bnds \(time, bnds\) datetime64\[ns\] (80B )?\.\.\.
27-
Dimensions without coordinates: bnds
16+
self.assertIn("<xarray.Dataset>", result.output)
17+
self.assertIn("Coordinates:\n", result.output)
18+
self.assertIn(" * lon (lon) float64 ", result.output)
19+
self.assertIn("Data variables:\n", result.output)
20+
self.assertIn(" precipitation (time, lat, lon) float64 ", result.output)
21+
self.assertIn("Attributes:\n", result.output)
22+
self.assertIn("title: Test Cube", result.output)
23+
24+
variables_regex = r"""
2825
Data variables:
29-
precipitation \(time, lat, lon\) float64 (3MB )?...
30-
temperature \(time, lat, lon\) float64 (3MB )?...
31-
soil_moisture \(time, lat, lon\) float64 (3MB )?...
32-
Attributes:
33-
Conventions: CF-1.7
34-
title: Test Cube
35-
time_coverage_start: 2010-01-01T00:00:00.000000000
36-
time_coverage_end: 2010-01-06T00:00:00.000000000
37-
geospatial_lon_min: -180.0
38-
geospatial_lon_max: 180.0
39-
geospatial_lon_units: degrees_east
40-
geospatial_lat_min: -90.0
41-
geospatial_lat_max: 90.0
42-
geospatial_lat_units: degrees_north
26+
precipitation \(time, lat, lon\) float64 (3MB)? ...
27+
temperature \(time, lat, lon\) float64 (3MB)? ...
28+
soil_moisture \(time, lat, lon\) float64 (3MB)? ...
4329
"""
4430

45-
self.assertRegex(result.output, output_regex)
31+
self.assertRegex(result.output, variables_regex)
4632
self.assertEqual(0, result.exit_code)

test/core/resampling/test_reproject.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ def test_reproject_complex_dask_array(self):
217217
source_ds, target_gm=target_gm, interpolation="bilinear"
218218
)
219219
self.assertCountEqual(["temperature"], list(target_ds.data_vars))
220-
self.assertEqual(target_ds.temperature.values[0, 0, 0], 6427.718652710034)
221-
self.assertEqual(target_ds.temperature.values[0, -1, -1], 3085.9507290783004)
220+
self.assertAlmostEqual(target_ds.temperature.values[0, 0, 0], 6427.718652710034)
221+
self.assertAlmostEqual(target_ds.temperature.values[0, -1, -1], 3085.9507290783004)
222222
self.assertEqual(
223223
[2, 5, 5],
224224
[

test/webapi/datasets/test_controllers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def test_dataset_with_details(self):
7171
self.assertIsInstance(dataset.get("bbox"), (tuple, list))
7272
self.assertIsInstance(dataset.get("geometry"), dict)
7373
self.assertIsInstance(dataset.get("spatialRef"), str)
74+
self.assertIsInstance(dataset.get("resolutions"), (tuple, list))
75+
self.assertIsInstance(dataset.get("spatialUnits"), str)
7476
self.assertNotIn("rgbSchema", dataset)
7577
if dataset["id"] == "demo":
7678
demo_dataset = dataset

test/webapi/ows/stac/demo-collection.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,12 @@
524524
]
525525
},
526526
"spatialRef": "EPSG:4326",
527+
"resolutions": [
528+
0.0025,
529+
0.005,
530+
0.01
531+
],
532+
"spatialUnits": "degree",
527533
"variables": [
528534
{
529535
"id": "demo.conc_chl",

test/webapi/ows/stac/stac-datacubes-item.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@
362362
]
363363
},
364364
"spatialRef": "EPSG:4326",
365+
"resolutions": [
366+
0.0025,
367+
0.005,
368+
0.01
369+
],
370+
"spatialUnits": "degree",
365371
"variables": [
366372
{
367373
"id": "demo-1w.conc_chl",

test/webapi/ows/stac/stac-single-item.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@
362362
]
363363
},
364364
"spatialRef": "EPSG:4326",
365+
"resolutions": [
366+
0.0025,
367+
0.005,
368+
0.01
369+
],
370+
"spatialUnits": "degree",
365371
"variables": [
366372
{
367373
"id": "demo-1w.conc_chl",

xcube/webapi/datasets/controllers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ def get_dataset(
224224
dataset_dict["bbox"] = list(ds_bbox)
225225
dataset_dict["geometry"] = get_bbox_geometry(dataset_bounds, transformer)
226226
dataset_dict["spatialRef"] = crs.to_string()
227+
dataset_dict["resolutions"] = list(ml_ds.avg_resolutions)
228+
dataset_dict["spatialUnits"] = ml_ds.grid_mapping.spatial_unit_name
227229

228230
variable_dicts = []
229231
dim_names = set()

0 commit comments

Comments
 (0)