MultiSlices
- class PlasmaCalcs.dimensions.dimension_tools.multi_slices.MultiSlices(*args_super, multi_slices={}, ndim=None, dims=None, ikeep=0, **kw_super)
Bases:
dictmanaging multiple slices dicts in one place, while also providing options for “special slices”.
Special slices options involve creating slices dicts for each possible combination of N dimensions,e.g. in a 3D simulation with dimensions [‘x’, ‘y’, ‘z’], creating slices for N=2 meansslices would be dict(keep_x_y=dict(z=0), keep_y_z=dict(x=0), keep_x_z=dict(y=0)).keys should be ANY names; these will be associated with results from applying each slice.(in MainDimensionsHaver, keys tell names of data_vars in resulting xarray.Dataset)values should be a dicts of slices or other indexers.e.g. one value might be {‘x’: slice(0, 10), ‘y’: 5, ‘z’: 0}.(in MainDimensionsHaver, these correspond to any valid value for obj.slices)- multi_slices: dict
- can provide keys and values here if desired, instead of directly as kwargs.
The following can be provided during __init__ or set as attrs of self:SPECIAL SLICES OPTIONS:- ndim: None or int
- None –> ignore, and do not create special slices.int –> create special slices to keep this many dims after applying each slice.Example: MultiSlices(ndim=2) is shorthand for“MultiSlices with one slices for every possible combination of keeping 2 dims”.Example: MultiSlices(ndim=2, dims=[‘x’, ‘y’, ‘z’], ikeep=0) is equivalent to:MultiSlices(keep_x_y=dict(z=0), keep_y_z=dict(x=0), keep_x_z=dict(y=0))Example: MultiSlices(ndim=1, dims=[‘x’, ‘y’, ‘z’], ikeep=0) is equivalent to:MultiSlices(keep_x=dict(y=0, z=0), keep_y=dict(x=0, z=0), keep_z=dict(x=0, y=0))
- dims: None, iterable of str, or callable of 0 arguments -> iterable of str.
- dimensions to consider when applying special slices.None –> do not create any special slices.
- ikeep: int or number between -1 < ikeep < 1
- index to take when picking a single value for sliced dimensions for special slices.Default is 0, e.g. when slicing x, keep x[0].int –> when slicing dim, keep dim[ikeep]. E.g. 10 –> keep x[10]non-int between -1 and 1 –> multiply by length of dim to get index.see interprets_fractional_indexing for more details.
if ndim and dims are provided, special slices will be included in self.get_slices().Note that the naming convention for keys will be ‘keep_’+’_’.join(unsliced_dims),e.g. ‘keep_x’, ‘keep_x_y’, or ‘keep_x_y_z’.unsliced_dims will be in the same order as dims.Methods
__eq__(other)return whether self is equal to other.
__ne__(other)return whether self is not equal to other.
as_kw()return dict of kwargs to use to recreate this object.
clear()copy()return a copy of self
fromkeys([value])Create a new dictionary with keys from iterable and values set to value.
get(key[, default])Return the value for key if key is in the dictionary, else default.
get_slices([dims, ikeep])return dict of all multi_slices to apply.
get_special_slices([ndim, dims, ikeep])return dict of special slices to apply.
items()keys()pop(k[,d])If key is not found, default is returned if given, otherwise KeyError is raised
popitem()Remove and return a (key, value) pair as a 2-tuple.
setdefault(key[, default])Insert key with a value of default if key is not in the dictionary.
update([E, ]**F)If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]
values()return list of strings to include in repr of self.
Attributes
dims to consider when applying special slices.
- __eq__(other)
return whether self is equal to other.
- __ne__(other)
return whether self is not equal to other.
- _repr_contents()
return list of strings to include in repr of self.
- as_kw()
return dict of kwargs to use to recreate this object.
- clear() None. Remove all items from D.
- copy()
return a copy of self
- property dims
dims to consider when applying special slices.
if set to be a callable, will call it each time getting self.dims.
- fromkeys(value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- get_slices(dims=UNSET, *, ikeep=UNSET)
return dict of all multi_slices to apply.
if self.ndim is None, only use the slices explicitly provided to self.(i.e. don’t get any special slices.)otherwise, create and include special slices in the result.see self.get_special_slices for details.if any special slices’ names match slice names explicitly provided in self,use the explicitly-provided slice name instead.- dims, ikeep: passed to self.get_special_slices, if creating any special slices.
- dims: None, iterable of str, or callable of 0 arguments -> iterable of str.dimensions to consider when applying special slices.None –> do not create any special slices.ikeep: int or number between -1 < ikeep < 1index to take when picking a single value for sliced dimensions for special slices.Default is 0, e.g. when slicing x, keep x[0].int –> when slicing dim, keep dim[ikeep]. E.g. 10 –> keep x[10]non-int between -1 and 1 –> multiply by length of dim to get index.see interprets_fractional_indexing for more details.
- get_special_slices(ndim=UNSET, dims=UNSET, *, ikeep=UNSET)
return dict of special slices to apply.
- ndim: UNSET or None or int
- None –> ignore, and do not create special slices.int –> create special slices to keep this many dims after applying each slice.Example: MultiSlices(ndim=2) is shorthand for“MultiSlices with one slices for every possible combination of keeping 2 dims”.Example: MultiSlices(ndim=2, dims=[‘x’, ‘y’, ‘z’], ikeep=0) is equivalent to:MultiSlices(keep_x_y=dict(z=0), keep_y_z=dict(x=0), keep_x_z=dict(y=0))Example: MultiSlices(ndim=1, dims=[‘x’, ‘y’, ‘z’], ikeep=0) is equivalent to:MultiSlices(keep_x=dict(y=0, z=0), keep_y=dict(x=0, z=0), keep_z=dict(x=0, y=0))UNSET –> use self.ndim
- dims: UNSET or None, iterable of str, or callable of 0 arguments -> iterable of str.
- dimensions to consider when applying special slices.None –> do not create any special slices.UNSET –> use self.dims
- ikeep: UNSET or int or number between -1 < ikeep < 1
- index to take when picking a single value for sliced dimensions for special slices.Default is 0, e.g. when slicing x, keep x[0].int –> when slicing dim, keep dim[ikeep]. E.g. 10 –> keep x[10]non-int between -1 and 1 –> multiply by length of dim to get index.see interprets_fractional_indexing for more details.UNSET –> use self.ikeep
Note that the naming convention for keys will be ‘keep_’+’_’.join(unsliced_dims),e.g. ‘keep_x’, ‘keep_x_y’, or ‘keep_x_y_z’.unsliced_dims will be in the same order as dims.returns dict of dicts, where each inner dict is instructions for applying a slice.result will be empty if ndim is None or if dims is None.
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- pop(k[, d]) v, remove specified key and return the corresponding value.
If key is not found, default is returned if given, otherwise KeyError is raised
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order.
Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from dict/iterable E and F.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]
If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = vIn either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D's values