crrlpy.models.rrlmod module

Module with RRL models.

Models are not shipped with the code.

crrlpy.models.rrlmod.I_Bnu(specie, Z, n, Inu_funct, *args)[source]

Calculates the product \(B_{n+\Delta n,n}I_{\nu}\) to compute the line broadening due to a radiation field \(I_{\nu}\).

Parameters:
  • specie (string) – Atomic specie to calculate for.

  • n (int or list) – Principal quantum number at which to evaluate \(\dfrac{2}{\pi}\sum\limits_{\Delta n}B_{n+\Delta n,n}I_{n+\Delta n,n}(\nu)\).

  • Inu_funct (function) – Function to call and evaluate \(I_{n+\Delta n,n}(\nu)\). It’s first argument must be the frequency.

  • args – Arguments to Inu_funct. The frequency must be left out. The frequency will be passed internally in units of MHz. Use the same unit when required. Inu_funct must take the frequency as first parameter.

Returns:

(Hz)

Return type:

array

Example:

>>> I_Bnu('CI', 1.,  500, I_broken_plaw, 800, 26*u.MHz.to('Hz'), -1., -2.6)
array([6.6554062])
crrlpy.models.rrlmod.I_broken_plaw(nu, Tr, nu0, alpha1, alpha2)[source]

Returns the blackbody function evaluated at nu. As temperature a broken power law is used. The power law shape has parameters: Tr, nu0, alpha1 and alpha2.

Parameters:
Returns:

Specific intensity in \(\rm{erg}\,\rm{cm}^{-2}\,\rm{Hz}^{-1}\,\rm{s}^{-1}\,\rm{sr}^{-1}\). See astropy.modeling.physical_models.BlackBody

Return type:

astropy.units.Quantity

crrlpy.models.rrlmod.I_cont(nu, Te, tau, I0, unitless=False)[source]

Computes the specific intensity due to a blackbody at temperature \(T_{e}\) and optical depth \(\tau\). It considers that there is background radiation with \(I_{0}\).

Parameters:
  • nu ((Hz) or astropy.units.Quantity) – Frequency.

  • Te – Temperature of the source function. (K) or astropy.units.Quantity

  • tau – Optical depth of the medium.

  • I0 – Specific intensity of the background radiation. Must have units of erg / (cm2 Hz s sr) or see unitless.

  • unitless – If True the return

Returns:

The specific intensity of a ray of light after traveling in an LTE medium with source function \(B_{\nu}(T_{e})\) after crossing an optical depth \(\tau_{\nu}\). The units are erg / (cm2 Hz s sr). See astropy.modeling.physical_models.BlackBody

crrlpy.models.rrlmod.I_external(nu, Tbkg, Tff, tau_ff, Tr, nu0=<Quantity 1.e+08 MHz>, alpha=-2.6)[source]

This method is equivalent to the IDL routine

Parameters:

nu – Frequency. (Hz) or astropy.units.Quantity

crrlpy.models.rrlmod.I_total(nu, Te, tau, I0, eta)[source]
crrlpy.models.rrlmod.beta(n, bn, te, line='RRL_CIalpha')[source]

Computes the correction factor for stimulated emission.

Parameters:
  • n – principal quantum number.

  • bn – level population departure coefficient.

  • te – electron temperature.

crrlpy.models.rrlmod.bnbeta_approx(n, Te, ne, Tr)[source]

Approximates \(b_{n}\beta_{n^{\prime}n}\) for a particular set of conditions. Uses Equation (B1) of Salas et al. (2016).

Parameters:
  • n (int) – Principal quantum number

  • Te (float) – Electron temperature in K.

  • ne (float) – Electron density per cubic centimeters.

  • Tr (float) – Temperature of the radiation field in K at 100 MHz.

Returns:

The value of \(b_{n}\beta_{n^{\prime}n}\) given an approximate expression.

Return type:

float

crrlpy.models.rrlmod.bnbeta_approx_full(Te, ne, Tr, coefs)[source]

Approximates \(b_{n}\beta_{n^{\prime}n}\) given a set of coefficients. Uses Equations (5) and (B1)-(B5) of Salas et al. (2016).

crrlpy.models.rrlmod.broken_plaw(nu, nu0, T0, alpha1, alpha2)[source]

Defines a broken power law.

\[ \begin{align}\begin{aligned}T(\nu) = T_{0}\left(\dfrac{\nu}{\nu_{0}}\right)^{\alpha_1}\mbox{ if }\nu<\nu_{0}\\T(\nu) = T_{0}\left(\dfrac{\nu}{\nu_{0}}\right)^{\alpha_2}\mbox{ if }\nu\geq\nu_{0}\end{aligned}\end{align} \]
Parameters:
  • nu – Frequency.

  • nu0 – Frequency at which the power law breaks.

  • T0 – Value of the power law at nu0.

  • alpha1 – Index of the power law for nu<nu0.

  • alpha2 – Index of the power law for nu>=nu0.

Returns:

Broken power law evalueated at nu.

crrlpy.models.rrlmod.chi(n, Te, Z)[source]

Computes the \(\chi_{n}\) value as defined by Salgado et al. (2015).

crrlpy.models.rrlmod.eta(freq, Te, ne, nion, Z, Tr, trans, n_max=1500)[source]

Returns the correction factor for the Planck function.

crrlpy.models.rrlmod.fnnp_app(n, dn)[source]

Eq. (1) Menzel (1969)

crrlpy.models.rrlmod.itau(temp, dens, line, n_min=5, n_max=1000, other='', verbose=False, value='itau', location='/home/psalas/Documents/astro/trunk/CRRLpy/crrlpy/models')[source]

Gives the integrated optical depth for a given temperature and density. It assumes that the background radiation field dominates the continuum emission. The emission measure is unity. The output units are Hz.

Parameters:
  • temp (string) – Electron temperature. Must be a string of the form ‘8d1’.

  • dens (float) – Electron density.

  • line (string) – Line to load models for.

  • n_min (int) – Minimum n value to include in the output. Default 1

  • n_max (int) – Maximum n value to include in the output. Default 1500, Maximum allowed value 9900

  • other (string) – String to search for different radiation fields and others.

  • verbose (bool) – Verbose output?

  • value (string) – [‘itau’|’bbnMdn’|’None’] Value to output. itau will output the integrated optical depth. bbnMdn will output the \(\beta_{n,n^{\prime}}b_{n}\) times the oscillator strenght \(M(\Delta n)\). None will output the \(\beta_{n,n^{\prime}}b_{n}\) values.

Returns:

The principal quantum number and its asociated value.

crrlpy.models.rrlmod.itau_h(temp, dens, trans, n_max=1000, other='', verbose=False, value='itau')[source]

Gives the integrated optical depth for a given temperature and density. The emission measure is unity. The output units are Hz.

crrlpy.models.rrlmod.itau_lte(n, Te, dn, mdn_, em)[source]

Returns the CRRL optical depth integrated in velocity in units of Hz.

crrlpy.models.rrlmod.itau_norad(n, Te, b, dn, mdn_)[source]

Returns the optical depth using the approximate solution to the radiative transfer problem.

crrlpy.models.rrlmod.j_line_lte(n, ne, nion, Te, Z, trans)[source]
crrlpy.models.rrlmod.kappa_cont(freq, Te, ne, nion, Z)[source]

Computes the absorption coefficient for the free-free process.

crrlpy.models.rrlmod.kappa_cont_base(nu, Te, ne, nion, Z)[source]
crrlpy.models.rrlmod.kappa_line(Te, ne, nion, Z, Tr, trans, n_max=1500)[source]

Computes the line absorption coefficient for CRRLs between levels \(n_{i}\) and \(n_{f}\), \(n_{i}>n_{f}\). This can only go up to \(n_{\rm{max}}\) 1500 because of the tables used for the Einstein Anm coefficients.

Parameters:
  • Te (float) – Electron temperature of the gas. (K)

  • ne (float) – Electron density. (\(\mbox{cm}^{-3}\))

  • nion (float) – Ion density. (\(\mbox{cm}^{-3}\))

  • Z (int) – Electric charge of the atoms being considered.

  • Tr (float) – Temperature of the radiation field felt by the gas. This specifies the temperature of the field at 100 MHz. (K)

  • trans (string) – Transition for which to compute the absorption coefficient.

  • n_max (int<1500) – Maximum principal quantum number to include in the output.

Returns:

Return type:

array

crrlpy.models.rrlmod.kappa_line_lte(nu, Te, ne, nion, Z, Tr, line, n_min=1, n_max=1500)[source]

Returns the line absorption coefficient under LTE conditions.

Parameters:
  • nu (array) – Frequency. (Hz)

  • Te (float) – Electron temperature of the gas. (K)

  • ne (float) – Electron density. (\(\mbox{cm}^{-3}\))

  • nion (float) – Ion density. (\(\mbox{cm}^{-3}\))

  • Z (int) – Electric charge of the atoms being considered.

  • Tr (float) – Temperature of the radiation field felt by the gas. This specifies the temperature of the field at 100 MHz. (K)

  • trans (string) – Transition for which to compute the absorption coefficient.

  • n_max (int<1500) – Maximum principal quantum number to include in the output.

Returns:

Return type:

array

crrlpy.models.rrlmod.level_pop_lte(n, ne, nion, Te, Z)[source]

Returns the level population of level n. The return has units of \(\mbox{cm}^{-3}\).

crrlpy.models.rrlmod.load_betabn(temp, dens, other='', trans='RRL_CIalpha', verbose=False, location='/home/psalas/Documents/astro/trunk/CRRLpy/crrlpy/models')[source]

Loads a model for the CRRL emission.

location = “{0}/bbn2_CIalpha”.format(rrlmod.LOCALDIR)

crrlpy.models.rrlmod.load_betabn_h(temp, dens, other='', trans='alpha', verbose=False)[source]

Loads a model for the HRRL emission.

crrlpy.models.rrlmod.load_bn(te, ne, tr='', ncrit='1.5d3', n_min=5, n_max=1000, verbose=False, location='/home/psalas/Documents/astro/trunk/CRRLpy/crrlpy/models')[source]

Loads the bn values from the CRRL models.

Parameters:
  • te (string) – Electron temperature of the model.

  • ne (string) – Electron density of the model.

  • other (string) – Radiation field of the model or any other string with model characteristics.

  • verbose (bool) – Verbose output?

Returns:

The \(b_{n}\) value for the given model conditions.

Return type:

array

crrlpy.models.rrlmod.load_bn_all(n_min=5, n_max=1000, verbose=False, location='/home/psalas/Documents/astro/trunk/CRRLpy/crrlpy/models')[source]
crrlpy.models.rrlmod.load_bn_dict(dict, n_min=5, n_max=1000, verbose=False, location='/home/psalas/Documents/astro/trunk/CRRLpy/crrlpy/models', ncrit='1.5d3')[source]

Loads the \(b_{n}\) values defined by dict.

Parameters:
  • dict (dict) – Dictionary containing a list with values for Te, ne and Tr.

  • line (string) – Which models should be loaded.

  • n_min (int) – Minimum n number to include in the output.

  • n_max (int) – Maximum n number to include in the output.

  • verbose (bool) – Verbose output?

Returns:

List with the \(b_{n}\) values for the conditions defined by dict.

Return type:

numpy.array

Example:

>>> from crrlpy.models import rrlmod

First define the range of parameters

>>> Te = np.array(['1d1', '2d1', '3d1', '4d1', '5d1'])
>>> ne = np.arange(0.01,0.105,0.01)
>>> Tr = np.array([800])

Put them in a dictionary

>>> models = {'Te':[t_ for t_ in Te for n_ in ne for tr_ in Tr],                   'ne':[round(n_,3) for t_ in Te for n_ in ne for tr_ in Tr],                   'Tr':['case_diffuse_{0}'.format(rrlmod.val2str(tr_))                         for t_ in Te for n_ in ne for tr_ in Tr]}

Load the models

>>> bn = rrlmod.load_bn_dict(models, n_min=200, n_max=500, verbose=False)
crrlpy.models.rrlmod.load_bn_h(te, ne, other='', n_min=5, n_max=1000, verbose=False)[source]

Loads the bn values from the HRRL models.

Parameters:
  • te (string) – Electron temperature of the model.

  • ne (string) – Electron density of the model.

  • other (string) – Radiation field of the model or any other string with model characteristics.

  • verbose (bool) – Verbose output?

Returns:

The \(b_{n}\) value for the given model conditions.

Return type:

array

crrlpy.models.rrlmod.load_itau_all(line='RRL_CIalpha', n_min=5, n_max=1000, verbose=False, value='itau')[source]

Loads all the available models for Carbon.

Parameters:
  • line (string) – Which models should be loaded.

  • n_min (int) – Minimum n number to include in the output.

  • n_max (int) – Maximum n number to include in the output.

  • verbose (bool) – Verbose output?

  • value (string) – [‘itau’|’bbnMdn’|None] Which value should be in the output.

crrlpy.models.rrlmod.load_itau_all_hydrogen(trans='alpha', n_max=1000, verbose=False, value='itau')[source]

Loads all the available models for Hydrogen.

