Skip to content

Commit

Permalink
raise exception if projection info is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
observingClouds committed Jan 10, 2025
1 parent b4c67d7 commit 60bda54
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mllam_data_prep/ops/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ def validate_projection_consistency(
>>> validate_projection_consistency([proj2, proj4])
Traceback (most recent call last):
...
ValueError: Multiple projections found in the dataset.Currently only one projection is supported.
NotImplementedError: Multiple projections found in the dataset. Currently only one projection is supported.
"""
proj_obs = [pyproj.CRS.from_cf(proj) for proj in projections]

# Check that all projections are the same
if len(set(proj_obs)) > 1:
raise ValueError(
"Multiple projections found in the dataset."
raise NotImplementedError(
"Multiple projections found in the dataset. "
"Currently only one projection is supported."
)

Expand Down Expand Up @@ -256,7 +256,7 @@ def get_projection_crs(ds: xr.Dataset) -> Dict[str, Any]:
vars_wo_proj = set(ds.data_vars) - set(vars_w_proj.keys()) - proj_vars

if len(proj_vars) > 1:
raise ValueError(
raise NotImplementedError(
f"Multiple referenced projections found in the dataset {ds.encoding.get('source',None)}: {proj_vars}. "
"Currently only one projection is supported."
)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_from_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,28 @@ def test_projection_from_config(projection: Dict):
), "CRS mismatch"


@pytest.mark.parametrize(
"projection",
[
{"proj2": {"dims": "[x y]", "crs_wkt": "EPSG:4326"}},
],
)
def test_requirement_of_single_projection(projection: Dict):
"""
Test that assertion is raised when projections
are missing from input datasets.
"""
# Adding projection config to the example config
config = yaml.safe_load(testconfig.VALID_EXAMPLE_CONFIG_YAML)
config["inputs"]["danra_surface"]["projections"] = projection
config_yaml = yaml.dump(config)

config = mdp.Config.from_yaml(config_yaml)

with pytest.raises(NotImplementedError):
mdp.create_dataset(config=config)


def test_danra_example():
fp_config = Path(__file__).parent.parent / "example.danra.yaml"
with tempfile.TemporaryDirectory(suffix=".zarr") as tmpdir:
Expand Down

0 comments on commit 60bda54

Please sign in to comment.