In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import pyneb as pn
The class RedCorr manages the extinction (reddening) correction. It can compute the logarithmic extinction at H$\beta$ by comparing an observed ratio to a theoretical one (usually H$\alpha$/H$\beta$, but any other ratio can be used). The object is also able to compute the correction to be applied to any intensity, given the wavelength of the line.
Various extinction laws are included in the class, and any user-defined function can also be implemented. The available extinction laws can be listed by entering (here no need to instantiate an object):
To explore some properties, you can directly use the class methods:
In [2]:
pn.RedCorr().printLaws()
Less detailed output is obtained with:
In [3]:
pn.RedCorr().getLaws()
Out[3]:
To apply a correction, you need to instantiate the object:
In [4]:
rc = pn.RedCorr(E_BV = 1.2, R_V = 3.2, law = 'F99')
The parameters can also be defined and modified after the instantiation:
In [5]:
rc = pn.RedCorr()
rc.E_BV = 1.34
rc.law = 'S79 H83 CCM89'
$c(H\beta)$ and $E_{B-V}$ are related through:
$$(1-f_\lambda).c(H\beta) = 0.4 E_{B-V} X_\lambda$$applied to $\lambda$ = 4861, with $f_\beta$ = 0. so that, once one of the two parameters is defined, the other is also automatically defined; to output its value, enter:
In [6]:
rc.cHbeta
Out[6]:
In [7]:
rc.cHbeta = 2.
print(rc.E_BV)
The reddening of a given spectrum is determined by using the ratio of two observed line intensities relative to the theoretical value, for example:
In [8]:
rc.setCorr(obs_over_theo=6.5 / 2.86, wave1=6563., wave2=4861.)
In [9]:
print(rc.cHbeta)
Once a law and either c(H$\beta$) or E$_{B-V}$ are defined, the correction for any wavelength is obtained by:
In [10]:
wave = 5007.0
corr = rc.getCorr(wave)
print(corr)
where wave can either be a single wavelength or a list or array of wavelengths.
The correction relative to the H$\beta$ correction is given by:
In [11]:
corr = rc.getCorrHb(wave)
print(corr)
and the correction relative to any other wavelength (p. ej., H$\alpha$) is given by:
In [12]:
corr = rc.getCorr(5007., 6563.)
print(corr)
The class includes a plotting tool to have a quick look at the different extinction laws:
In [13]:
f, ax = plt.subplots(figsize=(8,8))
rc.plot(laws = 'all', ax=ax)
A user-defined method can also be used. User-defined methods must accept 2 parameters: the first is the wavelength (or wavelength array), in Angstrom, and the second is an optional parameter (which can also be a list). The method must return $X(\lambda) = A(\lambda)/E_{B-V} = R_V A(\lambda)/A_V$. The correction is then: $10^{0.4 E_{B-V} X(\lambda)}$
Here is an example of a user-defined function:
In [14]:
def my_X(wave, params = [5000., 1., 2., 3.]):
return params[1] * (wave/params[0]) + params[2] * (wave/params[0])**-1 + params[3] * (wave/params[0])**-2
rc.UserFunction = my_X
rc.UserParams = [6000., 1., 5., 1.]
rc.law = 'user'
print(rc.getCorr(5007))