Utility classes and functions
ProxyList
- class iniabu.utilities.ProxyList(parent, proxy_cls, valid_set, *args, **kwargs)
Proxy for accessing elements and isotopes as lists.
This class is inspired by a class with the same name from the project
InstrumentKit
by Galvant Industries. It is used to generate lists of objects. The valid keys are defined by the valid_set initialization parameter. This allows generating a single property for elements and isotopes to access them.
get_all_available_isos()
- iniabu.utilities.get_all_available_isos(ele)
Get all available isotopes of a given element, stable and unstable.
This is particularly interesting if we want to know the mass of unstable isotopes.
- Parameters:
ele (str) – Element name
- Returns:
All isotopes of the element as a list.
- Return type:
list(str)
get_all_stable_isos()
item_formatter()
- iniabu.utilities.item_formatter(iso: str) str
Transform iso into correct format, e.g,. from 46Ti to Ti-46.
Also appropriately capitalizes isotopes and elements.
Supported formats: - 46Ti - Ti46 - Ti-46
- Parameters:
iso – Isotope as string or element name.
- Returns:
iso, but in transformed notation and capitalized
linear_units()
- iniabu.utilities.linear_units(ini, mass_fraction)
Context manager to turn current instants units linear if logarithmic.
This is used mainly for ratio calculation, since logarithmic cannot be ratioed to each other.
- Parameters:
ini (IniAbu) – Initialized iniabu instance
mass_fraction (bool or None) – Mass fraction variable passed on from last routine
- Yield:
ini as with adjusted units (if necessary)
- Ytype:
IniAbu instance
make_iso_dict()
- iniabu.utilities.make_iso_dict(element_dict)
Make an isotope dictionary from an element dictionary.
- Parameters:
element_dict (dict) – Element dictionary.
- Returns:
Isotope dictionaries with same abundances as element dictionary.
- Return type:
dict
make_log_abu_dict()
- iniabu.utilities.make_log_abu_dict(element_dict)
Make element and isotope dictionaries for logarithmic abundances.
This routine takes an element dictionary with linear abundances, normed to Si equals 1e6, and returns new dictionaries with logarithmic abundances, normed to log10(Nx/NH) + 12, where Nx is the number abundance of the element in question and NH is the number abundance of hydrogen.
- Parameters:
element_dict (dict) – Element dictionary.
- Returns:
Element and isotope dictionaries with logarithmic solar abundances.
- Return type:
dict,dict
make_mf_dict()
- iniabu.utilities.make_mf_dict(element_dict)
Make element and isotope dictionaries for mass fractions.
This routine takes an element dictionary with linear abundances, normed to Si equals 1e6, and returns new dictionaries with mass fractions. The mass fraction Xi of an isotope i is defined as Xi = Ni mi / sum(Ni mi). Here, Ni is the number abundance of a element / isotope i and mi is its mass.
- Parameters:
element_dict (dict) – Element dictionary.
- Returns:
Element and isotope dictionaries with mass fractions.
- Return type:
dict,dict
return_as_ndarray()
- iniabu.utilities.return_as_ndarray(val)
Return the input as a ndarray.
- Parameters:
val (int,float,list,tuple,ndarray) – Input value.
- Returns:
Array of input value if not an array, otherwise return itself.
- Return type:
ndarray
return_string_as_list()
- iniabu.utilities.return_string_as_list(s)
Return the input as a list.
- Parameters:
s (str,list) – Input value.
- Returns:
List of input value if not a list, otherwise return itself.
- Return type:
list
return_list_simplifier()
- iniabu.utilities.return_list_simplifier(return_list)
Simplify standard return values.
Specifically written for classes with multiple return types, such as
iniabu.elements.Elements
andiniabu.isotopes.Isotopes
. If only one entry is in the list, it should not be returned as a list but as a value. Otherwise, return the list.- Parameters:
return_list (list,ndarray) – List or numpy array with the value to be returned.
- Returns:
If only one entry in list, return that entry. Otherwise return list.