Skip to content

Commit 2520754

Browse files
authored
Merge pull request #32 from icweaver/F19
2 parents 2308bec + 507f1f6 commit 2520754

File tree

10 files changed

+976
-19
lines changed

10 files changed

+976
-19
lines changed

Project.toml

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

66
[deps]
77
DataDeps = "124859b0-ceae-595e-8997-d05f6a7a8dfe"
8+
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
89
Dierckx = "39dd38d3-220a-591b-8e3c-4c3a8c710a94"
910
FITSIO = "525bcba6-941b-5504-bd06-fd0dc1a4d2eb"
1011
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"

docs/plots.jl

Lines changed: 27 additions & 14 deletions
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, f04_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, f19_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+
# F99
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 = f99_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, "F99_plot.svg"))
95+
8396
#--------------------------------------------------------------------------------
8497
# F04
8598

@@ -93,6 +106,19 @@ xlabel!(L"x\ \left[\mu m ^{-1}\right]")
93106
ylabel!(L"A(x)/A(V)")
94107
savefig(joinpath(dir, "F04_plot.svg"))
95108

109+
#--------------------------------------------------------------------------------
110+
# F19
111+
112+
w = range(0.3, 8.7, length=1000)
113+
plot()
114+
for rv in [2.0, 3.1, 4.0, 5.0, 6.0]
115+
m = f19_invum.(w, rv)
116+
plot!(w, m, label="Rv=$rv")
117+
end
118+
xlabel!(L"x\ \left[\mu m ^{-1}\right]")
119+
ylabel!(L"A(x)/A(V)")
120+
savefig(joinpath(dir, "F19_plot.svg"))
121+
96122
#--------------------------------------------------------------------------------
97123
# FM90
98124

@@ -115,16 +141,3 @@ plot!(w, m4, label = "FUV rise term")
115141
xlabel!(L"\mu m ^{-1}")
116142
ylabel!(L"E(\lambda - V)/E(B - V)")
117143
savefig(joinpath(dir, "FM90_plot.svg"))
118-
119-
#--------------------------------------------------------------------------------
120-
# F99
121-
122-
w = range(0.3, 10.0, length=1000)
123-
plot()
124-
for rv in [2.0, 3.1, 4.0, 5.0, 6.0]
125-
m = f99_invum.(w, rv)
126-
plot!(w, m, label="Rv=$rv")
127-
end
128-
xlabel!(L"x\ \left[\mu m ^{-1}\right]")
129-
ylabel!(L"A(x)/A(V)")
130-
savefig(joinpath(dir, "F99_plot.svg"))

docs/src/assets/F19_plot.svg

Lines changed: 807 additions & 0 deletions
Loading

docs/src/assets/f19.bib

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@ARTICLE{2019ApJ...886..108F,
2+
author = {{Fitzpatrick}, E.~L. and {Massa}, Derck and {Gordon}, Karl D. and
3+
{Bohlin}, Ralph and {Clayton}, Geoffrey C.},
4+
title = "{An Analysis of the Shapes of Interstellar Extinction Curves. VII. Milky Way Spectrophotometric Optical-through-ultraviolet Extinction and Its R-dependence}",
5+
journal = {\apj},
6+
keywords = {Interstellar dust, Interstellar dust extinction, Interstellar dust processes, Interstellar absorption, Interstellar reddening, Interstellar scattering, Astrophysics - Astrophysics of Galaxies, Astrophysics - Solar and Stellar Astrophysics},
7+
year = 2019,
8+
month = dec,
9+
volume = {886},
10+
number = {2},
11+
eid = {108},
12+
pages = {108},
13+
doi = {10.3847/1538-4357/ab4c3a},
14+
archivePrefix = {arXiv},
15+
eprint = {1910.08852},
16+
primaryClass = {astro-ph.GA},
17+
adsurl = {https://ui.adsabs.harvard.edu/abs/2019ApJ...886..108F},
18+
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
19+
}

docs/src/color_laws.md

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

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

@@ -192,6 +193,14 @@ F99
192193
F04
193194
```
194195

196+
### Fitzpatrick (2019)
197+
198+
![](assets/F19_plot.svg)
199+
200+
```@docs
201+
F19
202+
```
203+
195204
## API/Reference
196205

197206
```@docs

docs/src/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ There are various citations relevant to this work. Please be considerate when us
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) |
4343
| [`F04`](@ref) | [Fitzpatrick (2004)](https://ui.adsabs.harvard.edu/abs/2004ASPC..309...33F) | [download](assets/f04.bib) |
44+
| [`F19`](@ref) | [Fitzpatrick (2019)](https://ui.adsabs.harvard.edu/abs/2019ApJ...886..108F) | [download](assets/f19.bib) |
4445

4546
## Index
4647

src/DustExtinction.jl

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

@@ -163,6 +164,13 @@ function __init__()
163164
"https://sncosmo.github.io/data/dust/SFD_dust_4096_sgp.fits"],
164165
["50b6aaad0b880762d0fd081177802dcc17c39d7044a410dd5649e2dfd0503e97",
165166
"84891a59054adab44a7be54051e4dcf0e66e3f13eee0d845ce3739242f553b83"]))
167+
register(DataDep("F19",
168+
"""
169+
Tabulated data from Fitzpatrick et al (2019) extinction model calculation
170+
Paper: https://ui.adsabs.harvard.edu/abs/2019ApJ...886..108F
171+
""",
172+
["https://raw.githubusercontent.com/karllark/dust_extinction/master/dust_extinction/data/F19_tabulated.dat"],
173+
["34011693065bba25396085823ab1df43c058336a95da7d4fdb567f03103b35bc"]))
166174
end
167175

