Skip to content

Commit d17f633

Browse files
author
icweaver
committed
merged in master/F19 (2520754)
2 parents c042984 + 2520754 commit d17f633

File tree

10 files changed

+975
-22
lines changed

10 files changed

+975
-22
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, m14_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, m14_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

@@ -116,19 +142,6 @@ xlabel!(L"\mu m ^{-1}")
116142
ylabel!(L"E(\lambda - V)/E(B - V)")
117143
savefig(joinpath(dir, "FM90_plot.svg"))
118144

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"))
131-
132145
#--------------------------------------------------------------------------------
133146
# M14
134147

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
### Maiz Apellaniz et al. (2014)
196205

197206
![](assets/m14_plot.svg)

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
| [`M14`](@ref) | [Maiz Apellaniz et al. (2014)](https://ui.adsabs.harvard.edu/abs/2014A%26A...564A..63M) | [download](assets/m14.bib) |
4546

4647
## Index

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
M14,
1920
# Fittable laws
2021
FM90,
@@ -147,7 +148,7 @@ include("fittable_laws.jl")
147148
# at which point adding `(l::ExtinctionLaw)(wave::Quantity)` is possible, until then
148149
# using this code-gen does the trick but requires manually editing
149150
# instead of providing support for all <: ExtinctionLaw
150-
for law in [CCM89, OD94, CAL00, GCC09, VCG04, FM90, F99, F04, M14]
151+
for law in [CCM89, OD94, CAL00, GCC09, VCG04, FM90, F99, F04, F19, M14]
151152
(l::law)(wavelength::Quantity) = l(ustrip(u"Å", wavelength)) * u"mag"
152153
end
153154

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

169177
end # module

src/color_laws.jl

Lines changed: 61 additions & 5 deletions
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
@@ -453,16 +453,74 @@ function f04_invum(x::Real, Rv::Real)
453453
)
454454
end
455455

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
515+
456516
# Optical
457517
const m14_x1 = (1.0)
458518
const m14_xi1 = first(m14_x1)
459519
const m14_x2 = (1.15, 1.81984, 2.1, 2.27015, 2.7)
460520
const m14_x3 = (3.5, 3.9, 4.0, 4.1, 4.2)
461521
const m14_xi3 = last(m14_x3)
462522
const m14_a1v = 0.574 * m14_x1^1.61
463-
#const m14_a1d = 0.574 * 1.61 * m14_xi1^0.61
464523
const m14_b1v = -0.527 * m14_x1^1.61
465-
#const m14_b1d = -0.527 * 1.61 * m14_xi1^0.61
466524
const m14_x2_diff = m14_x2 .- 1.82
467525
const m14_a2v = @. (
468526
1
@@ -491,14 +549,12 @@ const m14_a3v = @. (
491549
- 0.104 / ((m14_x3 - 4.67)^2 + 0.341)
492550
+ (0.442, 0.341, 0.130, 0.020, 0.000)
493551
)
494-
#const m14_a3d = -0.316 + 0.104 * 2.0 * (m14_xi3 - 4.67) / ((m14_xi3 - 4.67)^2 + 0.341)^2
495552
const m14_b3v = @. (
496553
-3.090
497554
+ 1.825 * m14_x3
498555
+ 1.206 / ((m14_x3 - 4.62)^2 + 0.263)
499556
- (1.256, 1.021, 0.416, 0.064, 0.000)
500557
)
501-
#const m14_b3d = 1.825 - 1.206 * 2 * (m14_xi3 - 4.62) / ((m14_xi3 - 4.62)^2 + 0.263)^2
502558
const m14_xn = collect((m14_x1..., m14_x2..., m14_x3...))
503559
const m14_anv = collect((m14_a1v..., m14_a2v..., m14_a3v...))
504560
const m14_bnv = collect((m14_b1v..., m14_b2v..., m14_b3v...))

test/color_laws.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using DustExtinction: ccm89_invum,
88
ccm89_cb,
99
f99_invum,
1010
f04_invum,
11+
f19_invum,
1112
m14_invum
1213

1314
@testset "helper" begin
@@ -326,6 +327,44 @@ end
326327
end
327328
end
328329

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

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, M14]
13+
for LAW in [CCM89, OD94, CAL00, GCC09, VCG04, FM90, F99, F04, F19, M14]
1414
@test bounds(LAW) == bounds(LAW())
1515
@test checkbounds(LAW, 1000) == checkbounds(LAW(), 1000)
1616
low, high = bounds(LAW)

0 commit comments

Comments
 (0)