crrlpy.models.rrlmod.load_itau_all_match(trans_out='alpha', trans_tin='beta', n_max=1000, verbose=False, value='itau')[source]

Loads all trans_out models that can be found in trans_tin. This is useful when analyzing line ratios.

crrlpy.models.rrlmod.load_itau_all_norad(trans='alpha', n_max=1000)[source]

Loads all the available models.

crrlpy.models.rrlmod.load_itau_dict(dict, line, n_min=5, n_max=1000, verbose=False, value='itau', location='/home/psalas/Documents/astro/trunk/CRRLpy/crrlpy/models')[source]

Loads the models defined by dict.

Parameters:
  • dict (dict) – Dictionary containing a list with values for Te, ne and Tr.

  • line (string) – Which models should be loaded.

  • n_min (int) – Minimum n number to include in the output.

  • n_max (int) – Maximum n number to include in the output.

  • verbose (bool) – Verbose output?

  • value (string) – [‘itau’|’bbnMdn’|None] Which value should be in the output.

Example:

>>> from crrlpy.models import rrlmod

First define the range of parameters

>>> Te = np.array(['1d1', '2d1', '3d1', '4d1', '5d1'])
>>> ne = np.arange(0.01,0.105,0.01)
>>> Tr = np.array([2000])

Put them in a dictionary

>>> models = {'Te':[t_ for t_ in Te for n_ in ne for tr_ in Tr],
...           'ne':[round(n_,3) for t_ in Te for n_ in ne for tr_ in Tr],
...           'Tr':['case_diffuse_{0}'.format(rrlmod.val2str(tr_))
...                 for t_ in Te for n_ in ne for tr_ in Tr]}

# Load the models

>>> itau_mod = rrlmod.load_itau_dict(models, 'CIalpha', n_min=250, n_max=300,                                          verbose=False, value='itau')
crrlpy.models.rrlmod.load_itau_nelim(temp, dens, trad, trans, n_max=1000, verbose=False, value='itau')[source]

Loads models given a temperature, radiation field and an upper limit for the electron density.

crrlpy.models.rrlmod.load_itau_numpy(filename)[source]

Loads all the models contained in filename.npy

Parameters:
filenamestring

Filename with the models.

Returns
——-
crrlpy.models.rrlmod.load_models(models, trans, n_max=1000, verbose=False, value='itau')[source]

Loads the models in backwards compatible mode. It will sort the models by Te, ne and Tr.

crrlpy.models.rrlmod.make_betabn(line, temp, dens, n_min=5, n_max=1000, other='')[source]
crrlpy.models.rrlmod.make_betabn2(line, temp, dens, n_min=5, n_max=1000, other='')[source]
crrlpy.models.rrlmod.mdn(dn)[source]

Gives the \(M(\Delta n)\) factor for a given \(\Delta n\). ref. Menzel (1968)

Parameters:

dn\(\Delta n\).

Returns:

\(M(\Delta n)\)

Return type:

float

Example:

>>> mdn(1)
0.1908
>>> mdn(5)
0.001812
crrlpy.models.rrlmod.models_dict(Te, ne, Tr)[source]

Creates a dict for loading models given arrays with ne, Te and Tr.

crrlpy.models.rrlmod.plaw(x, x0, y0, alpha)[source]

Returns a power law.

\[y(x)=y_0\left(\frac{x}{x_0}\right)^{\alpha}\]
Parameters:
  • x (float or array like) – x values for which to compute the power law.

  • x0 (float) – x value for which the power law has amplitude y0.

  • y0 (float) – Amplitude of the power law at x0.

  • alpha (float) – Index of the power law.

Returns:

A power law of index alpha evaluated at x, with amplitude y0 at x0.

Return type:

float or array

crrlpy.models.rrlmod.str2val(str)[source]

Converts a string representing a number to a float. The string must follow the IDL convention for floats.

Parameters:

str (string) – String to convert.

Returns:

The equivalent number.

Return type:

float

Example:

>>> str2val('2d2')
200.0
crrlpy.models.rrlmod.tau_exact(t, ne, Ni, n, fnnp, line='RRL_CIalpha')[source]

Uses the column density of ions as input.

crrlpy.models.rrlmod.val2str(val)[source]

Converts a float to the string format required for loading the CRRL models.

Parameters:

val (float) – Value to convert to a string.

Returns:

The value of val represented as a string in IDL double format.

Return type:

string

Example:

>>> val2str(200)
'2d2'
crrlpy.models.rrlmod.valid_ne(line)[source]

Checks all the available models and lists the available ne values.