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

make dimension.py xarray compatible #397

Merged
merged 9 commits into from
Aug 12, 2024
Merged

Conversation

mats-knmi
Copy link
Contributor

Converted the methods in dimension.py to work with the new xarray datamodel. Since these methods can largely be replaced by xarray functionality, I updated these methods to make use of this.

@mats-knmi mats-knmi linked an issue Jul 19, 2024 that may be closed by this pull request
Copy link
Member

@dnerini dnerini left a comment

Choose a reason for hiding this comment

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

Fantastic work @mats-knmi ! Code is really looking much better (and this PR has a negative impact on the number of lines, brilliant!) and I know that the code you had to adapt is not easy to navigate... so well done!

I only had few minor comments, mostly concerning documentation - how are we going to make sure that the structure of the dataset is clearly documented? perhaps it could also be a good idea to add some basic input validator with a decorator, what do you think?

"""Aggregate fields in time.

Parameters
----------
R: array-like
Array of shape (t,m,n) or (l,t,m,n) containing
dataset: Dataset
Copy link
Member

Choose a reason for hiding this comment

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

I would still mention here that this is an xarray dataset, even if it's already obvious from the type hints

Copy link
Member

Choose a reason for hiding this comment

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

also, the methods expect certain attributes, not just any kind of dataset. These should be mentioned somehow. See for example the description of "metadata" where we referenced the documention in pysteps.io.importers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes indeed a documentation similar to the "metadata" description (but for the dataset structure), which we can link to from these docstrings, would be very a very useful addition. I will take a look at this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
dataset: Dataset
dataset: xarray.Dataset

Is this what you mean?

"""
Upscale fields in space.

Parameters
----------
R: array-like
Array of shape (m,n), (t,m,n) or (l,t,m,n) containing a single field or
dataset: Dataset
Copy link
Member

Choose a reason for hiding this comment

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

need to update the name in the rest of the docstrings (see the text for space_window)

metadata: dict
The metadata with updated attributes.
dataset: Dataset
The new dataset.
Copy link
Member

Choose a reason for hiding this comment

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

Is it self-explanatory how the fields are aggregate with a given spatial window?


_aggregation_methods = dict(
sum=np.sum, mean=np.mean, nanmean=np.nanmean, nansum=np.nansum
)


def aggregate_fields_time(R, metadata, time_window_min, ignore_nan=False):
def aggregate_fields_time(dataset: xr.Dataset, time_window_min, ignore_nan=False):
Copy link
Member

Choose a reason for hiding this comment

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

need to specify the type of the output, as it's not detailed in the docstrings

@mats-knmi
Copy link
Contributor Author

mats-knmi commented Jul 30, 2024

@dnerini I have added a ticket to the project backlog, for a basic input validator with a decorator.

@mats-knmi
Copy link
Contributor Author

@dnerini I believe I have also taken care of the remaining comments you had, let me know what you think

@mats-knmi mats-knmi merged commit a04b189 into xarray/main Aug 12, 2024
1 check failed
mats-knmi added a commit that referenced this pull request Sep 2, 2024
* make dimension.py xarray compatible

* convert final method in the dimension module

* nanmin in stead of zerovalue in square domain method

* make test steps skill run

* undo accidental change

* remove commented out code

* The dataset can contain more than one dataarray

* Address pull request comments

* Add links to dataset documentation everywhere
mats-knmi added a commit that referenced this pull request Sep 23, 2024
* make dimension.py xarray compatible

* convert final method in the dimension module

* nanmin in stead of zerovalue in square domain method

* make test steps skill run

* undo accidental change

* remove commented out code

* The dataset can contain more than one dataarray

* Address pull request comments

* Add links to dataset documentation everywhere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert dimmension.py to xarray
2 participants