Skip to content

Commit 84668d2

Browse files
committed
Fix: add pydantic check on var_template_shape for zarr
1 parent 44414a5 commit 84668d2

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

aodn_cloud_optimised/bin/generic_cloud_optimised_creation.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ class ZarrSchemaTransformation(BaseModel):
456456
default_factory=dict,
457457
description="Global attributes to modify. Supports 'delete' and 'set' keys.",
458458
)
459+
var_template_shape: Union[str, List[str]] = Field(
460+
..., description="Variable name(s) used to define the template shape."
461+
)
459462
dimensions: Optional[dict[str, dict[str, Any]]] = None
460463
dataset_sort_by: Optional[list[str]] = None
461464
vars_incompatible_with_region: Optional[list[str]] = None
@@ -638,6 +641,31 @@ def validate_add_variables(cls, value):
638641

639642
return value
640643

644+
@model_validator(mode="after")
645+
def validate_var_template_shape(self) -> "ZarrSchemaTransformation":
646+
# 1. Ensure it's not empty
647+
if not self.var_template_shape:
648+
raise ValueError("var_template_shape cannot be empty.")
649+
650+
# 2. Coerce to a list for easier validation logic
651+
vars_to_check = (
652+
[self.var_template_shape]
653+
if isinstance(self.var_template_shape, str)
654+
else self.var_template_shape
655+
)
656+
657+
# 3. Check that every variable exists in the dataset_schema
658+
schema_keys = self.dataset_schema.keys()
659+
missing = [v for v in vars_to_check if v not in schema_keys]
660+
661+
if missing:
662+
raise ValueError(
663+
f"var_template_shape variable(s) {missing} not found in 'schema'. "
664+
f"Available variables: {list(schema_keys)}"
665+
)
666+
667+
return self
668+
641669
# @model_validator(mode="after")
642670
# def validate_gattrs_to_variable_dimensions(self) -> "DatasetConfig":
643671
# if self.gattrs_to_variables:

aodn_cloud_optimised/config/dataset/satellite_optical_water_type_1day_snpp.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
"batch_size": 60
4141
},
4242
"metadata_uuid": "8f44f09a-07a3-4f9b-ba26-2fc4983fef69",
43+
"schema_transformation": {
44+
"global_attributes": {
45+
"set": {
46+
"title": ""
47+
}
48+
},
49+
"var_template_shape": "owtd_csiro"
50+
},
4351
"schema": {
4452
"time": {
4553
"type": "timestamp[ns]",

aodn_cloud_optimised/config/dataset/satellite_sst_1day_aqua.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"type": "files",
1010
"s3_uri": "s3://imos-data/IMOS/SRS/OC/gridded/aqua/P1D/",
1111
"filter": [
12-
".*sst\\.nc$"
12+
".*\\.aust\\.sst\\.nc"
1313
],
1414
"year_range": [
1515
2002,
@@ -40,6 +40,14 @@
4040
"batch_size": 60
4141
},
4242
"metadata_uuid": "468f550b-bbd8-42b1-91b5-313d5898d9e6",
43+
"schema_transformation": {
44+
"global_attributes": {
45+
"set": {
46+
"title": ""
47+
}
48+
},
49+
"var_template_shape": "sst"
50+
},
4351
"schema": {
4452
"time": {
4553
"type": "timestamp[ns]",

aodn_cloud_optimised/config/dataset/satellite_sst_1day_snpp.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"type": "files",
1010
"s3_uri": "s3://imos-data/IMOS/SRS/OC/gridded/snpp/P1D/",
1111
"filter": [
12-
".*sst\\.nc$"
12+
".*\\.aust\\.sst\\.nc"
1313
],
1414
"year_range": [
1515
2022,
@@ -40,6 +40,14 @@
4040
"batch_size": 60
4141
},
4242
"metadata_uuid": "8e00907f-716d-4080-b212-534fcd78a602",
43+
"schema_transformation": {
44+
"global_attributes": {
45+
"set": {
46+
"title": ""
47+
}
48+
},
49+
"var_template_shape": "sst"
50+
},
4351
"schema": {
4452
"time": {
4553
"type": "timestamp[ns]",

0 commit comments

Comments
 (0)