Skip to content

Commit

Permalink
no updates in theory
Browse files Browse the repository at this point in the history
  • Loading branch information
uriii3 committed Jan 16, 2025
1 parent 38fa222 commit e72b349
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 47 deletions.
23 changes: 15 additions & 8 deletions copernicusmarine/download_functions/subset_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"longitude": ["longitude", "nav_lon", "y", "lon"],
"time": ["time_counter", "time"],
"depth": ["depth", "deptht", "elevation"],
"x": ["x"],
"y": ["y"],
}

NETCDF_CONVENTION_VARIABLE_ATTRIBUTES = [
Expand Down Expand Up @@ -146,7 +148,7 @@ def _nearest_selection(

def _dataset_custom_sel(
dataset: xarray.Dataset,
coord_type: Literal["latitude", "longitude", "depth", "time"],
coord_type: Literal["latitude", "longitude", "depth", "time", "x", "y"],
coord_selection: Union[float, slice, datetime, None],
coordinates_selection_method: CoordinatesSelectionMethod,
) -> xarray.Dataset:
Expand Down Expand Up @@ -290,9 +292,12 @@ def _y_subset(
if minimum_y == maximum_y
else slice(minimum_y, maximum_y)
)
dataset = dataset.sel(
{"y": y_selection}
) # TODO: add the custom selection
return _dataset_custom_sel(
dataset,
"y",
y_selection,
coordinates_selection_method,
)

return dataset

Expand All @@ -310,10 +315,12 @@ def _x_subset(
if minimum_x == maximum_x
else slice(minimum_x, maximum_x)
)
dataset = dataset.sel(
{"x": x_selection}
) # TODO: add the custom selection

return _dataset_custom_sel(
dataset,
"x",
x_selection,
coordinates_selection_method,
)
return dataset


Expand Down
77 changes: 38 additions & 39 deletions tests/test_originalGrid_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
["cmems_mod_arc_bgc_anfc_ecosmo_P1D-m", "2020"],
["cmems_mod_arc_bgc_anfc_ecosmo_P1M-m", "2020"],
["cmems_mod_arc_phy_anfc_6km_detided_PT1H-i", "2022"],
["cmems_mod_arc_phy_anfc_6km_detided_PT6H-m", "2020"],
["cmems_mod_arc_phy_anfc_6km_detided_P1D-m", "2020"],
["cmems_mod_arc_phy_anfc_6km_detided_P1M-m", "2020"],
["cmems_mod_arc_phy_anfc_6km_detided_PT6H-m", "2024"],
["cmems_mod_arc_phy_anfc_6km_detided_P1D-m", "2024"],
["cmems_mod_arc_phy_anfc_6km_detided_P1M-m", "2024"],
# "cmems_mod_arc_phy_anfc_nextsim_P1M-m", "2020", # not yet available
# "cmems_mod_arc_phy_anfc_nextsim_hm", # not yet available
# "dataset-topaz6-arc-15min-3km-be", # not yet available
Expand Down Expand Up @@ -149,39 +149,38 @@ def test_originalGrid_works_when_time_and_depth_subsetting(self, tmp_path):

def test_originalGrid_works_when_subsetting(self):
for dataset_info in datasets_w_originalGrid:
dataset_name = dataset_info[0]
dataset_year = dataset_info[1]
command = [
"copernicusmarine",
"subset",
"-i",
dataset_name,
"--dataset-part",
"originalGrid",
"--maximum-x",
"8",
"--minimum-x",
"6",
"--maximum-y",
"10",
"--minimum-y",
"5",
"-t",
dataset_year,
"-T",
dataset_year,
"--dry-run",
]
self.output = execute_in_terminal(command)
assert self.output.returncode == 0
returned_value = loads(self.output.stdout)
assert (
returned_value["coordinates_extent"][0]["coordinate_id"] == "y"
)
assert returned_value["coordinates_extent"][0]["maximum"] == 10
assert returned_value["coordinates_extent"][0]["minimum"] == 5
assert (
returned_value["coordinates_extent"][1]["coordinate_id"] == "x"
)
assert returned_value["coordinates_extent"][1]["maximum"] == 8
assert returned_value["coordinates_extent"][1]["minimum"] == 6
self.run_one_dataset(dataset_info)

def run_one_dataset(self, dataset_info):
dataset_name = dataset_info[0]
dataset_year = dataset_info[1]
command = [
"copernicusmarine",
"subset",
"-i",
dataset_name,
"--dataset-part",
"originalGrid",
"--maximum-x",
"8",
"--minimum-x",
"6",
"--maximum-y",
"10",
"--minimum-y",
"5",
"-t",
dataset_year,
"-T",
dataset_year,
"--dry-run",
]
self.output = execute_in_terminal(command)
assert self.output.returncode == 0
returned_value = loads(self.output.stdout)
assert returned_value["coordinates_extent"][0]["coordinate_id"] == "y"
assert returned_value["coordinates_extent"][0]["maximum"] == 10
assert returned_value["coordinates_extent"][0]["minimum"] == 5
assert returned_value["coordinates_extent"][1]["coordinate_id"] == "x"
assert returned_value["coordinates_extent"][1]["maximum"] == 8
assert returned_value["coordinates_extent"][1]["minimum"] == 6

0 comments on commit e72b349

Please sign in to comment.