FluidList
- class PlasmaCalcs.dimensions.fluids.FluidList(*args_list, istart=None, **kw_list)
Bases:
DimensionValueListlist of fluids
Methods
__getitem__(ii, **kw_new)return self[ii], giving element from self if int(ii) possible, else new instance of type(self).
append(object, /)Append object to the end of the list.
array_equals(other)tells whether self == other (which is assumed to be a numpy array or xarray.DataArray).
charged()return FluidList of charged fluids from self.
clear()Remove all items from list.
copy()Return a shallow copy of the list.
count(value, /)Return number of occurrences of value.
return FluidList of electrons from self.
extend(iterable, /)Extend list by appending elements from the iterable.
from_array(array)return DimensionValueList from 0D or 1D array.
from_dict(int_to_element)return DimensionValueList from dict of {i: element}.
from_dicts(dicts, *[, istart])return cls instance from iterable of dicts
from_lists(**kw_lists)return DimensionValueList from zipping these lists of kwarg values.
from_strings(strings)return cls instance from iterable of strings.
get(key)return element(s) corresponding to key.
return the single electron fluid from self.
get_ion()return the single ion fluid from self.
return the single neutral fluid from self.
return indices of charged fluids in self
return index of the single electron fluid from self.
return indices of electrons in self
i_ion()return index of the single ion fluid from self.
i_ions()return indices of ions in self
return index of the single neutral fluid from self.
return indices of neutrals in self
return indices of non-electrons in self
index(value[, start, stop])Return first index of value.
indices(key, *[, return_get, to_list])return indices of element(s) corresponding to key, during self.get(key).
insert(index, object, /)Insert object before index.
inserted(i, element, **kw_new)return copy of self but with element inserted at i.
ions()return FluidList of ions from self.
return xarray.DataArray telling whether each fluid in self is charged.
return xarray.DataArray telling whether each fluid in self is an electron.
is_ion()return xarray.DataArray telling whether each fluid in self is an ion.
return xarray.DataArray telling whether each fluid in self is neutral.
return xarray.DataArray telling whether each fluid in self is not an electron.
iter_pairs([other, ordered, allow_same, ...])iterator over all possible pairs of (value from self, value from other).
lookup(key, *[, unique_missing_ok, ...])return element given int, str, or element in self.
return dict for looking up elements given int or str (or element) in self.
neutrals()return FluidList of neutrals from self.
return FluidList of non-electrons from self.
pairs([other, ordered, allow_same, get_attr])list of all possible pairs of (value from self, value from other).
pop([index])Remove and return item at index (default last).
popped(key, *[, return_indices])return (self.get(key), self.without_i(indices corresponding to key)).
remove(value, /)Remove first occurrence of value.
reverse()Reverse *IN PLACE*.
return serialization of self, into a list of dictionaries.
sort(*[, key, reverse])Sort the list in ascending order and return None.
to_dict()returns a list of dictionaries,
unique(*[, istart])return DimensionValueList of unique elements from self.
unique_from(elements, *elements_as_args[, ...])return DimensionValueList of unique elements from elements.
where(f, *[, single])return element(s) where f(element)==True.
with_istart([istart])return new DimensionValueList with elements reindexed, starting from istart.
without(key, **kw_init)return a copy of self but dropping element(s) corresponding to key.
without_i(i, **kw_init)return a copy of self but dropping elements currently at these indices.
_assert_array_equals(other)raise DimensionValueError unless self.array_equals(other).
_assert_single(vals, *[, meaning])assert len(vals)==1.
_display_contents(f1[, f2, thresh1, thresh2])return str to display self's contents, probably using f1(element) for each element.
_new(*args, **kw)return new instance of type(self), with these args and kw.
return simple repr for self; includes type, len, and a repr_simple for a few elements.
return a shorter repr of self; just includes type & len.
Attributes
mnamendimqalias to with_istart
ssize- __getitem__(ii, **kw_new)
return self[ii], giving element from self if int(ii) possible, else new instance of type(self).
- _assert_array_equals(other)
raise DimensionValueError unless self.array_equals(other).
- classmethod _assert_single(vals, *, meaning='value')
assert len(vals)==1. Raise DimensionKeyError if len==0; DimensionValueError if len>=2.
meaning can be provided to clarify what vals should represent, in case of crash;error message will be ‘expected exactly 1 {meaning}, but got {len(vals)}’.The implementation here is equivalent to cls.value_type._assert_single(vals, meaning=meaning).
- _dimension_key_error
alias of
FluidKeyError
- _dimension_value_error
alias of
FluidValueError
- _display_contents(f1, f2=<class 'str'>, *, thresh1=4, thresh2=UNSET)
return str to display self’s contents, probably using f1(element) for each element.
f1: callable of element -> str“full-ish” repr for each element. Reasonable to use a detailed repr.Gets called if only showing a few elements from self,i.e. if len(self) <= thresh1, or if len(self) > thresh2.(when len(self) > thresh2, result tells only len(self), self[0], self[1], and self[-1])f2: callable of element -> strabbreviated repr for each element. Should return short string.Gets called if showing a decent number of elements from self,i.e. if thresh1 < len(self) <= thresh2.thresh1: int, see abovethresh2: UNSET or int, see above.If UNSET, use DEFAULTS.DIMENSION_VALUE_LIST_DISPLAY_MAXLEN(to see repr for all entries in self consider using list(self).)
- _new(*args, **kw)
return new instance of type(self), with these args and kw.
- _repr_simple()
return simple repr for self; includes type, len, and a repr_simple for a few elements.
if less than 4 elements, just uses repr_simple for the elements (doesn’t include len).
- _short_repr()
return a shorter repr of self; just includes type & len.
- append(object, /)
Append object to the end of the list.
- array_equals(other)
tells whether self == other (which is assumed to be a numpy array or xarray.DataArray).
return False if other.ndim >= 2, or other.size != len(self).Else, compare via np.all(other == self) (or, other.values == self, for xarray.)(Extremely convenient if comparing to xarray DataArray or numpy array,with potentially unknown size / dimensionality.Also, convenient if “self” might be DimensionValue instead,because DimensionValue also provides an array_equals method.)
- charged()
return FluidList of charged fluids from self.
- clear()
Remove all items from list.
- copy()
Return a shallow copy of the list.
- count(value, /)
Return number of occurrences of value.
- electrons()
return FluidList of electrons from self.
- extend(iterable, /)
Extend list by appending elements from the iterable.
- classmethod from_array(array)
return DimensionValueList from 0D or 1D array.
array values should be DimensionValue objects, strings, or ints.DimensionValue objects –> use as-isstrings –> use cls.value_type(s, i=i) for i in range(len(array))ints –> use cls.value_type(i=i) for i in array
- classmethod from_dict(int_to_element)
return DimensionValueList from dict of {i: element}.
See also: cls.from_dicts()
- classmethod from_dicts(dicts, *, istart=UNSET, **kw_value_init)
return cls instance from iterable of dicts
values will all be DimensionValue objects, with type == cls.value_type.
dicts: iterable of dicts
each one corresponds to one (cls.value_type) object in result.istart: UNSET, None, or intmode for inferring i values if needed.UNSET –> dicts[k] uses i=dicts[k][‘i’] if it exists, else i=k.None –> use i from dict if it exists, else None.int –> dicts[k] uses i=istart+k, ignoring any ‘i’ provided in dict.additional kwargs will be passed to cls.value_type.__init__(in case of conflict with any dicts values, use dicts values).
- classmethod from_lists(**kw_lists)
return DimensionValueList from zipping these lists of kwarg values.
E.g. from_lists(s=[‘e’, ‘H’, ‘H+’], q=[-1, 0, 1]) is equivalent tocls.from_dicts([dict(s=’e’, q=-1), dict(s=’H’, q=0), dict(s=’H+’, q=1)])
- classmethod from_strings(strings)
return cls instance from iterable of strings. (i will be determined automatically.)
Equivalent to cls(cls.value_type(s, i) for i, s in enumerate(strings)).
- get(key)
return element(s) corresponding to key.
key: None, int, str, element, DimensionSpecialValueSpecifier, range, slice, or tuple/listSome keys will look up and return corresponding element(s):nonnegative int, str, or element –> return corresponding element.DimensionSpecialValueSpecifier spec –> return spec.getter(self).tuple/list –> return tuple/list(self.get(k) for k in key),flattening any term which would otherwise become a DimensionValueList.(e.g. [ELECTRON, IONS] –> [e, ion1, ion2, ion3], not [e, [ion1, ion2, ion3]])range –> return type(self)(self.get(k) for k in key).Other keys will index self using the usual list-like indexing rules:None –> return self, unchanged.negative int –> return self[key], i.e. the key’th element, counting from end.slice –> return self[key], i.e. apply this slice to self.Note that the result will have the same type as self.Note that this supports interprets_fractional_indexing,e.g. slice(0.3, 0.7) will slice(len(self) * 0.3, len(self) * 0.7).if any element in a tuple or list is not in self,keep it unchanged if it is a UniqueDimensionValue,else raise DimensionKeyError.Note that the result will always be single element, a tuple, a list, or a DimensionValueList.
- get_electron()
return the single electron fluid from self. Crash if there isn’t exactly 1.
if 0, raise FluidKeyError. if 2+, raise FluidValueError.
- get_ion()
return the single ion fluid from self. Crash if there isn’t exactly 1.
if 0, raise FluidKeyError. if 2+, raise FluidValueError.
- get_neutral()
return the single neutral fluid from self. Crash if there isn’t exactly 1.
if 0, raise FluidKeyError. if 2+, raise FluidValueError.
- i_charged()
return indices of charged fluids in self
- i_electron()
return index of the single electron fluid from self. Crash if there isn’t exactly 1.
if 0, raise FluidKeyError. if 2+, raise FluidValueError.
- i_electrons()
return indices of electrons in self
- i_ion()
return index of the single ion fluid from self. Crash if there isn’t exactly 1.
if 0, raise FluidKeyError. if 2+, raise FluidValueError.
- i_ions()
return indices of ions in self
- i_neutral()
return index of the single neutral fluid from self. Crash if there isn’t exactly 1.
if 0, raise FluidKeyError. if 2+, raise FluidValueError.
- i_neutrals()
return indices of neutrals in self
- i_nonelectrons()
return indices of non-electrons in self
- index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
- indices(key, *, return_get=False, to_list=False)
return indices of element(s) corresponding to key, during self.get(key).
to_list: bool.True –> return [index] instead of index, if self.get(key) is a single DimensionValue.return_get: boolTrue –> return (indices, self.get(key)) instead of just indices.result will have same length as self.get(key); self[result[i]] is self.get(key)[i].
- insert(index, object, /)
Insert object before index.
- inserted(i, element, **kw_new)
return copy of self but with element inserted at i. kwargs passed to new self.__init__.
- ions()
return FluidList of ions from self.
- is_charged()
return xarray.DataArray telling whether each fluid in self is charged.
- is_electron()
return xarray.DataArray telling whether each fluid in self is an electron.
- is_ion()
return xarray.DataArray telling whether each fluid in self is an ion.
- is_neutral()
return xarray.DataArray telling whether each fluid in self is neutral.
- is_nonelectron()
return xarray.DataArray telling whether each fluid in self is not an electron.
- iter_pairs(other=None, *, ordered=False, allow_same=True, get_attr=None)
iterator over all possible pairs of (value from self, value from other).
other: None or iterable (probably DimensionValueList)
None –> use other = self, i.e. just get pairings from within self.ordered: boolwhether to only return pairs (A,B) with A <= B.allow_same: boolwhether to allow pairs (A,B) with A == B.get_attr: Noneattr to return from objects, instead of returning the objects themselves.E.g. return_attr=’s’ –> pairs will be like (A.s, B.s) instead of (A, B).
- lookup(key, *, unique_missing_ok=False, handle_special=True)
return element given int, str, or element in self. raise DimensionKeyError if key not in self.
unique_missing_ok: boolwhether it is okay for self to be missing key if key is a UniqueDimensionValue.if True and key is a UniqueDimensionValue, return key instead of raising error.handle_special: boolwhether to handle DimensionSpecialValueSpecifier in special way,i.e. if key is a DimensionSpecialValueSpecifier, return key.getter(self).
- lookup_dict()
return dict for looking up elements given int or str (or element) in self.
uses caching; assumes int(element) & str(element) never changes for any element.
- neutrals()
return FluidList of neutrals from self.
- nonelectrons()
return FluidList of non-electrons from self.
- pairs(other=None, *, ordered=False, allow_same=True, get_attr=None)
list of all possible pairs of (value from self, value from other).
other: None or iterable (probably DimensionValueList)
None –> use other = self, i.e. just get pairings from within self.ordered: boolwhether to only return pairs (A,B) with A <= B.allow_same: boolwhether to allow pairs (A,B) with A == B.get_attr: Noneattr to return from objects, instead of returning the objects themselves.E.g. return_attr=’s’ –> pairs will be like (A.s, B.s) instead of (A, B).
- pop(index=-1, /)
Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
- popped(key, *, return_indices=False, **kw_init)
return (self.get(key), self.without_i(indices corresponding to key)).
see help(self.get) for details on allowed keys.return_indices: boolif True, also return the indices (as a list) of the popped element(s),i.e. return (indices, popped element(s), self.without_i(…), self with elements removed).index will be None if no elements were removed.kw_init are used when making the copy of self. E.g. use istart=0 to make the copy start at 0.See also: self.without(), which just returns self with elements removed.
- property reindexed
alias to with_istart
- remove(value, /)
Remove first occurrence of value.
Raises ValueError if the value is not present.
- reverse()
Reverse *IN PLACE*.
- serialize()
return serialization of self, into a list of dictionaries.
- sort(*, key=None, reverse=False)
Sort the list in ascending order and return None.
The sort is in-place (i.e. the list itself is modified) and stable (i.e. the
order of two equal elements is maintained).If a key function is given, apply it once to each list item and sort them,ascending or descending, according to their function values.The reverse flag can be set to sort in descending order.
- to_dict()
returns a list of dictionaries,
each dictionary corresponds to each DimensionValue in the DimensionValueList.
- unique(*, istart=None)
return DimensionValueList of unique elements from self.
equality checked via element.equal_except_i, i.e. ignore index.(if all elements are unique, return self, else return new DimensionValueList.)istart: None or int. int –> use result[k].with_i(istart + k) for all k.
- classmethod unique_from(elements, *elements_as_args, istart=None)
return DimensionValueList of unique elements from elements.
equality checked via element.equal_except_i, i.e. ignore index.elements: iterable of DimensionValue of cls.value_type.or, single DimensionValue, in which case treat it as first arg,and can provide more elements as additional args.istart: None or int. int –> use result[k].with_i(istart + k) for all k.
- where(f, *, single=False)
return element(s) where f(element)==True.
f: callable of element -> boolfunction to apply to each element in self.single: boolwhether to return a single element instead of a DimensionValueList.if True, ensure exactly one element satisfied f(element)==True, else crash.
- with_istart(istart=0)
return new DimensionValueList with elements reindexed, starting from istart.
elements with incorrect i will be replaced with copies.if istart is None, just return self, unchanged.
- without(key, **kw_init)
return a copy of self but dropping element(s) corresponding to key.
see help(self.get) for details on allowed keys.See also: self.popped(), which additionally returns the popped elements.
- without_i(i, **kw_init)
return a copy of self but dropping elements currently at these indices.
i: int or iterable of int. indices to remove.kw_init are passed to __init__ when making the copy of self.