Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: reading 'positive' attribute back to the depth dimension #103

Merged
merged 5 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,36 @@ The `copernicusmarine` offers capabilities through both **Command Line Interface

## Installation


For installation, multiple options are available depending on your setup:

### Mamba | Conda


A `conda` package is available on [Anaconda](https://anaconda.org/conda-forge/copernicusmarine).

You can install it using `mamba` (or conda) through the `conda-forge` channel with the following command:


```bash
mamba install conda-forge::copernicusmarine --yes
```

To upgrade the Toolbox with mamba (or conda):


```bash
mamba update --name copernicusmarine copernicusmarine --yes
```

### Docker


A docker image is also available here: [https://hub.docker.com/r/copernicusmarine/copernicusmarine](https://hub.docker.com/r/copernicusmarine/copernicusmarine)

First step is to pull the container image:


```bash
docker pull copernicusmarine/copernicusmarine:latest
```

Then run it:


```bash
docker run -it --rm copernicusmarine/copernicusmarine --version
```
Expand All @@ -75,14 +68,12 @@ python -m pip install copernicusmarine

And to **upgrade the package** to the newest available version, run:


```bash
python -m pip install copernicusmarine --upgrade
```

## User Guide


For more comprehensive details on how to use the `copernicusmarine` Toolbox, please refer to our [Help Center](https://help.marine.copernicus.eu/en/collections/9080063-copernicus-marine-toolbox). It ensures a smooth migration for existing users of legacy services such as MOTU, OPeNDAP or FTP.

### Network configuration
Expand Down Expand Up @@ -174,7 +165,6 @@ You can use the `--skip-if-user-logged-in` option to skip the configuration file

#### Access points migration and evolution


If you still have a configuration for legacy services (e.g. `~/motuclient/motuclient-python.ini`, `~/.netrc` or `~/_netrc`) in your home directory, it will automatically be taken into account with commands `get` and `subset` without the need for running the `login` command.
If the configuration files are already available in another directory, when running commands `subset` or `get`, you can use the `--credentials-file` option to point to the files.

Expand Down
6 changes: 4 additions & 2 deletions copernicusmarine/core_functions/credentials_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
# TODO: handle cache of the credentials without cachier


class CredentialCannotBeNone(Exception): ...
class CredentialCannotBeNone(Exception):
...


class InvalidUsernameOrPassword(Exception): ...
class InvalidUsernameOrPassword(Exception):
...


def _load_credential_from_copernicus_marine_configuration_file(
Expand Down
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":
Comment on lines +380 to +384
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might seem weird but makes quite sense and it will all be deleted with the other PR... but I wanted to keep it separated just in case.

attrs["valid_min"] = coord.values.min()
attrs["valid_max"] = coord.values.max()
elif coordinate_label == "longitude":
Expand Down
75 changes: 20 additions & 55 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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