-
Notifications
You must be signed in to change notification settings - Fork 31
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
Preserve Coordinates when Indexing UxDataArray #1003
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I tested the change and tried to replicate the issue I had #818 with the uxarray.UxDataArray.Indexes disappearing but had no problems.
However, given this fix, I can think of two other places a similar change might be needed:
uxarray/uxarray/remap/nearest_neighbor.py
Line 110 in ec5cc8f
coords=source_uxda.coords, |
and
coords=source_uxda.coords, |
Good catches, I'll update these also. |
When remapping, should the coordinates from the original data array be dropped? It wouldn't make much sense to preserve them (unless I'm understanding it wrong), since the coordinates from the original array are no longer representative of the new remapped grid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spatial coordinates should not be transferred, but if there are non-spatial coordinates like time
, ensemble_member
, or forecast_hour
, then those should be transferred to the destination. I think that's why I originally thought the coords
argument was necessary.
That makes sense! I wasn't considering the non-spatial cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I provided a way to drop the remapped coordinate (which I agree, should not get transferred from the source) and still preserve any non-spatial coordinates.
@@ -148,7 +148,6 @@ def _inverse_distance_weighted_remap_uxda( | |||
uxda_remap = uxarray.core.dataarray.UxDataArray( | |||
data=destination_data, | |||
name=source_uxda.name, | |||
coords=source_uxda.coords, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@philipc2 Here's my solution to preserve any non-spatial coordinates (like time or ensemble_member) while dropping the spatial one:
Copy source_uxda.coords
to a new xarray.Coordinates
object. Then delete the key associated with the spatial dimension. Then use that new object as the coords argument to uxarray.core.dataarray.UxDataArray
.
destination_coords = source_uxda.coords
del(destination_coords[destination_dim])
# construct data array for remapping variable
uxda_remap = uxarray.core.dataarray.UxDataArray(
data=destination_data,
name=source_uxda.name,
coords=destination_coords,
Does this make sense?
Closes #945
Overview
UxDataArray