Skip to content

Commit 2308bec

Browse files
authored
Merge pull request #31 from icweaver/F04
2 parents c30f719 + 7a73ae8 commit 2308bec

File tree

10 files changed

+970
-11
lines changed

10 files changed

+970
-11
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DustExtinction"
22
uuid = "fb44c06c-c62f-5397-83f5-69249e0a3c8e"
33
license = "MIT"
4-
version = "0.8.0"
4+
version = "0.9.0"
55

66
[deps]
77
DataDeps = "124859b0-ceae-595e-8997-d05f6a7a8dfe"

docs/plots.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Plots, LaTeXStrings
2-
import DustExtinction: ccm89_ca, ccm89_cb, od94_ca, od94_cb, cal00_invum, ccm89_invum, vcg04_invum, gcc09_invum, f99_invum, FM90
2+
import DustExtinction: ccm89_ca, ccm89_cb, od94_ca, od94_cb, cal00_invum, ccm89_invum, vcg04_invum, gcc09_invum, f99_invum, f04_invum, FM90
33

44
dir = joinpath(@__DIR__, "src", "assets")
55

@@ -80,6 +80,19 @@ xlabel!(L"\mu m ^{-1}")
8080
ylabel!("E(B-V)")
8181
savefig(joinpath(dir, "vcg04_plot.svg"))
8282

83+
#--------------------------------------------------------------------------------
84+
# F04
85+
86+
w = range(0.3, 10.0, length=1000)
87+
plot()
88+
for rv in [2.0, 3.1, 4.0, 5.0, 6.0]
89+
m = f04_invum.(w, rv)
90+
plot!(w, m, label="Rv=$rv")
91+
end
92+
xlabel!(L"x\ \left[\mu m ^{-1}\right]")
93+
ylabel!(L"A(x)/A(V)")
94+
savefig(joinpath(dir, "F04_plot.svg"))
95+
8396
#--------------------------------------------------------------------------------
8497
# FM90
8598

docs/src/assets/F04_plot.svg

Lines changed: 798 additions & 0 deletions
Loading

