NEI¶

class
plasmapy_nei.nei.
NEI
(inputs, abundances: Union[Dict[KT, VT], str] = None, T_e: Union[Callable, astropy.units.quantity.Quantity] = None, n: Union[Callable, astropy.units.quantity.Quantity] = None, time_input: astropy.units.quantity.Quantity = None, time_start: astropy.units.quantity.Quantity = None, time_max: astropy.units.quantity.Quantity = None, max_steps: Union[int, numpy.integer] = 10000, tol: Union[int, float] = 1e15, dt: astropy.units.quantity.Quantity = None, dt_max: astropy.units.quantity.Quantity = <Quantity inf s>, dt_min: astropy.units.quantity.Quantity = <Quantity 0. s>, adapt_dt: bool = None, safety_factor: Union[int, float] = 1, verbose: bool = False)[source]¶ Bases:
object
Perform and analyze a nonequilibrium ionization simulation.
Parameters:  inputs –
 T_e (astropy.units.Quantity or callable) – The electron temperature, which may be a constant, an array of temperatures corresponding to the times in time_input, or a function that yields the temperature as a function of time.
 n (astropy.units.Quantity or callable) – The number density multiplicative factor. The number density of
each element will be
n
times the abundance given inabundances
. For example, ifabundance['H'] = 1
, then this will correspond to the number density of hydrogen (including neutral hydrogen and protons). This factor may be a constant, an array of number densities over time, or a function that yields a number density as a function of time.  time_input (astropy.units.Quantity, optional) – An array containing the times associated with
n
andT_e
in units of time.  time_start (astropy.units.Quantity, optional) – The start time for the simulation. If density and/or
temperature are given by arrays, then this argument must be
greater than
time_input[0]
. If this argument is not supplied, thentime_start
defaults totime_input[0]
(if given) and zero seconds otherwise.  time_max (astropy.units.Quantity) – The maximum time for the simulation. If density and/or
temperature are given by arrays, then this argument must be less
than
time_input[1]
.  max_steps (int) – The maximum number of time steps to be taken during a simulation.
 dt (astropy.units.Quantity) – The time step. If
adapt_dt
is False, thendt
is the time step for the whole simulation.  dt_max (astropy.units.Quantity) – The maximum time step to be used with an adaptive time step.
 dt_min (astropy.units.Quantity) – The minimum time step to be used with an adaptive time step.
 adapt_dt (bool) – If True, change the time step based on the characteristic ionization and recombination time scales and change in temperature. Not yet implemented.
 safety_factor (float or int) – A multiplicative factor to multiply by the time step when
adapt_dt
is True. Lower values improve accuracy, whereas higher values reduce computational time. Not yet implemented.  tol (float) – The absolute tolerance to be used in comparing ionic fractions.
 verbose (bool, optional) – A flag stating whether or not to print out information for every
time step. Setting
verbose
to True is useful for testing. Defaults to False.  abundances (dict) –
Examples
>>> import numpy as np >>> import astropy.units as u
>>> inputs = {'H': [0.9, 0.1], 'He': [0.9, 0.099, 0.001]} >>> abund = {'H': 1, 'He': 0.085} >>> n = u.Quantity([1e9, 1e8], u.cm**3) >>> T_e = np.array([10000, 40000]) * u.K >>> time = np.array([0, 300]) * u.s >>> dt = 0.25 * u.s
The initial conditions can be accessed using the initial attribute.
>>> sim = NEI(inputs=inputs, abundances=abund, n=n, T_e=T_e, time_input=time, adapt_dt=False, dt=dt)
After having inputted all of the necessary information, we can run the simulation.
>>> results = sim.simulate()
The initial results are stored in the
initial
attribute.>>> sim.initial.ionic_fractions['H'] array([0.9, 0.1])
The final results can be access with the
final
attribute.>>> sim.final.ionic_fractions['H'] array([0.16665179, 0.83334821]) >>> sim.final.ionic_fractions['He'] array([0.88685261, 0.11218358, 0.00096381]) >>> sim.final.T_e <Quantity 40000. K>
Both
initial
andfinal
are instances of theIonizationStates
class.Notes
The ionization and recombination rates are from Chianti version 8.7. These rates include radiative and dielectronic recombination. Photoionization is not included.
Attributes Summary
EigenDataDict
Return a dict containing ~plasmapy_nei.eigen.EigenData instances for each element. T_e_input
The temperature input. abundances
Return the abundances. adapt_dt
Return True if the time step is set to be adaptive, False if the time step is set to not be adapted, and None if this attribute was not set. dt_input
Return the inputted time step. dt_max
dt_min
The minimum time step. elements
A list of the elements. final
Return the ionization states of the plasma at the end of the simulation. initial
Return the ionization states of the plasma at the beginning of the simulation. max_steps
The maximum number of steps that a simulation will be allowed to take. n_input
The number density factor input. results
Return the ~plasmapy_nei.nei.SimulationResults class instance that corresponds to the simulation results. safety_factor
The multiplicative factor that the time step is to be multiplied by when using an adaptive time step. time_input
time_max
The maximum time allowed for the simulation. time_start
The start time of the simulation. tol
The tolerance for comparisons between different ionization states. verbose
Return True if verbose output during a simulation is requested, and False otherwise. Methods Summary
electron_temperature
(time)equil_ionic_fractions
(T_e, time)Return the equilibrium ionic fractions for a temperature or at a given time. hydrogen_number_density
(time)in_time_interval
(time, buffer)Return True if the time
is betweentime_start  buffer
andtime_max + buffer
, and False otherwise.index_to_time
(index)Returns the time value or array given the index/indices save
(filename)Save the ~plasmapy_nei.nei.NEI instance to an HDF5 file. set_timestep
(dt)Set the time step for the next nonequilibrium ionization time advance. simulate
()Perform a nonequilibrium ionization simulation. time_advance
()Advance the simulation by one time step. time_to_index
(time)Returns the closest index value or array for the given time(s) Attributes Documentation

