PyAtomDB AtomDB module

This modules is designed to interact with the main atomic database, extracting real values of coefficients and so on.

The atomdb module contains several routines for interfacing with the AtomDB database to extract useful physical quantities, line lists, write new fits files and more. It is currently a dump of everything I’ve done with AtomDB. This should all be considered unstable and possibly susceptible to being wrong. It will be fixed, including moving many routines out of this library, as time goes on.

Version 0.1 - initial release Adam Foster July 17th 2015

Version 0.2 - added PI reading routines and get_data online enhancements. Adam Foster August 17th 2015

Version 0.3 - added RRC generation routines Adam Foster August 28th 2015

pyatomdb.atomdb.B_hyd(s, l, m, eta)
pyatomdb.atomdb.G_hyd(l, m, eta, rho)
pyatomdb.atomdb.addline(xbins, yvals, wv, amp, dx)
pyatomdb.atomdb.addline2(xbins, wv, amp, dx)
pyatomdb.atomdb.calc_ionrec_ci(cidat, Te, extrap=False)
pyatomdb.atomdb.calc_ionrec_dr(cidat, Te, extrap=False)
pyatomdb.atomdb.calc_ionrec_ea(cidat, Te, extrap=False)
pyatomdb.atomdb.calc_ionrec_rr(cidat, Te, extrap=False)
pyatomdb.atomdb.calc_kato(coll_type, par, Z, Te)
pyatomdb.atomdb.calc_maxwell_rates(coll_type, min_T, max_T, Tarr, om, dE, T, Z, degl, degu, quiet=False, levdat=False, ladat=False, lolev=False, uplev=False, force_extrap=False, did_extrap=False)
pyatomdb.atomdb.calc_rad_rec_cont(Z, z1, z1_drv, T, ebins, abund, ion_pop, settings)
pyatomdb.atomdb.calc_rrc(Z, z1, eedges, Te, lev, xstardat=False, xstarlevfinal=1, settings=False)

z1 is the recombined ion

pyatomdb.atomdb.calc_sampson_h(om, Z, Te)
pyatomdb.atomdb.calc_sampson_p(om, Z, Te)
pyatomdb.atomdb.calc_sampson_s(om, Z, Te)
pyatomdb.atomdb.calc_spline_atomdb(xa, ya, y2a, n, x)
pyatomdb.atomdb.ci_younger(Te, c)

Calculates Collisional Ionization Rates from Younger formula

Parameters:

Te : array(float)

Temperatures in Kelvin

c : the ionrec_par from the transition in the AtomDB IR file

Returns:

array(float)

returns ionization rate in cm^3 s^-1

pyatomdb.atomdb.dr_mazzotta(Te, c)
pyatomdb.atomdb.ea_mazzotta(Te, c, par_type)

Te is an array in Kelvin c is the ionrec_par par_type is the number denoting the type of the parameter returns excitation-autoionization rate in cm^3 s^-1

pyatomdb.atomdb.ea_mazzotta_iron(T_eV, c)
pyatomdb.atomdb.extract_n(conf_str)
pyatomdb.atomdb.f1_fcn(x)
pyatomdb.atomdb.f2_fcn(x)
pyatomdb.atomdb.get_abundance(abundfile, abundset, element=[-1])
pyatomdb.atomdb.get_bt_approx(om, Tin, Tout, uplev, lolev, levdat, ladat)
pyatomdb.atomdb.get_burgess_tully_extrap(bttype, lolev, uplev, Aval, Tarr, om, TTarg)
pyatomdb.atomdb.get_burgess_tully_transition_type(lolev, uplev, Aval)
pyatomdb.atomdb.get_data(Z, z1, ftype, settings=False, indexzero=False, offline=False)

Read AtomDB data of type ftype for ion rmJ of element Z.

If settings are set, the filemap can be overwritten (see below), otherwise $ATOMDB/filemap will be used to locate the file. If indexzero is set, all levels will have 1 subtracted from them (AtomDB indexes lines from 1, but python and C index arrays from 0, so this can be useful)

Parameters:

Z : int

Element nuclear charge

rmJ : int

Ion charge +1 (e.g. 5 for C^{4+}, a.k.a. C V)

ftype : string

type of data to read. Currently available
  • ‘IR’ - ionization and recombination
  • ‘LV’ - energy levels
  • ‘LA’ - radiative transition data (lambda and A-values)
  • ‘EC’ - electron collision data
  • ‘PC’ - proton collision data
  • ‘DR’ - dielectronic recombination satellite line data
  • ‘PI’ - XSTAR photoionization data
  • ‘AI’ - autoionization data

settings: dict

This is complicated one. If set, settings should be a dictionary, even if blank (e.g. settings={}) It serves multiple purposes:

  • Settings[‘data’] will store a copy of the data you read in. This means that if your code ends up calling for the same file multiple times, rather than re-reading from the disk, it will just point to this data already in memory. To clear the read files, just reset the data dictionary (e.g. settings[‘data’] ={})
  • settings[‘datasums’] stores the datasum when read in. Can be used later to check files are the same.