docs/src/assets/f04.bib

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@INPROCEEDINGS{2004ASPC..309...33F,
2+
author = {{Fitzpatrick}, E.~L.},
3+
title = "{Interstellar Extinction in the Milky Way Galaxy}",
4+
keywords = {Astrophysics},
5+
booktitle = {Astrophysics of Dust},
6+
year = 2004,
7+
editor = {{Witt}, Adolf N. and {Clayton}, Geoffrey C. and {Draine}, Bruce T.},
8+
series = {Astronomical Society of the Pacific Conference Series},
9+
volume = {309},
10+
month = may,
11+
pages = {33},
12+
archivePrefix = {arXiv},
13+
eprint = {astro-ph/0401344},
14+
primaryClass = {astro-ph},
15+
adsurl = {https://ui.adsabs.harvard.edu/abs/2004ASPC..309...33F},
16+
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
17+
}

docs/src/color_laws.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ and is loosely associated with the size of the dust grains in the interstellar m
134134
- [`VCG04`](@ref)
135135
- [`GCC09`](@ref)
136136
- [`F99`](@ref)
137+
- [`F04`](@ref)
137138

138139
### Clayton, Cardelli and Mathis (1989)
139140

@@ -183,6 +184,14 @@ GCC09
183184
F99
184185
```
185186

187+
### Fitzpatrick (2004)
188+
189+
![](assets/F04_plot.svg)
190+
191+
```@docs
192+
F04
193+
```
194+
186195
## API/Reference
187196

188197
```@docs

docs/src/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ There are various citations relevant to this work. Please be considerate when us
4040
| [`FM90`](@ref) | [Fitzpatrick & Massa (1990)](https://ui.adsabs.harvard.edu/abs/1990ApJS...72..163F) | [download](assets/fm90.bib) |
4141
| [`SFD98Map`](@ref) | [Schlegel, Finkbeiner and Davis (1998)](https://ui.adsabs.harvard.edu/abs/1998ApJ...500..525S) | [download](assets/sfd98.bib) |
4242
| [`F99`](@ref) | [Fitzpatrick (1999)](https://ui.adsabs.harvard.edu/abs/1999PASP..111...63F) | [download](assets/f99.bib) |
43+
| [`F04`](@ref) | [Fitzpatrick (2004)](https://ui.adsabs.harvard.edu/abs/2004ASPC..309...33F) | [download](assets/f04.bib) |
4344

4445
## Index
4546

src/DustExtinction.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export redden,
1414
GCC09,
1515
VCG04,
1616
F99,
17+
F04,
1718
# Fittable laws
1819
FM90,
1920
# Dust maps
@@ -145,7 +146,7 @@ include("fittable_laws.jl")
145146
# at which point adding `(l::ExtinctionLaw)(wave::Quantity)` is possible, until then
146147
# using this code-gen does the trick but requires manually editing
147148
# instead of providing support for all <: ExtinctionLaw
148-
for law in [CCM89, OD94, CAL00, GCC09, VCG04, FM90, F99]
149+
for law in [CCM89, OD94, CAL00, GCC09, VCG04, FM90, F99, F04]
149150
(l::law)(wavelength::Quantity) = l(ustrip(u"Å", wavelength)) * u"mag"
150151
end
151152

src/color_laws.jl

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,12 @@ const f99_gamma = 0.99
298298

299299
"""
300300
F99(;Rv=3.1)
301-
302301
Fitzpatrick (1999) dust law.
303-
304302
Returns E(B-V) in magnitudes at the given wavelength relative to the
305303
extinction. This model applies to the UV and optical to NIR spectral range.
306304
The default support is [1000, 33333] Å. Outside of that range this will return
307305
0. Rv is the selective extinction and is valid over [2, 6]. A typical value for
308306
the Milky Way is 3.1.
309-
310307
# References
311308
[Fitzpatrick (1999)](https://ui.adsabs.harvard.edu/abs/1999PASP..111...63F/)
312309
"""
@@ -324,7 +321,6 @@ bounds(::Type{F99}) = (1000.0, 33333.3)
324321

325322
"""
326323
DustExtinction.f99_invum(x, Rv)
327-
328324
The algorithm used for the [`F99`](@ref) extinction law, given inverse microns and Rv. For more information, seek the original paper.
329325
"""
330326
function f99_invum(x::Real, Rv::Real)
@@ -370,3 +366,89 @@ function f99_invum(x::Real, Rv::Real)
370366
optnir_axebv_y,
371367
)
372368
end
369+
370+
# spline points
371+
const f04_opt_axav_x = aa_to_invum.((6000, 5470, 4670, 4110))
372+
const f04_nir_axav_x = (0.50, 0.75, 1.0)
373+
374+
# **Use NIR spline x values in FM07, clipped to K band for now
375+
const f04_optnir_axav_x = (f04_nir_axav_x..., f04_opt_axav_x...)
376+
377+
# c1-c2 correlation terms
378+
const f04_c3 = 2.991
379+
const f04_c4 = 0.319
380+
const f04_x0 = 4.592
381+
const f04_gamma = 0.922
382+
383+
"""
384+
F04(;Rv=3.1)
385+
Fitzpatrick (2004) dust law.
386+
Returns E(B-V) in magnitudes at the given wavelength relative to the
387+
extinction. This model applies to the UV and optical to NIR spectral range.
388+
The default support is [1000, 33333] Å. Outside of that range this will return
389+
0. Rv is the selective extinction and is valid over [2, 6]. A typical value for
390+
the Milky Way is 3.1.
391+
Equivalent to the F99 model with an updated NIR Rv dependence
392+
See also Fitzpatrick & Massa (2007, ApJ, 663, 320)
393+
# References
394+
[Fitzpatrick (2004)](https://ui.adsabs.harvard.edu/abs/2004ASPC..309...33F/)
395+
"""
396+
@with_kw struct F04 <: ExtinctionLaw
397+
Rv::Float64 = 3.1
398+
end
399+
400+
function (law::F04)(wave::T) where T
401+
checkbounds(law, wave) || return zero(float(T))
402+
x = aa_to_invum(wave)
403+
return f04_invum(x, law.Rv)
404+
end
405+
406+
bounds(::Type{F04}) = (1000.0, 33333.3)
407+
408+
"""
409+
DustExtinction.f04_invum(x, Rv)
410+
The algorithm used for the [`F04`](@ref) extinction law, given inverse microns and Rv. For more information, seek the original paper.
411+
"""
412+
function f04_invum(x::Real, Rv::Real)
413+
if !(0.3 <= x <= 10.0)
414+
error("out of bounds of F04, support is over $(bounds(F04)) angstrom")
415+
end
416+
417+
# original F99 Rv dependence
418+
c2 = @evalpoly (1. / Rv) -0.824 4.717
419+
# updated F04 C1-C2 correlation
420+
c1 = @evalpoly c2 2.18 -2.91
421+
422+
# **Keep optical spline points from F99:
423+
# Final optical spline point has a leading "-1.208" in Table 4
424+
# of F99, but that does not reproduce Table 3.
425+
# Additional indication that this is not correct is from
426+
# fm_unred.pro
427+
# which is based on FMRCURVE.pro distributed by Fitzpatrick.
428+
# --> confirmation needed?
429+
opt_axebv_y =
430+
(@evalpoly Rv -0.426 1.0044),
431+
(@evalpoly Rv -0.050 1.0016),
432+
(@evalpoly Rv 0.701 1.0016),
433+
(@evalpoly Rv 1.208 1.0032 -0.00033)
434+
435+
# updated NIR curve from F04, note R dependence
436+
# Julia v1.0 workaround: https://github.com/JuliaAstro/DustExtinction.jl/pull/31#commitcomment-40605778
437+
nir_axebv_y_coeff = (0.63 * Rv - 0.84)
438+
nir_axebv_y = @. nir_axebv_y_coeff * f04_nir_axav_x^1.84
439+
440+
optnir_axebv_y = @. (nir_axebv_y..., opt_axebv_y...) / Rv
441+
442+
return _curve_F99_method(
443+
x,
444+
Rv,
445+
c1,
446+
c2,
447+
f04_c3,
448+
f04_c4,
449+
f04_x0,
450+
f04_gamma,
451+
f04_optnir_axav_x,
452+
optnir_axebv_y,
453+
)
454+
end

test/color_laws.jl

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ using DustExtinction: ccm89_invum,
66
aa_to_invum,
77
ccm89_ca,
88
ccm89_cb,
9-
f99_invum
9+
f99_invum,
10+
f04_invum
1011

1112
@testset "helper" begin
1213
@test aa_to_invum(10000) 1
@@ -286,3 +287,40 @@ end
286287
@test ustrip.(reddening) ref_values[rv] rtol = 0.016
287288
end
288289
end
290+
291+
@testset "F04" begin
292+
# From Fitzpatrick (1999) Table 3
293+
294+
x_inv_microns = [0.377, 0.820, 1.667, 1.828, 2.141, 2.433, 3.704, 3.846]
295+
wave = 1e4 ./ x_inv_microns
296+
297+
ref_values = Dict(
298+
3.1 => [0.185, 0.772, 2.688, 3.055, 3.805, 4.315, 6.456, 6.781] ./ 3.1,
299+
)
300+
301+
# test defaults
302+
@test F04().(wave) ref_values[3.1] rtol = 0.016
303+
304+
for rv in keys(ref_values)
305+
law = F04(Rv = rv)
306+
output = @inferred map(law, wave)
307+
@test output ref_values[rv] rtol = 0.016
308+
309+
bad_waves = [100, 4e4]
310+
@test @inferred(map(law, bad_waves)) == zeros(length(bad_waves))
311+
@test_throws ErrorException f04_invum(aa_to_invum(bad_waves[1]), rv)
312+
@test_throws ErrorException f04_invum(aa_to_invum(bad_waves[2]), rv)
313+
314+
# uncertainties
315+
noise = rand(length(wave)) .* 0.01
316+
wave_unc = wave noise
317+
reddening = map(w -> @uncertain(law(w)), wave_unc)
318+
@test Measurements.value.(reddening) ref_values[rv] rtol = 1e-3
319+
320+
# Unitful
321+
wave_u = wave * u"angstrom"
322+
reddening = @inferred map(law, wave_u)
323+
@test eltype(reddening) <: Gain
324+
@test ustrip.(reddening) ref_values[rv] rtol = 0.016
325+
end
326+
end

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ include("dust_maps.jl")
1010
include("fittable_laws.jl")
1111

1212
@testset "interfaces" begin
13-
for LAW in [CCM89, OD94, CAL00, GCC09, VCG04, FM90, F99]
13+
for LAW in [CCM89, OD94, CAL00, GCC09, VCG04, FM90, F99, F04]
1414
@test bounds(LAW) == bounds(LAW())
1515
@test checkbounds(LAW, 1000) == checkbounds(LAW(), 1000)
16-
low, high = bounds(LAW)
17-
@test all(checkbounds.(LAW, rand(low:high, 1000)))
16+
low, high = bounds(LAW)
17+
@test all(checkbounds.(LAW, rand(low:high, 1000)))
1818
end
1919
@test bounds(DustExtinction.ExtinctionLaw) == (0, Inf)
2020
end

0 commit comments

Comments
 (0)