Skip to content

Commit a8ed467

Browse files
committed
Extension/datacube - applied suggest changes from pr #645
1 parent f4f5d83 commit a8ed467

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
([#590](https://github.com/stac-utils/pystac/pull/590))
1919
- Links will get their `title` from their target if no `title` is provided ([#607](https://github.com/stac-utils/pystac/pull/607))
2020
- Relax typing on `LabelClasses` from `List` to `Sequence` ([#627](https://github.com/stac-utils/pystac/pull/627))
21+
- Upgraded datacube-extension to version 2.0.0 ([#645](https://github.com/stac-utils/pystac/pull/645))
2122

2223
### Fixed
2324

docs/api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,14 @@ AdditionalDimension
362362
:show-inheritance:
363363
:inherited-members:
364364

365+
Variable
366+
~~~~~~~~
367+
368+
.. autoclass:: pystac.extensions.datacube.Variable
369+
:members:
370+
:show-inheritance:
371+
:inherited-members:
372+
365373
DatacubeExtension
366374
~~~~~~~~~~~~~~~~~
367375

pystac/extensions/datacube.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
T = TypeVar("T", pystac.Collection, pystac.Item, pystac.Asset)
1919

20-
SCHEMA_URI = "https://stac-extensions.github.io/datacube/v1.0.0/schema.json"
20+
SCHEMA_URI = "https://stac-extensions.github.io/datacube/v2.0.0/schema.json"
2121

2222
PREFIX: str = "cube:"
2323
DIMENSIONS_PROP = PREFIX + "dimensions"
@@ -34,6 +34,14 @@
3434
DIM_REF_SYS_PROP = "reference_system"
3535
DIM_UNIT_PROP = "unit"
3636

37+
# Variable properties
38+
VAR_TYPE_PROP = "type"
39+
VAR_DESC_PROP = "description"
40+
VAR_EXTENT_PROP = "extent"
41+
VAR_VALUES_PROP = "values"
42+
VAR_DIMENSIONS_PROP = "dimensions"
43+
VAR_UNIT_PROP = "unit"
44+
3745

3846
class DimensionType(str, Enum):
3947
"""Dimension object types for spatial and temporal Dimension Objects."""
@@ -415,81 +423,81 @@ def __init__(self, properties: Dict[str, Any]) -> None:
415423

416424
@property
417425
def dimensions(self) -> List[str]:
418-
"""The dimensions of the variable. Should refer to keys in the `cube:dimensions` object
419-
or be an empty list if the variable has no dimensions"""
426+
"""The dimensions of the variable. Should refer to keys in the ``cube:dimensions``
427+
object or be an empty list if the variable has no dimensions"""
420428
return get_required(
421-
self.properties.get(DIM_DIMENSIONS_PROP),
429+
self.properties.get(VAR_DIMENSIONS_PROP),
422430
"cube:variable",
423-
DIM_DIMENSIONS_PROP,
431+
VAR_DIMENSIONS_PROP,
424432
)
425433

426434
@dimensions.setter
427435
def dimensions(self, v: List[str]) -> None:
428-
self.properties[DIM_DIMENSIONS_PROP] = v
436+
self.properties[VAR_DIMENSIONS_PROP] = v
429437

430438
@property
431439
def var_type(self) -> Union[VariableType, str]:
432-
"""Type of the variable, either `data` or `auxiliary`"""
440+
"""Type of the variable, either ``data`` or ``auxiliary``"""
433441
return get_required(
434-
self.properties.get(DIM_TYPE_PROP), "cube:variable", DIM_TYPE_PROP
442+
self.properties.get(VAR_TYPE_PROP), "cube:variable", VAR_TYPE_PROP
435443
)
436444

437445
@var_type.setter
438446
def var_type(self, v: Union[VariableType, str]) -> None:
439-
self.properties[DIM_TYPE_PROP] = v
447+
self.properties[VAR_TYPE_PROP] = v
440448

441449
@property
442450
def description(self) -> Optional[str]:
443451
"""Detailed multi-line description to explain the variable. `CommonMark 0.29
444452
<http://commonmark.org/>`__ syntax MAY be used for rich text representation."""
445-
return self.properties.get(DIM_DESC_PROP)
453+
return self.properties.get(VAR_DESC_PROP)
446454

447455
@description.setter
448456
def description(self, v: Optional[str]) -> None:
449457
if v is None:
450-
self.properties.pop(DIM_DESC_PROP, None)
458+
self.properties.pop(VAR_DESC_PROP, None)
451459
else:
452-
self.properties[DIM_DESC_PROP] = v
460+
self.properties[VAR_DESC_PROP] = v
453461

454462
@property
455463
def extent(self) -> List[Union[float, str, None]]:
456464
"""If the variable consists of `ordinal values
457465
<https://en.wikipedia.org/wiki/Level_of_measurement#Ordinal_scale>`, the extent
458-
(lower and upper bounds) of the values as two-dimensional array. Use `None` for
459-
open intervals"""
466+
(lower and upper bounds) of the values as two-dimensional array. Use ``None``
467+
for open intervals"""
460468
return get_required(
461-
self.properties.get(DIM_EXTENT_PROP), "cube:variable", DIM_EXTENT_PROP
469+
self.properties.get(VAR_EXTENT_PROP), "cube:variable", VAR_EXTENT_PROP
462470
)
463471

464472
@extent.setter
465473
def extent(self, v: List[Union[float, str, None]]) -> None:
466-
self.properties[DIM_EXTENT_PROP] = v
474+
self.properties[VAR_EXTENT_PROP] = v
467475

468476
@property
469477
def values(self) -> Optional[List[Union[float, str]]]:
470478
"""A set of all potential values, especially useful for `nominal values
471479
<https://en.wikipedia.org/wiki/Level_of_measurement#Nominal_level>`."""
472-
return self.properties.get(DIM_VALUES_PROP)
480+
return self.properties.get(VAR_VALUES_PROP)
473481

474482
@values.setter
475483
def values(self, v: Optional[List[Union[float, str]]]) -> None:
476484
if v is None:
477-
self.properties.pop(DIM_VALUES_PROP)
485+
self.properties.pop(VAR_VALUES_PROP)
478486
else:
479-
self.properties[DIM_VALUES_PROP] = v
487+
self.properties[VAR_VALUES_PROP] = v
480488

481489
@property
482490
def unit(self) -> Optional[str]:
483491
"""The unit of measurement for the data, preferably compliant to `UDUNITS-2
484492
<https://ncics.org/portfolio/other-resources/udunits2/>` units (singular)"""
485-
return self.properties.get(DIM_UNIT_PROP)
493+
return self.properties.get(VAR_UNIT_PROP)
486494

487495
@unit.setter
488496
def unit(self, v: Optional[str]) -> None:
489497
if v is None:
490-
self.properties.pop(DIM_UNIT_PROP)
498+
self.properties.pop(VAR_UNIT_PROP)
491499
else:
492-
self.properties[DIM_UNIT_PROP] = v
500+
self.properties[VAR_UNIT_PROP] = v
493501

494502
@staticmethod
495503
def from_dict(d: Dict[str, Any]) -> "Variable":

tests/data-files/datacube/item.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"stac_version": "1.0.0-rc.1",
33
"stac_extensions": [
4-
"https://stac-extensions.github.io/datacube/v1.0.0/schema.json"
4+
"https://stac-extensions.github.io/datacube/v2.0.0/schema.json"
55
],
66
"id": "datacube-123",
77
"type": "Feature",

0 commit comments

Comments
 (0)