EigenDataDict
¶ Return a dict containing ~plasmapy_nei.eigen.EigenData instances for each element.

T_e_input
¶ The temperature input.

abundances
¶ Return the abundances.

adapt_dt
¶ Return True if the time step is set to be adaptive, False if the time step is set to not be adapted, and None if this attribute was not set.

dt_input
¶ Return the inputted time step.

dt_max
¶

dt_min
¶ The minimum time step.

elements
¶ A list of the elements.

final
¶ Return the ionization states of the plasma at the end of the simulation.

initial
¶ Return the ionization states of the plasma at the beginning of the simulation.

max_steps
¶ The maximum number of steps that a simulation will be allowed to take.

n_input
¶ The number density factor input.

results
¶ Return the ~plasmapy_nei.nei.SimulationResults class instance that corresponds to the simulation results.

safety_factor
¶ The multiplicative factor that the time step is to be multiplied by when using an adaptive time step.

time_input
¶

time_max
¶ The maximum time allowed for the simulation.

time_start
¶ The start time of the simulation.

tol
¶ The tolerance for comparisons between different ionization states.

verbose
¶ Return True if verbose output during a simulation is requested, and False otherwise.
Methods Documentation

electron_temperature
(time: astropy.units.quantity.Quantity) → astropy.units.quantity.Quantity[source]¶

equil_ionic_fractions
(T_e: astropy.units.quantity.Quantity = None, time: astropy.units.quantity.Quantity = None) → Dict[str, numpy.ndarray][source]¶ Return the equilibrium ionic fractions for a temperature or at a given time.
Parameters:  T_e (astropy.units.Quantity, optional) – The electron temperature in units that can be converted to kelvin.
 time (astropy.units.Quantity, optional) – The time in units that can be converted to seconds.
Returns: equil_ionfracs – The equilibrium ionic fractions for the elements contained within this class
Return type: dict
Notes
Only one of
T_e
andtime
may be included as an argument. If neitherT_e
ortime
is provided and the temperature for the simulation is given by a constant, the this method will assume thatT_e
is the temperature of the simulation.

hydrogen_number_density
(time: astropy.units.quantity.Quantity) → astropy.units.quantity.Quantity[source]¶

in_time_interval
(time: Unit("s"), buffer: Unit("s") = <Quantity 1.e09 s>)[source]¶ Return True if the
time
is betweentime_start  buffer
andtime_max + buffer
, and False otherwise.Raises: TypeError
– Iftime
orbuffer
is not aastropy.units.Quantity
astropy.units.UnitsError
– Iftime
orbuffer
is not in units of time.

index_to_time
(index)[source]¶ Returns the time value or array given the index/indices
Parameters: index (arraylike) – A value or array of values representing the index of the time array created by the simulation Returns: get_time – The time value associated with index input(s) Return type: astropy.units.Quantity

save
(filename: str = 'nei.h5')[source]¶ Save the ~plasmapy_nei.nei.NEI instance to an HDF5 file. Not implemented.

set_timestep
(dt: astropy.units.quantity.Quantity = None)[source]¶ Set the time step for the next nonequilibrium ionization time advance.
Parameters: dt (astropy.units.Quantity, optional) – The time step to be used for the next time advance. Notes
If
dt
is not None, then the time step will be set todt
.If
dt
is not set and theadapt_dt
attribute of an ~plasmapy_nei.nei.NEI instance is True, then this method will calculate the time step corresponding to how long it will be until the temperature rises or drops into the next temperature bin. If this time step is betweendtmin
anddtmax
, thenIf
dt
is not set and theadapt_dt
attribute is False, then this method will set the time step as what was inputted to the ~plasmapy_nei.nei.NEI class upon instantiation in thedt
argument or through the ~plasmapy_nei.nei.NEI class’sdt_input
attribute.Raises: NEIError
– If the time step cannot be set, for example if thedt
argument is invalid or the time step cannot be adapted.

simulate
() → plasmapy_nei.nei.nei.SimulationResults[source]¶ Perform a nonequilibrium ionization simulation.
Returns: results – The results from the simulation (which are also stored in the results
attribute of the ~plasmapy_nei.nei.NEI instance this method was called from.Return type: ~plasmapy_nei.classes.Simulation

time_to_index
(time)[source]¶ Returns the closest index value or array for the given time(s)
Parameters: time (arraylike,) – A value or array of values representing the values of the time array created by the simulation Returns: index – The index value associated with the time input(s) Return type: int or arraylike,