pynucastro.nucdata.composition module#

Classes and methods for describing a collection of nuclei and their abundances.

class pynucastro.nucdata.composition.Composition(nuclei, small=1e-16, init=None)[source]#

Bases: UserDict

A composition holds the mass fractions of the nuclei in a network.

Parameters:
  • nuclei (list, tuple) – an iterable of Nucleus objects

  • small (float) – a floor for nuclei mass fractions, used as the default value.

  • init (str) – Different modes to set up the initial composition. Valid choices are [uniform, random, solar]. If “solar” is selected, assume we work with metallicity, Z=0.02. If init=None, then no initial composition will be set.

property A#

Nucleus molar masses

Returns:

A – {Nucleus : A} pairs

Return type:

dict

property X#

backwards-compatible getter for self.X

property Z#

Nucleus charge

Returns:

Z – {Nucleus : Z} pairs

Return type:

dict

property abar#

Return the mean molecular weight

Return type:

float

bin_as(nuclei, *, verbose=False, exclude=None)[source]#

Given a list of nuclei, return a new Composition object with the current composition mass fractions binned into the new nuclei.

Parameters:
  • nuclei (list) – Input nuclei (either as string names or Nucleus objects) defining the new composition.

  • verbose (bool) – Output more information

  • exclude (bool) – List of nuclei in nuclei that only exact matches from the original composition can map into

Returns:

new_composition – The new binned composition

Return type:

Composition

get_molar()[source]#

Return a dictionary of molar fractions, Y = X/A.

Returns:

molar – {Nucleus : Y}

Return type:

dict

get_nuclei()[source]#

Return a list of Nuclei objects that make up this composition.

Return type:

list

get_sum_X()[source]#

Return the sum of the mass fractions.

Return type:

float

normalize(*, half_life_thresh=None)[source]#

Normalize the mass fractions to sum to 1.

Parameters:

half_life_thresh (float) – The half life value below which to zero the mass fraction of a nucleus. This prevents us from making a composition that is not really stable.

plot(trace_threshold=0.1, hard_limit=None, size=(9, 5))[source]#

Make a pie chart of Composition. group trace nuclei together and explode into bar chart

Parameters:
  • trace_threshold (float) – the threshold to consider a component to be trace.

  • hard_limit (float) – limit below which an abundance will not be included in the trace nuclei wedget of the plot.

  • size (tuple) – width, height of the plot in inches

Return type:

matplotlib.figure.Figure

set_all(xval)[source]#

Set all species to the same scalar value.

Parameters:

xval (float) – mass fraction value for all species

set_array(arr)[source]#

Set the mass fractions of all species to the values in arr, get_nuclei()

Parameters:

arr (list, tuple, numpy.ndarray) – input values of mass fractions

set_equal()[source]#

Set all species to be equal

set_nuc(name, xval)[source]#

Set nuclei name to the mass fraction xval.

Parameters:
set_random(alpha=None, seed=None)[source]#

Set all species using a Dirichlet distribution with parameters alpha and specified rng seed.

Parameters:
  • alpha (list, tuple, numpy.ndarray) – distribution length for the Dirichlet distribution

  • seed (float) – seed for the random number generator

set_solar_like(*, Z=0.02, half_life_thresh=None)[source]#

Approximate a solar abundance, setting p to 0.7, He4 to 0.3 - Z and the remainder evenly distributed with Z.

Parameters:
  • Z (float) – The desired metalicity

  • half_life_thresh (float) – The half life value below which to zero the mass fraction of a nucleus. This prevents us from making a composition that is not really stable.

property ye#

Return the electron fraction of the composition

Return type:

float

property zbar#

Return the mean charge, Zbar

Return type:

float

class pynucastro.nucdata.composition.LoddersComposition(Z=None, half_life_thresh=None)[source]#

Bases: Composition

A class to use present day solar abundances from Lodders et al. 2020 & 2021.

Parameters:
  • Z (float) – Target metallicity \(Z\) to scale the Lodders solar mixture to. If None (the default), the unscaled Lodders abundances are used.

  • half_life_thresh (float) – The half life value below which to zero the mass fraction of a nucleus. This prevents us from making a composition that is not really stable.

Notes

The Lodders abundances are stored in LODDERS_DATA as mass fractions for individual isotopes.