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

Add support for multi-dimensional coordinates in from_structured #202

Merged
merged 4 commits into from
Jan 31, 2024

Conversation

Huite
Copy link
Collaborator

@Huite Huite commented Jan 24, 2024

@roeldegoede:

I realized the name rotated isn't appropriate: supporting multi-dimensional coordinates is more general, e.g. if you have a curvilinear grid (which is approximated by straight edges). I also ran into the trouble of finding out how the coordinates are called. In your example, they are called xc and yc, but in many other cases they will have different names.

This implementation currently assumes that the last two logical dimensions are always called ("y", "x"), but the multi-dimensional coordinates may be arbitrarily named. They could technically be identified by their attrs (if set), but this seems much simpler.

Taking your example in the issue:

uda = xu.UgridDataArray.from_structured(da)
uda.ugrid.plot()

This doesn't specifiy the x and y coordinates, so it works as before: it looks at the x and y dimensions/coordinates. In this case, they are unlabeled, so they are just a range of 0...N.

image

To succesfully use the multi-dimensional coordinates, specify them explicitly:

uda = xu.UgridDataArray.from_structured(da, x="xc", y="yc")
uda.ugrid.plot()

image

This seems to work, if we check with a plot of the original:

da.plot(x="xc", y="yc")

image

The .ugrid.plot seems a bit sharper, maybe due to how to matplotlib treats a PolyCollection (bit of a surprise to me).

@Huite Huite requested a review from roeldegoede January 24, 2024 14:17
Copy link

@roeldegoede roeldegoede left a comment

Choose a reason for hiding this comment

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

Awesome work! Seems to work flawless so far :)

@Huite Huite merged commit 65c007a into main Jan 31, 2024
4 checks passed
@Huite Huite deleted the from_structured_rotated branch July 11, 2024 15:37
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.

2 participants