PlasmaCalcs.mhd.elements.ElementList
- class PlasmaCalcs.mhd.elements.ElementList(*args_list, istart=None, **kw_list)
Bases:
FluidListList of Element objects.cls.DEFAULTS provides defaults for infotypes: ‘m’, ‘ionize_ev’, ‘saha_g1g0’, ‘abundance’dict of {infotype: {defaultname: {elementname: value of this infotype}}}e.g. {‘m’: {‘physical’: {‘H’: 1, ‘He’: 4}},‘ionize_ev’: {‘physical’: {‘H’: 13.6, ‘He’: 24.6}},‘saha_g1g0’: {‘physical’: {‘H’: 0.5, ‘He’: 2.0}},‘abundance’: {‘photospheric_v0’: {‘H’: 12, ‘He’: 10.93},‘photospheric_v1’: {‘H’: 12, ‘He’: 11.00}}the default for ‘physical’ for m and ionize_ev are in PlasmaCalcs.DEFAULTS.defaults assume names will be title-case element symbol, e.g. ‘H’, ‘He’;using different names is allowed but will prevent default lookups.- __init__(*args_list, istart=None, **kw_list)
Methods
__init__(*args_list[, istart])append(object, /)charged()clear()copy()count(value, /)extend(iterable, /)from_array(array)from_dict(int_to_element)from_dicts(dicts, *[, istart])from_names([names, m, ionize_ev, saha_g1g0, ...])from_strings(strings)get(key)get_ion()i_ion()i_ions()index(value[, start, stop])indices(key, *[, return_get, to_list])insert(index, object, /)inserted(i, element, **kw_new)ion_list(*[, q, unique, default, istart])ions()is_ion()lookup(key, *[, unique_missing_ok, ...])mtot()n_per_nH([elem])n_per_ntot([elem])neutral_list(*[, unique, default, istart])neutrals()one_neutral_many_ions(*[, q, unique, ...])pop([index])popped(key, *[, return_indices])prepend_electron(*[, electron, istart])r_per_nH([elem])r_per_rtot([elem])register_default(infotype, defaultname, ...)remove(value, /)reverse()saha_list(*[, istart])sort(*[, key, reverse])to_dict()unique(*[, istart])unique_elements(*[, istart])unique_from(elements, *elements_as_args[, ...])with_istart([istart])without_i(i, **kw_init)Attributes
DEFAULTSabundanceionize_evmnamendimqssaha_g1g0size- append(object, /)
- Append object to the end of the list.
- 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.
- property element
- [fluid.element for fluid in self].To ignore fluids missing elements, consider self.unique_elements() instead.
- element_list_cls
alias of
ElementList
- property elements
- alias to element
- 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 dictsvalues 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 int
- mode 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_names(names=None, *names_as_args, m='physical', ionize_ev='physical', saha_g1g0='physical', abundance={}, missing_ok=True, **common_info)
- create ElementList from names and dicts of info about each element.
- names: None or list of str
- names of elements.None –> use keys of other dicts.list –> use these names in this order.defaults assume names will be title-case element symbol, e.g. ‘H’, ‘He’;using different names is allowed but will prevent default lookups.
- names_as_args: additional names
- only allowed if names is a string; can list extra strings here.from_names(‘H’, ‘He’, …) equivalent to from_names([‘H’, ‘He’, …]).
- m: str or dict
- masses of elements, in atomic mass units. E.g., {‘H’: 1}.str –> use cls.DEFAULTS[‘m’][m].
- ionize_ev: str or dict
- first ionization potentials of elements [eV]. E.g., {‘H’: 13.6}.str –> use cls.DEFAULTS[‘ionize_ev’][ionize_ev]
- saha_g1g0: str or dict
- ratio of g (degeneracy of states) for g1 (ions) to g0 (neutrals). E.g., {‘H’: 0.5}.str –> use cls.DEFAULTS[‘saha_g1g0’][saha_g1g0]
- abundance: str or dict
- abundances of elements relative to H. E.g., {‘H’: 12}.A(elem) = 12 + log10(n(elem) / n(H)), n = number density.str –> use cls.DEFAULTS[‘abundance’][abundance]
- missing_ok: bool
- whether to allow missing values for m, ionize_ev, or abundance.if False, missing values (i.e., None) will cause crash with FluidKeyError.
additional kwargs passed to Element.__init__ for every element.
- 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/list
- Some keys will look up and return corresponding element(s):nonnegative int, str, or element –> return corresponding element.DimensionSpecialValueSpecifier spec –> return spec.getter(self).tuple –> return tuple(self.get(k) for k in key)list –> return list(self.get(k) for k in key)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
- 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: bool
- True –> 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__.
- ion_list(*, q=1, unique=False, default=NO_VALUE, istart=0, **kw_specie)
- return MhdFluidList of once-ionized ions for elements of fluids in self.
- q: number, probably int
- charge in elementary charge units. (default: +1)
- unique: bool
- whether to give result based on self.unique_elements(), or ion(f) for f in self.False –> result[k] guaranteed to correspond to self[k] for all k.(IonMixtures will remain IonMixtures.)True –> ignore fluids without ions (e.g. electron, or fluid without element),and allow fluids to provide multiple ions (e.g. IonMixture with len>1).
- default: bool
- if provided, when unique=False and element missing, return default instead of crash.
- istart: None or int.
- int –> use result[k].with_i(istart + k) for all k.
- ion_mixture_cls
alias of
IonMixture
- 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.
- 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: bool
- whether 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: bool
- whether 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.
- mhd_fluid_list_cls
alias of
MhdFluidList
- mtot()
- return “average” mass of all elements in self, weighted by n (implied by abundances).mtot = sum_x(mx ax) / sum_x(ax), where ax = nx / nH, and x is an element in self.
- Note: mtot = rtot / ntot. This can be proven as follows:
- rtot = sum_x(rx) = sum_x(mx nx) = sum_x(mx ax nH) = sum_x(mx ax) nHntot = sum_x(nx) = sum_x(ax nH) = sum_x(ax) nH–> rtot / ntot = sum_x(mx ax) / sum_x(ax)
(note: ntot does not include electrons)
- n_per_nH(elem=None)
- n(elem)/n(H) for self.get(elem) (all elems in self if None).
- n_per_ntot(elem=None)
- n(elem)/n(total) for self.get(elem) (all elems in self if None).
- neutral_list(*, unique=False, default=NO_VALUE, istart=0, **kw_specie)
- return MhdFluidList of neutral species for elements of fluids in self.
- unique: bool
- whether to give result based on self.unique_elements(), or neutral(f) for f in self.False –> result[k] guaranteed to correspond to self[k] for all k.True –> ignore fluids without neutral (e.g. electron, or fluid without element),and allow fluids to provide multiple neutrals (e.g. IonMixture with len>1).
- default: NO_VALUE or any value
- if provided, when unique=False and element missing, return default instead of crash.
- istart: None or int.
- int –> use result[k].with_i(istart + k) for all k.
- neutrals()
- return FluidList of neutrals from self.
- ntot_per_nH()
- sum(n(elem)/n(H)) == n(total)/n(H). Summed across all elems in self.
- one_neutral_many_ions(*, q=1, unique=False, default=NO_VALUE, istart=0, **kw_specie)
- return MhdFluidList of self[0].neutral() then self.ion_list(q=q).q, unique, and default all get passed directly to self.ion_list.
istart: None or int. int –> use result[k].with_i(istart + k) for all k.
- 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: bool
- if 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.
- prepend_electron(*, electron=UNSET, istart=0, **kw_specie)
- return MhdFluidList like self but prepend electron to result.
- electron: UNSET or Specie
- UNSET –> make new electron Specie via Specie.electron().Specie –> assert is_electron() then prepend this specie to result.
istart: None or int. int –> use result[k].with_i(istart + k) for all k.
- r_per_nH(elem=None)
- r(elem)/n(H) for self.get(elem) (all elems in self if None).
- r_per_rtot(elem=None)
- r(elem)/r(total) for self.get(elem) (all elems in self if None).
- classmethod register_default(infotype, defaultname, element2value)
- register a default lookup table for an infotype.e.g. cls.register_default(‘abundance’, ‘photospheric_v0’, {‘H’: 12, ‘He’: 10.93})
- 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.
- rtot_per_nH()
- sum(r(elem)/n(H)) == r(total)/n(H). Summed across all elems in self.
- saha_list(*, istart=0, **kw_specie)
- return MhdFluidList of neutral & once-ionized ion for elements of fluids in self.Internally, equivalent to: [spec for f in self for spec in f.saha_list()]crashes if any fluid is missing an element.
istart: None or int. int –> use result[k].with_i(istart + k) for all k.
- 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. theorder 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.
- unique_elements(*, istart=None)
- return ElementList composed of unique elements from ElementHandlers in self.
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.
- 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_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.