Skip to content

Commit

Permalink
add r_v kwarg to fitzpatrick99()
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarbary committed Dec 14, 2016
1 parent 2665bc9 commit 19be03f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
25 changes: 10 additions & 15 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,28 @@ Get extinction in magnitudes at a set of wavelengths for various dust laws::
>>> extinction.odonnell94(wave, 1.0, 3.1)
array([ 2.84252644, 1.42617802, 0.60793495])

# Fitzpatrick (1999)
>>> extinction.fitzpatrick99(wave, 1.0, 3.1)
array([ 2.76225609, 1.79674653, 1.42325373])

The Fitzpatrick (1999) and Fitzpatrick & Massa (2007) functions have fixed
:math:`R_V` of 3.1::
# Fitzpatrick (1999) for fixed R_V = 3.1
>>> extinction.fitzpatrick99(wave, 1.0)
array([ 2.76225609, 1.42338583, 0.55346406])

The Fitzpatrick & Massa (2007) function has a fixed :math:`R_V` of 3.1::

>>> extinction.fm07(wave, 1.0)
array([ 2.90478329, 1.42645161, 0.54703201])
# Fitzpatrick (1999) can also be used with other R_V values.
# First, construct a function for a given R_V value (note capital "F"):
>>> f = extinction.Fitzpatrick99(2.1)

# Then, call the function:
>>> f(wave, 1.0)
array([ 4.28908428, 1.6266948 , 0.47992809])

All extinction laws accept a ``unit`` keyword to change the interpretation of
the wavelength array from Angstroms to inverse microns::

>>> wave = np.array([5., 2.5, 1.25]) # wavelength in inverse microns

>>> extinction.ccm89(wave, 1.0, 3.1, unit='invum')
array([ 2.84252644, 1.4645557 , 0.59748901]) # extinction in magnitudes


Redden or deredden
..................

To "redden" or "deredden" flux values by some amount, use the
``apply`` convenience function::

Expand Down
14 changes: 9 additions & 5 deletions extinction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,10 @@ cdef class Fitzpatrick99(object):
_fitzpatrick99_fixed = Fitzpatrick99(3.1)


def fitzpatrick99(wave, a_v, unit='aa'):
"""fitzpatrick99(wave, a_v, unit='aa')
def fitzpatrick99(wave, a_v, r_v=3.1, unit='aa'):
"""fitzpatrick99(wave, a_v, r_v=3.1, unit='aa')
Fitzpatrick (1999) dust extinction function for R_V = 3.1.
Fitzpatrick (1999) dust extinction function.
Fitzpatrick (1999) [1]_ model which relies on the parametrization
of Fitzpatrick & Massa (1990) [2]_ in the UV (below 2700 A) and
Expand All @@ -467,6 +467,8 @@ def fitzpatrick99(wave, a_v, unit='aa'):
Input wavelengths or wavenumbers (see units).
a_v : float
Total V-band extinction in magnitudes.
r_v : float
Ratio of total to selective extinction, A_V / E(B-V).
unit : {'aa', 'invum'}, optional
Wavelength units: Angstroms or inverse microns.
Expand All @@ -479,8 +481,10 @@ def fitzpatrick99(wave, a_v, unit='aa'):
.. [1] Fitzpatrick, E. L. 1999, PASP, 111, 63
.. [2] Fitzpatrick, E. L. & Massa, D. 1990, ApJS, 72, 163
"""
return _fitzpatrick99_fixed(wave, a_v, unit=unit)

if r_v == 3.1:
return _fitzpatrick99_fixed(wave, a_v, unit=unit)
else:
return Fitzpatrick99(r_v)(wave, a_v, unit=unit)

# -----------------------------------------------------------------------------
# Fitzpatrick & Massa 2007
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
version = re.findall(r"__version__ = \"(.*?)\"", open(fname).read())[0]

classifiers = [
"Development Status :: 3 - Alpha",
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand Down
9 changes: 9 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ def test_fitzpatrick99_r_v():
assert f.r_v == 2.1


def test_fitzpatrick99_func():
"""Check passing R_V."""

wave = np.array([2000., 30000.])
for r_v in (3.1, 4.0):
assert np.all(extinction.Fitzpatrick99(r_v)(wave, 1.0) ==
extinction.fitzpatrick99(wave, 1.0, r_v))


def test_fm07():
wave = np.arange(3000., 9000., 1000)

Expand Down

0 comments on commit 19be03f

Please sign in to comment.