take_along_dimension
- PlasmaCalcs.tools.xarray_tools.xarray_dimensions.take_along_dimension(dimension, array, at=None, *, i=None, default=UNSET, drop_labels=False, as_dict=False, item=False)
returns something like: [array.sel({dimension: val}) for val in
`at`]i.e., list of taking these values along this dimension of array.- at: None or list-like of values in this dimension
- take at these values. None –> use values from array.coords[dimension]
- i: None or indices.
- (if provided) take only at these indices; use isel.
- default: UNSET or any value
- if provided, use this value for any at[i] not in array.coords[dimension].if not already an xarray.DataArray, convert it, and set coords[dimension]=at[i].(e.g. take_along_dimension(‘component’, arr, at=[‘x’], default=0),if arr doesn’t have ‘component’==’x’, will give xarray.DataArray(0, coords={‘component’: ‘x’}))
- drop_labels: bool, default False
- if True, drop the labels along the taken dimension.E.g., if dimension==’component’ and labels=[‘x’, ‘y’],by default, result[0].component==’x’ and result[1].component==’y’but if drop_labels then result[0] and result[1] will not have .component at all.
- as_dict: bool, default False
- if True, return dict of {dim value: array value at this dim}(instead of a list of array value at each dim value)
- item: bool
- if True, convert arrays to single values via array.item().
if array is 0-d along dimension,returns [array] if labels corresponds to the one label in this dimension.