Both data and datasums store the data in identical trees, e.g.: settings[‘data’][Z][rmJ][ftype] will have the data.

indexzero: bool

If True, subtract 1 from all level indexes as python indexes from 0, while AtomDB indexes from 1.

offline: bool

If True, do not search online to download data files - just return as if data does not exist

Returns:

HDUlist

the opened pyfits hdulist if succesful. False if file doesn’t exist

pyatomdb.atomdb.get_emissivity(linefile, elem, ion, upper, lower, kT=[-1], hdu=[-1], kTunits='keV')
pyatomdb.atomdb.get_filemap_file(ftype, Z, z1, fmapfile=False, atomdbroot=False, quiet=False, misc=False)

Find the correct file from the database for atomic data of type ftype for ion with nuclear charge Z and ioncharge+1 = z1

Parameters:

ftype : str

  • ‘ir’ = ionization & recombination data
  • ‘lv’ = energy levels
  • ‘la’ = wavelength and transition probabilities (lambda & a-values)
  • ‘ec’ = electron collision rates
  • ‘pc’ = proton collision rates
  • ‘dr’ = dielectronic recombination satellite line information
  • ‘ai’ = autoionization rate data
  • ‘pi’ = XSTAR photoionization data
  • ‘em’ = emission feature data (currently unused)

Z : int

Element atomic number (=6 for C+4)

z1 : int

Ion charge +1 (=5 for C+4)

fmapfile : str

Specific filemap to use. Otherwise defaults to atomdbroot+’/filemap’

atomdbroot : str

Location of ATOMDB database. Defaults to ATOMDB environment variable. all $ATOMDB in the filemap will be expanded to this value

quiet : bool

If true, suppress warnings about files not being present for certain ions

misc : bool

If requesting “misc” data, i.e. the Bremsstrahlung inputs, use this. This is for non ion-specific data.

Returns:

str

The filename for the relevant file, with all $ATOMDB expanded. If no file exists, returns zero length string.

pyatomdb.atomdb.get_ion_lines(linefile, Z, z1, fullinfo=False)
pyatomdb.atomdb.get_ionbal(ionbalfile, element, ion=-1)
pyatomdb.atomdb.get_ionfrac(ionbalfile, Z, te, z1=-1)

Reads the ionization fraction of a given ion at a given Te from an ionbalfile Assumes ionization equilibrium

Parameters:

ionbalfile : str

location of ionization balance file

Z : int

atomic number of element (e.g. 6 for carbon)

te : float

electron temperature (in K)

z1 : int

if provided, z+1 of ion (e.g. 5 for O V)

if omitted, returns ionization fraction for all ions of element

Returns

——-

ionization fraction of ion or, if not specified, of all ions at Te

pyatomdb.atomdb.get_ionpot(Z, z1, filemap=False, atomdbroot=False, settings=False)
pyatomdb.atomdb.get_ionrec_rate(Te_in, irdat_in, lvdat_in=False, Te_unit='K', lvdatp1_in=False, ionpot=False, separate=False, Z=-1, z1=-1, settings=False, extrap=False)

Get the ionization and recombination rates at temperture(s) Te from ionization and recombination rate data file irdat.

Parameters:

Te_in : float or arr(float)

electron temperature in K (default), eV, or keV

irdat_in : HDUList

ionization and recombination rate data

lvdat_in : HDUList

level data for ion with lower charge (i.e. ionizing ion or recombined ion)

Te_unit : {‘K’ , ‘keV’ , ‘eV’}

temperature unit

lvdatp1_in : HDUList

level data for the ion with higher charge (i.e ionized or recombining ion)

ionpot : float

ionization potential of ion (eV).

separate : bool

if set, return DR, RR, EA and CI rates seperately. (DR = dielectronic recombination, RR = radiative recombination, EA = excitaiton autoionization, CI = collisional ionization) Note that EA & CI are not stored separately in all cases, so may return zeros for EA as the data is incorporated into CI rates.

Z : int

Element charge to get rates for (ignores “irdat_in”)

z1 : int

Ion charge +1 to get rates for (ignores “irdat_in”) e.g. Z=6,z1=4 for C IV (C 3+)

settings : str

if supplied, will be used to read/store previously opened data files. Will prevent unneccessarily reopening files in case where Z, z1 is specified.

extrap : bool

Extrappolate rates to Te ranges which are off the provided scale

Returns:

float, float:

(ionization rate coeff., recombination rate coeff.) in cm^3 s^-1 unless separate is set, in which case:

float, float, float, float:

(CI, EA, RR, DR rate coeffs) in cm^3 s^-1 Note that these assume low density & to get the real rates you need to multiply by N_e N_ion.

pyatomdb.atomdb.get_level_details(level, Z=-1, z1=-1, filename='', filemap='', atomdbroot='')

Function returns the details in the level file for the specified level. LV file can be specified by filename, or by filemap, Z, z1

