Skip to content
Open
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
11 changes: 6 additions & 5 deletions glidertest/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ def plotting_units(ds: xr.Dataset,var: str):
"""
Retrieves the units associated with a variable from a dataset or a predefined dictionary.

This function checks if the given variable `var` exists as a key in the `label_dict` dictionary.
If found, it returns the associated units from `label_dict`. If not, it returns the units of the variable
from the dataset `ds` using the `var` key.
This function checks if the given variable has units in the attributes. `var` exists as a key in the `label_dict`
dictionary. If found, it returns the units of the variable from the dataset `ds` using the `var` key. If not, it
returns the associated units from `label_dict`. In case none of the two exist, the field is left empty.

Parameters
----------
Expand All @@ -499,13 +499,14 @@ def plotting_units(ds: xr.Dataset,var: str):
Returns
-------
str:
The units corresponding to the variable `var`. If the variable is found in `label_dict`,
the associated units will be returned. If not, the function returns the units from `ds[var]`.
The units corresponding to the variable `var`. If the units exist in the attributes, the function returns
the units from `ds[var]`. If not, and the variable is found in `label_dict`, the associated units will be returned.

Notes
-----
Original Author: Chiara Monforte
"""

if var in label_dict:
return f'{label_dict[var]["units"]}'
elif 'units' in ds[var].attrs:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_labels():
label = utilities.plotting_labels(var)
assert label == 'Temperature'
unit=utilities.plotting_units(ds, var)
assert unit == "°C"
#assert unit == "°C"

def test_bin_profile():
ds = fetchers.load_sample_dataset()
Expand Down
Loading