Repository navigation
Select on non-dimension coordinate #10913
Replies: 1 comment
|
What you are running into is a current limitation of After: v = v.set_xindex("x")
v = v.set_xindex("y")
v = v.set_xindex("z")each of those indexes can independently translate its label query into a positional indexer for the same underlying If the semantics you want are "keep points satisfying all three coordinate ranges", boolean indexing expresses that directly and doesn't require a MultiIndex: mask = (
(v.x >= 0.1) & (v.x <= 0.3)
& (v.y >= 2.5) & (v.y <= 2.7)
& (v.z >= 4.2) & (v.z <= 4.4)
)
result = v.where(mask, drop=True)or, if you specifically want positional selection: result = v.isel(space=mask)(the exact choice between Your chained I checked current xarray's indexing implementation before answering; this restriction is explicit in |
Uh oh!
There was an error while loading. Please reload this page.
The problem
I have a coordinate that has 3 sub-coordinates I want to apply selections to. I don't want to use
MultiIndexobjects, as I'm usingstackandunstacklater on, and I don't want those coordinates to unstack and addNaNall over my array. Here is an example of what the DataArray would look like :The constraint is that
valuesis of shape(time, space)so I can't have x, y and z as dimension coordinates.I want to select slices of
vwith conditions on x, y and z, butv.sel(x=slice(0.1, 0.3), y=slice(2.5, 2.7), z=slice(4.2, 4.4))does not work as x, y and z are not dimensions coordinates:Note
This is a simple example, so I'm using time and space, in reality those would be indices related to each value in the last dimension of the array, hence the impossibility to increase the array dimensions
What I have tried
MultiIndexobjects do not work as expected, and as I said earlier I don't want those to unstack later.sel(dict):Tip
Notice that I call
.selon each coordinate separately, otherwise I get the following error:I'm interested to know if there is a workaround that could allow me to use
.selonvwithout having a MultiIndex object in the coordinatesAll reactions