pyatomdb.atomdb.get_line_emissivity(linefile, Z, z1, upind, loind, ion_drv=False, elem_drv=False)
pyatomdb.atomdb.get_maxwell_rate(Te, colldata, index, lvdata, Te_unit='K', lvdatap1=False, ionpot=False, force_extrap=False, silent=True)

Get the maxwellian rate for a transition from a file, typically for ionization, recombination or excitation.

Parameters:

Te: float

electron temperature(s), in K by default

colldata: HDUList

The collisional data of interest

index: int

The line in the data to do the calculation for. Indexed from 0.

lvdata: HDUList

the hdulist for the energy level file (as returned by pyfits.open(‘file’))

lvdatap1 : HDUList

The level data for the recombining or ionized data.

Te_unit: {‘K’,’eV’,’keV’}

Units of temperature grid.

Returns:

float or array(float)

Maxwellian rate coefficient, in units of cm^3 s^-1

pyatomdb.atomdb.get_pi_param(Z, z1, z1_drv, T, ebins, abund, ion_pop, settings)

Code to get the photoionization rate parameters for a given ion

pyatomdb.atomdb.interp_rate(Te, npar, Te_grid, ionrec_par)
pyatomdb.atomdb.interpol_huntd(x, y, z)
pyatomdb.atomdb.interpolate_ionrec_rate(cidat, Te, force_extrap=False)
pyatomdb.atomdb.make_level_descriptor(lv)
pyatomdb.atomdb.prep_spline_atomdb(x, y, n)
pyatomdb.atomdb.read_filemap(filemap=False, atomdbroot=False)

Reads the AtomDB filemap file in to memory. By default, tries to read $ATOMDB/filemap, replacing all instances of $ATOMDB in the filemap file with the value of the environment variable $ATOMDB

KWARGS filemap: string : the filemap file to read atomdbroot: string: string to replace $ATOMDB by

Version 0.1 - initial release Adam Foster August 15th 2015

pyatomdb.atomdb.rr_shull(Te, c)
pyatomdb.atomdb.rr_verner(Te, c)
pyatomdb.atomdb.rrc_ph_value(E, Z, z1, rrc_ph_factor, IonE, kT, levdat, xstardata=False, xstarfinallev=False)
pyatomdb.atomdb.sigma_hydrogenic(N, L, Z, Ein)

Calculate the PI cross sections of type hydrogenic.

INPUTS N: n shell L: l quantum number Z: nuclear charge Ein: energy grid for PI cross sections (in keV)

RETURNS Photoionization cross section (in cm^2)

Version 0.1 - initial release Adam Foster August 28th 2015

pyatomdb.atomdb.sigma_photoion(E, Z, z1, pi_type, pi_coeffts, xstardata=False, xstarfinallev=1)

Returns the photoionization cross section at E, given an input of sig_coeffts.

Parameters:

E: float or array of floats

Energy/ies to find PI cross section at (keV)

Z: int

Atomic number of element (i.e. 8 for Oxygen)

pi_type : int

the “PI_TYPE” from the energy level file for this level, can be:

-1. No PI data 0. Hydrogenic 1. Clark 2. Verner 3. XSTAR

pi_coeffts : array(float)

the “PI_PARAM” array for this level from the LV file

xstardata : dict, str or HDUList

if the data is XSTAR data (pi_type=3), supply the xstardata. This can be a dictionary with 2 arrays, one “Energy”, one “sigma”, the file name, or the entire PI file (already loaded):

# load level data
lvdata = atomdb.get_data(26, 24, 'LV', settings)

# load XSTAR PI data if it exists
pidata = atomdb.get_data(26, 24, 'PI', settings)

# get pi xsection at energy E for the ground state to ground state
sigma_photoion(E,
               lvdata[1].data['pi_type'][0],
               lvdata[1].data['pi_param'][0],
               xstardata=pidata,
               xstarfinallev=1)

xstarfinallev: the level to ionize in to. Defaults to 1.

Returns:

array(float)

pi cross section in cm^2 at energy E.

pyatomdb.atomdb.sort_pi_data(pidat, lev_init, lev_final)

Given the pidat (returned by opening the PI data file, i.e. pyfits.open(‘XX_YY_PI.fits’), and the initial and final levels, return the PI cross section data.

Parameters:

pidat : hdulist

The photoionization data for the ion

lev_init: int

The initial level

lev_final: int :

The final level

Returns:

dict:

which contains the following information: pi[‘ion_init’] - the initial ion charge +1 pi[‘lev_init’] - the initial level pi[‘ion_final’] - the final ion charge+1 (should be ion_init+1) pi[‘lev_final’] - the final level pi[‘pi_type’] - the type. (best to ignore) pi[‘g_ratio’] - the ratio of the statistical weight of the intitial and final levels pi[‘energy’] - the array of energies (keV) pi[‘pi_param’] - the array of pi cross sections in Mbarn.

pyatomdb.atomdb.write_filemap(d, filemap, atomdbroot='')