Skip to content

Reindex on a coordinate dependent on two dimensions #8431

Closed Answered by dcherian
maresb asked this question in Q&A
Discussion options

You must be logged in to vote

One way to approach this would be to simply group by ["local_time", "lon"], but unfortunately .groupby() simply doesn't work with multiple indices.

Your intuition is correct, you'll just need to use flox to execute though.

import flox.xarray

flox.xarray.xarray_reduce(
    da, da.local_time, da.lon, func="first", fill_value=np.nan
)

This simpler groupby works too:

import flox.xarray

flox.xarray.xarray_reduce(
    da, da.local_time, func="first", dim="utc_time", fill_value=np.nan
).transpose()

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by dcherian
Comment options

You must be logged in to vote
1 reply
@benbovy
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants