Debian Codegraph @

docs/index.rst

raw
1 extinction
2 ==========
3
4 *Fast interstellar dust extinction laws in Python*
5
6 Cython-optimized implementations of empirical dust exitinction laws
7 found in the literature.
8
9 Installation
10 ------------
11
12 Using conda::
13
14 conda install -c conda-forge extinction
15
16 Using pip (requires a C compiler)::
17
18 pip install extinction
19
20 Extinction depends on numpy.
21
22 **Development version / source code:** https://github.com/sncosmo/extinction
23
24
25 Usage
26 -----
27
28 **Functions:**
29
30 .. autosummary::
31 :toctree: api
32
33 extinction.ccm89
34 extinction.odonnell94
35 extinction.calzetti00
36 extinction.fitzpatrick99
37 extinction.fm07
38 extinction.apply
39 extinction.remove
40
41 **Classes:**
42
43 .. autosummary::
44 :toctree: api
45
46 extinction.Fitzpatrick99
47
48 **Examples:**
49
50 Get extinction in magnitudes at a set of wavelengths for various dust laws::
51
52 >>> import numpy as np
53 >>> import extinction
54
55 >>> wave = np.array([2000., 4000., 8000.]) # wavelength in Angstroms
56
57 # Cardelli, Clayton & Mathis (1989) with A_V = 1 and R_V = 3.1
58 >>> extinction.ccm89(wave, 1.0, 3.1)
59 array([ 2.84252644, 1.4645557 , 0.59748901]) # extinction in magnitudes
60
61 # O'Donnell (1994)
62 >>> extinction.odonnell94(wave, 1.0, 3.1)
63 array([ 2.84252644, 1.42617802, 0.60793495])
64
65 # Fitzpatrick (1999)
66 >>> extinction.fitzpatrick99(wave, 1.0, 3.1)
67 array([ 2.76225609, 1.79674653, 1.42325373])
68
69
70 The Fitzpatrick & Massa (2007) function has a fixed :math:`R_V` of 3.1::
71
72 >>> extinction.fm07(wave, 1.0)
73 array([ 2.90478329, 1.42645161, 0.54703201])
74
75 All extinction laws accept a ``unit`` keyword to change the interpretation of
76 the wavelength array from Angstroms to inverse microns::
77
78 >>> wave = np.array([5., 2.5, 1.25]) # wavelength in inverse microns
79
80 >>> extinction.ccm89(wave, 1.0, 3.1, unit='invum')
81 array([ 2.84252644, 1.4645557 , 0.59748901]) # extinction in magnitudes
82
83
84 Redden or deredden
85 ..................
86
87 To "redden" or "deredden" flux values by some amount, use the
88 ``apply`` and ``remove`` convenience functions::
89
90
91 >>> from extinction import ccm89, apply
92
93 >>> flux = np.ones(3)
94
95 # "redden" flux by A_V = 1.0
96 >>> apply(ccm89(wave, 1.0, 3.1), flux)
97 array([ 0.07294397, 0.25952412, 0.5767723 ])
98
99 # "deredden" flux by A_V = 1.0
100 >>> remove(ccm89(wave, 1.0, 3.1), flux)
101 array([ 13.70915145, 3.85320647, 1.73378645])
102
103
104
105 Comparison of functions
106 .......................
107
108 .. plot::
109
110 import numpy as np
111 import extinction
112 from extinction_plot import extinction_figure
113
114 wave = np.logspace(np.log10(910.), np.log10(30000.), 2000)
115
116 a_lambda = {'ccm89': extinction.ccm89(wave, 1.0, 3.1),
117 'odonnell94': extinction.odonnell94(wave, 1.0, 3.1),
118 'fitzpatrick99': extinction.fitzpatrick99(wave, 1.0),
119 'fm07': extinction.fm07(wave, 1.0)}
120 extinction_figure(wave, a_lambda, 'fitzpatrick99')
121
122
123 R_V dependence of odonnell94
124 ............................
125
126 .. plot::
127
128 from collections import OrderedDict
129 import numpy as np
130 import extinction
131 from extinction_plot import extinction_figure
132
133 wave = np.logspace(np.log10(910.), np.log10(30000.), 2000)
134
135 a_lambda = OrderedDict([
136 ('$R_V$ = 2.1', extinction.odonnell94(wave, 1.0, 2.1)),
137 ('$R_V$ = 2.6', extinction.odonnell94(wave, 1.0, 2.6)),
138 ('$R_V$ = 3.1', extinction.odonnell94(wave, 1.0, 3.1)),
139 ('$R_V$ = 3.6', extinction.odonnell94(wave, 1.0, 3.6)),
140 ('$R_V$ = 4.1', extinction.odonnell94(wave, 1.0, 4.1))
141 ])
142 extinction_figure(wave, a_lambda, '$R_V$ = 3.1',
143 residual_lims=(-0.2, 0.6),
144 title_text='odonnell94')
145
146
147
148 R_V dependence of Fitzpatrick99
149 ...............................
150 .. plot::
151
152 from collections import OrderedDict
153 import numpy as np
154 import extinction
155 from extinction_plot import extinction_figure
156
157 wave = np.logspace(np.log10(910.), np.log10(30000.), 2000)
158
159 a_lambda = OrderedDict([
160 ('$R_V$ = 2.1', extinction.Fitzpatrick99(2.1)(wave, 1.0)),
161 ('$R_V$ = 2.6', extinction.Fitzpatrick99(2.6)(wave, 1.0)),
162 ('$R_V$ = 3.1', extinction.Fitzpatrick99(3.1)(wave, 1.0)),
163 ('$R_V$ = 3.6', extinction.Fitzpatrick99(3.6)(wave, 1.0)),
164 ('$R_V$ = 4.1', extinction.Fitzpatrick99(4.1)(wave, 1.0))
165 ])
166 extinction_figure(wave, a_lambda, '$R_V$ = 3.1',
167 residual_lims=(-0.2, 0.6),
168 title_text='Fitzpatrick99')
169
170
171
172 A note on parameterization
173 ..........................
174
175 Most extinction laws here have two parameters: :math:`A_V` and
176 :math:`R_V`. :math:`A_V` is a simply a linear scaling parameter; that
177 is: ``ccm89(wave, 2.0, 3.1)`` is the same as ``2.0 * ccm89(wave, 1.0,
178 3.1)``. :math:`R_V` changes the *shape* of the extinction
179 curve, rather than just the amplitude.
180
181 Traditionally, the meaning ascribed to these parameters was that
182 :math:`A_V` is the extinction in the *V* band, and :math:`R_V`
183 describes the ratio of total to selective extinction: :math:`R_V = A_V
184 / E(B-V)`, where :math:`E(B-V)` is the difference in extinction
185 between the *B* and *V* bands. While this is approximately correct,
186 the *measured* extinction of a source in actual *B* and *V* bandpasses
187 will generally depend on the source spectrum and the shape of the
188 specific bandpasses. Therefore, the :math:`A_V` and :math:`R_V` that
189 are parameters in our extinction law will not correspond perfectly to
190 measured *B* and *V* extinctions. So, in the context of these
191 extinction laws, it is best to think of :math:`A_V` and :math:`R_V` as
192 simply parameters that describe the amplitude and shape of the
193 wavelength dependence, rather than corresponding directly to measured
194 magnitudes.
195
196 Finally, for a given shape of the extinction curve (described by
197 :math:`R_V`), one can equally well use :math:`E(B-V)` as a linear
198 scaling parameter in place of :math:`A_V`, with the equivalence
199 :math:`E(B-V) = A_V / R_V`. Note that the above caution applies here:
200 :math:`E(B-V)` should be considered simply a parameter describing
201 amplitude of extinction; it will not correspond exactly to a
202 difference in measured *B* and *V* extinctions.
203
204
205 License and Credits
206 -------------------
207
208 The license is MIT. Part of this code originated in the specutils package.