pynucastro.rates package

The core routines needed to read and interpret nuclear reaction rates

Submodules

pynucastro.rates.known_duplicates module

pynucastro.rates.known_duplicates.find_duplicate_rates(rate_list)[source]

given a list of rates, return a list of groups of duplicate rates

pynucastro.rates.known_duplicates.is_allowed_dupe(rate_list)[source]

rate_list is a list of rates that provide the same connection in a network. Return True if this is an allowed duplicate

pynucastro.rates.library module

class pynucastro.rates.library.LangankeLibrary[source]

Bases: TabularLibrary

Load all of the tabular rates inside /library/tabular/langanke/ and return a Library.

lib_path = '/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/pynucastro/rates/../library/tabular/langanke'
class pynucastro.rates.library.Library(libfile=None, rates=None)[source]

Bases: object

A Library is a Rate container that reads a single file containing one or many Reaclib rates, possibly containing multiple sets per rate.

The Library class also implements searching based on rules specified by RateFilter objects.

add_rate(rate)[source]

Manually add a rate by giving a Rate object

backward()[source]

Select only the reverse rates, obtained by detailed balance.

derived_backward(compute_Q=False, use_pf=False)[source]

This library contains the detailed balance reverse reactions over the selected .derived_forward(), computed by hand.

derived_forward()[source]

In this library, we exclude the weak and tabular rates from the .forward() library which includes all the ReacLib forward reactions.

In a future PR, we will classify forward reactions as exothermic (Q>0), and reverse by endothermic (Q<0). However, ReacLib does not follow this path. If a reaction is measured experimentally (independent of Q), they use detailed balance to get the opposite direction. Eventually, I want to classify forward and reverse by positive Q and negative Q; however, for testing purposes, making this classification may eventually lead to computing the detailed balance twice.

The idea of derived_forward is to eliminate the reverse and weak, and see if our job gives the same Reaclib predictions, checking the NSE convergence with the pf functions. In the future, I want to move this function in a unit test.

diff(other_library)[source]

Return a Library containing the rates in this library that are not contained in other_library

filter(filter_spec)[source]

filter_specs should be an iterable of RateFilter objects or a single RateFilter object. Library.filter yields all rates matching any RateFilter in filter_specs. If RateFilter.exact, then return rates with exactly the reactants or products passed in as arguments.

report on an rates where another rate exists that has the same reactants and products. These may not be the same Rate object (e.g., one could be tabular the other a simple decay), but they will present themselves in the network as the same link.

We return a list, where each entry is a list of all the rates that share the same link

forward()[source]

Select only the forward rates, discarding the inverse rates obtained by detailed balance.

get_nuclei()[source]

get the list of unique nuclei

get_num_rates()[source]

Return the number of rates known to the library

get_rate(rid)[source]

Return a rate matching the id provided.

get_rate_by_name(name)[source]

Given a string representing a rate in the form ‘A(x,y)B’ (or a list of strings for multiple rates) return the Rate objects that match from the Library. If there are multiple inputs, then a list of Rate objects is returned.

get_rate_by_nuclei(reactants, products)[source]

given a list of reactants and products, return any matching rates

get_rates()[source]

Return a list of the rates in this library.

heaviest()[source]

Return the heaviest nuclide in this library.

lightest()[source]

Return the lightest nuclide in this library.

linking_nuclei(nuclist, with_reverse=True, print_warning=True)[source]

Return a Library object containing the rates linking the nuclei provided in the list of Nucleus objects or nucleus abbreviations ‘nuclist’.

If with_reverse is True, then include reverse rates. Otherwise include only forward rates.

If print_warning is True, then print out a warning if one of the input nuclei is not linked.

remove_rate(rate)[source]

Manually remove a rate from the library by supplying the short name “A(x,y)B, a Rate object, or the rate id

write_to_file(filename, prepend_rates_dir=False)[source]

Write the library out to a file of the given name in Reaclib format. Will be automatically written to the pynucastro rate file directory if True is passed in as the second argument.

class pynucastro.rates.library.RateFilter(reactants=None, products=None, exact=True, reverse=None, min_reactants=None, max_reactants=None, min_products=None, max_products=None, filter_function=None)[source]

Bases: object

RateFilter filters out a specified rate or set of rates A RateFilter stores selection rules specifying a rate or group of rates to assist in searching for rates stored in a Library.

invert()[source]

Return a RateFilter matching the inverse rate.

matches(r)[source]

Given a Rate r, see if it matches this RateFilter.

class pynucastro.rates.library.ReacLibLibrary[source]

Bases: Library

Load the latest stored version of the ReacLib library and return a Library

class pynucastro.rates.library.SuzukiLibrary[source]

