fix: xarray roi selection - #672
Conversation
…erest in KeyData.xarray fix: correctly name default dimensions when an intermediate dimension is dropped.
|
@takluyver as discussed offline, we're now adding coordinates if we provide extra_dims argument or if the new extra_coords is True. extra_coords can also be used to provide custom coordinates as a dict. |
| # Count non-Ellipsis, non-newaxis dimensions | ||
| n_before = sum(1 for x in indexing[:ellipsis_idx] if x is not None) | ||
| n_after = sum(1 for x in indexing[ellipsis_idx + 1:] if x is not None) |
There was a problem hiding this comment.
This can also be simplified now that we're not supporting None
| Name the array itself. The default is the source and key joined by a | ||
| dot. Ignored for structured data when a dataset is returned. | ||
| extra_coords: bool or dict | ||
| Add coordinates to the returned DataArray. |
There was a problem hiding this comment.
So if you pass both a coordinates dict and a ROI, the coordinates should describe the data after selecting the ROI, if I've understood correctly? I don't have a feeling about which way is better, but it's probably good to document it.
|
So just to check I've understood correctly, passing only I think this design sounds OK. |
|
In terms of the implementation, I think you can give xarray extra coordinates for dimensions that aren't in the data, without having to do the trick with expanding the array dimensions and then squeezing them back out. Have I misunderstood something? Does that produce a subtly different result? E.g. attaching a 'z' coordinate with no z dimension: xr.DataArray(
np.random.randn(2, 3),
dims=("x", "y"),
coords={"x": [10, 20], 'z': 6}
) |
- simplify expand_indexing - improve xarray() docstring for extra_coords option - simplify handling coordinate for dropped dims
Yes, that's exactly that! |
|
Thanks, LGTM! |
|
Thanks for the review! |
This fixes a few bugs found after #662 was deployed:
For example, with Jungfrau data, shape (1,512,1024) per trainId
Enhancement:
Provides a new
extra_coordsargument that takes either a dict for user provided coordinates, or a bool to generate default coordinates.