Skip to content

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?

----------
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?

----------
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?



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 force-pushed the xarray/convert-dimension branch from ee4bbed to cb25820 Compare August 12, 2024 06:53
@mats-knmi mats-knmi merged commit a04b189 into xarray/main Aug 12, 2024
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