168176
end # module

src/color_laws.jl

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Dierckx
1+
using Dierckx, DelimitedFiles
22

33
# Convenience function for wavelength conversion
44
@inline aa_to_invum(wave::Real) = 10000 / wave
@@ -452,3 +452,63 @@ function f04_invum(x::Real, Rv::Real)
452452
optnir_axebv_y,
453453
)
454454
end
455+
456+
"""
457+
F19(;Rv=3.1)
458+
459+
Fitzpatrick (2019) dust law.
460+
461+
Returns E(B-V) in magnitudes at the given wavelength relative to the
462+
extinction. This model applies to the UV and optical to NIR spectral range.
463+
The default support is [1149, 33333] Å. Outside of that range this will return
464+
0. Rv is the selective extinction and is valid over [2, 6]. A typical value for
465+
the Milky Way is 3.1.
466+
467+
Fitzpatrick, Massa, Gordon et al. (2019, ApJ, 886, 108) model. Based on a
468+
sample of stars observed spectroscopically in the optical with HST/STIS.
469+
470+
# References
471+
[Fitzpatrick (2019)](https://ui.adsabs.harvard.edu/abs/2019ApJ...886..108F/)
472+
"""
473+
@with_kw struct F19 <: ExtinctionLaw
474+
Rv::Float64 = 3.1
475+
end
476+
477+
function (law::F19)(wave::T) where T
478+
checkbounds(law, wave) || return zero(float(T))
479+
x = aa_to_invum(wave)
480+
return f19_invum(x, law.Rv)
481+
end
482+
483+
bounds(::Type{F19}) = (1149.4, 33333.3)
484+
485+
"""
486+
DustExtinction.f19_invum(x, Rv)
487+
488+
The algorithm used for the [`F19`](@ref) extinction law, given inverse microns
489+
and Rv. For more information, seek the original paper.
490+
"""
491+
function f19_invum(x::Real, Rv::Real)
492+
# read and unpack tabulated data
493+
data_x, data_k, data_delta_k, data_sigma_k = let data = readdlm(joinpath(datadep"F19", "F19_tabulated.dat"), skipstart=1)
494+
(data[:, i] for i in 1:4)
495+
end
496+
497+
if !(0.3 <= x <= 8.7)
498+
error("out of bounds of F19, support is over $(bounds(F19)) angstrom")
499+
end
500+
501+
# compute E(lambda-55)/E(B-55) on the tabulated x points
502+
k_rV_tab_x = @. data_k + data_delta_k * (Rv - 3.10) * 0.990
503+
504+
# setup spline interpolation
505+
spl = Spline1D(collect(data_x), collect(k_rV_tab_x), k=3)
506+
507+
# use spline interpolation to evaluate the curve for the input x values
508+
k_rV = spl(x)
509+
510+
# convert to A(x)/A(55) from E(x-55)/E(44-55)
511+
a_rV = k_rV / Rv + 1.0
512+
513+
return a_rV
514+
end

test/color_laws.jl

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ using DustExtinction: ccm89_invum,
77
ccm89_ca,
88
ccm89_cb,
99
f99_invum,
10-
f04_invum
10+
f04_invum,
11+
f19_invum
1112

1213
@testset "helper" begin
1314
@test aa_to_invum(10000) 1
@@ -324,3 +325,41 @@ end
324325
@test ustrip.(reddening) ref_values[rv] rtol = 0.016
325326
end
326327
end
328+
329+
@testset "F19" begin
330+
# x values from Fitzpatrick et al. (2000) Table 3
331+
332+
x_inv_microns = [1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
333+
wave = 1e4 ./ x_inv_microns
334+
335+
# convert from E(x-V)/E(B-V) to A(x)/A(V)
336+
ref_values = Dict(
337+
3.1 => @. ([-1.757, -0.629, 0.438, 2.090, 4.139, 5.704, 4.904, 5.684, 7.150] + 3.1) / 3.1
338+
)
339+
340+
# test defaults
341+
@test F19().(wave) ref_values[3.1] rtol = 0.016
342+
343+
for rv in keys(ref_values)
344+
law = F19(Rv = rv)
345+
output = @inferred map(law, wave)
346+
@test output ref_values[rv] rtol = 0.016
347+
348+
bad_waves = [100, 4e4]
349+
@test @inferred(map(law, bad_waves)) == zeros(length(bad_waves))
350+
@test_throws ErrorException f19_invum(aa_to_invum(bad_waves[1]), rv)
351+
@test_throws ErrorException f19_invum(aa_to_invum(bad_waves[2]), rv)
352+
353+
# uncertainties
354+
noise = rand(length(wave)) .* 0.01
355+
wave_unc = wave noise
356+
reddening = map(w -> @uncertain(law(w)), wave_unc)
357+
@test Measurements.value.(reddening) ref_values[rv] rtol = 1e-3
358+
359+
# Unitful
360+
wave_u = wave * u"angstrom"
361+
reddening = @inferred map(law, wave_u)
362+
@test eltype(reddening) <: Gain
363+
@test ustrip.(reddening) ref_values[rv] rtol = 0.016
364+
end
365+
end

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ 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, F04]
13+
for LAW in [CCM89, OD94, CAL00, GCC09, VCG04, FM90, F99, F04, F19]
1414
@test bounds(LAW) == bounds(LAW())
1515
@test checkbounds(LAW, 1000) == checkbounds(LAW(), 1000)
1616
low, high = bounds(LAW)

0 commit comments

Comments
 (0)