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

Issue 99 #120

Merged
merged 5 commits into from
Jul 24, 2023
Merged

Issue 99 #120

merged 5 commits into from
Jul 24, 2023

Conversation

HendrikKok
Copy link
Contributor

No description provided.

… dask in structured arrays + fix for dx/dy output structured + add test with dask arrays (structured)
Copy link
Contributor

@JoerivanEngelen JoerivanEngelen left a comment

Choose a reason for hiding this comment

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

I have a few comments,

mainly because I wasn't sure why some changes were made.

I think next time it helps to summarize in the PR the changes you made and why you made them.

"x": self._target.xbounds.midpoints,
}
)
regridded = regridded.assign_coords(coords=self._target.coords)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the y coordinates still flipped in this implementation?

It is important to have y coordinates in descending order

I see you defined a new property coords, but I don't see it referring to midpoints, which I think is what we want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the coords property to the StructuredGrid- class. There it uses the actual grid properties directly and not the possible flipped midpoints. This implementation was needed to get the right dx/dy from the target-grid.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good, just to double check: This doesn't result in grids which are flipped from descending y to ascending y coordinates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it does not indeed. Only the midpoints arrays are fliped for computing the proper weights. The original coords are untouched and now used. I double checked myself + it is also tested in the testbench

@@ -155,17 +165,16 @@ def _regrid_array(self, source):
chunks=chunks,
meta=np.array((), dtype=source.dtype),
)
out = out.compute().reshape(out_shape)
Copy link
Contributor

Choose a reason for hiding this comment

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

Mind that the call to compute results that the results are loaded into memory. Not sure if that fits each use case. For now it is fine, we can optimize this later. Perhaps add a #TODO comment to later investigate 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.

yes that is possible suboptimal. I tried to use the dask.array.reshape() first, but that does not work for splitting up dimensions unevenly (https://docs.dask.org/en/stable/_modules/dask/array/reshape.html). So I used there suggestion to compute first. But definitely a TODO.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah thanks for the info, a proper struggle with reshaping! We can resolve this conversation when the TODO is added, and I think we can make an issue for this!

xugrid/regrid/regridder.py Outdated Show resolved Hide resolved

# E.g.: sizes of ("time", "layer") + ("y", "x")
out_shape = first_dims_shape + self._target.shape
return out.reshape(out_shape)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you calling the reshape in the if else tree above, instead of at the end like it was? The original version appears to be cleaner to me, as reshape only has to be mentioned once, instead of twice after your alterations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the reshape does not work for a dask-array. For the dask-array I first used the dask.array.reshape(), which gives the result that we want. For the current implementation (see reply above) I could move it back indeed.

Copy link
Contributor

@JoerivanEngelen JoerivanEngelen Jul 13, 2023

Choose a reason for hiding this comment

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

Ah an understandable struggle with dask.array.reshape :-) I would prefer if you moved these lines back down because we can leave the code as it was now that the call to dask.array.compute was introduced.

xugrid/regrid/regridder.py Outdated Show resolved Hide resolved
…r defining blocks of extra dimension(s), use .shape for the topology dimension.
@HendrikKok HendrikKok requested a review from Huite July 20, 2023 14:39
@Huite Huite marked this pull request as ready for review July 24, 2023 08:32
@Huite Huite merged commit b5e08ed into main Jul 24, 2023
2 checks passed
@Huite Huite deleted the Issue_99 branch July 24, 2023 08:32
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.

3 participants