Advanced positional Indexing along dimensions #32
-
|
Hello everyone, Is it possible to perform indexing instead of slicing along dimension using sel or isel functions ? Thanks in advance for your help ! PS: Thank you very much for XDAS development ! :) |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
|
Dear Ianis, Thank you for this very first technical question abour Xdas on github discussions ! You can definitevely perform index based selection with the da.isel(time=<something>)This will check what is the axis corresponding to the time dimension. Let's imagine the time dimension is the first one in that case it will perform: da[<something>]if time is the second dimension it will perform this instead: da[:, <something>]and so on. Now about the At the time of writing of this answer, coordinate objects should not be a problem. On the other side if you data array contain a virtual object, this could lead to some issue as this kind of object might not support advanced numpy indexing. In that case, the simplest work around is to first load the data to get a numpy data object and then to do your fancy indexing: da = da.load()
da.isel(dim=<some_advanced_indexing>)This is not optimal but should be efficient enough in most cases. And unfortunately Xdas provides obscure errors when you hit this kind of issues. Try to first make simple indexing on the virtual object, then load the minimal part of the data of interest and then make the advanced indexing. Let me know if this answer you question ! |
Beta Was this translation helpful? Give feedback.
-
|
Hi all, I'd like to ask a follow-up question here. Is it possible to use |
Beta Was this translation helpful? Give feedback.
-
|
Hi @Linvill If you want to do fancy selections while keeping virtual objects the more flexible way to go is to slice and concatenate. You could do something like: keep = [slice(<start1>, <end1>), ..., slice(<startN>, <endN>)]
objs = [da.sel(distance=slc) for slc in keep]
da_clean = xdas.concatenate(objs, dim="distance")In this example I used Let me know if this works for you. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @atrabattoni, thanks for your fast response, this works nicely, I even added the different objects of the different boreholes into a DataCollection, which works beautifully. Thanks & Cheers |
Beta Was this translation helpful? Give feedback.

Dear Ianis, Thank you for this very first technical question abour Xdas on github discussions !
You can definitevely perform index based selection with the
Dataarray.iselmethod. For example:This will check what is the axis corresponding to the time dimension. Let's imagine the time dimension is the first one in that case it will perform:
if time is the second dimension it will perform this instead:
and so on.
Now about the
<something>part. What you can do or can't do depend on the type of coordinate an data objects the DataArray is composed of. In most cases it should work fine and all the type of indexing supported by Numpy …