Astrochem Python Module reference

This documents gives a description of Astrochem Python module. The module itself contains two packages: the tool package, which allows to work on chemical networks and astrochem output files and wrapper package , which allows to run Astrochem from Python. For an example on how to do this, see calling Astrochem from Python

Tools (astrochem.tools)

Various tools for Astrochem.

tools.converttolegacy(filename, specie)

Convert a hdf5 output file specific species to .abun and .rout legacy format.

Parameters:
  • filename (str) – Path to the output file
  • species (str) – Name of specie to read abundance and route of
tools.listspecies(filename)

Print available species from an hdf5 output file and return it in a array

Parameters:filename (str) – Path to output file.
Returns:Species list
Return type:list if str
class tools.network_reader(reactions)

Chemical network reader class.

__repr__()

Returns the string representation of a network.

Returns:The string representation of the network.
Return type:str
duplicate_react_numbers()

Find reactions with the same reaction number.

Returns:List of duplicated reaction_numbers.
Return type:list of str
duplicate_reactions()

Find duplicate reactions.

Returns:List of reaction_numbers of duplicated reactions.
Return type:list of int
static fromfile(f, fileformat)

Read a network from a file.

This function reads a chemistry network from a file and creates a network instance. Supported formats are chm, osu and kida.

Parameters:
  • f (file) – Network file
  • fileformat (str) – Network file format (“chm”, “osu” or “kida”)
Returns:

Network

Return type:

network_reader

getreact(number)

Returns the reaction with a given number.

Parameters:number (int) – The reaction number.
Returns:The reaction found.
Return type:reaction
Raises:ValueError – If no reaction with this number if found.
tofile(f, renumber=False)

Write network in a file.

Parameters:
  • f (file) – Network file handle
  • renumber (bool, optional) – Renumber reactions (default False)
class tools.reaction(reactants, products, alpha, beta, gamma, rtype, rnumber)

Chemical reaction class.

reactants

list of str

List of reactants.

products

list of str

List of products.

alpha

float

Reaction constant.

beta

float

Reaction constant.

gamma

float

Reaction constant.

rtype

int

Reaction type.

rnumber

int

Reaction number.

__eq__(other)

Compares the reaction with another.

This method compares two reactions. The reactions are supposed to be equal if both the reactants and products are equal, regardless of the reaction rates.

Parameters:other (reaction) – Reaction instance to compare with.
Returns:True if the reactions are equal, False otherwise.
Return type:bool
__repr__()

Returns the string representation of a reaction.

Returns:The string representation of the reaction.
Return type:str
totex()

Returns a reaction in TeX format.

Returns:TeX formated reaction string.
Return type:str
tools.readabun(filename, specie)

Read abundances for a specific specie from an hdf5 output file and return arrays of time and abundances

Parameters:
  • filename (str) – Path to the output file
  • specie (str) – Name of specie to read abundance of
Returns:

  • timesteps (list of float) – List of timesteps
  • abundance (list of float) – List of abundances

tools.readabunlegacy(filename)

Read an abund file and return arrays of time and abundances.

Parameters:filename (str) – Path to the abund file.
Returns:
  • timesteps (list of floats) – List of timesteps
  • abundances (list of floats) – List of abundances
tools.readfilesattrs(filename)

Read chem_file and source_file attributes from an hdf5 output file

Parameters:filename (str) – Path to output file.
Returns:
  • chemfile (str) – chem_file attribute
  • sourcefile (str) – source_file attribute
tools.readrout(filename, specie)

Read a rout from a hdf5 output file and return arrays of time, shell number, formation/destruction rates.

Parameters:
  • filename (str) – Path to the output file.
  • specie (str) – Name of specie to read route of.
Returns:

  • timesteps (list of float) – List of timesteps.
  • shells (list of float) – List of shell numbers.
  • formation_reac (list of reaction) – List of formation reactions.
  • formation_rate (list of float) – List of formation rates.
  • destruction_reac (list of reaction) – List of destruction reactions.
  • destruction_rate (list of float) – List of destruction rates.

tools.readroutlegacy(filename)

Read a rout file and return arrays of time, cell number, formation/destruction rates

Parameters:filename (str) – Path to the output file.
Returns:
  • timesteps (list of float) – List of timesteps.
  • shells (list of float) – List of shell numbers.
  • formation_reac (list of reaction) – List of formation reactions.
  • formation_rate (list of float) – List of formation rates.
  • destruction_reac (list of reaction) – List of destruction reactions.
  • destruction_rate (list of float) – List of destruction rates.

Wrapper (astrochem.wrapper)

Python wrapper for libpyastrochem.

class wrapper.cell(av, nh, tgas, tdust)

Cell class.

av

float

Visual extinction in magnitudes.

nh

float

Hydrogen density in cm^-3.

tgas

float

Gas temperature in K.

tdust

float

Dust temperature in K.

class wrapper.network(chem_file, verbose)

Network class.

chem_file

str

File containing a network to load.

verbose

int

Verbose if 1, Quiet if 0.

class wrapper.phys

Physical parameters to use in chemical reaction solver.

chi

float

Chi physical property.

cosmic

float

Cosmic physical property.

grain_abundance

float

Grain Abundance physical property.

grain_size

float

Grain Size physical property.

class wrapper.solver(cell, chem_file, phys, abs_err, rel_err, initial_abundances, density, verbose)

Chemical reaction solver.

cell

cell

Chemical cell class to use in solver.

chem_file

str

Chemical network file string to load network from and use in solver.

phys

phys

Physical properties class to use in solver.

abs_err

float

Absolute acceptable error to use in solver.

rel_err

float

Relative acceptable error to use in solver.

initial_abundances

dict

Initial abundances (format {Species:Value}).

density

float

Density to use in solver.

verbose

int

verbose if 1, quiet if 0.

solve(time, new_cell)

Solve chemical reaction for a certain time

Parameters:
  • time (float) – Time to solve the system at
  • new_cell (cell) – Cell class to use in solver, optionnal