Skip to content

Commit

Permalink
Updated datacube to schema 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
huard committed Nov 15, 2023
1 parent a56dbef commit 93af1ac
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 46 deletions.
2 changes: 1 addition & 1 deletion STACpopulator/implementations/CMIP6_UofT/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def dimensions(self) -> dict:
extent = ["", ""]

properties = dict(
type=type_,
type=type_.value,
extent=extent,
description=v.get("description", v.get("long_name", criteria["standard_name"][0])) or "",
)
Expand Down
194 changes: 150 additions & 44 deletions tests/schemas/datacube.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,67 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://stac-extensions.github.io/datacube/v2.0.0/schema.json",
"$id": "https://stac-extensions.github.io/datacube/v2.2.0/schema.json",
"title": "Datacube Extension",
"description": "Datacube Extension for STAC Items and STAC Collections.",
"description": "STAC Datacube Extension for STAC Items and STAC Collections.",
"oneOf": [
{
"$comment": "This is the schema for STAC Items. Remove this object if this extension only applies to Collections.",
"$comment": "This is the schema for STAC Items.",
"allOf": [
{
"$ref": "#/definitions/stac_extensions"
},
{
"type": "object",
"required": [
"type",
"properties",
"assets"
"type"
],
"properties": {
"type": {
"const": "Feature"
},
}
}
},
{
"$ref": "#/definitions/stac_extensions"
}
],
"anyOf": [
{
"type": "object",
"required": [
"properties"
],
"properties": {
"properties": {
"allOf": [
{
"$comment": "Require fields here for Item Properties.",
"required": [
"cube:dimensions"
]
"$ref": "#/definitions/require_field"
},
{
"$ref": "#/definitions/fields"
}
]
},
}
}
},
{
"$comment": "This validates the fields in Item Assets.",
"required": [
"assets"
],
"properties": {
"assets": {
"$comment": "This validates the fields in Item Assets, but does not require them.",
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/fields"
"not": {
"additionalProperties": {
"not": {
"allOf": [
{
"$ref": "#/definitions/require_field"
},
{
"$ref": "#/definitions/fields"
}
]
}
}
}
}
}
Expand All @@ -65,21 +88,18 @@
],
"anyOf": [
{
"$comment": "This is the schema for the top-level fields in a Collection. Remove this if this extension does not define top-level fields for Collections.",
"$comment": "This is the schema for the top-level fields in a Collection.",
"allOf": [
{
"$comment": "Require fields here for Collections (top-level).",
"required": [
"cube:dimensions"
]
"$ref": "#/definitions/require_field"
},
{
"$ref": "#/definitions/fields"
}
]
},
{
"$comment": "This validates the fields in Collection Assets, but does not require them.",
"$comment": "This validates the fields in Collection Assets.",
"required": [
"assets"
],
Expand All @@ -91,7 +111,7 @@
"not": {
"allOf": [
{
"$ref": "#/definitions/require_any_field"
"$ref": "#/definitions/require_field"
},
{
"$ref": "#/definitions/fields"
Expand All @@ -104,7 +124,7 @@
}
},
{
"$comment": "This is the schema for the fields in Item Asset Definitions. It doesn't require any fields.",
"$comment": "This is the schema for the fields in Item Asset Definitions.",
"required": [
"item_assets"
],
Expand Down Expand Up @@ -152,7 +172,7 @@
"stac_extensions": {
"type": "array",
"contains": {
"const": "https://stac-extensions.github.io/datacube/v2.0.0/schema.json"
"const": "https://stac-extensions.github.io/datacube/v2.2.0/schema.json"
}
}
}
Expand All @@ -164,6 +184,11 @@
{"required": ["cube:variables"]}
]
},
"require_field": {
"required": [
"cube:dimensions"
]
},
"fields": {
"$comment": "Add your new fields here. Don't require them here, do that above in the corresponding schema.",
"type": "object",
Expand All @@ -185,7 +210,7 @@
"additionalProperties": {
"anyOf": [
{
"$ref": "#/definitions/additional_dimension"
"$ref": "#/definitions/vector_dimension"
},
{
"$ref": "#/definitions/horizontal_spatial_dimension"
Expand All @@ -195,6 +220,9 @@
},
{
"$ref": "#/definitions/temporal_dimension"
},
{
"$ref": "#/definitions/additional_dimension"
}
]
}
Expand Down Expand Up @@ -229,17 +257,13 @@
},
"properties": {
"type": {
"allOf": [
{
"type": "string"
},
{
"not": {
"type": "string",
"const": "spatial"
}
}
]
"type": "string",
"not": {
"enum": [
"spatial",
"geometry"
]
}
},
"description": {
"$ref": "#/definitions/description"
Expand Down Expand Up @@ -270,7 +294,7 @@
}
},
"horizontal_spatial_dimension": {
"title": "Horizontal Spatial Dimension Object",
"title": "Horizontal Spatial Raster Dimension Object",
"type": "object",
"required": [
"type",
Expand Down Expand Up @@ -347,6 +371,79 @@
}
}
},
"vector_dimension": {
"title": "Spatial Vector Dimension Object",
"type": "object",
"required": [
"type",
"bbox"
],
"properties": {
"type": {
"type": "string",
"const": "geometry"
},
"axes": {
"type": "array",
"uniqueItems": true,
"items": {
"type": "string",
"enum": [
"x",
"y",
"z"
]
}
},
"description": {
"$ref": "#/definitions/description"
},
"bbox": {
"title": "Spatial extent",
"type": "array",
"oneOf": [
{
"minItems":4,
"maxItems":4
},
{
"minItems":6,
"maxItems":6
}
],
"items": {
"type": "number"
}
},
"values": {
"type": "array",
"minItems": 1,
"items": {
"description": "WKT or Identifier",
"type": "string"
}
},
"geometry_types": {
"type": "array",
"uniqueItems": true,
"items": {
"type": "string",
"enum": [
"Point",
"MultiPoint",
"LineString",
"MultiLineString",
"Polygon",
"MultiPolygon",
"GeometryCollection"
]
}
},
"reference_system": {
"$ref": "#/definitions/reference_system_spatial"
}
}
},
"temporal_dimension": {
"title": "Temporal Dimension Object",
"type": "object",
Expand Down Expand Up @@ -502,10 +599,19 @@
"type": "string"
},
"reference_system_spatial": {
"type": [
"string",
"number",
"object"
"oneOf": [
{
"description": "WKT2",
"type": "string"
},
{
"description": "EPSG code",
"type": "integer",
"minimum": 0
},
{
"$ref": "https://proj.org/schemas/v0.4/projjson.schema.json"
}
],
"default": 4326
},
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cmip6_datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from STACpopulator.stac_utils import STAC_item_from_metadata
from STACpopulator.implementations.CMIP6_UofT.add_CMIP6 import CMIP6ItemProperties
from STACpopulator.models import GeoJSONPolygon
import json
from pystac import Item
from pystac.validation.stac_validator import JsonSchemaSTACValidator

Expand All @@ -27,7 +26,9 @@ def test_datacube_helper():
# Validate
schema_uri = DIR / "schemas" / "datacube.json"
val = JsonSchemaSTACValidator()

val.validate_extension(stac_dict=item.to_dict(),
stac_object_type=Item,
stac_version="1.0",
extension_id=schema_uri)

0 comments on commit 93af1ac

Please sign in to comment.