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
Warning
The Astrochem Python module is recent, and its API is subject to change in future releases.
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)
Returns a list of species that are available in an hdf5 file
- Parameters:
filename (str) – Path to output file.
- Returns:
Species list
- Return type:
list if str
- class tools.network_reader(reactions)
Chemical network reader class.
- 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 reactants.
- Type:
list of str
- products
List of products.
- Type:
list of str
- alpha
Reaction constant.
- Type:
float
- beta
Reaction constant.
- Type:
float
- gamma
Reaction constant.
- Type:
float
- rtype
Reaction type.
- Type:
int
- rnumber
Reaction number.
- Type:
int
- 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
Visual extinction in magnitudes.
- Type:
float
- nh
Hydrogen density in cm^-3.
- Type:
float
- tgas
Gas temperature in K.
- Type:
float
- tdust
Dust temperature in K.
- Type:
float
- class wrapper.Network(chem_file, verbose)
Network class.
- chem_file
File containing a network to load.
- Type:
str
- verbose
Verbose if 1, Quiet if 0.
- Type:
int
- class wrapper.Phys
Physical parameters to use in chemical reaction solver.
- chi
Chi physical property.
- Type:
float
- cosmic
Cosmic physical property.
- Type:
float
- grain_abundance
Grain Abundance physical property.
- Type:
float
- grain_size
Grain Size physical property.
- Type:
float
- class wrapper.Solver(cell, chem_file, phys, abs_err, rel_err, initial_abundances, density, verbose)
Chemical reaction solver.
- cell
Chemical cell class to use in solver.
- Type:
cell
- chem_file
Chemical network file string to load network from and use in solver.
- Type:
str
- phys
Physical properties class to use in solver.
- Type:
phys
- abs_err
Absolute acceptable error to use in solver.
- Type:
float
- rel_err
Relative acceptable error to use in solver.
- Type:
float
- initial_abundances
Initial abundances (format {Species:Value}).
- Type:
dict
- density
Density to use in solver.
- Type:
float
- verbose
verbose if 1, quiet if 0.
- Type:
int
- solve(time, new_cell=None)
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