From 19be03f7e04ce22802c52137205aa67ae7a0a8de Mon Sep 17 00:00:00 2001 From: Kyle Barbary Date: Tue, 13 Dec 2016 18:18:35 -0800 Subject: [PATCH] add r_v kwarg to fitzpatrick99() --- docs/index.rst | 25 ++++++++++--------------- extinction.pyx | 14 +++++++++----- setup.py | 2 +- test.py | 9 +++++++++ 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 1b872f5..2a8a31d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -61,25 +61,16 @@ 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:: @@ -87,7 +78,11 @@ the wavelength array from Angstroms to 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:: diff --git a/extinction.pyx b/extinction.pyx index 54e7fa1..e4ab297 100644 --- a/extinction.pyx +++ b/extinction.pyx @@ -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 @@ -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. @@ -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 diff --git a/setup.py b/setup.py index cf78c73..31a64cf 100755 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/test.py b/test.py index c519772..436bb0a 100755 --- a/test.py +++ b/test.py @@ -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)