diff --git a/datasets/datasets.json b/datasets/datasets.json index 6eecbdc..2e7194a 100644 --- a/datasets/datasets.json +++ b/datasets/datasets.json @@ -9,7 +9,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/cbofs_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "mllwtomsl", - "vdatum_name": "mllw" + "vdatum_name": "mllw", + "multiplier": -1.0 }, "roms": {} } @@ -24,7 +25,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/ciofs_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "mllwtomsl", - "vdatum_name": "mllw" + "vdatum_name": "mllw", + "multiplier": -1.0 }, "roms": {} } @@ -39,7 +41,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/creofs_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "mllwtomsl", - "vdatum_name": "mllw" + "vdatum_name": "mllw", + "multiplier": -1.0 } } }, @@ -53,7 +56,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/dbofs_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "mllwtomsl", - "vdatum_name": "mllw" + "vdatum_name": "mllw", + "multiplier": -1.0 }, "roms": {} } @@ -68,7 +72,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/gomofs_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "mllwtomsl", - "vdatum_name": "mllw" + "vdatum_name": "mllw", + "multiplier": -1.0 }, "roms": {} } @@ -83,7 +88,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/gomofs_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "mllwtomsl", - "vdatum_name": "mllw" + "vdatum_name": "mllw", + "multiplier": -1.0 }, "roms": {} } @@ -98,7 +104,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/leofs_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "igld85tolwd", - "vdatum_name": "igld85" + "vdatum_name": "igld85", + "multiplier": -1.0 } } }, @@ -112,7 +119,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/lmhofs_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "igld85tolwd", - "vdatum_name": "igld85" + "vdatum_name": "igld85", + "multiplier": 1.0 } } }, @@ -126,7 +134,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/loofs_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "igld85tolwd", - "vdatum_name": "igld85" + "vdatum_name": "igld85", + "multiplier": 1.0 } } }, @@ -140,7 +149,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/lsofs_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "igld85tolwd", - "vdatum_name": "igld85" + "vdatum_name": "igld85", + "multiplier": 1.0 } } }, @@ -161,7 +171,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/ngofs2_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "mllwtomsl", - "vdatum_name": "mllw" + "vdatum_name": "mllw", + "multiplier": -1.0 } } }, @@ -175,7 +186,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/ngofs2_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "mllwtomsl", - "vdatum_name": "mllw" + "vdatum_name": "mllw", + "multiplier": -1.0 } } }, @@ -189,7 +201,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/sfbofs_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "mllwtomsl", - "vdatum_name": "mllw" + "vdatum_name": "mllw", + "multiplier": -1.0 } } }, @@ -209,7 +222,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/tbofs_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "mllwtomsl", - "vdatum_name": "mllw" + "vdatum_name": "mllw", + "multiplier": -1.0 }, "roms": {} } @@ -224,7 +238,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/wcofs_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "mllwtomsl", - "vdatum_name": "mllw" + "vdatum_name": "mllw", + "multiplier": -1.0 }, "roms": {} } @@ -239,7 +254,8 @@ "path": "s3://nextgen-dmac-cloud-ingest/nos_vdatums/wcofs_vdatums.nc.zarr", "water_level_var": "zeta", "vdatum_var": "mllwtomsl", - "vdatum_name": "mllw" + "vdatum_name": "mllw", + "multiplier": -1.0 }, "roms": {} } diff --git a/xreds/extensions/vdatum.py b/xreds/extensions/vdatum.py index 8929a78..652cafa 100644 --- a/xreds/extensions/vdatum.py +++ b/xreds/extensions/vdatum.py @@ -1,3 +1,4 @@ +from typing import Literal import xarray as xr from xreds.config import settings @@ -13,6 +14,7 @@ def transform_datum( target_zeta_var: str, target_datum_var: str, target_datum_name: str, + multiplier: float, out_datum_var: str, ) -> xr.Dataset: """Transform the dataset to target datum @@ -20,6 +22,11 @@ def transform_datum( Args: ds (xr.Dataset): The dataset to transform ds_vdatum (xr.Dataset): The vdatum dataset + target_zeta_var (str): The variable name of the water level + target_datum_var (str): The variable name of the target datum + target_datum_name (str): The name of the target datum + multiplier (float): The multiplier to apply to the target datum. Usually 1.0 or -1.0 + out_datum_var (str): The name of the output variable Returns: xr.Dataset: The transformed dataset @@ -36,7 +43,7 @@ def transform_datum( for o, k in new_dims.items(): assert ds_vdatum[target_datum_var][o].shape == ds.zeta[k].shape - zeta_to_datum = zeta - datum.rename(new_dims) + zeta_to_datum = zeta + (multiplier * datum.rename(new_dims)) zeta_to_datum = zeta_to_datum.assign_attrs({"datum": target_datum_name}) ds_transformed = ds.assign({out_datum_var: zeta_to_datum}) @@ -75,6 +82,7 @@ def transform_dataset(self, ds: xr.Dataset, config: dict) -> xr.Dataset: target_zeta_var = config.get("water_level_var", "zeta") target_datum_var = config.get("vdatum_var", None) target_datum_name = config.get("vdatum_name", None) + multiplier = config.get("multiplier", 1.0) if target_datum_var is None or target_datum_name is None: logger.warning( @@ -84,5 +92,13 @@ def transform_dataset(self, ds: xr.Dataset, config: dict) -> xr.Dataset: out_datum_var = f"{target_zeta_var}_{target_datum_name}" - ds_transformed = transform_datum(ds, ds_vdatum, target_zeta_var, target_datum_var, target_datum_name, out_datum_var) + ds_transformed = transform_datum( + ds, + ds_vdatum, + target_zeta_var, + target_datum_var, + target_datum_name, + multiplier, + out_datum_var + ) return ds_transformed