Bases: TabularLibrary

Load all of the tabular rates inside /library/tabular/suzuki/ and return a Library.

lib_path = '/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/pynucastro/rates/../library/tabular/suzuki'
class pynucastro.rates.library.TabularLibrary[source]

Bases: Library

Load all of the tabular rates known and return a Library

lib_path = '/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/pynucastro/rates/../library/tabular'
pynucastro.rates.library.capitalize_rid(rid, delimiter)[source]
pynucastro.rates.library.list_known_rates()[source]

list the rates found in the library

pynucastro.rates.rate module

Classes and methods to interface with files storing rate data.

class pynucastro.rates.rate.ApproximateRate(primary_rate, secondary_rates, primary_reverse, secondary_reverse, is_reverse=False, approx_type='ap_pg')[source]

Bases: ReacLibRate

eval(T, rhoY=None)[source]

evaluate the approximate rate

function_string_cxx(dtype='double', specifiers='inline', leave_open=False, extra_args=())[source]

Return a string containing C++ function that computes the approximate rate

function_string_py()[source]

Return a string containing python function that computes the approximate rate

get_child_rates()[source]

return a list of all of the rates that are used in this approximation

class pynucastro.rates.rate.DerivedRate(rate, compute_Q=False, use_pf=False)[source]

Bases: ReacLibRate

This class is a derived class from Rate with the purpose of computing the inverse rate by the application of detailed balance to the forward reactions.

counter_factors()[source]

This function returns the nucr! = nucr_1! * … * nucr_r! for each repeated nucr reactant and nucp! = nucp_1! * … * nucp_p! for each reactant nucp product in a ordered pair (nucr!, nucp!). The factors nucr! and nucp! avoid overcounting when more than one nuclei is involve in the reaction, otherwise it will return 1.0.

eval(T, rhoY=None)[source]

evauate the reaction rate for temperature T

function_string_cxx(dtype='double', specifiers='inline', leave_open=False, extra_args=())[source]

Return a string containing C++ function that computes the rate

function_string_py()[source]

Return a string containing python function that computes the rate

class pynucastro.rates.rate.Rate(reactants=None, products=None, Q=None, weak_type='', label='generic')[source]

Bases: object

The base reaction rate class. Most rate types will subclass this and extend to their particular format.

cname()[source]

a C++-safe version of the rate name

eval(T, rhoY=None)[source]
eval_jacobian_term(T, rho, comp, y_i)[source]

Evaluate drate/d(y_i), y_i is a Nucleus object. This rate term has the full composition and density dependence, i.e.:

rate = rho**n Y1**a Y2**b … N_A <sigma v>

The derivative is only non-zero if this term depends on nucleus y_i.

get_rate_id()[source]

Get an identifying string for this rate.

heaviest()[source]

Return the heaviest nuclide in this Rate.

If two nuclei are tied in mass number, return the one with the lowest atomic number.

jacobian_string_py(y_i)[source]

Return a string containing the term in a jacobian matrix in a reaction network corresponding to this rate differentiated with respect to y_i

y_i is an object of the class Nucleus.

lightest()[source]

Return the lightest nuclide in this Rate.

If two nuclei are tied in mass number, return the one with the highest atomic number.

ydot_string_py()[source]

Return a string containing the term in a dY/dt equation in a reaction network corresponding to this rate.

exception pynucastro.rates.rate.RateFileError[source]

Bases: Exception

An error occurred while trying to read a Rate from a file.

class pynucastro.rates.rate.RatePair(forward=None, reverse=None)[source]

Bases: object

the forward and reverse rates for a single reaction sequence. Forward rates are those with Q >= 0.

Variables:
  • forward – the forward reaction Rate object

  • reverse – the reverse reaction Rate object

class pynucastro.rates.rate.ReacLibRate(rfile=None, chapter=None, original_source=None, reactants=None, products=None, sets=None, labelprops=None, Q=None)[source]

Bases: Rate

A single reaction rate. Currently, this is a ReacLib rate, which can be composed of multiple sets, or a tabulated electron capture rate.

Raises:

RateFileError, UnsupportedNucleus

eval(T, rhoY=None)[source]

evauate the reaction rate for temperature T

eval_deriv(T, rhoY=None)[source]

evauate the derivative of reaction rate with respect to T

function_string_cxx(dtype='double', specifiers='inline', leave_open=False, extra_args=())[source]

Return a string containing C++ function that computes the rate

function_string_py()[source]

Return a string containing python function that computes the rate

get_rate_exponent(T0)[source]

for a rate written as a power law, r = r_0 (T/T0)**nu, return nu corresponding to T0

