chemdiff package
Submodules
chemdiff.candyio module
- chemdiff.candyio.gather_all_abundances(col: Column, outputdirr: str, outputfile: str, tf: float, delete_subdir: bool) None[source]
(DEPRECATED) reads in all of the astrochem outputs from a column and puts all the output params into a single .npz file
- Parameters:
col (Column) – CANDY column
outputdirr (str) – output directory
outputfile (str) – output file
tf (float) – final time of simulation
delete_subdir (bool) – option to delete subdirectories after
abundances (gathering)
- chemdiff.candyio.gather_static_abuns(col: Column, outputdirr: str, outputfile: str, tf: float, delete_subdir: bool)[source]
Gather outputs from column into single .npz file for a static run of CANDY
- Parameters:
col (Column) – CANDY column
outputdirr (str) – output directory
outputfile (str) – output filename
tf (float) – final time from the simulation
delete_subdir (bool) – option to delete subdirectories after
file (creating .npz)
- chemdiff.candyio.get_abundict(filename='astrochem_output.h5', specs='all') tuple[ndarray, dict][source]
Create a dictionary of species abundances from an astrochem output
- Parameters:
filename (str, optional) – astrochem output h5 file. Defaults to ‘astrochem_output.h5’.
specs (list[str] | str, optional) – list of species to include in the output dictionary. Defaults to ‘all’.
- Returns:
array of times and the dictionary of species and abundances
- Return type:
tuple[np.ndarray, dict]
- chemdiff.candyio.get_defaults() tuple[dict, dict, dict][source]
Returns the default parameters for CANDY run as a tuple of dictionaries.
- Returns:
tuple of dictionaries containing default model params, physical params, and abundances
- Return type:
tuple[dict, dict, dict]
- chemdiff.candyio.get_final_abuns(f_name: str, specs: list[str] | str = 'all') dict[source]
Create a dictionary of the species abundances at the last time of the astrochem output
- Parameters:
f_name (str) – name of astrochem .h5 file
specs (list[str] | str, optional) – list of species to include. Defaults to ‘all’.
- Returns:
dictionary of species and abundances
- Return type:
dict
- chemdiff.candyio.get_nh_and_av(source_file: str) tuple[float, float][source]
Read the number denisty of hydrogen and visual extinction from the astrochem source file
- Parameters:
source_file (str) – name of astrochem source file
- Returns:
number density of hydrogen and visual extinction
- Return type:
tuple[float, float]
- chemdiff.candyio.get_specs_array(outputdirr: str) ndarray[source]
Returns an array of species used from astrochem output. Reads in from outputdirr/z00/astrochem_output.h5
- Parameters:
outputdirr (str) – name of output directory
- Returns:
array of species names
- Return type:
np.ndarray
- chemdiff.candyio.get_touts(tf: float) list[float][source]
Create the default list of output times
- Parameters:
tf (float) – final time to create touts until
- Returns:
list of output times
- Return type:
list[float]
- chemdiff.candyio.new_save_outputs(col: Column, nout: int, time: float, outputdirr: str, outputfile: str, delete_subdir: bool = False) None[source]
Save the current abundances of ice and gas into npz file. This saves from the memory and accounts for ices lost due to grain growth
- Parameters:
col (Column) – CANDY column of cells
nout (int) – output index
time (float) – the current time
outputdirr (str) – output directory
outputfile (str) – output file name
delete_subdir (bool, optional) – Delete subdirectories after values are saved. Defaults to False.
- chemdiff.candyio.parse_list(s: str) list[source]
Read in a string and convert to a python list. Used to read in touts from input file.
- Parameters:
s (str) – list string
- Returns:
parsed list
- Return type:
list
- chemdiff.candyio.read_infile(fin: str) tuple[dict, dict, dict][source]
Reads the input file to create input parameters dictionaries for CANDY
- Parameters:
fin (str) – name of input file
- Returns:
dictionaries of model params, physical params, and abundances
- Return type:
tuple[dict, dict, dict]
- chemdiff.candyio.read_touts_from_file(fname: str) ndarray[source]
Helper to read in output times saved in times.out
- Parameters:
fname (str) – name of file
- Returns:
array of output times
- Return type:
np.ndarray
- chemdiff.candyio.readh5file(filename: str = 'astrochem_output.h5') tuple[File, Dataset, Dataset, Dataset][source]
Helper function to read astrochem output and return relevent information
- Parameters:
filename (str, optional) – name of .h5 file to read. Defaults to ‘astrochem_output.h5’.
- Returns:
- tuple of outputs
opened h5.File object (be sure to close this later!)
list of species from astrochem
array of abundances for each species over time
list of times
- Return type:
tuple[h5.File, dict, dict, dict]
- chemdiff.candyio.save_outputs(col: Column, nout: int, outputdirr: str) None[source]
Copy and paste astrochem outputs to store as backup or to continue a run
- Parameters:
col (Column) – CANDY column of cells
nout (int) – the output index
outputdirr (str) – directory where savefiles should be stored
- chemdiff.candyio.save_pebbles(col: Column, pebcomp: dict, f_pebout: str, time: float) None[source]
Save the pebble compistion to text file
- Parameters:
col (Column) – CANDY column
pebcomp (dict) – dictionary of pebble compositions
f_pebout (str) – name of pebble text file
time (float) – the current time
chemdiff.cell module
- class chemdiff.cell.Cell(r, z, chi=1, cosmic=1.3e-17, grain_size=0.1, dust_gas_ratio=0.01, av=1, rho=10000000000.0, Tgas=50, Tdust=50, xray=0, NCO=1.0, NH2=1.0, NHD=1.0, NH=1.0, abundances={})[source]
Bases:
objectA cell has:
- a physical location
r,z
- physical parameters for the solver
chi, cosmic, grain size, dust/gas ratio
- source model parameters
- given
Av, nh, Tgas, Tdust, xrays
- calculated
NCO, NH2, (density)
- abundances
dict of abundances
- diffusion parameters
- given
omega, alpha, dz, dt (solver params?)
- calculated
cs, h, D, beta
- update_abundances(new_dict: dict)[source]
Update the abundances of each species in the cell
- Parameters:
new_dict (dict) – dictionary of new species and abundances
- write_chem_inputs(tf: float, abs_err: float, rel_err: float, abun_out: str = 'all', f_net: str = 'network.chm', f_input: str = 'input.ini', f_source: str = 'source.mdl')[source]
Write the chmical input and source files for astrochem
- Parameters:
tf (float) – final time for chemistry
abs_err (float) – absolute error for chemistry. If abundance is less than this set to zero
rel_err (float) – relative error for chemistry
abun_out (str, optional) – what species to track. Defaults to ‘all’.
f_net (str, optional) – chemical network to use for chemistry. Defaults to ‘network.chm’.
f_input (str, optional) – name of input file to write. Defaults to ‘input.ini’.
f_source (str, optional) – name of source file to write. Defaults to ‘source.mdl’.
chemdiff.chemistry module
- chemdiff.chemistry.chem_helper(args: tuple) dict[source]
Helper function to parallelize chemistry calculation. Calls Astrochem on a given cell
- Parameters:
args – tuple of arguments from do_chemistry() function
- Returns:
update abundance dictionary after chemistry
- Return type:
dict
- chemdiff.chemistry.do_chemistry(col: Column, chemtime: float, f_chm: str, outdirr: str, abs_err=1e-20, rel_err=1e-10) None[source]
Setup chem_helper() function to call astrochem in parallel using python multiprocessing library.
- Parameters:
col – Column to do chemistry on
chemtime – Time (in years) over which to do chemistry
f_chm – chm file to use for chemistry
outdirr – output directory
abs_err – absolute and relative errors for chemistry integration
rel_err – absolute and relative errors for chemistry integration
- chemdiff.chemistry.make_chmfile(abuns: dict) str[source]
Make a chm file with each species doing nothing so that their abundances are still returned in the output file.
- Parameters:
abuns (dict) – dictionary where the keys are species to be included in the do-nothing network
- Returns:
name of file created
- Return type:
str
chemdiff.column module
- class chemdiff.column.Column(r: float, alpha: float = 0.001, ncells: int = 50)[source]
Bases:
object1D Column of cells to allow for chemistry, diffusion, and grain growth
- get_abundance_array() dict[source]
Returns dictionary of chemical abundances for each cell
- Returns:
dictionary of abundances. Keys are the string of the chemical and values are arrays of length (nz,)
- Return type:
dict
- update_column_densities(opacity: float)[source]
Update the column densities and visual extinctions throughout the column given the current cell abundances. This should be called after column abundances are changed to remain consistent
- Parameters:
opacity (float) – The opacity of small dust grains [cm2 g-1]ß
chemdiff.constants module
chemdiff.diffusion module
- chemdiff.diffusion.do_diffusion(col: Column, diffdt: float) None[source]
Do the diffusion between cells in the column
- Parameters:
col (Column) – CANDY Column
diffdt (float) – timestep for the diffusion
- chemdiff.diffusion.grow_grains(col: Column, diffdt: float, pebcomp: dict, growth_timescale_factor: float, growth_height: float, outputdir: str) dict[source]
Grow the grains from the column. Remove ices and grains and update the pebble abundances
- Parameters:
col (Column) – CANDY Column
diffdt (float) – diffusion timestep
pebcomp (dict) – pebble composition dictionary
growth_timescale_factor (float) – growth timescale factor. tau_grow = (this)*1/(epsilon*Omega)
growth_height (float) – scaleheight under which pebbles will grow
outputdir (str) – output directory (unused)
- Returns:
updated dictionary of pebble abundances
- Return type:
dict
chemdiff.disk module
- chemdiff.disk.get_density(r: float, z: float) float[source]
Return the gas density at a given 2d location
- Parameters:
r (float) – radial distance [cm]
z (float) – height above midplane [cm]
- Returns:
gas density [g cm-3]
- Return type:
float
- chemdiff.disk.get_midplane_temp(r: float) float[source]
Midplane temperature of the disk, following Krijt et al. 2018
- Parameters:
r (float) – radial distance [cm]
- Returns:
midplane temperature [K]
- Return type:
float
- chemdiff.disk.get_omega(r: float) float[source]
Return Keplerian frequency at given radial location
- Parameters:
r (float) – radial distance [cm]
- Returns:
Keplerian Frequency [s-1]
- Return type:
float
- chemdiff.disk.get_scaleheight(r: float) float[source]
Return the scaleheight at a given location
- Parameters:
r (float) – radial distance [cm]
- Returns:
scaleheight [cm]
- Return type:
float
- chemdiff.disk.get_soundspeed(r: float) float[source]
Return the soundspeed at a given location in the disk
- Parameters:
r (float) – radial distance [cm]
- Returns:
soundspeed [cm/s]
- Return type:
float
- chemdiff.disk.get_surface_density(r: float) float[source]
Surface density at a given location in the disk following a powerlaw. Assumes disk is 0.05Msun in mass, and edge of disk is at 100 AU. Power law slope of -1
- Parameters:
r (float) – radial distance [cm]
- Returns:
Surface density, Sigma(r) [g cm-2]
- Return type:
float