PlasmaCalcs.tools.xarray_tools.xarray_coords.xarray_index_coords

PlasmaCalcs.tools.xarray_tools.xarray_coords.xarray_index_coords(array, coords=None, newname='{coord}_index', *, drop=False, promote=False, exist_ok=False, max_ndim=None)
return copy of array with coord_index coords telling np.arange() for each coord.
0D coords’ index will be 0 if provided explicitly in coords input, else ignored.
1D coords’ index will be np.arange, e.g. coord_index[i] == i.
2D+ coords’ index will be reshaped np.ndindex, such that coord_index[i,j] == (i,j).
coords: None or iterable of strs
if None, use all coords and dims which don’t already have coord_index.
(e.g. ‘fluid’ –> make ‘fluid_index’, unless ‘fluid_index’ already exists.)
newname: str
string for new (index) coord names: newname.format(coord=coord).
Default: ‘{coord}_index’. To keep original names, use ‘{coord}’
drop: bool
whether to drop original coords after creating coord_index coords.
(e.g. ‘fluid’ –> drop ‘fluid’ after making ‘fluid_index’)
promote: bool
whether to promote all non-dim new index coords to dimensions.
if True, xarray_promote_dim for all new index coords.
exist_ok: bool
whether it is okay if newname for coord (e.g. ‘fluid_index’) already exists.
True –> replace existing coord with new coord_index.
max_ndim: None or int
if not None, skip any coords with ndim > max_ndim.
E.g. max_ndim=1 prevents making indexes for coords with ndim>=2.