get_rate_id()[source]

Get an identifying string for this rate. Don’t include resonance state since we combine resonant and non-resonant versions of reactions.

modify_products(new_products)[source]
plot(Tmin=100000000.0, Tmax=1600000000.0, rhoYmin=390000000.0, rhoYmax=2000000000.0, figsize=(10, 10))[source]

plot the rate’s temperature sensitivity vs temperature

Parameters:
  • Tmin (float) – minimum temperature for plot

  • Tmax (float) – maximum temperature for plot

  • rhoYmin (float) – minimum electron density to plot (e-capture rates only)

  • rhoYmax (float) – maximum electron density to plot (e-capture rates only)

  • figsize (tuple) – figure size specification for matplotlib

Returns:

a matplotlib figure object

Return type:

matplotlib.figure.Figure

write_to_file(f)[source]

Given a file object, write rate data to the file.

class pynucastro.rates.rate.SingleSet(a, labelprops)[source]

Bases: object

a set in Reaclib is one piece of a rate, in the form

lambda = exp[ a_0 + sum_{i=1}^5 a_i T_9**(2i-5)/3 + a_6 log T_9]

A single rate in Reaclib can be composed of multiple sets

Parameters:
  • a – the coefficients of the exponential fit

  • labelprops – a collection of flags that classify a ReacLib rate

dfdT()[source]

return a function for this dratedT(tf), where tf is a Tfactors object

dln_set_string_dT9_cxx(prefix='dset_dT', plus_equal=False)[source]

return a string containing the C++ code for d/dT9 ln(set)

f()[source]

return a function for rate(tf) where tf is a Tfactors object

set_string_cxx(prefix='set', plus_equal=False, with_exp=True)[source]

return a string containing the C++ code for this set

set_string_py(prefix='set', plus_equal=False)[source]

return a string containing the python code for this set

class pynucastro.rates.rate.TableIndex(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

a simple enum-like container for indexing the electron-capture tables

DQ = 3
GAMMA = 7
MU = 2
NU = 6
RATE = 5
RHOY = 0
T = 1
VS = 4
class pynucastro.rates.rate.TableInterpolator(*args, **kwargs)[source]

Bases: TableInterpolator

A simple class that holds a pointer to the table data and methods that allow us to interpolate a variable

class_type = jitclass.TableInterpolator#7fcacc4da090<data:array(float64, 2d, A),table_rhoy_lines:int32,table_temp_lines:int32,rhoy:array(float64, 1d, A),temp:array(float64, 1d, A)>
class pynucastro.rates.rate.TabularRate(rfile=None)[source]

Bases: Rate

A tabular rate.

Raises:

RateFileError, UnsupportedNucleus

eval(T, rhoY=None)[source]

evauate the reaction rate for temperature T

function_string_py()[source]

Return a string containing python function that computes the rate

get_nu_loss(T, rhoY)[source]

get the neutrino loss rate for the reaction if tabulated

get_rate_id()[source]

Get an identifying string for this rate. Don’t include resonance state since we combine resonant and non-resonant versions of reactions.

get_tabular_rate()[source]

read the rate data from .dat file

plot(Tmin=100000000.0, Tmax=1600000000.0, rhoYmin=390000000.0, rhoYmax=2000000000.0, color_field='rate', figsize=(10, 10))[source]

plot the rate’s temperature sensitivity vs temperature

Parameters:
  • Tmin (float) – minimum temperature for plot

  • Tmax (float) – maximum temperature for plot

  • rhoYmin (float) – minimum electron density to plot (e-capture rates only)

  • rhoYmax (float) – maximum electron density to plot (e-capture rates only)

  • figsize (tuple) – figure size specification for matplotlib

Returns:

a matplotlib figure object

Return type:

matplotlib.figure.Figure

class pynucastro.rates.rate.Tfactors(*args, **kwargs)[source]

Bases: Tfactors

precompute temperature factors for speed

Parameters:

T (float) – input temperature (Kelvin)

Variables:
  • T9 – T / 1.e9 K

  • T9i – 1.0 / T9

  • T913i – 1.0 / T9 ** (1/3)

  • T913 – T9 ** (1/3)

  • T953 – T9 ** (5/3)

  • lnT9 – log(T9)

class_type = jitclass.Tfactors#7fcacc4be250<T9:float64,T9i:float64,T913:float64,T913i:float64,T953:float64,lnT9:float64>
pynucastro.rates.rate.get_rates_dir()[source]
pynucastro.rates.rate.get_tabular_dir()[source]
pynucastro.rates.rate.load_rate(rfile=None)[source]

Try to load a rate of any type.

Raises:

RateFileError, UnsupportedNucleus