Skip to content

Commit

Permalink
fix: adding again the positive attribute in the depth dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
uriii3 committed Jul 30, 2024
1 parent 68b010d commit 1059e44
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion copernicusmarine/download_functions/subset_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,11 @@ def _update_dataset_coordinate_attributes(
coord.encoding["units"].replace("_", " ").title()
)
coordinate_attributes.remove("units")
elif coordinate_label in ["latitude", "depth", "elevation"]:
elif coordinate_label in ["depth", "elevation"]:
attrs["valid_min"] = coord.values.min()
attrs["valid_max"] = coord.values.max()
coordinate_attributes.append("positive")
elif coordinate_label == "latitude":
attrs["valid_min"] = coord.values.min()
attrs["valid_max"] = coord.values.max()
elif coordinate_label == "longitude":
Expand Down
9 changes: 6 additions & 3 deletions tests/test_command_line_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,24 +1011,27 @@ def then_I_have_correct_sign_for_depth_coordinates_values(
assert dataset.elevation.min() >= -10
assert dataset.elevation.max() <= 0

def then_I_have_correct_attribute_value(self, output_path, dimention_name):
def then_I_have_correct_attribute_value(
self, output_path, dimention_name, attribute_value
):
filepath = pathlib.Path(output_path, "data.zarr")
dataset = xarray.open_dataset(filepath, engine="zarr")
assert dataset[dimention_name].attrs["standard_name"] == dimention_name
assert dataset[dimention_name].attrs["positive"] == attribute_value

def test_conversion_between_elevation_and_depth(self, tmp_path):
self.when_I_request_subset_dataset_with_zarr_service(tmp_path, True)
self.then_I_have_correct_sign_for_depth_coordinates_values(
tmp_path, "positive"
)
self.then_I_have_correct_attribute_value(tmp_path, "depth")
self.then_I_have_correct_attribute_value(tmp_path, "depth", "down")

def test_force_no_conversion_between_elevation_and_depth(self, tmp_path):
self.when_I_request_subset_dataset_with_zarr_service(tmp_path, False)
self.then_I_have_correct_sign_for_depth_coordinates_values(
tmp_path, "negative"
)
self.then_I_have_correct_attribute_value(tmp_path, "elevation")
self.then_I_have_correct_attribute_value(tmp_path, "elevation", "up")

def when_I_run_copernicus_marine_command_using_no_directories_option(
self, tmp_path, force_service: GetServiceToTest, output_directory=None
Expand Down
1 change: 1 addition & 0 deletions tests/test_python_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def test_subset_modify_attr_for_depth(self):
dataset = open_dataset(
dataset_id="cmems_mod_arc_phy_anfc_6km_detided_P1D-m"
)
assert dataset.depth.attrs["positive"] == "down"
assert dataset.depth.attrs["standard_name"] == "depth"
assert dataset.depth.attrs["long_name"] == "Depth"

Expand Down

0 comments on commit 1059e44

Please sign in to comment.