PlasmaCalcs.tools.fft_tools.fft_slices.FFTSlices

class PlasmaCalcs.tools.fft_tools.fft_slices.FFTSlices(*args_super, slices={}, keep=None, half=None, step=None, missing_slices='ignore', **kw_super)

Bases: dict

slicing fft result.
keys should be names of dimensions and/or coordinates.
pre-fft OR post-fft names both work (e.g. ‘x’, ‘freq_x’, or ‘k_x’)
values should be slices, or int, iterable, or non-integer between -1 and 1.
fractional indexing is supported as per interprets_fractional_indexing;
non-integers between -1 and 1 are interpreted as fractions of the length,
e.g. slice(0.25, 0.75) –> slice(int(0.25*L), int(0.75*L))
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:
keep: None, True, dict, or number in 0 < keep <= 1
implies the fraction of each dimension to keep.
(ignored for any dimensions which already have a slice specified.)
e.g. keep=0.4 with length=1000 would result in slice(300, 700),
since that keeps 400 out of 1000 points, and is centered at 1000/2.
None –> ignored.
True –> use keep = DEFAULTS.FFT_KEEP (default: 0.4).
dict –> different value in each dimension;
keys can be pre-fft OR post-fft dimension names.
half: None, str, or iterable of strs
dimensions along which to keep only the right half of the result.
(ignored for any dimensions which already have a slice specified.)
None –> ignored.
str or iterable of strs –>can be pre-fft OR post-fft dimension name(s).
Applied after keep, e.g. keep=0.4, length=1000, half=’x’ –> slice(500, 700) for x.
step: None, dict, int, or non-integer between -1 and 1
step to take along each dim.
(ignored for any dimensions which already have a slice specified.)
fractional value –> use fraction of length (e.g. 0.01 –> 1% of dim length), min |step|=1.
negative –> reverses direction (and swaps start & stop for the slice)
None –> equivalent to using step=1.
dict –> different value in each dimension;
keys can be pre-fft OR post-fft dimension names.
OTHER OPTIONS:
missing_slices: ‘ignore’, ‘warn’, or ‘raise’
tells how to handle keys not matching any fft-related coordinate.
‘ignore’ –> silently ignore these keys. This is the default.
‘warn’ –> issue a warning.
‘raise’ –> raise an error.
__init__(*args_super, slices={}, keep=None, half=None, step=None, missing_slices='ignore', **kw_super)

Methods

__init__(*args_super[, slices, keep, half, ...])

applied_to(fft_result[, dims, missing_slices])

as_kw()

clear()

copy()

fromkeys([value])

get(key[, default])

get_slice(post_fft_dim)

get_slices(post_fft_dims, *[, missing_slices])

get_special_slice(post_fft_dim)

items()

keys()

pop(k[,d])

popitem()

setdefault(key[, default])

update([E, ]**F)

values()

applied_to(fft_result, dims=None, *, missing_slices=UNSET)
apply slices from self to fft_result.
fft_result: array, probably xarray.DataArray.
the result of an fft along one or more dimensions.
dims: None or iterable of strs
apply slicing only to these dimensions.
None –> use fft_result.dims.
any of these can be pre-fft dims, in which case will use the corresponding post-fft dim,
inferred from fft_result. E.g. ‘x’ –> ‘freq_x’ or ‘k_x’ if one of those is in fft_result.
Any pre-fft dims with no corresponding dim in fft_result will cause DimensionKeyError.
missing_slices: UNSET or ‘ignore’, ‘warn’, or ‘raise’
tells how to handle keys not matching any fft-related coordinate.
‘ignore’ –> silently ignore these keys. This is the default.
‘warn’ –> issue a warning.
‘raise’ –> raise an error.
UNSET –> use self.missing_slices.
additional kwargs are passed to self.get_slices.
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
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_slice(post_fft_dim)
return slice for this dimension. Must provide name before & after fft,
to ensure self is compatible with using pre & post fft names.
get_slices(post_fft_dims, *, missing_slices=UNSET)
return slices for each dim in post_fft_dims.
post_fft_dims: iterable of strs
names of dimensions in the fft result, for which to get slices now.
missing_slices: UNSET or ‘ignore’, ‘warn’, or ‘raise’
tells how to handle keys not matching any fft-related coordinate.
‘ignore’ –> silently ignore these keys. This is the default.
‘warn’ –> issue a warning.
‘raise’ –> raise an error.
UNSET –> use self.missing_slices.
result will be a dict with keys from post_fft_dims,
excluding any keys for which self provides no slicing instructions.
get_special_slice(post_fft_dim)
return slice for this dim assuming it is a special case (only affected by keep, half, step).
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] = v
In either case, this is followed by: for k in F: D[k] = F[k]
values() an object providing a view on D's values