From e03d67dae3c1cdb2fd5346f1b78809c1773c0d25 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:04:10 -0400 Subject: [PATCH 01/34] Move docs workflow to separate file --- .github/workflows/ci.yml | 23 ++++------------------- .github/workflows/docs.yml | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/docs.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 14021d3..804b8b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,12 +5,15 @@ on: tags: ["*"] pull_request: branches: [master] + concurrency: # Skip intermediate builds: always. # Cancel intermediate builds: only if it is a pull request build. group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} + jobs: + test: name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} runs-on: ${{ matrix.os }} @@ -42,6 +45,7 @@ jobs: - uses: codecov/codecov-action@v1 with: file: lcov.info + aqua: name: Aqua tests runs-on: ubuntu-latest @@ -54,22 +58,3 @@ jobs: - uses: julia-actions/julia-buildpkg@v1 - run: julia -e 'using Pkg; Pkg.add("Aqua")' - run: julia --project=@. -e 'using Aqua, DustExtinction; Aqua.test_all(DustExtinction, ambiguities=false)' - docs: - name: Documentation - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: julia-actions/setup-julia@v1 - with: - version: '1' - - uses: julia-actions/cache@v1 - - run: | - julia --project=docs -e ' - using Pkg - Pkg.develop(PackageSpec(path=pwd())) - Pkg.instantiate()' - - run: julia --project=docs docs/make.jl - env: - GKSwstype: nul - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..f999dc4 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,31 @@ +name: Documentation + +on: + push: + branches: [master] + tags: ["*"] + pull_request: + branches: [master] + +jobs: + + docs: + name: Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: '1' + - uses: julia-actions/cache@v1 + - run: | + julia --project=docs -e ' + using Pkg + Pkg.develop(PackageSpec(path=pwd())) + Pkg.instantiate()' + - run: julia --project=docs docs/make.jl + env: + GKSwstype: nul + DATADEPS_ALWAYS_ACCEPT: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} From 483003e7bdbf006a21faaf5e0020dffed61bc0a3 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:05:21 -0400 Subject: [PATCH 02/34] Update checkout version in workflows --- .github/workflows/ci.yml | 4 ++-- .github/workflows/docs.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 804b8b2..1e689ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: arch: - x64 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v1 with: version: ${{ matrix.version }} @@ -50,7 +50,7 @@ jobs: name: Aqua tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v1 with: version: '1' diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index f999dc4..58a207d 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -13,7 +13,7 @@ jobs: name: Documentation runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v1 with: version: '1' From 4517fe9259cb7ab0432c779d89c2c3e890231f16 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:05:38 -0400 Subject: [PATCH 03/34] Tighten julia compat to 1.6 and up --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 9738d02..a72250c 100644 --- a/Project.toml +++ b/Project.toml @@ -19,7 +19,7 @@ FITSIO = "0.13.0, 0.14, 0.15, 0.16.1, 0.17" Parameters = "0.12" Unitful = "0.17.0, 1" UnitfulAstro = "0.3.0, 0.4, 1" -julia = "1.0" +julia = "1.6" [extras] Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7" From 7d7bfee2e2cc71552d69485d0f643ecac48d9965 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:06:00 -0400 Subject: [PATCH 04/34] Add compat bounds for Documenter.jl --- docs/Project.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/Project.toml b/docs/Project.toml index c314704..337cfc9 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -5,3 +5,6 @@ Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" UnitfulAstro = "6112ee07-acf9-5e0f-b108-d242c714bf9f" + +[compat] +Documenter = "1" From dd6f770437e4a6dd2bff29ea745b78b1f70c05e2 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:07:24 -0400 Subject: [PATCH 05/34] Change CI to run on 1.6 and higher --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e689ef..0db138c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: fail-fast: false matrix: version: - - '1.0' + - '1.6' - '1' - 'nightly' os: From b739eab54fb81eb87433d31d8bdb651ee93ad5ad Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:14:58 -0400 Subject: [PATCH 06/34] Add compat bounds for other doc dependencies --- docs/Project.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/Project.toml b/docs/Project.toml index 337cfc9..af8cbcd 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -8,3 +8,8 @@ UnitfulAstro = "6112ee07-acf9-5e0f-b108-d242c714bf9f" [compat] Documenter = "1" +LaTeXStrings = "1" +Measurements = "2" +Plots = "1" +Unitful = "1" +UnitfulAstro = "1" From b62c4034e9ddccd2164522e8d4bd464d3bb201c2 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:15:30 -0400 Subject: [PATCH 07/34] Fix doctests --- docs/src/color_laws.md | 51 +++++++++++++++++++++--------------------- docs/src/dust_maps.md | 2 +- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/docs/src/color_laws.md b/docs/src/color_laws.md index 1378bfe..a93b875 100644 --- a/docs/src/color_laws.md +++ b/docs/src/color_laws.md @@ -7,6 +7,7 @@ The following empirical laws allow us to model the reddening of light as it trav DocTestSetup = quote using DustExtinction, Random Random.seed!(1) + ENV["UNITFUL_FANCY_EXPONENTS"] = false end ``` @@ -17,17 +18,15 @@ Color laws are constructed and then used as a function for passing wavelengths. ```jldoctest julia> CCM89(Rv=3.1)(4000) 1.464555702942584 - ``` These laws can be applied across higher dimension arrays using the `.` operator ```jldoctest julia> CCM89(Rv=3.1).([4000, 5000]) -2-element Array{Float64,1}: +2-element Vector{Float64}: 1.464555702942584 1.1222468788993019 - ``` these laws return magnitudes, which we can apply directly to flux by mulitplication with a base-2.5 logarithmic system (because astronomers are fun): @@ -46,8 +45,8 @@ julia> flux = 1e-8 .* wave .+ 1e-2 0.01004:3.3333333333333333e-6:0.01005 julia> redden.(CCM89, wave, flux; Av=0.3) -4-element Array{Float64,1}: - 0.006698646015454752 +4-element Vector{Float64}: + 0.00669864601545475 0.006918253926353551 0.007154659823737299 0.007370491272731541 @@ -65,7 +64,7 @@ The color laws also have built-in support for uncertainties using [Measurements. julia> using Measurements julia> CCM89(Rv=3.1).([4000. ± 10.5, 5000. ± 10.2]) -2-element Array{Measurement{Float64},1}: +2-element Vector{Measurement{Float64}}: 1.4646 ± 0.0033 1.1222 ± 0.003 @@ -77,8 +76,8 @@ and also support units via [Unitful.jl](https://github.com/painterqubits/unitful julia> using Unitful, UnitfulAstro julia> mags = CCM89(Rv=3.1).([4000u"angstrom", 0.5u"μm"]) -2-element Array{Gain{Unitful.LogInfo{:Magnitude,10,-2.5},:?,Float64},1}: - 1.4645557029425837 mag +2-element Vector{Gain{Unitful.LogInfo{:Magnitude, 10, -2.5}, :?, Float64}}: + 1.464555702942584 mag 1.1222468788993019 mag ``` @@ -92,28 +91,28 @@ julia> wave = range(0.3, 1.0, length=5)u"μm" (0.3:0.175:1.0) μm julia> err = randn(length(wave)) -5-element Array{Float64,1}: - 0.2972879845354616 - 0.3823959677906078 - -0.5976344767282311 - -0.01044524463737564 - -0.839026854388764 +5-element Vector{Float64}: + -0.07058313895389791 + 0.5314767537831963 + -0.806852326006714 + 2.456991333983293 + 1.1648740735275196 julia> flux = @.(300 / ustrip(wave)^4 ± err)*u"Jy" -5-element Array{Quantity{Measurement{Float64},𝐌*𝐓⁻²,Unitful.FreeUnits{(Jy,),𝐌*𝐓⁻²,nothing}},1}: - 37037.04 ± 0.3 Jy - 5893.14 ± 0.38 Jy - 1680.61 ± -0.6 Jy - 647.598 ± -0.01 Jy - 300.0 ± -0.84 Jy +5-element Vector{Quantity{Measurement{Float64}, 𝐌 𝐓^-2, Unitful.FreeUnits{(Jy,), 𝐌 𝐓^-2, nothing}}}: + 37037.037 ± -0.071 Jy + 5893.14 ± 0.53 Jy + 1680.61 ± -0.81 Jy + 647.6 ± 2.5 Jy + 300.0 ± 1.2 Jy julia> redden.(CCM89, wave, flux; Av=0.3) -5-element Array{Quantity{Measurement{Float64},𝐌*𝐓⁻²,Unitful.FreeUnits{(Jy,),𝐌*𝐓⁻²,nothing}},1}: - 22410.8 ± 0.18 Jy - 4229.74 ± 0.27 Jy - 1337.12 ± 0.48 Jy - 554.3349 ± 0.0089 Jy - 268.31 ± 0.75 Jy +5-element Vector{Quantity{Measurement{Float64}, 𝐌 𝐓^-2, Unitful.FreeUnits{(Jy,), 𝐌 𝐓^-2, nothing}}}: + 22410.804 ± 0.043 Jy + 4229.74 ± 0.38 Jy + 1337.12 ± 0.64 Jy + 554.3 ± 2.1 Jy + 268.3 ± 1.0 Jy ``` diff --git a/docs/src/dust_maps.md b/docs/src/dust_maps.md index edbf31e..b6ab275 100644 --- a/docs/src/dust_maps.md +++ b/docs/src/dust_maps.md @@ -22,7 +22,7 @@ julia> b = range(-π/2, π/2, length=5) -1.5707963267948966:0.7853981633974483:1.5707963267948966 julia> [dustmap(l[i], b[j]) for i in 1:length(l), j in 1:length(b)] -5×5 Array{Float64,2}: +5×5 Matrix{Float64}: 0.0159853 0.105782 1.40486 0.0158918 0.0119615 0.0159853 0.0268289 3.47788 0.0654852 0.0119615 0.0159853 0.0343457 99.6976 0.103875 0.0119615 From b06809b0eef39c811dbb30246b03dce056994320 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:16:45 -0400 Subject: [PATCH 08/34] Fix more doctests --- src/dust_maps.jl | 8 ++++---- src/fittable_laws.jl | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dust_maps.jl b/src/dust_maps.jl index 58dc89b..ea4dc98 100644 --- a/src/dust_maps.jl +++ b/src/dust_maps.jl @@ -90,12 +90,12 @@ julia> m(1, 2) julia> l = 0:0.5:2; b = 0:0.5:2; julia> m.(l, b) -5-element Array{Float64,1}: - 99.69757461547852 - 0.10180447359074371 +5-element Vector{Float64}: + 99.69757461547852 + 0.10180447359074371 0.019595484241066132 0.010238757633890877 - 0.01862100327420125 + 0.01862100327420125 ``` """ diff --git a/src/fittable_laws.jl b/src/fittable_laws.jl index bde19d0..50c8dc1 100644 --- a/src/fittable_laws.jl +++ b/src/fittable_laws.jl @@ -28,7 +28,7 @@ julia> FM90()(1500) 5.152125845280013 julia> FM90(c1=0.2, c2=0.7, c3=3.23, c4=0.41, x0=4.6, gamma=0.99).([1000, 1200, 1800]) -3-element Array{Float64,1}: +3-element Vector{Float64}: 12.562237969522851 7.769215017329513 4.890128210972148 From dc9121cd20dc2a4ab39144ef4ec5422708fc3003 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:22:37 -0400 Subject: [PATCH 09/34] Update install instructions --- README.md | 6 ++++-- docs/src/index.md | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ecbc22b..b3caf3e 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,11 @@ Documentation: [DustExtinction](https://JuliaAstro.github.io/DustExtinction.jl/s ## Installation -From package manager (``` ]``` key) +From package manager (`]` key) -``` add DustExtinction``` +```julia-repl +pkg> add DustExtinction +``` ## Usage diff --git a/docs/src/index.md b/docs/src/index.md index 52a1d42..94ed5de 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -18,7 +18,7 @@ Extinction describes the effect of dust grains on observations of stars in space From the REPL, press `]` to enter Pkg mode ```julia -(v 1.4) pkg> add DustExtinction +pkg> add DustExtinction julia> using DustExtinction ``` @@ -40,18 +40,18 @@ There are various citations relevant to this work. Please be considerate when us | Law | Reference | BibTeX | | :----------------: | :--------------------------------------------------------------------------------------------- | :--------------------------- | -| [`CCM89`](@ref) | [Clayton, Cardelli and Mathis (1989)](https://ui.adsabs.harvard.edu/abs/1989ApJ...345..245C) | [download](assets/ccm89.bib) | -| [`OD94`](@ref) | [O'Donnell (1994)](https://ui.adsabs.harvard.edu/abs/1994ApJ...422..158O) | [download](assets/od94.bib) | -| [`CAL00`](@ref) | [Calzetti et al. (2000)](https://ui.adsabs.harvard.edu/abs/2000ApJ...533..682C) | [download](assets/cal00.bib) | -| [`VCG04`](@ref) | [Valencic, Clayton, & Gordon (2004)](https://ui.adsabs.harvard.edu/abs/2004ApJ...616..912V) | [download](assets/vcg04.bib) | -| [`GCC09`](@ref) | [Gordon, Cartledge, & Clayton (2009)](https://ui.adsabs.harvard.edu/abs/2009ApJ...705.1320G) | [download](assets/gcc09.bib) | -| [`FM90`](@ref) | [Fitzpatrick & Massa (1990)](https://ui.adsabs.harvard.edu/abs/1990ApJS...72..163F) | [download](assets/fm90.bib) | -| [`G16`](@ref) | [Gordon et al (2016) ](https://ui.adsabs.harvard.edu/abs/2016ApJ...826..104G) | [download](assets/g16.bib) | +| [`CCM89`](@ref) | [Clayton, Cardelli and Mathis (1989)](https://ui.adsabs.harvard.edu/abs/1989ApJ...345..245C) | [download](assets/ccm89.bib) | +| [`OD94`](@ref) | [O'Donnell (1994)](https://ui.adsabs.harvard.edu/abs/1994ApJ...422..158O) | [download](assets/od94.bib) | +| [`CAL00`](@ref) | [Calzetti et al. (2000)](https://ui.adsabs.harvard.edu/abs/2000ApJ...533..682C) | [download](assets/cal00.bib) | +| [`VCG04`](@ref) | [Valencic, Clayton, & Gordon (2004)](https://ui.adsabs.harvard.edu/abs/2004ApJ...616..912V) | [download](assets/vcg04.bib) | +| [`GCC09`](@ref) | [Gordon, Cartledge, & Clayton (2009)](https://ui.adsabs.harvard.edu/abs/2009ApJ...705.1320G) | [download](assets/gcc09.bib) | +| [`FM90`](@ref) | [Fitzpatrick & Massa (1990)](https://ui.adsabs.harvard.edu/abs/1990ApJS...72..163F) | [download](assets/fm90.bib) | +| [`G16`](@ref) | [Gordon et al (2016) ](https://ui.adsabs.harvard.edu/abs/2016ApJ...826..104G) | [download](assets/g16.bib) | | [`SFD98Map`](@ref) | [Schlegel, Finkbeiner and Davis (1998)](https://ui.adsabs.harvard.edu/abs/1998ApJ...500..525S) | [download](assets/sfd98.bib) | -| [`F99`](@ref) | [Fitzpatrick (1999)](https://ui.adsabs.harvard.edu/abs/1999PASP..111...63F) | [download](assets/f99.bib) | -| [`F04`](@ref) | [Fitzpatrick (2004)](https://ui.adsabs.harvard.edu/abs/2004ASPC..309...33F) | [download](assets/f04.bib) | -| [`F19`](@ref) | [Fitzpatrick (2019)](https://ui.adsabs.harvard.edu/abs/2019ApJ...886..108F) | [download](assets/f19.bib) | -| [`M14`](@ref) | [Maiz Apellaniz et al. (2014)](https://ui.adsabs.harvard.edu/abs/2014A%26A...564A..63M) | [download](assets/m14.bib) | +| [`F99`](@ref) | [Fitzpatrick (1999)](https://ui.adsabs.harvard.edu/abs/1999PASP..111...63F) | [download](assets/f99.bib) | +| [`F04`](@ref) | [Fitzpatrick (2004)](https://ui.adsabs.harvard.edu/abs/2004ASPC..309...33F) | [download](assets/f04.bib) | +| [`F19`](@ref) | [Fitzpatrick (2019)](https://ui.adsabs.harvard.edu/abs/2019ApJ...886..108F) | [download](assets/f19.bib) | +| [`M14`](@ref) | [Maiz Apellaniz et al. (2014)](https://ui.adsabs.harvard.edu/abs/2014A%26A...564A..63M) | [download](assets/m14.bib) | ## Index From 12f15bf4c2c8baea29aa0570b0b77c3ef1110373 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:23:07 -0400 Subject: [PATCH 10/34] Update example code blocks in README.md --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b3caf3e..a02007b 100644 --- a/README.md +++ b/README.md @@ -27,21 +27,21 @@ pkg> add DustExtinction Color laws: -```julia +```julia-repl julia> using DustExtinction julia> CCM89(Rv=3.1)(4000) 1.4645557029425842 julia> CCM89(Rv=3.1).([4000, 5000]) -2-element Array{Float64,1}: +2-element Vector{Float64}: 1.46456 1.12225 ``` Dust maps: -```julia +```julia-repl julia> dustmap = SFD98Map() SFD98Map("[...]") @@ -49,31 +49,31 @@ julia> dustmap(0.1, 0.1) 0.793093095733043 julia> dustmap.([0.1, 0.2], [0.1, 0.2]) -2-element Array{Float64,1}: +2-element Vector{Float64}: 0.793093 0.539507 ``` Reddening: -```julia +```julia-repl julia> wave = [4000., 5000.] -2-element Array{Float64,1}: +2-element Vector{Float64}: 4000.0 5000.0 julia> flux = [1.0, 1.5] -2-element Array{Float64,1}: +2-element Vector{Float64}: 1.0 1.5 julia> red = redden.(CCM89, wave, flux; Av=0.3, Rv=3.1) -2-element Array{Float64,1}: +2-element Vector{Float64}: 0.6671958182723856 1.1000733242882896 julia> deredden.(CCM89(Rv=3.1), wave, red; Av=0.3) -2-element Array{Float64,1}: +2-element Vector{Float64}: 1.0 1.5 ``` From 1cd8c99f4f58b71682fa76494699124dc1e103ff Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:26:59 -0400 Subject: [PATCH 11/34] Wrap lines and fix markdown --- src/DustExtinction.jl | 56 ++++++++++++++++++++++++++--------------- src/color_laws.jl | 50 ++++++++++++++++++++++++------------- src/dust_maps.jl | 12 ++++----- src/fittable_laws.jl | 13 ++++++---- src/mixture_laws.jl | 7 +++--- test/color_laws.jl | 58 +++++++++++++++++++++++++++++++------------ test/deprecate.jl | 3 ++- test/mixture_laws.jl | 6 +---- test/runtests.jl | 16 +++++++++++- 9 files changed, 147 insertions(+), 74 deletions(-) diff --git a/src/DustExtinction.jl b/src/DustExtinction.jl index f504989..f657e5e 100644 --- a/src/DustExtinction.jl +++ b/src/DustExtinction.jl @@ -29,29 +29,38 @@ export redden, """ DustExtinction.ExtinctionLaw -The abstract super-type for dust extinction laws. See the extended help (`??DustExtinction.ExtinctionLaw` from the REPL) for more information about the interface. +The abstract supertype for dust extinction laws. See the extended help +(`??DustExtinction.ExtinctionLaw` from the REPL) for more information about the interface. # Extended Help ## Interface Here's how to make a new extinction law, called `MyLaw` -* Create your struct. We strongly recommend using `Parameters.jl` to facilitate creating keyword argument constructors if your model is parameterized, which allows convenient usage with [`redden`](@ref) and [`deredden`](@ref). -```julia -struct MyLaw <: DustExtinction.ExtinctionLaw end -``` -* (Optional) Define the limits. This will default to `(0, Inf)`. Currently, this is used within the [`DustExtinction.checkbounds`](@ref) function and in the future will be used for plotting recipes. -```julia -DustExtinction.bounds(::Type{<:MyLaw}) = (min, max) -``` -* Define the law. You only need to provide one function which takes wavelength as angstrom. If your law is naturally written for inverse-micron, there is a helper function `aa_to_invum`. -```julia -(::MyLaw)(wavelength::Real) -``` -* (Optional) enable `Unitful.jl` support by adding this function. If you are building a new law within `DustExtinction.jl` you can add your law to the code-gen list inside `DustExtinction.jl/src/DustExtinction.jl`. -```julia -(l::MyLaw)(wavelength::Unitful.Quantity) = l(ustrip(u"angstrom", wavelength)) * u"mag" -``` +* Create your struct. We strongly recommend using `Parameters.jl` to facilitate + creating keyword argument constructors if your model is parameterized, which + allows convenient usage with [`redden`](@ref) and [`deredden`](@ref). + ```julia + struct MyLaw <: DustExtinction.ExtinctionLaw end + ``` +* (Optional) Define the limits. This will default to `(0, Inf)`. Currently, this + is used within the [`DustExtinction.checkbounds`](@ref) function and in the + future will be used for plotting recipes. + ```julia + DustExtinction.bounds(::Type{<:MyLaw}) = (min, max) + ``` +* Define the law. You only need to provide one function which takes wavelength + as angstrom. If your law is naturally written for inverse-micron, there is a + helper function `aa_to_invum`. + ```julia + (::MyLaw)(wavelength::Real) + ``` +* (Optional) enable `Unitful.jl` support by adding this function. If you are + building a new law within `DustExtinction.jl` you can add your law to the + code-gen list inside `DustExtinction.jl/src/DustExtinction.jl`. + ```julia + (l::MyLaw)(wavelength::Unitful.Quantity) = l(ustrip(u"angstrom", wavelength)) * u"mag" + ``` """ abstract type ExtinctionLaw end @@ -70,7 +79,8 @@ bounds(::Type{<:ExtinctionLaw}) = (0, Inf) DustExtinction.checkbounds(::ExtinctionLaw, wavelength)::Bool DustExtinction.checkbounds(::Type{<:ExtinctionLaw, wavelength}::Bool -Helper function that uses [`DustExtinction.bounds`](@ref) to return whether the given wavelength is in the support for the law. +Helper function that uses [`DustExtinction.bounds`](@ref) to return whether the +given wavelength is in the support for the law. """ checkbounds(::E, wave) where {E <: ExtinctionLaw} = checkbounds(E, wave) function checkbounds(E::Type{<:ExtinctionLaw}, wave) @@ -85,7 +95,10 @@ end Redden the given `flux` using the given extinction law at the given wavelength. -If `wave` is `<:Real` then it is expected to be in angstrom and if it is `<:Unitful.Quantity` it will be automatically converted. `Av` is the total extinction value. The extinction law can be a constructed struct or a `Type`. If it is a `Type`, `law_kwargs` will be passed to the constructor. +If `wave` is `<:Real` then it is expected to be in angstrom and if it is +`<:Unitful.Quantity` it will be automatically converted. `Av` is the total +extinction value. The extinction law can be a constructed struct or a `Type`. +If it is a `Type`, `law_kwargs` will be passed to the constructor. # Examples @@ -113,7 +126,10 @@ redden(law::ExtinctionLaw, wave::Quantity, flux::Quantity; Av = 1) = flux * (Av Deredden the given `flux` using the given extinction law at the given wavelength. -If `wave` is `<:Real` then it is expected to be in angstrom and if it is `<:Unitful.Quantity` it will be automatically converted. `Av` is the total extinction value. The extinction law can be a constructed struct or a `Type`. If it is a `Type`, `law_kwargs` will be passed to the constructor. +If `wave` is `<:Real` then it is expected to be in angstrom and if it is +`<:Unitful.Quantity` it will be automatically converted. `Av` is the total +extinction value. The extinction law can be a constructed struct or a `Type`. +If it is a `Type`, `law_kwargs` will be passed to the constructor. # Examples diff --git a/src/color_laws.jl b/src/color_laws.jl index 4a7241c..39ed1c4 100644 --- a/src/color_laws.jl +++ b/src/color_laws.jl @@ -18,7 +18,9 @@ const od94_cb = [0.0, 1.952, 2.908, -3.989, -7.985, 11.102, 5.491, -10.805, 3.34 Clayton, Cardelli and Mathis (1989) dust law. Returns E(B-V) in magnitudes at the given wavelength relative to the extinction -at 5494.5 Å. The default support is [1000, 33333]. Outside of that range this will return 0. `Rv` is the selective extinction and is valid over [2, 6]. A typical value for the Milky Way is 3.1. +at 5494.5 Å. The default support is [1000, 33333]. Outside of that range this +will return 0. `Rv` is the selective extinction and is valid over [2, 6]. +A typical value for the Milky Way is 3.1. # References [Clayton,Cardelli and Mathis (1989)](https://ui.adsabs.harvard.edu/abs/1989ApJ...345..245C) @@ -65,7 +67,9 @@ bounds(::Type{OD94}) = (1000, 33333) """ DustExtinction.ccm89_invum(x, Rv, c_a, c_b) -The algorithm used for the [`CCM89`](@ref) extinction law, given inverse microns, Rv, and a set of coefficients for use in the optical (only difference between ccm89 and od94). For more information, seek the original paper. +The algorithm used for the [`CCM89`](@ref) extinction law, given inverse microns, +Rv, and a set of coefficients for use in the optical (only difference between +ccm89 and od94). For more information, seek the original paper. """ function ccm89_invum(x::Real, Rv::Real, c_a::Vector{<:Real}, c_b::Vector{<:Real}) if x < 0.3 @@ -156,7 +160,8 @@ bounds(::Type{VCG04}) = (1250, 3030.3) """ DustExtinction.vcg04_invum(x, Rv) -The algorithm used for the [`VCG04`](@ref) extinction law, given inverse microns and Rv. For more information, seek the original paper. +The algorithm used for the [`VCG04`](@ref) extinction law, given inverse microns +and Rv. For more information, seek the original paper. """ function vcg04_invum(x::Real, Rv::Real) if 3.3 ≤ x ≤ 8.0 # NUV @@ -200,7 +205,8 @@ bounds(::Type{GCC09}) = (909.0909090909091, 3030.3030303030305) """ DustExtinction.gcc09_invum(x, Rv) -The algorithm used for the [`GCC09`](@ref) extinction law, given inverse microns and Rv. For more information, seek the original paper. +The algorithm used for the [`GCC09`](@ref) extinction law, given inverse microns +and Rv. For more information, seek the original paper. """ function gcc09_invum(x::Real, Rv::Real) if 3.3 ≤ x ≤ 11.0 # NUV @@ -288,9 +294,9 @@ const f99_gamma = 0.99 Fitzpatrick (1999) dust law. Returns E(B-V) in magnitudes at the given wavelength relative to the extinction. This model applies to the UV and optical to NIR spectral range. -The default support is [1000, 33333] Å. Outside of that range this will return -0. Rv is the selective extinction and is valid over [2, 6]. A typical value for -the Milky Way is 3.1. +The default support is [1000, 33333] Å. Outside of that range this will +return 0. Rv is the selective extinction and is valid over [2, 6]. +A typical value for the Milky Way is 3.1. # References [Fitzpatrick (1999)](https://ui.adsabs.harvard.edu/abs/1999PASP..111...63F/) """ @@ -308,7 +314,9 @@ bounds(::Type{F99}) = (1000.0, 33333.3) """ DustExtinction.f99_invum(x, Rv) -The algorithm used for the [`F99`](@ref) extinction law, given inverse microns and Rv. For more information, seek the original paper. + +The algorithm used for the [`F99`](@ref) extinction law, given inverse microns +and Rv. For more information, seek the original paper. """ function f99_invum(x::Real, Rv::Real) if !(0.3 <= x <= 10.0) @@ -369,14 +377,19 @@ const f04_gamma = 0.922 """ F04(;Rv=3.1) + Fitzpatrick (2004) dust law. -Returns E(B-V) in magnitudes at the given wavelength relative to the -extinction. This model applies to the UV and optical to NIR spectral range. -The default support is [1000, 33333] Å. Outside of that range this will return -0. Rv is the selective extinction and is valid over [2, 6]. A typical value for + +Returns E(B-V) in magnitudes at the given wavelength relative to the extinction. +This model applies to the UV and optical to NIR spectral range. +The default support is [1000, 33333] Å. Outside of that range this will return 0. +Rv is the selective extinction and is valid over [2, 6]. A typical value for the Milky Way is 3.1. + Equivalent to the F99 model with an updated NIR Rv dependence + See also Fitzpatrick & Massa (2007, ApJ, 663, 320) + # References [Fitzpatrick (2004)](https://ui.adsabs.harvard.edu/abs/2004ASPC..309...33F/) """ @@ -394,7 +407,9 @@ bounds(::Type{F04}) = (1000.0, 33333.3) """ DustExtinction.f04_invum(x, Rv) -The algorithm used for the [`F04`](@ref) extinction law, given inverse microns and Rv. For more information, seek the original paper. + +The algorithm used for the [`F04`](@ref) extinction law, given inverse microns +and Rv. For more information, seek the original paper. """ function f04_invum(x::Real, Rv::Real) if !(0.3 <= x <= 10.0) @@ -447,9 +462,9 @@ Fitzpatrick (2019) dust law. Returns E(B-V) in magnitudes at the given wavelength relative to the extinction. This model applies to the UV and optical to NIR spectral range. -The default support is [1149, 33333] Å. Outside of that range this will return -0. Rv is the selective extinction and is valid over [2, 6]. A typical value for -the Milky Way is 3.1. +The default support is [1149, 33333] Å. Outside of that range this will +return 0. Rv is the selective extinction and is valid over [2, 6]. +A typical value for the Milky Way is 3.1. Fitzpatrick, Massa, Gordon et al. (2019, ApJ, 886, 108) model. Based on a sample of stars observed spectroscopically in the optical with HST/STIS. @@ -582,7 +597,8 @@ bounds(::Type{M14}) = (3030.3030303030305, 33333.333333333336) """ DustExtinction.m14_invum(x, Rv) -The algorithm used for the [`M14`](@ref) extinction law, given inverse microns and Rv. For more information, seek the original paper. +The algorithm used for the [`M14`](@ref) extinction law, given inverse microns +and Rv. For more information, seek the original paper. """ function m14_invum(x::Real, Rv::Real) if !(0.3 <= x <= 3.3) diff --git a/src/dust_maps.jl b/src/dust_maps.jl index ea4dc98..998ac3b 100644 --- a/src/dust_maps.jl +++ b/src/dust_maps.jl @@ -23,13 +23,13 @@ end Schlegel, Finkbeiner and Davis (1998) dust map. -The first time this is constructed, the data files required will be downloaded -and stored in a directory following the semantics of +The first time this is constructed, the data files required will be downloaded +and stored in a directory following the semantics of [DataDeps.jl](https://github.com/oxinabox/datadeps.jl). To avoid being asked to - download the files, set the environment variable `DATADEPS_ALWAYS_ACCEPT` to - `true`. You can also provide the directory of the two requisite files manually - instead of relying on DataDeps.jl. Internally, this type keeps the FITS files - defining the map open, speeding up repeated queries for E(B-V) values. +download the files, set the environment variable `DATADEPS_ALWAYS_ACCEPT` to +`true`. You can also provide the directory of the two requisite files manually +instead of relying on DataDeps.jl. Internally, this type keeps the FITS files +defining the map open, speeding up repeated queries for E(B-V) values. # References [Schlegel, Finkbeiner and Davis (1998)](https://ui.adsabs.harvard.edu/abs/1998ApJ...500..525S/abstract) diff --git a/src/fittable_laws.jl b/src/fittable_laws.jl index 50c8dc1..62e92e8 100644 --- a/src/fittable_laws.jl +++ b/src/fittable_laws.jl @@ -4,7 +4,8 @@ FM90(;c1=0.10, c2=0.70, c3=3.23, c4=0.41, x0=4.60, gamma=0.9) FM90(coeffs, x0=4.60, gamma=0.9) -Fitzpatrick & Massa (1990) generative model for ultraviolet dust extinction. The default values are the published values for the Milky Way average. +Fitzpatrick & Massa (1990) generative model for ultraviolet dust extinction. The +default values are the published values for the Milky Way average. ## Parameters * `c1` - y-intercept of linear term @@ -36,10 +37,12 @@ julia> FM90(c1=0.2, c2=0.7, c3=3.23, c4=0.41, x0=4.6, gamma=0.99).([1000, 1200, ``` # Extended Help -The model has form ``c_1 + c_2x + c_3D(x; \\gamma, x_0) + c_4 F(x)`` where ``x`` is the wavenumber in inverse microns, ``D(x)`` -is a Drude profile (modified Lorentzian) used to model the 2175 Å bump with the scale-free parameters ``x_0`` (central wavenumber) -and ``\\gamma`` (damping coefficient), and ``F(x)``, a piecewise function for the far-UV. Note that the coefficients will change -the overall normalization, possibly changing the expected behavior of reddening via the parameter ``A_V``. +The model has form ``c_1 + c_2x + c_3D(x; γ, x_0) + c_4 F(x)`` where ``x`` is +the wavenumber in inverse microns, ``D(x)`` is a Drude profile (modified Lorentzian) +used to model the 2175 Å bump with the scale-free parameters ``x_0`` (central wavenumber) +and ``γ`` (damping coefficient), and ``F(x)``, a piecewise function for the far-UV. +Note that the coefficients will change the overall normalization, possibly +changing the expected behavior of reddening via the parameter ``A_V``. ## References [Fitzpatrick & Massa (1990)](https://ui.adsabs.harvard.edu/abs/1990ApJS...72..163F) diff --git a/src/mixture_laws.jl b/src/mixture_laws.jl index e3c0430..2662246 100644 --- a/src/mixture_laws.jl +++ b/src/mixture_laws.jl @@ -83,9 +83,10 @@ Gordon et al. (2016) Milky Way, LMC, & SMC R(V) and f_A dependent model Returns E(B-V) in magnitudes at the given wavelength relative to the extinction. This is mixture model between the F99 R(V) dependent model -(component A) and the [`G03_SMCBar`](@ref) model (component B) The default support is -[1000, 33333] Å. Outside of that range this will return 0. Rv is the selective -extinction and is valid over [2, 6]. A typical value for the Milky Way is 3.1. +(component A) and the [`G03_SMCBar`](@ref) model (component B). +The default support is [1000, 33333] Å. Outside of that range this will return 0. +Rv is the selective extinction and is valid over [2, 6]. +A typical value for the Milky Way is 3.1. # References [Gordon et al. (2016)](https://ui.adsabs.harvard.edu/abs/2016ApJ...826..104G/) diff --git a/test/color_laws.jl b/test/color_laws.jl index 771e037..12fd3ad 100644 --- a/test/color_laws.jl +++ b/test/color_laws.jl @@ -32,12 +32,28 @@ end wave = 1e4 ./ x_inv_microns # A(lambda)/A(V) for different R_V from Table 3 of CCM '89 - ref_values = Dict(3.1 => [5.23835484, 4.13406452, 3.33685933, 2.77962453, 2.52195399, 2.84252644, 3.18598916, 2.31531711, 1.64254927, 1.56880904, 1.32257836, 1.0, 0.75125994, 0.4780346, 0.28206957, 0.19200814, 0.11572348], - 2.0 => [9.407, 7.3065, 5.76223881, 4.60825807, 4.01559036, 4.43845534, 4.93952892, 3.39275574, 2.068771, 1.9075018, 1.49999733, 1.0, 0.68650255, 0.36750326, 0.21678862, 0.14757062, 0.08894094], - 3.0 => [5.491, 4.32633333, 3.48385202, 2.8904508, 2.6124774, 2.9392494, 3.2922643, 2.38061642, 1.66838089, 1.58933588, 1.33333103, 1.0, 0.74733525, 0.47133573, 0.27811315, 0.18931496, 0.11410029], - 4.0 => [3.533, 2.83625, 2.34465863, 2.03154717, 1.91092092, 2.18964643, 2.46863199, 1.87454675, 1.46818583, 1.43025292, 1.24999788, 1.0, 0.7777516, 0.52325196, 0.30877542, 0.21018713, 0.12667997], - 5.0 => [2.3582, 1.9422, 1.66114259, 1.51620499, 1.48998704, 1.73988465, 1.97445261, 1.57090496, 1.3480688, 1.33480314, 1.19999799, 1.0, 0.79600141, 0.5544017, 0.32717278, 0.22271044, 0.13422778], - 6.0 => [1.575, 1.34616667, 1.20546523, 1.17264354, 1.20936444, 1.44004346, 1.64499968, 1.36847709, 1.26799077, 1.27116996, 1.16666472, 1.0, 0.80816794, 0.5751682, 0.33943769, 0.23105931, 0.13925965]) + ref_values = Dict( + 3.1 => [5.23835484, 4.13406452, 3.33685933, 2.77962453, 2.52195399, + 2.84252644, 3.18598916, 2.31531711, 1.64254927, 1.56880904, + 1.32257836, 1.0, 0.75125994, 0.4780346, 0.28206957, 0.19200814, + 0.11572348], + 2.0 => [9.407, 7.3065, 5.76223881, 4.60825807, 4.01559036, 4.43845534, + 4.93952892, 3.39275574, 2.068771, 1.9075018, 1.49999733, 1.0, + 0.68650255, 0.36750326, 0.21678862, 0.14757062, 0.08894094], + 3.0 => [5.491, 4.32633333, 3.48385202, 2.8904508, 2.6124774, 2.9392494, + 3.2922643, 2.38061642, 1.66838089, 1.58933588, 1.33333103, 1.0, + 0.74733525, 0.47133573, 0.27811315, 0.18931496, 0.11410029], + 4.0 => [3.533, 2.83625, 2.34465863, 2.03154717, 1.91092092, 2.18964643, + 2.46863199, 1.87454675, 1.46818583, 1.43025292, 1.24999788, 1.0, + 0.7777516, 0.52325196, 0.30877542, 0.21018713, 0.12667997], + 5.0 => [2.3582, 1.9422, 1.66114259, 1.51620499, 1.48998704, 1.73988465, + 1.97445261, 1.57090496, 1.3480688, 1.33480314, 1.19999799, 1.0, + 0.79600141, 0.5544017, 0.32717278, 0.22271044, 0.13422778], + 6.0 => [1.575, 1.34616667, 1.20546523, 1.17264354, 1.20936444, + 1.44004346, 1.64499968, 1.36847709, 1.26799077, 1.27116996, + 1.16666472, 1.0, 0.80816794, 0.5751682, 0.33943769, 0.23105931, + 0.13925965] + ) # test defaults @@ -138,12 +154,18 @@ end @testset "CAL00" begin refwave = [3090.90909091, 4561.61616162, 6872.72727273, 9604.04040404, - 14646.46464646, 14646.46464646, 15486.86868687, 18218.18181818, - 20529.29292929, 20949.49494949] - - refmag = Dict(3.1 => [ 1.88010678, 1.27137591, 0.70513192, 0.33600273, 0.01622915, 0.01622915, -0.01682162, -0.10317769, -0.15830055, -0.16701622], - 2.4 => [ 2.13680458, 1.35052722, 0.61912873, 0.14233687, -0.27070401, -0.27070401, -0.3133946 , -0.42493784, -0.49613821, -0.50739595], - 4.05 => [1.67366198, 1.20771983, 0.77429851, 0.49175518, 0.24699022, 0.24699022, 0.22169209, 0.15559239, 0.11339958, 0.10672833]) + 14646.46464646, 14646.46464646, 15486.86868687, 18218.18181818, + 20529.29292929, 20949.49494949] + + refmag = Dict( + 3.1 => [1.88010678, 1.27137591, 0.70513192, 0.33600273, 0.01622915, + 0.01622915, -0.01682162, -0.10317769, -0.15830055, -0.16701622], + 2.4 => [2.13680458, 1.35052722, 0.61912873, 0.14233687, -0.27070401, + -0.27070401, -0.3133946 , -0.42493784, -0.49613821, + -0.50739595], + 4.05 => [1.67366198, 1.20771983, 0.77429851, 0.49175518, 0.24699022, + 0.24699022, 0.22169209, 0.15559239, 0.11339958, 0.10672833] + ) # test defaults @test CAL00().(refwave) ≈ refmag[4.05] @@ -176,12 +198,14 @@ end x_inv_microns = [8.0, 7.0, 6.0, 5.0, 4.6, 4.0, 3.4] wave = 1e4 ./ x_inv_microns - ref_values = Dict(3.1 => [3.36528, 2.84166, 2.58283, 2.88248, 3.25880, 2.43315, 2.00025], + ref_values = Dict( + 3.1 => [3.36528, 2.84166, 2.58283, 2.88248, 3.25880, 2.43315, 2.00025], 2.0 => [5.20767, 4.25652, 3.74640, 4.16150, 4.73050, 3.33399, 2.54668], 3.0 => [3.47694, 2.92741, 2.65335, 2.96000, 3.34799, 2.48775, 2.03337], 4.0 => [2.61157, 2.26285, 2.10683, 2.35925, 2.65674, 2.06463, 1.77671], 5.0 => [2.09235, 1.86411, 1.77892, 1.99880, 2.24199, 1.81076, 1.622711], - 6.0 => [1.74620, 1.59829, 1.56031, 1.75850, 1.96549, 1.64151, 1.52005]) + 6.0 => [1.74620, 1.59829, 1.56031, 1.75850, 1.96549, 1.64151, 1.52005] + ) # test defaults @test VCG04().(wave) ≈ ref_values[3.1] rtol = 0.016 @@ -215,12 +239,14 @@ end x_inv_microns = [10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.6, 4.0, 3.4] wave = 1e4 ./ x_inv_microns - ref_values = Dict(3.1 => [5.23161, 4.20810, 3.45123, 2.92264, 2.61283, 2.85130, 3.19451, 2.34301, 1.89256], + ref_values = Dict( + 3.1 => [5.23161, 4.20810, 3.45123, 2.92264, 2.61283, 2.85130, 3.19451, 2.34301, 1.89256], 2.0 => [10.5150, 8.07274, 6.26711, 5.00591, 4.24237, 4.42844, 4.99482, 3.42585, 2.59322], 3.0 => [5.55181, 4.44232, 3.62189, 3.04890, 2.71159, 2.94688, 3.30362, 2.40863, 1.93502], 4.0 => [3.07020, 2.62711, 2.29927, 2.07040, 1.94621, 2.20610, 2.45801, 1.90003, 1.60592], 5.0 => [1.58123, 1.53798, 1.50571, 1.48330, 1.48697, 1.76164, 1.95065, 1.59486, 1.40846], - 6.0 => [0.588581, 0.811898, 0.976660, 1.09190, 1.18082, 1.46533, 1.61241, 1.39142, 1.27682]) + 6.0 => [0.588581, 0.811898, 0.976660, 1.09190, 1.18082, 1.46533, 1.61241, 1.39142, 1.27682] + ) # test defaults diff --git a/test/deprecate.jl b/test/deprecate.jl index 0f5acea..6232a9c 100644 --- a/test/deprecate.jl +++ b/test/deprecate.jl @@ -1,6 +1,7 @@ @testset "v0.4 deprecations" begin - x_inv_microns = [10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.6, 4.0, 3.0, 2.78, 2.27, 1.82, 1.43, 1.11, 0.8, 0.63, 0.46] + x_inv_microns = [10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.6, 4.0, 3.0, + 2.78, 2.27, 1.82, 1.43, 1.11, 0.8, 0.63, 0.46] wave = 1e4 ./ x_inv_microns for law in [ccm89, od94] @test_deprecated law(wave) diff --git a/test/mixture_laws.jl b/test/mixture_laws.jl index a18d035..fb533a8 100644 --- a/test/mixture_laws.jl +++ b/test/mixture_laws.jl @@ -1,9 +1,5 @@ using Measurements -using DustExtinction: aa_to_invum, - g03_invum, - g16_invum, - G03_SMCBar, - G16 +using DustExtinction: aa_to_invum, g03_invum, g16_invum, G03_SMCBar, G16 @testset "G16" begin diff --git a/test/runtests.jl b/test/runtests.jl index 81b2fda..f47655a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -35,7 +35,21 @@ end 4814., 6571., 8183.] # Av=0.3, Rv=3.1, law=ccm89 - ref_values = [0.6376288197244566, 0.6937993158943373, 0.7556003129054399, 0.7959216081971665, 0.8508142213648981, 0.6517368195297566, 0.6930246485833793, 0.7596467718783736, 0.7990835963390542, 0.8493553321733043, 0.9264835715958143, 0.9524307890106202, 0.9694546832913796, 0.7467375901587614, 0.8026674093639407, 0.847310247751628, 0.8771971841412943, 0.8125473475954554, 0.6442645437827309, 0.7127773090414787, 0.6749407318003154, 0.7249166081334651, 0.7578933014813821, 0.6461535564599767, 0.7288900774623704, 0.7900092679188825, 0.8409405763429691, 0.881972061390043, 0.6091986958411011, 0.7151404275193919, 0.7587309863781261, 0.7798780926274524, 0.8151697825084553, 0.8500202342098636, 0.7219200730427752, 0.7980286586611023, 0.8538476253948861] + ref_values = [ + 0.6376288197244566, 0.6937993158943373, 0.7556003129054399, + 0.7959216081971665, 0.8508142213648981, 0.6517368195297566, + 0.6930246485833793, 0.7596467718783736, 0.7990835963390542, + 0.8493553321733043, 0.9264835715958143, 0.9524307890106202, + 0.9694546832913796, 0.7467375901587614, 0.8026674093639407, + 0.847310247751628, 0.8771971841412943, 0.8125473475954554, + 0.6442645437827309, 0.7127773090414787, 0.6749407318003154, + 0.7249166081334651, 0.7578933014813821, 0.6461535564599767, + 0.7288900774623704, 0.7900092679188825, 0.8409405763429691, + 0.881972061390043, 0.6091986958411011, 0.7151404275193919, + 0.7587309863781261, 0.7798780926274524, 0.8151697825084553, + 0.8500202342098636, 0.7219200730427752, 0.7980286586611023, + 0.8538476253948861 + ] flux = ones(length(wave)) output = @inferred broadcast((l, w, f)->redden(l, w, f; Av = 0.3), CCM89, wave, flux) From 901c02bbbe14d90440e33b91875aac141d26ddff Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:28:02 -0400 Subject: [PATCH 12/34] Fix indents and spacing --- src/DustExtinction.jl | 40 ++++++++++++++++++++++++---------------- src/color_laws.jl | 25 ++++++++++++------------- src/dust_maps.jl | 15 ++++++++------- src/fittable_laws.jl | 4 +--- 4 files changed, 45 insertions(+), 39 deletions(-) diff --git a/src/DustExtinction.jl b/src/DustExtinction.jl index f657e5e..252e364 100644 --- a/src/DustExtinction.jl +++ b/src/DustExtinction.jl @@ -176,22 +176,30 @@ end function __init__() # register our data dependencies - register(DataDep("sfd98_map", - """ - SFD98 Galactic Dust Maps - Website: https://sncosmo.github.io - """, - ["https://sncosmo.github.io/data/dust/SFD_dust_4096_ngp.fits", - "https://sncosmo.github.io/data/dust/SFD_dust_4096_sgp.fits"], - ["50b6aaad0b880762d0fd081177802dcc17c39d7044a410dd5649e2dfd0503e97", - "84891a59054adab44a7be54051e4dcf0e66e3f13eee0d845ce3739242f553b83"])) - register(DataDep("F19", - """ - Tabulated data from Fitzpatrick et al (2019) extinction model calculation - Paper: https://ui.adsabs.harvard.edu/abs/2019ApJ...886..108F - """, - ["https://raw.githubusercontent.com/karllark/dust_extinction/master/dust_extinction/data/F19_tabulated.dat"], - ["34011693065bba25396085823ab1df43c058336a95da7d4fdb567f03103b35bc"])) + register( + DataDep( + "sfd98_map", + """ + SFD98 Galactic Dust Maps + Website: https://sncosmo.github.io + """, + ["https://sncosmo.github.io/data/dust/SFD_dust_4096_ngp.fits", + "https://sncosmo.github.io/data/dust/SFD_dust_4096_sgp.fits"], + ["50b6aaad0b880762d0fd081177802dcc17c39d7044a410dd5649e2dfd0503e97", + "84891a59054adab44a7be54051e4dcf0e66e3f13eee0d845ce3739242f553b83"] + ) + ) + register( + DataDep( + "F19", + """ + Tabulated data from Fitzpatrick et al (2019) extinction model calculation + Paper: https://ui.adsabs.harvard.edu/abs/2019ApJ...886..108F + """, + ["https://raw.githubusercontent.com/karllark/dust_extinction/master/dust_extinction/data/F19_tabulated.dat"], + ["34011693065bba25396085823ab1df43c058336a95da7d4fdb567f03103b35bc"] + ) + ) end end # module diff --git a/src/color_laws.jl b/src/color_laws.jl index 39ed1c4..1e480ac 100644 --- a/src/color_laws.jl +++ b/src/color_laws.jl @@ -101,7 +101,7 @@ function ccm89_invum(x::Real, Rv::Real, c_a::Vector{<:Real}, c_b::Vector{<:Real} return a + b / Rv end -# -------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------ """ CAL00(;Rv=4.05) @@ -109,11 +109,11 @@ end Calzetti et al. (2000) Dust Law. Returns E(B-V) in magnitudes at the given wavelength. `λ` is the wavelength in Å - and has support over [1200, 22000]. Outside of that range this will return 0. +and has support over [1200, 22000]. Outside of that range this will return 0. Calzetti et al. (2000) developed a recipe for dereddening the spectra of galaxies where massive stars dominate the radiation output. They found the best - fit value for such galaxies was 4.05±0.80. +fit value for such galaxies was 4.05±0.80. # References [Calzetti et al. (2000)](https://ui.adsabs.harvard.edu/abs/2000ApJ...533..682C) @@ -231,16 +231,12 @@ const f99_x_splineval_uv = aa_to_invum.((2700, 2600)) # Shape models used by F99 and F04 function _curve_F99_method( - x, - Rv, - c1, - c2, - c3, - c4, - x0, - gamma, - optnir_axav_x, - optnir_axav_y, + x, + Rv, + c1, c2, c3, c4, + x0, + gamma, + optnir_axav_x, optnir_axav_y, ) # add in required spline points, otherwise just spline points @@ -291,12 +287,15 @@ const f99_gamma = 0.99 """ F99(;Rv=3.1) + Fitzpatrick (1999) dust law. + Returns E(B-V) in magnitudes at the given wavelength relative to the extinction. This model applies to the UV and optical to NIR spectral range. The default support is [1000, 33333] Å. Outside of that range this will return 0. Rv is the selective extinction and is valid over [2, 6]. A typical value for the Milky Way is 3.1. + # References [Fitzpatrick (1999)](https://ui.adsabs.harvard.edu/abs/1999PASP..111...63F/) """ diff --git a/src/dust_maps.jl b/src/dust_maps.jl index 998ac3b..dedd168 100644 --- a/src/dust_maps.jl +++ b/src/dust_maps.jl @@ -21,7 +21,7 @@ end """ SFD98Map([mapdir]) -Schlegel, Finkbeiner and Davis (1998) dust map. +Schlegel, Finkbeiner and Davis (1998) dust map. The first time this is constructed, the data files required will be downloaded and stored in a directory following the semantics of @@ -46,13 +46,14 @@ function SFD98Map(mapdir::String) sgp_crpix1 = read_key(sgp, "CRPIX1")[1] sgp_crpix2 = read_key(sgp, "CRPIX2")[1] sgp_lam_scal = read_key(sgp, "LAM_SCAL")[1] - SFD98Map(mapdir, + SFD98Map( + mapdir, ngp, ngp_size, ngp_crpix1, ngp_crpix2, ngp_lam_scal, sgp, sgp_size, sgp_crpix1, sgp_crpix2, sgp_lam_scal) catch error("Could not open dust map FITS files in directory $mapdir") end - + end SFD98Map() = SFD98Map(datadep"sfd98_map") @@ -72,10 +73,10 @@ end (dustmap::SFD98Map)(l::Real, b::Real) (dustmap::SFD98Map)(l::Quantity, b::Quantity) -Get E(B-V) value from a `SFD98Map` instance at galactic coordinates (`l`, `b`), -given in radians. Uses bilinear interpolation between pixel values. If `l` and -`b` are `Unitful.Quantity` they will be converted to radians and the output -will be given as `UnitfulAstro.mag`. +Get E(B-V) value from a `SFD98Map` instance at galactic coordinates (`l`, `b`), +given in radians. Uses bilinear interpolation between pixel values. If `l` and +`b` are `Unitful.Quantity` they will be converted to radians and the output +will be given as `UnitfulAstro.mag`. # Example diff --git a/src/fittable_laws.jl b/src/fittable_laws.jl index 62e92e8..a0b94f5 100644 --- a/src/fittable_laws.jl +++ b/src/fittable_laws.jl @@ -1,5 +1,4 @@ - """ FM90(;c1=0.10, c2=0.70, c3=3.23, c4=0.41, x0=4.60, gamma=0.9) FM90(coeffs, x0=4.60, gamma=0.9) @@ -47,7 +46,7 @@ changing the expected behavior of reddening via the parameter ``A_V``. ## References [Fitzpatrick & Massa (1990)](https://ui.adsabs.harvard.edu/abs/1990ApJS...72..163F) """ -@with_kw struct FM90{T<:Number} <: ExtinctionLaw @deftype T +@with_kw struct FM90{T<:Number} <: ExtinctionLaw @deftype T c1 = 0.10 c2 = 0.70 c3 = 3.23 @@ -79,4 +78,3 @@ function (law::FM90)(wave::T) where T return exvebv end - From f463f6a34bb766c30e29fea60ad9fc650b84b749 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 00:28:59 -0400 Subject: [PATCH 13/34] Update abstract type docstring header --- src/DustExtinction.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DustExtinction.jl b/src/DustExtinction.jl index 252e364..075f1e8 100644 --- a/src/DustExtinction.jl +++ b/src/DustExtinction.jl @@ -27,7 +27,7 @@ export redden, ebv_galactic """ - DustExtinction.ExtinctionLaw + abstract type DustExtinction.ExtinctionLaw The abstract supertype for dust extinction laws. See the extended help (`??DustExtinction.ExtinctionLaw` from the REPL) for more information about the interface. From 9be798f1350d61dbeaf44a4a420761a0b5662bce Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 10:14:43 -0400 Subject: [PATCH 14/34] Use more specific DomainError instead of error() --- src/color_laws.jl | 19 +++++++++++-------- src/mixture_laws.jl | 5 +++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/color_laws.jl b/src/color_laws.jl index 1e480ac..ec2398a 100644 --- a/src/color_laws.jl +++ b/src/color_laws.jl @@ -1,4 +1,5 @@ -using Dierckx, DelimitedFiles +using Dierckx +using DelimitedFiles # Convenience function for wavelength conversion @inline aa_to_invum(wave::Real) = 10000 / wave @@ -73,7 +74,7 @@ ccm89 and od94). For more information, seek the original paper. """ function ccm89_invum(x::Real, Rv::Real, c_a::Vector{<:Real}, c_b::Vector{<:Real}) if x < 0.3 - error("out of bounds of CCM89, support is over $(bounds(CCM89)) angstrom") + throw(DomainError(x, "out of bounds of CCM89, support is over $(bounds(CCM89)) angstrom")) elseif x < 1.1 # Near IR y = x^1.61 a = 0.574y @@ -168,7 +169,7 @@ function vcg04_invum(x::Real, Rv::Real) a = 1.808 - 0.215 * x - 0.134 / ((x - 4.558)^2 + 0.566) b = -2.350 + 1.403 * x + 1.103 / ((x - 4.587)^2 + 0.263) else - error("out of bounds of VCG04, support is over $(bounds(VCG04)) angstrom") + throw(DomainError(x, "out of bounds of VCG04, support is over $(bounds(VCG04)) angstrom")) end if 5.9 ≤ x ≤ 8.0 # far-NUV y = x - 5.9 @@ -213,7 +214,7 @@ function gcc09_invum(x::Real, Rv::Real) a = 1.894 - 0.373 * x - 0.0101 / ((x - 4.57)^2 + 0.0384) b = -3.490 + 2.057 * x + 0.706 / ((x - 4.59)^2 + 0.169) else # out of bounds - error("out of bounds of GCC09, support is over $(bounds(GCC09)) angstrom") + throw(DomainError(x, "out of bounds of GCC09, support is over $(bounds(GCC09)) angstrom")) end if 5.9 ≤ x ≤ 11.0 # far-NUV y = x - 5.9 @@ -319,7 +320,7 @@ and Rv. For more information, seek the original paper. """ function f99_invum(x::Real, Rv::Real) if !(0.3 <= x <= 10.0) - error("out of bounds of F99, support is over $(bounds(F99)) angstrom") + throw(DomainError(x, "out of bounds of F99, support is over $(bounds(F99)) angstrom")) end # terms depending on Rv @@ -412,7 +413,7 @@ and Rv. For more information, seek the original paper. """ function f04_invum(x::Real, Rv::Real) if !(0.3 <= x <= 10.0) - error("out of bounds of F04, support is over $(bounds(F04)) angstrom") + throw(DomainError(x, "out of bounds of F04, support is over $(bounds(F04)) angstrom")) end # original F99 Rv dependence @@ -496,7 +497,8 @@ function f19_invum(x::Real, Rv::Real) end if !(0.3 <= x <= 8.7) - error("out of bounds of F19, support is over $(bounds(F19)) angstrom") + throw(DomainError( + x, "out of bounds of F19, support is over $(bounds(F19)) angstrom")) end # compute E(lambda-55)/E(B-55) on the tabulated x points @@ -601,7 +603,8 @@ and Rv. For more information, seek the original paper. """ function m14_invum(x::Real, Rv::Real) if !(0.3 <= x <= 3.3) - error("out of bounds of M14, support is over $(bounds(M14)) angstrom") + throw(DomainError( + x, "out of bounds of M14, support is over $(bounds(M14)) angstrom")) end a = zero(x) diff --git a/src/mixture_laws.jl b/src/mixture_laws.jl index 2662246..96c2579 100644 --- a/src/mixture_laws.jl +++ b/src/mixture_laws.jl @@ -58,7 +58,7 @@ end function g03_invum(x::Real, Rv::Real) if !(0.3 <= x <= 10.0) - error("out of bounds of G03_SMCBar, support is over $(bounds(G03_SMCBar)) angstrom") + throw(DomainError(x, "out of bounds of G03_SMCBar, support is over $(bounds(G03_SMCBar)) angstrom")) end # return A(x)/A(V) @@ -109,12 +109,13 @@ end """ DustExtinction.g16_invum(x, Rv) + The algorithm used for the [`G16`](@ref) extinction law, given inverse microns and Rv. For more information, seek the original paper. """ function g16_invum(x::Real, Rv::Real, f_A::Number) if !(0.3 <= x <= 10.0) - error("out of bounds of G16, support is over $(bounds(G16)) angstrom") + throw(DomainError(x, "out of bounds of G16, support is over $(bounds(G16)) angstrom")) end # get the A component extinction model From ae2e5153e9b135767810233ac4bcc9ae0c3e89d9 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 10:20:09 -0400 Subject: [PATCH 15/34] Move error handling to top of method --- src/color_laws.jl | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/color_laws.jl b/src/color_laws.jl index ec2398a..a070e41 100644 --- a/src/color_laws.jl +++ b/src/color_laws.jl @@ -73,9 +73,10 @@ Rv, and a set of coefficients for use in the optical (only difference between ccm89 and od94). For more information, seek the original paper. """ function ccm89_invum(x::Real, Rv::Real, c_a::Vector{<:Real}, c_b::Vector{<:Real}) - if x < 0.3 + if x < 0.3 || x > 10.0 throw(DomainError(x, "out of bounds of CCM89, support is over $(bounds(CCM89)) angstrom")) - elseif x < 1.1 # Near IR + end + if x < 1.1 # Near IR y = x^1.61 a = 0.574y b = -0.527y @@ -92,12 +93,10 @@ function ccm89_invum(x::Real, Rv::Real, c_a::Vector{<:Real}, c_b::Vector{<:Real} a += @evalpoly y 0.0 0.0 -0.04473 -0.009779 b += @evalpoly y 0.0 0.0 0.213 0.1207 end - elseif x ≤ 10.0 # FUV + else # FUV y = x - 8.0 a = @evalpoly y -1.073 -0.628 0.137 -0.07 b = @evalpoly y 13.67 4.257 -0.42 0.374 - else - error("out of bounds of CCM89, support is over $(bounds(CCM89)) angstrom") end return a + b / Rv end @@ -165,13 +164,14 @@ The algorithm used for the [`VCG04`](@ref) extinction law, given inverse microns and Rv. For more information, seek the original paper. """ function vcg04_invum(x::Real, Rv::Real) - if 3.3 ≤ x ≤ 8.0 # NUV - a = 1.808 - 0.215 * x - 0.134 / ((x - 4.558)^2 + 0.566) - b = -2.350 + 1.403 * x + 1.103 / ((x - 4.587)^2 + 0.263) - else + if x < 3.3 || x > 8.0 throw(DomainError(x, "out of bounds of VCG04, support is over $(bounds(VCG04)) angstrom")) end - if 5.9 ≤ x ≤ 8.0 # far-NUV + + # NUV + a = 1.808 - 0.215 * x - 0.134 / ((x - 4.558)^2 + 0.566) + b = -2.350 + 1.403 * x + 1.103 / ((x - 4.587)^2 + 0.263) + if 5.9 ≤ x ≤ 8.0 # far-NUV y = x - 5.9 a += @evalpoly y 0.0 0.0 -0.0077 -0.0030 b += @evalpoly y 0.0 0.0 0.2060 0.0550 @@ -210,13 +210,13 @@ The algorithm used for the [`GCC09`](@ref) extinction law, given inverse microns and Rv. For more information, seek the original paper. """ function gcc09_invum(x::Real, Rv::Real) - if 3.3 ≤ x ≤ 11.0 # NUV - a = 1.894 - 0.373 * x - 0.0101 / ((x - 4.57)^2 + 0.0384) - b = -3.490 + 2.057 * x + 0.706 / ((x - 4.59)^2 + 0.169) - else # out of bounds + if x < 3.3 || x > 11.0 # out of bounds throw(DomainError(x, "out of bounds of GCC09, support is over $(bounds(GCC09)) angstrom")) end - if 5.9 ≤ x ≤ 11.0 # far-NUV + # NUV + a = 1.894 - 0.373 * x - 0.0101 / ((x - 4.57)^2 + 0.0384) + b = -3.490 + 2.057 * x + 0.706 / ((x - 4.59)^2 + 0.169) + if 5.9 ≤ x ≤ 11.0 # far-NUV y = x - 5.9 a += @evalpoly y 0.0 0.0 -0.110 -0.0100 b += @evalpoly y 0.0 0.0 0.531 0.0544 From 516831ab0d8c8bb0e132e2008d0ed79566b41b3c Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:23:30 -0400 Subject: [PATCH 16/34] Fix tests to catch correct exception type --- test/color_laws.jl | 28 ++++++++++++++-------------- test/mixture_laws.jl | 8 ++++---- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/test/color_laws.jl b/test/color_laws.jl index 12fd3ad..bac82b2 100644 --- a/test/color_laws.jl +++ b/test/color_laws.jl @@ -67,8 +67,8 @@ end bad_waves = [100, 4e4] @test @inferred(broadcast(law, bad_waves)) == zeros(length(bad_waves)) - @test_throws ErrorException ccm89_invum(aa_to_invum(bad_waves[1]), rv, ccm89_ca, ccm89_cb) - @test_throws ErrorException ccm89_invum(aa_to_invum(bad_waves[2]), rv, ccm89_ca, ccm89_cb) + @test_throws DomainError ccm89_invum(aa_to_invum(bad_waves[1]), rv, ccm89_ca, ccm89_cb) + @test_throws DomainError ccm89_invum(aa_to_invum(bad_waves[2]), rv, ccm89_ca, ccm89_cb) # uncertainties noise = randn(length(wave)) .* 0.01 @@ -217,8 +217,8 @@ end bad_waves = [100, 4e4] @test @inferred(broadcast(law, bad_waves)) == zeros(length(bad_waves)) - @test_throws ErrorException vcg04_invum(aa_to_invum(bad_waves[1]), rv) - @test_throws ErrorException vcg04_invum(aa_to_invum(bad_waves[2]), rv) + @test_throws DomainError vcg04_invum(aa_to_invum(bad_waves[1]), rv) + @test_throws DomainError vcg04_invum(aa_to_invum(bad_waves[2]), rv) # uncertainties noise = randn(length(wave)) .* 0.01 @@ -259,8 +259,8 @@ end bad_waves = [100, 4e4] @test @inferred(broadcast(law, bad_waves)) == zeros(length(bad_waves)) - @test_throws ErrorException gcc09_invum(aa_to_invum(bad_waves[1]), rv) - @test_throws ErrorException gcc09_invum(aa_to_invum(bad_waves[2]), rv) + @test_throws DomainError gcc09_invum(aa_to_invum(bad_waves[1]), rv) + @test_throws DomainError gcc09_invum(aa_to_invum(bad_waves[2]), rv) # uncertainties noise = randn(length(wave)) .* 0.01 @@ -296,8 +296,8 @@ end bad_waves = [100, 4e4] @test @inferred(map(law, bad_waves)) == zeros(length(bad_waves)) - @test_throws ErrorException f99_invum(aa_to_invum(bad_waves[1]), rv) - @test_throws ErrorException f99_invum(aa_to_invum(bad_waves[2]), rv) + @test_throws DomainError f99_invum(aa_to_invum(bad_waves[1]), rv) + @test_throws DomainError f99_invum(aa_to_invum(bad_waves[2]), rv) # uncertainties noise = rand(length(wave)) .* 0.01 @@ -333,8 +333,8 @@ end bad_waves = [100, 4e4] @test @inferred(map(law, bad_waves)) == zeros(length(bad_waves)) - @test_throws ErrorException f04_invum(aa_to_invum(bad_waves[1]), rv) - @test_throws ErrorException f04_invum(aa_to_invum(bad_waves[2]), rv) + @test_throws DomainError f04_invum(aa_to_invum(bad_waves[1]), rv) + @test_throws DomainError f04_invum(aa_to_invum(bad_waves[2]), rv) # uncertainties noise = rand(length(wave)) .* 0.01 @@ -371,8 +371,8 @@ end bad_waves = [100, 4e4] @test @inferred(map(law, bad_waves)) == zeros(length(bad_waves)) - @test_throws ErrorException f19_invum(aa_to_invum(bad_waves[1]), rv) - @test_throws ErrorException f19_invum(aa_to_invum(bad_waves[2]), rv) + @test_throws DomainError f19_invum(aa_to_invum(bad_waves[1]), rv) + @test_throws DomainError f19_invum(aa_to_invum(bad_waves[2]), rv) # uncertainties noise = rand(length(wave)) .* 0.01 @@ -408,8 +408,8 @@ end bad_waves = [100, 4e4] @test @inferred(map(law, bad_waves)) == zeros(length(bad_waves)) - @test_throws ErrorException m14_invum(aa_to_invum(bad_waves[1]), rv) - @test_throws ErrorException m14_invum(aa_to_invum(bad_waves[2]), rv) + @test_throws DomainError m14_invum(aa_to_invum(bad_waves[1]), rv) + @test_throws DomainError m14_invum(aa_to_invum(bad_waves[2]), rv) # uncertainties noise = rand(length(wave)) .* 0.01 diff --git a/test/mixture_laws.jl b/test/mixture_laws.jl index fb533a8..052410c 100644 --- a/test/mixture_laws.jl +++ b/test/mixture_laws.jl @@ -29,8 +29,8 @@ using DustExtinction: aa_to_invum, g03_invum, g16_invum, G03_SMCBar, G16 model = G16(Rv=3.1, f_A=1.0) bad_waves = [100, 4e4] @test model.(bad_waves) == zeros(length(bad_waves)) - @test_throws ErrorException g16_invum(aa_to_invum(bad_waves[1]), 3.1, 1.0) - @test_throws ErrorException g16_invum(aa_to_invum(bad_waves[2]), 3.1, 1.0) + @test_throws DomainError g16_invum(aa_to_invum(bad_waves[1]), 3.1, 1.0) + @test_throws DomainError g16_invum(aa_to_invum(bad_waves[2]), 3.1, 1.0) # uncertainties x_invum, ref_values = get_fA_1_ref() @@ -64,8 +64,8 @@ end model = G03_SMCBar(Rv=2.74) bad_waves = [100, 4e4] @test model.(bad_waves) == zeros(length(bad_waves)) - @test_throws ErrorException g03_invum(aa_to_invum(bad_waves[1]), 3.1) - @test_throws ErrorException g03_invum(aa_to_invum(bad_waves[2]), 3.1) + @test_throws DomainError g03_invum(aa_to_invum(bad_waves[1]), 3.1) + @test_throws DomainError g03_invum(aa_to_invum(bad_waves[2]), 3.1) # uncertainties model = G03_SMCBar(Rv=2.74) From a6d2bc635eff21687fa6564774e7a97168a4c504 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:23:43 -0400 Subject: [PATCH 17/34] Make curve F99 method more type stable --- src/color_laws.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/color_laws.jl b/src/color_laws.jl index a070e41..e590fee 100644 --- a/src/color_laws.jl +++ b/src/color_laws.jl @@ -2,7 +2,7 @@ using Dierckx using DelimitedFiles # Convenience function for wavelength conversion -@inline aa_to_invum(wave::Real) = 10000 / wave +@inline aa_to_invum(wave::Real) = 10_000 / wave # -------------------------------------------------------------------------------- @@ -241,10 +241,9 @@ function _curve_F99_method( ) # add in required spline points, otherwise just spline points + xuv = collect(f99_x_splineval_uv) if x >= f99_x_cutval_uv - xuv = (f99_x_splineval_uv..., x) - else - xuv = f99_x_splineval_uv + push!(xuv, x) end # FM90 model and values From ef7b5c0198be1782c334e1abff40aab1c6192f0a Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:25:49 -0400 Subject: [PATCH 18/34] Move bibtex asset files to their own directory --- docs/src/assets/{ => bibtex}/cal00.bib | 0 docs/src/assets/{ => bibtex}/ccm89.bib | 0 docs/src/assets/{ => bibtex}/f04.bib | 0 docs/src/assets/{ => bibtex}/f19.bib | 0 docs/src/assets/{ => bibtex}/f99.bib | 0 docs/src/assets/{ => bibtex}/fm90.bib | 0 docs/src/assets/{ => bibtex}/g16.bib | 0 docs/src/assets/{ => bibtex}/gcc09.bib | 0 docs/src/assets/{ => bibtex}/m14.bib | 6 +----- docs/src/assets/{ => bibtex}/od94.bib | 0 docs/src/assets/{ => bibtex}/sfd98.bib | 0 docs/src/assets/{ => bibtex}/vcg04.bib | 0 docs/src/index.md | 28 +++++++++++++------------- 13 files changed, 15 insertions(+), 19 deletions(-) rename docs/src/assets/{ => bibtex}/cal00.bib (100%) rename docs/src/assets/{ => bibtex}/ccm89.bib (100%) rename docs/src/assets/{ => bibtex}/f04.bib (100%) rename docs/src/assets/{ => bibtex}/f19.bib (100%) rename docs/src/assets/{ => bibtex}/f99.bib (100%) rename docs/src/assets/{ => bibtex}/fm90.bib (100%) rename docs/src/assets/{ => bibtex}/g16.bib (100%) rename docs/src/assets/{ => bibtex}/gcc09.bib (100%) rename docs/src/assets/{ => bibtex}/m14.bib (77%) rename docs/src/assets/{ => bibtex}/od94.bib (100%) rename docs/src/assets/{ => bibtex}/sfd98.bib (100%) rename docs/src/assets/{ => bibtex}/vcg04.bib (100%) diff --git a/docs/src/assets/cal00.bib b/docs/src/assets/bibtex/cal00.bib similarity index 100% rename from docs/src/assets/cal00.bib rename to docs/src/assets/bibtex/cal00.bib diff --git a/docs/src/assets/ccm89.bib b/docs/src/assets/bibtex/ccm89.bib similarity index 100% rename from docs/src/assets/ccm89.bib rename to docs/src/assets/bibtex/ccm89.bib diff --git a/docs/src/assets/f04.bib b/docs/src/assets/bibtex/f04.bib similarity index 100% rename from docs/src/assets/f04.bib rename to docs/src/assets/bibtex/f04.bib diff --git a/docs/src/assets/f19.bib b/docs/src/assets/bibtex/f19.bib similarity index 100% rename from docs/src/assets/f19.bib rename to docs/src/assets/bibtex/f19.bib diff --git a/docs/src/assets/f99.bib b/docs/src/assets/bibtex/f99.bib similarity index 100% rename from docs/src/assets/f99.bib rename to docs/src/assets/bibtex/f99.bib diff --git a/docs/src/assets/fm90.bib b/docs/src/assets/bibtex/fm90.bib similarity index 100% rename from docs/src/assets/fm90.bib rename to docs/src/assets/bibtex/fm90.bib diff --git a/docs/src/assets/g16.bib b/docs/src/assets/bibtex/g16.bib similarity index 100% rename from docs/src/assets/g16.bib rename to docs/src/assets/bibtex/g16.bib diff --git a/docs/src/assets/gcc09.bib b/docs/src/assets/bibtex/gcc09.bib similarity index 100% rename from docs/src/assets/gcc09.bib rename to docs/src/assets/bibtex/gcc09.bib diff --git a/docs/src/assets/m14.bib b/docs/src/assets/bibtex/m14.bib similarity index 77% rename from docs/src/assets/m14.bib rename to docs/src/assets/bibtex/m14.bib index 4bb5dbb..325a108 100644 --- a/docs/src/assets/m14.bib +++ b/docs/src/assets/bibtex/m14.bib @@ -1,9 +1,5 @@ @ARTICLE{2014A&A...564A..63M, - author = {{Ma{\'\i}z Apell{\'a}niz}, J. and {Evans}, C.~J. and {Barb{\'a}}, R.~H. and - {Gr{\"a}fener}, G. and {Bestenlehner}, J.~M. and {Crowther}, P.~A. and - {Garc{\'\i}a}, M. and {Herrero}, A. and {Sana}, H. and - {Sim{\'o}n-D{\'\i}az}, S. and {Taylor}, W.~D. and {van Loon}, J. Th. and - {Vink}, J.~S. and {Walborn}, N.~R.}, + author = {{Ma{\'\i}z Apell{\'a}niz}, J. and {Evans}, C.~J. and {Barb{\'a}}, R.~H. and {Gr{\"a}fener}, G. and {Bestenlehner}, J.~M. and {Crowther}, P.~A. and {Garc{\'\i}a}, M. and {Herrero}, A. and {Sana}, H. and {Sim{\'o}n-D{\'\i}az}, S. and {Taylor}, W.~D. and {van Loon}, J. Th. and {Vink}, J.~S. and {Walborn}, N.~R.}, title = "{The VLT-FLAMES Tarantula Survey. XVI. The optical and NIR extinction laws in 30 Doradus and the photometric determination of the effective temperatures of OB stars}", journal = {\aap}, keywords = {open clusters and associations: individual: 30 Doradus, dust, extinction, Magellanic Clouds, stars: early-type, stars: fundamental parameters, Astrophysics - Astrophysics of Galaxies, Astrophysics - Cosmology and Nongalactic Astrophysics, Astrophysics - Instrumentation and Methods for Astrophysics, Astrophysics - Solar and Stellar Astrophysics}, diff --git a/docs/src/assets/od94.bib b/docs/src/assets/bibtex/od94.bib similarity index 100% rename from docs/src/assets/od94.bib rename to docs/src/assets/bibtex/od94.bib diff --git a/docs/src/assets/sfd98.bib b/docs/src/assets/bibtex/sfd98.bib similarity index 100% rename from docs/src/assets/sfd98.bib rename to docs/src/assets/bibtex/sfd98.bib diff --git a/docs/src/assets/vcg04.bib b/docs/src/assets/bibtex/vcg04.bib similarity index 100% rename from docs/src/assets/vcg04.bib rename to docs/src/assets/bibtex/vcg04.bib diff --git a/docs/src/index.md b/docs/src/index.md index 94ed5de..9f4bfc0 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -38,20 +38,20 @@ For more examples, view the [Color Laws](@ref laws) and [Dust Maps](@ref maps) s There are various citations relevant to this work. Please be considerate when using this work or any derivate of it by adding the appropriate citations. -| Law | Reference | BibTeX | -| :----------------: | :--------------------------------------------------------------------------------------------- | :--------------------------- | -| [`CCM89`](@ref) | [Clayton, Cardelli and Mathis (1989)](https://ui.adsabs.harvard.edu/abs/1989ApJ...345..245C) | [download](assets/ccm89.bib) | -| [`OD94`](@ref) | [O'Donnell (1994)](https://ui.adsabs.harvard.edu/abs/1994ApJ...422..158O) | [download](assets/od94.bib) | -| [`CAL00`](@ref) | [Calzetti et al. (2000)](https://ui.adsabs.harvard.edu/abs/2000ApJ...533..682C) | [download](assets/cal00.bib) | -| [`VCG04`](@ref) | [Valencic, Clayton, & Gordon (2004)](https://ui.adsabs.harvard.edu/abs/2004ApJ...616..912V) | [download](assets/vcg04.bib) | -| [`GCC09`](@ref) | [Gordon, Cartledge, & Clayton (2009)](https://ui.adsabs.harvard.edu/abs/2009ApJ...705.1320G) | [download](assets/gcc09.bib) | -| [`FM90`](@ref) | [Fitzpatrick & Massa (1990)](https://ui.adsabs.harvard.edu/abs/1990ApJS...72..163F) | [download](assets/fm90.bib) | -| [`G16`](@ref) | [Gordon et al (2016) ](https://ui.adsabs.harvard.edu/abs/2016ApJ...826..104G) | [download](assets/g16.bib) | -| [`SFD98Map`](@ref) | [Schlegel, Finkbeiner and Davis (1998)](https://ui.adsabs.harvard.edu/abs/1998ApJ...500..525S) | [download](assets/sfd98.bib) | -| [`F99`](@ref) | [Fitzpatrick (1999)](https://ui.adsabs.harvard.edu/abs/1999PASP..111...63F) | [download](assets/f99.bib) | -| [`F04`](@ref) | [Fitzpatrick (2004)](https://ui.adsabs.harvard.edu/abs/2004ASPC..309...33F) | [download](assets/f04.bib) | -| [`F19`](@ref) | [Fitzpatrick (2019)](https://ui.adsabs.harvard.edu/abs/2019ApJ...886..108F) | [download](assets/f19.bib) | -| [`M14`](@ref) | [Maiz Apellaniz et al. (2014)](https://ui.adsabs.harvard.edu/abs/2014A%26A...564A..63M) | [download](assets/m14.bib) | +| Law | Reference | BibTeX | +| :----------------: | :--------------------------------------------------------------------------------------------- | :---------------------------------- | +| [`CCM89`](@ref) | [Clayton, Cardelli and Mathis (1989)](https://ui.adsabs.harvard.edu/abs/1989ApJ...345..245C) | [download](assets/bibtex/ccm89.bib) | +| [`OD94`](@ref) | [O'Donnell (1994)](https://ui.adsabs.harvard.edu/abs/1994ApJ...422..158O) | [download](assets/bibtex/od94.bib) | +| [`CAL00`](@ref) | [Calzetti et al. (2000)](https://ui.adsabs.harvard.edu/abs/2000ApJ...533..682C) | [download](assets/bibtex/cal00.bib) | +| [`VCG04`](@ref) | [Valencic, Clayton, & Gordon (2004)](https://ui.adsabs.harvard.edu/abs/2004ApJ...616..912V) | [download](assets/bibtex/vcg04.bib) | +| [`GCC09`](@ref) | [Gordon, Cartledge, & Clayton (2009)](https://ui.adsabs.harvard.edu/abs/2009ApJ...705.1320G) | [download](assets/bibtex/gcc09.bib) | +| [`FM90`](@ref) | [Fitzpatrick & Massa (1990)](https://ui.adsabs.harvard.edu/abs/1990ApJS...72..163F) | [download](assets/bibtex/fm90.bib) | +| [`G16`](@ref) | [Gordon et al (2016) ](https://ui.adsabs.harvard.edu/abs/2016ApJ...826..104G) | [download](assets/bibtex/g16.bib) | +| [`SFD98Map`](@ref) | [Schlegel, Finkbeiner and Davis (1998)](https://ui.adsabs.harvard.edu/abs/1998ApJ...500..525S) | [download](assets/bibtex/sfd98.bib) | +| [`F99`](@ref) | [Fitzpatrick (1999)](https://ui.adsabs.harvard.edu/abs/1999PASP..111...63F) | [download](assets/bibtex/f99.bib) | +| [`F04`](@ref) | [Fitzpatrick (2004)](https://ui.adsabs.harvard.edu/abs/2004ASPC..309...33F) | [download](assets/bibtex/f04.bib) | +| [`F19`](@ref) | [Fitzpatrick (2019)](https://ui.adsabs.harvard.edu/abs/2019ApJ...886..108F) | [download](assets/bibtex/f19.bib) | +| [`M14`](@ref) | [Maiz Apellaniz et al. (2014)](https://ui.adsabs.harvard.edu/abs/2014A%26A...564A..63M) | [download](assets/bibtex/m14.bib) | ## Index From 000e455b34a7440b269706ba19c896c091c65c13 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:27:50 -0400 Subject: [PATCH 19/34] Fix capitalization --- docs/src/color_laws.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/color_laws.md b/docs/src/color_laws.md index a93b875..5d73607 100644 --- a/docs/src/color_laws.md +++ b/docs/src/color_laws.md @@ -202,7 +202,7 @@ F19 ### Maiz Apellaniz et al. (2014) -![](assets/m14_plot.svg) +![](assets/M14_plot.svg) ```@docs M14 From d571900a476311a6b7733a2fb9893e77b3ee3489 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:42:44 -0400 Subject: [PATCH 20/34] Add docstrings to site for G03_SMCBar --- docs/src/color_laws.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/src/color_laws.md b/docs/src/color_laws.md index 5d73607..ce59e29 100644 --- a/docs/src/color_laws.md +++ b/docs/src/color_laws.md @@ -229,6 +229,12 @@ FM90 ### Mixture Extinction Laws +#### Gordon et al. (2003) + +```@docs +G03_SMCBar +``` + #### Gordon et al. (2016) ![](assets/G16_fixed_f_A_plot.svg) From f73fba114a4541fdd4adac45b092c0c8d11d3f47 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:43:19 -0400 Subject: [PATCH 21/34] Add docstring for checkbounds to site --- docs/src/color_laws.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/src/color_laws.md b/docs/src/color_laws.md index ce59e29..d022b5d 100644 --- a/docs/src/color_laws.md +++ b/docs/src/color_laws.md @@ -215,6 +215,7 @@ redden deredden DustExtinction.ExtinctionLaw DustExtinction.bounds +DustExtinction.checkbounds ``` ### Fittable Extinction Laws From ec5824a0901f5b1aad6d41a30cd86d9900797d1b Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:44:11 -0400 Subject: [PATCH 22/34] Turn docstrings missing from doc site into warnings --- docs/make.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index 984a074..59e8c0c 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -7,7 +7,8 @@ makedocs(modules = [DustExtinction], sitename = "DustExtinction.jl", format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"), authors = "Kyle Barbary, Mosé Giordano, Miles Lucas", - pages = pages + pages = pages, + warnonly = [:missing_docs], ) deploydocs(repo = "github.com/JuliaAstro/DustExtinction.jl.git", push_preview = true) From dd5d3ca6a55fe199b062e7cca4b30e6d78a6013f Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:44:40 -0400 Subject: [PATCH 23/34] Split up color laws into separate files --- src/color_laws.jl | 559 +--------------------------------- src/color_laws/ccm89.jl | 67 ++++ src/color_laws/fitzpatrick.jl | 289 ++++++++++++++++++ src/color_laws/gcc09.jl | 44 +++ src/color_laws/m14.jl | 105 +++++++ src/color_laws/vcg04.jl | 45 +++ 6 files changed, 555 insertions(+), 554 deletions(-) create mode 100644 src/color_laws/ccm89.jl create mode 100644 src/color_laws/fitzpatrick.jl create mode 100644 src/color_laws/gcc09.jl create mode 100644 src/color_laws/m14.jl create mode 100644 src/color_laws/vcg04.jl diff --git a/src/color_laws.jl b/src/color_laws.jl index e590fee..17bb323 100644 --- a/src/color_laws.jl +++ b/src/color_laws.jl @@ -6,38 +6,6 @@ using DelimitedFiles # -------------------------------------------------------------------------------- -# Optical coefficients -const ccm89_ca = [1.0, 0.17699, -0.50447, -0.02427, 0.72085, 0.01979, -0.7753, 0.32999, 0.0] -const ccm89_cb = [0.0, 1.41338, 2.28305, 1.07233, -5.38434, -0.62251, 5.3026, -2.09002, 0.0] - -const od94_ca = [1.0, 0.104, -0.609, 0.701, 1.137, -1.718, -0.827, 1.647, -0.505] -const od94_cb = [0.0, 1.952, 2.908, -3.989, -7.985, 11.102, 5.491, -10.805, 3.347] - -""" - CCM89(;Rv=3.1) - -Clayton, Cardelli and Mathis (1989) dust law. - -Returns E(B-V) in magnitudes at the given wavelength relative to the extinction -at 5494.5 Å. The default support is [1000, 33333]. Outside of that range this -will return 0. `Rv` is the selective extinction and is valid over [2, 6]. -A typical value for the Milky Way is 3.1. - -# References -[Clayton,Cardelli and Mathis (1989)](https://ui.adsabs.harvard.edu/abs/1989ApJ...345..245C) -""" -@with_kw struct CCM89 <: ExtinctionLaw - Rv::Float64 = 3.1 -end - -function (law::CCM89)(wave::T) where T - checkbounds(law, wave) || return zero(float(T)) - x = aa_to_invum(wave) - return ccm89_invum(x, law.Rv, ccm89_ca, ccm89_cb) -end - -bounds(::Type{CCM89}) = (1000, 33333) - """ OD94(;Rv=3.1) @@ -65,42 +33,6 @@ end bounds(::Type{OD94}) = (1000, 33333) -""" - DustExtinction.ccm89_invum(x, Rv, c_a, c_b) - -The algorithm used for the [`CCM89`](@ref) extinction law, given inverse microns, -Rv, and a set of coefficients for use in the optical (only difference between -ccm89 and od94). For more information, seek the original paper. -""" -function ccm89_invum(x::Real, Rv::Real, c_a::Vector{<:Real}, c_b::Vector{<:Real}) - if x < 0.3 || x > 10.0 - throw(DomainError(x, "out of bounds of CCM89, support is over $(bounds(CCM89)) angstrom")) - end - if x < 1.1 # Near IR - y = x^1.61 - a = 0.574y - b = -0.527y - elseif x < 3.3 # Optical - y = x - 1.82 - yn = 1.0 - a = @evalpoly y c_a[1] c_a[2] c_a[3] c_a[4] c_a[5] c_a[6] c_a[7] c_a[8] c_a[9] - b = @evalpoly y c_b[1] c_b[2] c_b[3] c_b[4] c_b[5] c_b[6] c_b[7] c_b[8] c_b[9] - elseif x < 8.0 # NUV - a = 1.752 - 0.316x - (0.104 / ((x - 4.67)^2 + 0.341)) - b = -3.090 + 1.825x + (1.206 / ((x - 4.62)^2 + 0.263)) - if x > 5.9 # Far NUV - y = x - 5.9 - a += @evalpoly y 0.0 0.0 -0.04473 -0.009779 - b += @evalpoly y 0.0 0.0 0.213 0.1207 - end - else # FUV - y = x - 8.0 - a = @evalpoly y -1.073 -0.628 0.137 -0.07 - b = @evalpoly y 13.67 4.257 -0.42 0.374 - end - return a + b / Rv -end - # ------------------------------------------------------------------------------ """ @@ -134,489 +66,8 @@ end bounds(::Type{CAL00}) = (1200, 22000) -""" - VCG04(;Rv=3.1) - -Valencic, Clayton, & Gordon (2004) dust law. - -This model applies to the UV spectral region all the way to 912 Å. -This model was not derived for the optical or NIR. - -# References -[Valencic, Clayton, & Gordon (2004)](https://ui.adsabs.harvard.edu/abs/2004ApJ...616..912V/) -""" -@with_kw struct VCG04 <: ExtinctionLaw - Rv::Float64 = 3.1 -end - -function (law::VCG04)(wave::T) where T - checkbounds(law, wave) || return zero(float(T)) - x = aa_to_invum(wave) - return vcg04_invum(x, law.Rv) -end - -bounds(::Type{VCG04}) = (1250, 3030.3) - -""" - DustExtinction.vcg04_invum(x, Rv) - -The algorithm used for the [`VCG04`](@ref) extinction law, given inverse microns -and Rv. For more information, seek the original paper. -""" -function vcg04_invum(x::Real, Rv::Real) - if x < 3.3 || x > 8.0 - throw(DomainError(x, "out of bounds of VCG04, support is over $(bounds(VCG04)) angstrom")) - end - - # NUV - a = 1.808 - 0.215 * x - 0.134 / ((x - 4.558)^2 + 0.566) - b = -2.350 + 1.403 * x + 1.103 / ((x - 4.587)^2 + 0.263) - if 5.9 ≤ x ≤ 8.0 # far-NUV - y = x - 5.9 - a += @evalpoly y 0.0 0.0 -0.0077 -0.0030 - b += @evalpoly y 0.0 0.0 0.2060 0.0550 - end - - return a + b / Rv -end - -""" - GCC09(;Rv=3.1) - -Gordon, Cartledge, & Clayton (2009) dust law. - -This model applies to the UV spectral region all the way to 909.09 Å. -This model was not derived for the optical or NIR. - -# References -[Gordon, Cartledge, & Clayton (2009)](https://ui.adsabs.harvard.edu/abs/2009ApJ...705.1320G/) -""" -@with_kw struct GCC09 <: ExtinctionLaw - Rv::Float64 = 3.1 -end - -function (law::GCC09)(wave::T) where T - checkbounds(law, wave) || return zero(float(T)) - x = aa_to_invum(wave) - return gcc09_invum(x, law.Rv) -end - -bounds(::Type{GCC09}) = (909.0909090909091, 3030.3030303030305) - -""" - DustExtinction.gcc09_invum(x, Rv) - -The algorithm used for the [`GCC09`](@ref) extinction law, given inverse microns -and Rv. For more information, seek the original paper. -""" -function gcc09_invum(x::Real, Rv::Real) - if x < 3.3 || x > 11.0 # out of bounds - throw(DomainError(x, "out of bounds of GCC09, support is over $(bounds(GCC09)) angstrom")) - end - # NUV - a = 1.894 - 0.373 * x - 0.0101 / ((x - 4.57)^2 + 0.0384) - b = -3.490 + 2.057 * x + 0.706 / ((x - 4.59)^2 + 0.169) - if 5.9 ≤ x ≤ 11.0 # far-NUV - y = x - 5.9 - a += @evalpoly y 0.0 0.0 -0.110 -0.0100 - b += @evalpoly y 0.0 0.0 0.531 0.0544 - end - - return a + b / Rv -end - -# x value above which FM90 parametrization used -const f99_x_cutval_uv = aa_to_invum(2700) -# required UV points for spline interpolation -const f99_x_splineval_uv = aa_to_invum.((2700, 2600)) - -# Shape models used by F99 and F04 -function _curve_F99_method( - x, - Rv, - c1, c2, c3, c4, - x0, - gamma, - optnir_axav_x, optnir_axav_y, - ) - - # add in required spline points, otherwise just spline points - xuv = collect(f99_x_splineval_uv) - if x >= f99_x_cutval_uv - push!(xuv, x) - end - - # FM90 model and values - fm90_model = FM90(c1=c1, c2=c2, c3=c3, c4=c4, x0=x0, gamma=gamma) - # evaluate model and get results in A(x)/A(V) - axav_fm90 = @. fm90_model(aa_to_invum(xuv)) / Rv + 1 - - # ignore the spline points - if x >= f99_x_cutval_uv - axav = last(axav_fm90) - else - # **Optical Portion** - - # save spline points - y_splineval_uv = axav_fm90 - - # spline points - x_splineval_optir = (0.0, optnir_axav_x...) - - # determine optical/IR values at spline points - y_splineval_optir = (0.0, optnir_axav_y...) - spline_x = (x_splineval_optir..., f99_x_splineval_uv...) - spline_y = (y_splineval_optir..., y_splineval_uv...) - spl = Spline1D(collect(spline_x), collect(spline_y), k=3) - axav = spl(x) - end - - # return A(x)/A(V) - return axav -end - -# spline points -const f99_optnir_axav_x = aa_to_invum.((26500, 12200, 6000, 5470, 4670, 4110)) -const f99_nir_axebv_y_params = @. (0.265, 0.829) / 3.1 - -# c1-c2 correlation terms -const f99_c3 = 3.23 -const f99_c4 = 0.41 -const f99_x0 = 4.596 -const f99_gamma = 0.99 - -""" - F99(;Rv=3.1) - -Fitzpatrick (1999) dust law. - -Returns E(B-V) in magnitudes at the given wavelength relative to the -extinction. This model applies to the UV and optical to NIR spectral range. -The default support is [1000, 33333] Å. Outside of that range this will -return 0. Rv is the selective extinction and is valid over [2, 6]. -A typical value for the Milky Way is 3.1. - -# References -[Fitzpatrick (1999)](https://ui.adsabs.harvard.edu/abs/1999PASP..111...63F/) -""" -@with_kw struct F99 <: ExtinctionLaw - Rv::Float64 = 3.1 -end - -function (law::F99)(wave::T) where T - checkbounds(law, wave) || return zero(float(T)) - x = aa_to_invum(wave) - return f99_invum(x, law.Rv) -end - -bounds(::Type{F99}) = (1000.0, 33333.3) - -""" - DustExtinction.f99_invum(x, Rv) - -The algorithm used for the [`F99`](@ref) extinction law, given inverse microns -and Rv. For more information, seek the original paper. -""" -function f99_invum(x::Real, Rv::Real) - if !(0.3 <= x <= 10.0) - throw(DomainError(x, "out of bounds of F99, support is over $(bounds(F99)) angstrom")) - end - - # terms depending on Rv - c2 = @evalpoly (1. / Rv) -0.824 4.717 - # original F99 c1-c2 correlation - c1 = @evalpoly c2 2.030 -3.007 - - # determine optical/IR values at spline points - # Final optical spline point has a leading "-1.208" in Table 4 - # of F99, but that does not reproduce Table 3. - # Additional indication that this is not correct is from - # fm_unred.pro - # which is based on FMRCURVE.pro distributed by Fitzpatrick. - # --> confirmation needed? - # - # Also, fm_unred.pro has different coeff and # of terms, - # but later work does not include these terms - # --> check with Fitzpatrick? - opt_axebv_y = - (@evalpoly Rv -0.426 1.0044), - (@evalpoly Rv -0.050 1.0016), - (@evalpoly Rv 0.701 1.0016), - (@evalpoly Rv 1.208 1.0032 -0.00033) - - nir_axebv_y = @. f99_nir_axebv_y_params * Rv - optnir_axebv_y = @. (nir_axebv_y..., opt_axebv_y...) / Rv - - return _curve_F99_method( - x, - Rv, - c1, - c2, - f99_c3, - f99_c4, - f99_x0, - f99_gamma, - f99_optnir_axav_x, - optnir_axebv_y, - ) -end - -# spline points -const f04_opt_axav_x = aa_to_invum.((6000, 5470, 4670, 4110)) -const f04_nir_axav_x = (0.50, 0.75, 1.0) - -# **Use NIR spline x values in FM07, clipped to K band for now -const f04_optnir_axav_x = (f04_nir_axav_x..., f04_opt_axav_x...) - -# c1-c2 correlation terms -const f04_c3 = 2.991 -const f04_c4 = 0.319 -const f04_x0 = 4.592 -const f04_gamma = 0.922 - -""" - F04(;Rv=3.1) - -Fitzpatrick (2004) dust law. - -Returns E(B-V) in magnitudes at the given wavelength relative to the extinction. -This model applies to the UV and optical to NIR spectral range. -The default support is [1000, 33333] Å. Outside of that range this will return 0. -Rv is the selective extinction and is valid over [2, 6]. A typical value for -the Milky Way is 3.1. - -Equivalent to the F99 model with an updated NIR Rv dependence - -See also Fitzpatrick & Massa (2007, ApJ, 663, 320) - -# References -[Fitzpatrick (2004)](https://ui.adsabs.harvard.edu/abs/2004ASPC..309...33F/) -""" -@with_kw struct F04 <: ExtinctionLaw - Rv::Float64 = 3.1 -end - -function (law::F04)(wave::T) where T - checkbounds(law, wave) || return zero(float(T)) - x = aa_to_invum(wave) - return f04_invum(x, law.Rv) -end - -bounds(::Type{F04}) = (1000.0, 33333.3) - -""" - DustExtinction.f04_invum(x, Rv) - -The algorithm used for the [`F04`](@ref) extinction law, given inverse microns -and Rv. For more information, seek the original paper. -""" -function f04_invum(x::Real, Rv::Real) - if !(0.3 <= x <= 10.0) - throw(DomainError(x, "out of bounds of F04, support is over $(bounds(F04)) angstrom")) - end - - # original F99 Rv dependence - c2 = @evalpoly (1. / Rv) -0.824 4.717 - # updated F04 C1-C2 correlation - c1 = @evalpoly c2 2.18 -2.91 - - # **Keep optical spline points from F99: - # Final optical spline point has a leading "-1.208" in Table 4 - # of F99, but that does not reproduce Table 3. - # Additional indication that this is not correct is from - # fm_unred.pro - # which is based on FMRCURVE.pro distributed by Fitzpatrick. - # --> confirmation needed? - opt_axebv_y = - (@evalpoly Rv -0.426 1.0044), - (@evalpoly Rv -0.050 1.0016), - (@evalpoly Rv 0.701 1.0016), - (@evalpoly Rv 1.208 1.0032 -0.00033) - - # updated NIR curve from F04, note R dependence - # Julia v1.0 workaround: https://github.com/JuliaAstro/DustExtinction.jl/pull/31#commitcomment-40605778 - nir_axebv_y_coeff = (0.63 * Rv - 0.84) - nir_axebv_y = @. nir_axebv_y_coeff * f04_nir_axav_x^1.84 - - optnir_axebv_y = @. (nir_axebv_y..., opt_axebv_y...) / Rv - - return _curve_F99_method( - x, - Rv, - c1, - c2, - f04_c3, - f04_c4, - f04_x0, - f04_gamma, - f04_optnir_axav_x, - optnir_axebv_y, - ) -end - -""" - F19(;Rv=3.1) - -Fitzpatrick (2019) dust law. - -Returns E(B-V) in magnitudes at the given wavelength relative to the -extinction. This model applies to the UV and optical to NIR spectral range. -The default support is [1149, 33333] Å. Outside of that range this will -return 0. Rv is the selective extinction and is valid over [2, 6]. -A typical value for the Milky Way is 3.1. - -Fitzpatrick, Massa, Gordon et al. (2019, ApJ, 886, 108) model. Based on a -sample of stars observed spectroscopically in the optical with HST/STIS. - -# References -[Fitzpatrick (2019)](https://ui.adsabs.harvard.edu/abs/2019ApJ...886..108F/) -""" -@with_kw struct F19 <: ExtinctionLaw - Rv::Float64 = 3.1 -end - -function (law::F19)(wave::T) where T - checkbounds(law, wave) || return zero(float(T)) - x = aa_to_invum(wave) - return f19_invum(x, law.Rv) -end - -bounds(::Type{F19}) = (1149.4252873563219, 33333.333333333336) - -""" - DustExtinction.f19_invum(x, Rv) - -The algorithm used for the [`F19`](@ref) extinction law, given inverse microns -and Rv. For more information, seek the original paper. -""" -function f19_invum(x::Real, Rv::Real) - # read and unpack tabulated data - data_x, data_k, data_delta_k, data_sigma_k = let data = readdlm(joinpath(datadep"F19", "F19_tabulated.dat"), skipstart=1) - (data[:, i] for i in 1:4) - end - - if !(0.3 <= x <= 8.7) - throw(DomainError( - x, "out of bounds of F19, support is over $(bounds(F19)) angstrom")) - end - - # compute E(lambda-55)/E(B-55) on the tabulated x points - k_rV_tab_x = @. data_k + data_delta_k * (Rv - 3.10) * 0.990 - - # setup spline interpolation - spl = Spline1D(collect(data_x), collect(k_rV_tab_x), k=3) - - # use spline interpolation to evaluate the curve for the input x values - k_rV = spl(x) - - # convert to A(x)/A(55) from E(x-55)/E(44-55) - a_rV = k_rV / Rv + 1.0 - - return a_rV -end - -# Optical -const m14_x1 = (1.0) -const m14_xi1 = first(m14_x1) -const m14_x2 = (1.15, 1.81984, 2.1, 2.27015, 2.7) -const m14_x3 = (3.5, 3.9, 4.0, 4.1, 4.2) -const m14_xi3 = last(m14_x3) -const m14_a1v = 0.574 * m14_x1^1.61 -const m14_b1v = -0.527 * m14_x1^1.61 -const m14_x2_diff = m14_x2 .- 1.82 -const m14_a2v = @. ( - 1 - + 0.17699 * (m14_x2_diff) - - 0.50447 * (m14_x2_diff)^2 - - 0.02427 * (m14_x2_diff)^3 - + 0.72085 * (m14_x2_diff)^4 - + 0.01979 * (m14_x2_diff)^5 - - 0.77530 * (m14_x2_diff)^6 - + 0.32999 * (m14_x2_diff)^7 - + (0.0, 0.0, -0.011, 0.0, 0.0) -) -const m14_b2v = @. ( - 1.41338 * (m14_x2 - 1.82) - + 2.28305 * (m14_x2 - 1.82)^2 - + 1.07233 * (m14_x2 - 1.82)^3 - - 5.38434 * (m14_x2 - 1.82)^4 - - 0.62251 * (m14_x2 - 1.82)^5 - + 5.30260 * (m14_x2 - 1.82)^6 - - 2.09002 * (m14_x2 - 1.82)^7 - + (0.0, 0.0, 0.091, 0.0, 0.0) -) -const m14_a3v = @. ( - 1.752 - - 0.316 * m14_x3 - - 0.104 / ((m14_x3 - 4.67)^2 + 0.341) - + (0.442, 0.341, 0.130, 0.020, 0.000) -) -const m14_b3v = @. ( - -3.090 - + 1.825 * m14_x3 - + 1.206 / ((m14_x3 - 4.62)^2 + 0.263) - - (1.256, 1.021, 0.416, 0.064, 0.000) -) -const m14_xn = collect((m14_x1..., m14_x2..., m14_x3...)) -const m14_anv = collect((m14_a1v..., m14_a2v..., m14_a3v...)) -const m14_bnv = collect((m14_b1v..., m14_b2v..., m14_b3v...)) -const m14_a_spl = Spline1D(m14_xn, m14_anv, bc="nearest") -const m14_b_spl = Spline1D(m14_xn, m14_bnv, bc="nearest") - -""" - M14(;Rv=3.1) - -Maiz Apellaniz et al (2014) Milky Way & LMC R(V) dependent model. - -Returns E(B-V) in magnitudes at the given wavelength relative to the -extinction. The published UV extinction curve is identical to Clayton, -Cardelli, and Mathis (1989, CCM). Forcing the optical section to match smoothly -with CCM introduces a non-physical feature at high values of R5495 around 3.9 -inverse microns; see section 5 in Maiz Apellaniz et al. (2014) for more -discussion. For that reason, we provide the M14 model only through 3.3 inverse -microns, the limit of the optical in CCM. Outside of that range this will -return 0. Rv is the selective extinction and is valid over [2, 6]. A typical -value for the Milky Way is 3.1. R5495 = A(5485)/E(4405-5495) Spectral -equivalent to photometric R(V). - -# References -[Maiz Apellaniz et al. (2014)](https://ui.adsabs.harvard.edu/abs/2014A%26A...564A..63M/) -""" -@with_kw struct M14 <: ExtinctionLaw - Rv::Float64 = 3.1 -end - -function (law::M14)(wave::T) where T - checkbounds(law, wave) || return zero(float(T)) - x = aa_to_invum(wave) - return m14_invum(x, law.Rv) -end - -bounds(::Type{M14}) = (3030.3030303030305, 33333.333333333336) - -""" - DustExtinction.m14_invum(x, Rv) - -The algorithm used for the [`M14`](@ref) extinction law, given inverse microns -and Rv. For more information, seek the original paper. -""" -function m14_invum(x::Real, Rv::Real) - if !(0.3 <= x <= 3.3) - throw(DomainError( - x, "out of bounds of M14, support is over $(bounds(M14)) angstrom")) - end - - a = zero(x) - b = zero(x) - if x < m14_xi1 - # Infrared - a = 0.574 * x^1.61 - b = -0.527 * x^1.61 - elseif x < m14_xi3 - # Optical - a = m14_a_spl(x) - b = m14_b_spl(x) - end - - return a + b / Rv -end +include("color_laws/ccm89.jl") +include("color_laws/fitzpatrick.jl") +include("color_laws/gcc09.jl") +include("color_laws/m14.jl") +include("color_laws/vcg04.jl") diff --git a/src/color_laws/ccm89.jl b/src/color_laws/ccm89.jl new file mode 100644 index 0000000..b2403fc --- /dev/null +++ b/src/color_laws/ccm89.jl @@ -0,0 +1,67 @@ +# Optical coefficients +const ccm89_ca = [1.0, 0.17699, -0.50447, -0.02427, 0.72085, 0.01979, -0.7753, 0.32999, 0.0] +const ccm89_cb = [0.0, 1.41338, 2.28305, 1.07233, -5.38434, -0.62251, 5.3026, -2.09002, 0.0] + +const od94_ca = [1.0, 0.104, -0.609, 0.701, 1.137, -1.718, -0.827, 1.647, -0.505] +const od94_cb = [0.0, 1.952, 2.908, -3.989, -7.985, 11.102, 5.491, -10.805, 3.347] + +""" + CCM89(;Rv=3.1) + +Clayton, Cardelli and Mathis (1989) dust law. + +Returns E(B-V) in magnitudes at the given wavelength relative to the extinction +at 5494.5 Å. The default support is [1000, 33333]. Outside of that range this +will return 0. `Rv` is the selective extinction and is valid over [2, 6]. +A typical value for the Milky Way is 3.1. + +# References +[Clayton,Cardelli and Mathis (1989)](https://ui.adsabs.harvard.edu/abs/1989ApJ...345..245C) +""" +@with_kw struct CCM89 <: ExtinctionLaw + Rv::Float64 = 3.1 +end + +function (law::CCM89)(wave::T) where T + checkbounds(law, wave) || return zero(float(T)) + x = aa_to_invum(wave) + return ccm89_invum(x, law.Rv, ccm89_ca, ccm89_cb) +end + +bounds(::Type{CCM89}) = (1000, 33333) + +""" + DustExtinction.ccm89_invum(x, Rv, c_a, c_b) + +The algorithm used for the [`CCM89`](@ref) extinction law, given inverse microns, +Rv, and a set of coefficients for use in the optical (only difference between +ccm89 and od94). For more information, seek the original paper. +""" +function ccm89_invum(x::Real, Rv::Real, c_a::Vector{<:Real}, c_b::Vector{<:Real}) + if x < 0.3 || x > 10.0 + throw(DomainError(x, "out of bounds of CCM89, support is over $(bounds(CCM89)) angstrom")) + end + if x < 1.1 # Near IR + y = x^1.61 + a = 0.574y + b = -0.527y + elseif x < 3.3 # Optical + y = x - 1.82 + yn = 1.0 + a = @evalpoly y c_a[1] c_a[2] c_a[3] c_a[4] c_a[5] c_a[6] c_a[7] c_a[8] c_a[9] + b = @evalpoly y c_b[1] c_b[2] c_b[3] c_b[4] c_b[5] c_b[6] c_b[7] c_b[8] c_b[9] + elseif x < 8.0 # NUV + a = 1.752 - 0.316x - (0.104 / ((x - 4.67)^2 + 0.341)) + b = -3.090 + 1.825x + (1.206 / ((x - 4.62)^2 + 0.263)) + if x > 5.9 # Far NUV + y = x - 5.9 + a += @evalpoly y 0.0 0.0 -0.04473 -0.009779 + b += @evalpoly y 0.0 0.0 0.213 0.1207 + end + else # FUV + y = x - 8.0 + a = @evalpoly y -1.073 -0.628 0.137 -0.07 + b = @evalpoly y 13.67 4.257 -0.42 0.374 + end + return a + b / Rv +end diff --git a/src/color_laws/fitzpatrick.jl b/src/color_laws/fitzpatrick.jl new file mode 100644 index 0000000..c8265d6 --- /dev/null +++ b/src/color_laws/fitzpatrick.jl @@ -0,0 +1,289 @@ +# x value above which FM90 parametrization used +const f99_x_cutval_uv = aa_to_invum(2700) +# required UV points for spline interpolation +const f99_x_splineval_uv = aa_to_invum.((2700, 2600)) + +# Shape models used by F99 and F04 +function _curve_F99_method( + x, + Rv, + c1, c2, c3, c4, + x0, + gamma, + optnir_axav_x, optnir_axav_y, + ) + + # add in required spline points, otherwise just spline points + xuv = collect(f99_x_splineval_uv) + if x >= f99_x_cutval_uv + push!(xuv, x) + end + + # FM90 model and values + fm90_model = FM90(c1=c1, c2=c2, c3=c3, c4=c4, x0=x0, gamma=gamma) + # evaluate model and get results in A(x)/A(V) + axav_fm90 = @. fm90_model(aa_to_invum(xuv)) / Rv + 1 + + # ignore the spline points + if x >= f99_x_cutval_uv + axav = last(axav_fm90) + else + # **Optical Portion** + + # save spline points + y_splineval_uv = axav_fm90 + + # spline points + x_splineval_optir = (0.0, optnir_axav_x...) + + # determine optical/IR values at spline points + y_splineval_optir = (0.0, optnir_axav_y...) + spline_x = (x_splineval_optir..., f99_x_splineval_uv...) + spline_y = (y_splineval_optir..., y_splineval_uv...) + spl = Spline1D(collect(spline_x), collect(spline_y), k=3) + axav = spl(x) + end + + # return A(x)/A(V) + return axav +end + +# spline points +const f99_optnir_axav_x = aa_to_invum.((26500, 12200, 6000, 5470, 4670, 4110)) +const f99_nir_axebv_y_params = @. (0.265, 0.829) / 3.1 + +# c1-c2 correlation terms +const f99_c3 = 3.23 +const f99_c4 = 0.41 +const f99_x0 = 4.596 +const f99_gamma = 0.99 + +""" + F99(;Rv=3.1) + +Fitzpatrick (1999) dust law. + +Returns E(B-V) in magnitudes at the given wavelength relative to the +extinction. This model applies to the UV and optical to NIR spectral range. +The default support is [1000, 33333] Å. Outside of that range this will +return 0. Rv is the selective extinction and is valid over [2, 6]. +A typical value for the Milky Way is 3.1. + +# References +[Fitzpatrick (1999)](https://ui.adsabs.harvard.edu/abs/1999PASP..111...63F/) +""" +@with_kw struct F99 <: ExtinctionLaw + Rv::Float64 = 3.1 +end + +function (law::F99)(wave::T) where T + checkbounds(law, wave) || return zero(float(T)) + x = aa_to_invum(wave) + return f99_invum(x, law.Rv) +end + +bounds(::Type{F99}) = (1000.0, 33333.3) + +""" + DustExtinction.f99_invum(x, Rv) + +The algorithm used for the [`F99`](@ref) extinction law, given inverse microns +and Rv. For more information, seek the original paper. +""" +function f99_invum(x::Real, Rv::Real) + if !(0.3 <= x <= 10.0) + throw(DomainError(x, "out of bounds of F99, support is over $(bounds(F99)) angstrom")) + end + + # terms depending on Rv + c2 = @evalpoly (1. / Rv) -0.824 4.717 + # original F99 c1-c2 correlation + c1 = @evalpoly c2 2.030 -3.007 + + # determine optical/IR values at spline points + # Final optical spline point has a leading "-1.208" in Table 4 + # of F99, but that does not reproduce Table 3. + # Additional indication that this is not correct is from + # fm_unred.pro + # which is based on FMRCURVE.pro distributed by Fitzpatrick. + # --> confirmation needed? + # + # Also, fm_unred.pro has different coeff and # of terms, + # but later work does not include these terms + # --> check with Fitzpatrick? + opt_axebv_y = + (@evalpoly Rv -0.426 1.0044), + (@evalpoly Rv -0.050 1.0016), + (@evalpoly Rv 0.701 1.0016), + (@evalpoly Rv 1.208 1.0032 -0.00033) + + nir_axebv_y = @. f99_nir_axebv_y_params * Rv + optnir_axebv_y = @. (nir_axebv_y..., opt_axebv_y...) / Rv + + return _curve_F99_method( + x, + Rv, + c1, + c2, + f99_c3, + f99_c4, + f99_x0, + f99_gamma, + f99_optnir_axav_x, + optnir_axebv_y, + ) +end + +# spline points +const f04_opt_axav_x = aa_to_invum.((6000, 5470, 4670, 4110)) +const f04_nir_axav_x = (0.50, 0.75, 1.0) + +# **Use NIR spline x values in FM07, clipped to K band for now +const f04_optnir_axav_x = (f04_nir_axav_x..., f04_opt_axav_x...) + +# c1-c2 correlation terms +const f04_c3 = 2.991 +const f04_c4 = 0.319 +const f04_x0 = 4.592 +const f04_gamma = 0.922 + +""" + F04(;Rv=3.1) + +Fitzpatrick (2004) dust law. + +Returns E(B-V) in magnitudes at the given wavelength relative to the extinction. +This model applies to the UV and optical to NIR spectral range. +The default support is [1000, 33333] Å. Outside of that range this will return 0. +Rv is the selective extinction and is valid over [2, 6]. A typical value for +the Milky Way is 3.1. + +Equivalent to the F99 model with an updated NIR Rv dependence + +See also Fitzpatrick & Massa (2007, ApJ, 663, 320) + +# References +[Fitzpatrick (2004)](https://ui.adsabs.harvard.edu/abs/2004ASPC..309...33F/) +""" +@with_kw struct F04 <: ExtinctionLaw + Rv::Float64 = 3.1 +end + +function (law::F04)(wave::T) where T + checkbounds(law, wave) || return zero(float(T)) + x = aa_to_invum(wave) + return f04_invum(x, law.Rv) +end + +bounds(::Type{F04}) = (1000.0, 33333.3) + +""" + DustExtinction.f04_invum(x, Rv) + +The algorithm used for the [`F04`](@ref) extinction law, given inverse microns +and Rv. For more information, seek the original paper. +""" +function f04_invum(x::Real, Rv::Real) + if !(0.3 <= x <= 10.0) + throw(DomainError(x, "out of bounds of F04, support is over $(bounds(F04)) angstrom")) + end + + # original F99 Rv dependence + c2 = @evalpoly (1. / Rv) -0.824 4.717 + # updated F04 C1-C2 correlation + c1 = @evalpoly c2 2.18 -2.91 + + # **Keep optical spline points from F99: + # Final optical spline point has a leading "-1.208" in Table 4 + # of F99, but that does not reproduce Table 3. + # Additional indication that this is not correct is from + # fm_unred.pro + # which is based on FMRCURVE.pro distributed by Fitzpatrick. + # --> confirmation needed? + opt_axebv_y = + (@evalpoly Rv -0.426 1.0044), + (@evalpoly Rv -0.050 1.0016), + (@evalpoly Rv 0.701 1.0016), + (@evalpoly Rv 1.208 1.0032 -0.00033) + + # updated NIR curve from F04, note R dependence + # Julia v1.0 workaround: https://github.com/JuliaAstro/DustExtinction.jl/pull/31#commitcomment-40605778 + nir_axebv_y_coeff = (0.63 * Rv - 0.84) + nir_axebv_y = @. nir_axebv_y_coeff * f04_nir_axav_x^1.84 + + optnir_axebv_y = @. (nir_axebv_y..., opt_axebv_y...) / Rv + + return _curve_F99_method( + x, + Rv, + c1, + c2, + f04_c3, + f04_c4, + f04_x0, + f04_gamma, + f04_optnir_axav_x, + optnir_axebv_y, + ) +end + +""" + F19(;Rv=3.1) + +Fitzpatrick (2019) dust law. + +Returns E(B-V) in magnitudes at the given wavelength relative to the +extinction. This model applies to the UV and optical to NIR spectral range. +The default support is [1149, 33333] Å. Outside of that range this will +return 0. Rv is the selective extinction and is valid over [2, 6]. +A typical value for the Milky Way is 3.1. + +Fitzpatrick, Massa, Gordon et al. (2019, ApJ, 886, 108) model. Based on a +sample of stars observed spectroscopically in the optical with HST/STIS. + +# References +[Fitzpatrick (2019)](https://ui.adsabs.harvard.edu/abs/2019ApJ...886..108F/) +""" +@with_kw struct F19 <: ExtinctionLaw + Rv::Float64 = 3.1 +end + +function (law::F19)(wave::T) where T + checkbounds(law, wave) || return zero(float(T)) + x = aa_to_invum(wave) + return f19_invum(x, law.Rv) +end + +bounds(::Type{F19}) = (1149.4252873563219, 33333.333333333336) + +""" + DustExtinction.f19_invum(x, Rv) + +The algorithm used for the [`F19`](@ref) extinction law, given inverse microns +and Rv. For more information, seek the original paper. +""" +function f19_invum(x::Real, Rv::Real) + # read and unpack tabulated data + data_x, data_k, data_delta_k, data_sigma_k = let data = readdlm(joinpath(datadep"F19", "F19_tabulated.dat"), skipstart=1) + (data[:, i] for i in 1:4) + end + + if !(0.3 <= x <= 8.7) + throw(DomainError( + x, "out of bounds of F19, support is over $(bounds(F19)) angstrom")) + end + + # compute E(lambda-55)/E(B-55) on the tabulated x points + k_rV_tab_x = @. data_k + data_delta_k * (Rv - 3.10) * 0.990 + + # setup spline interpolation + spl = Spline1D(collect(data_x), collect(k_rV_tab_x), k=3) + + # use spline interpolation to evaluate the curve for the input x values + k_rV = spl(x) + + # convert to A(x)/A(55) from E(x-55)/E(44-55) + a_rV = k_rV / Rv + 1.0 + + return a_rV +end diff --git a/src/color_laws/gcc09.jl b/src/color_laws/gcc09.jl new file mode 100644 index 0000000..abb1f62 --- /dev/null +++ b/src/color_laws/gcc09.jl @@ -0,0 +1,44 @@ +""" + GCC09(;Rv=3.1) + +Gordon, Cartledge, & Clayton (2009) dust law. + +This model applies to the UV spectral region all the way to 909.09 Å. +This model was not derived for the optical or NIR. + +# References +[Gordon, Cartledge, & Clayton (2009)](https://ui.adsabs.harvard.edu/abs/2009ApJ...705.1320G/) +""" +@with_kw struct GCC09 <: ExtinctionLaw + Rv::Float64 = 3.1 +end + +function (law::GCC09)(wave::T) where T + checkbounds(law, wave) || return zero(float(T)) + x = aa_to_invum(wave) + return gcc09_invum(x, law.Rv) +end + +bounds(::Type{GCC09}) = (909.0909090909091, 3030.3030303030305) + +""" + DustExtinction.gcc09_invum(x, Rv) + +The algorithm used for the [`GCC09`](@ref) extinction law, given inverse microns +and Rv. For more information, seek the original paper. +""" +function gcc09_invum(x::Real, Rv::Real) + if x < 3.3 || x > 11.0 # out of bounds + throw(DomainError(x, "out of bounds of GCC09, support is over $(bounds(GCC09)) angstrom")) + end + # NUV + a = 1.894 - 0.373 * x - 0.0101 / ((x - 4.57)^2 + 0.0384) + b = -3.490 + 2.057 * x + 0.706 / ((x - 4.59)^2 + 0.169) + if 5.9 ≤ x ≤ 11.0 # far-NUV + y = x - 5.9 + a += @evalpoly y 0.0 0.0 -0.110 -0.0100 + b += @evalpoly y 0.0 0.0 0.531 0.0544 + end + + return a + b / Rv +end diff --git a/src/color_laws/m14.jl b/src/color_laws/m14.jl new file mode 100644 index 0000000..a523e16 --- /dev/null +++ b/src/color_laws/m14.jl @@ -0,0 +1,105 @@ +# Optical +const m14_x1 = (1.0) +const m14_xi1 = first(m14_x1) +const m14_x2 = (1.15, 1.81984, 2.1, 2.27015, 2.7) +const m14_x3 = (3.5, 3.9, 4.0, 4.1, 4.2) +const m14_xi3 = last(m14_x3) +const m14_a1v = 0.574 * m14_x1^1.61 +const m14_b1v = -0.527 * m14_x1^1.61 +const m14_x2_diff = m14_x2 .- 1.82 +const m14_a2v = @. ( + 1 + + 0.17699 * (m14_x2_diff) + - 0.50447 * (m14_x2_diff)^2 + - 0.02427 * (m14_x2_diff)^3 + + 0.72085 * (m14_x2_diff)^4 + + 0.01979 * (m14_x2_diff)^5 + - 0.77530 * (m14_x2_diff)^6 + + 0.32999 * (m14_x2_diff)^7 + + (0.0, 0.0, -0.011, 0.0, 0.0) +) +const m14_b2v = @. ( + 1.41338 * (m14_x2 - 1.82) + + 2.28305 * (m14_x2 - 1.82)^2 + + 1.07233 * (m14_x2 - 1.82)^3 + - 5.38434 * (m14_x2 - 1.82)^4 + - 0.62251 * (m14_x2 - 1.82)^5 + + 5.30260 * (m14_x2 - 1.82)^6 + - 2.09002 * (m14_x2 - 1.82)^7 + + (0.0, 0.0, 0.091, 0.0, 0.0) +) +const m14_a3v = @. ( + 1.752 + - 0.316 * m14_x3 + - 0.104 / ((m14_x3 - 4.67)^2 + 0.341) + + (0.442, 0.341, 0.130, 0.020, 0.000) +) +const m14_b3v = @. ( + -3.090 + + 1.825 * m14_x3 + + 1.206 / ((m14_x3 - 4.62)^2 + 0.263) + - (1.256, 1.021, 0.416, 0.064, 0.000) +) +const m14_xn = collect((m14_x1..., m14_x2..., m14_x3...)) +const m14_anv = collect((m14_a1v..., m14_a2v..., m14_a3v...)) +const m14_bnv = collect((m14_b1v..., m14_b2v..., m14_b3v...)) +const m14_a_spl = Spline1D(m14_xn, m14_anv, bc="nearest") +const m14_b_spl = Spline1D(m14_xn, m14_bnv, bc="nearest") + +""" + M14(;Rv=3.1) + +Maiz Apellaniz et al (2014) Milky Way & LMC R(V) dependent model. + +Returns E(B-V) in magnitudes at the given wavelength relative to the +extinction. The published UV extinction curve is identical to Clayton, +Cardelli, and Mathis (1989, CCM). Forcing the optical section to match smoothly +with CCM introduces a non-physical feature at high values of R5495 around 3.9 +inverse microns; see section 5 in Maiz Apellaniz et al. (2014) for more +discussion. For that reason, we provide the M14 model only through 3.3 inverse +microns, the limit of the optical in CCM. Outside of that range this will +return 0. Rv is the selective extinction and is valid over [2, 6]. A typical +value for the Milky Way is 3.1. R5495 = A(5485)/E(4405-5495) Spectral +equivalent to photometric R(V). + +# References +[Maiz Apellaniz et al. (2014)](https://ui.adsabs.harvard.edu/abs/2014A%26A...564A..63M/) +""" +@with_kw struct M14 <: ExtinctionLaw + Rv::Float64 = 3.1 +end + +function (law::M14)(wave::T) where T + checkbounds(law, wave) || return zero(float(T)) + x = aa_to_invum(wave) + return m14_invum(x, law.Rv) +end + +bounds(::Type{M14}) = (3030.3030303030305, 33333.333333333336) + +""" + DustExtinction.m14_invum(x, Rv) + +The algorithm used for the [`M14`](@ref) extinction law, given inverse microns +and Rv. For more information, seek the original paper. +""" +function m14_invum(x::Real, Rv::Real) + if !(0.3 <= x <= 3.3) + throw(DomainError( + x, "out of bounds of M14, support is over $(bounds(M14)) angstrom")) + end + + a = zero(x) + b = zero(x) + if x < m14_xi1 + # Infrared + a = 0.574 * x^1.61 + b = -0.527 * x^1.61 + elseif x < m14_xi3 + # Optical + a = m14_a_spl(x) + b = m14_b_spl(x) + end + + return a + b / Rv +end diff --git a/src/color_laws/vcg04.jl b/src/color_laws/vcg04.jl new file mode 100644 index 0000000..073f7d4 --- /dev/null +++ b/src/color_laws/vcg04.jl @@ -0,0 +1,45 @@ +""" + VCG04(;Rv=3.1) + +Valencic, Clayton, & Gordon (2004) dust law. + +This model applies to the UV spectral region all the way to 912 Å. +This model was not derived for the optical or NIR. + +# References +[Valencic, Clayton, & Gordon (2004)](https://ui.adsabs.harvard.edu/abs/2004ApJ...616..912V/) +""" +@with_kw struct VCG04 <: ExtinctionLaw + Rv::Float64 = 3.1 +end + +function (law::VCG04)(wave::T) where T + checkbounds(law, wave) || return zero(float(T)) + x = aa_to_invum(wave) + return vcg04_invum(x, law.Rv) +end + +bounds(::Type{VCG04}) = (1250, 3030.3) + +""" + DustExtinction.vcg04_invum(x, Rv) + +The algorithm used for the [`VCG04`](@ref) extinction law, given inverse microns +and Rv. For more information, seek the original paper. +""" +function vcg04_invum(x::Real, Rv::Real) + if x < 3.3 || x > 8.0 + throw(DomainError(x, "out of bounds of VCG04, support is over $(bounds(VCG04)) angstrom")) + end + + # NUV + a = 1.808 - 0.215 * x - 0.134 / ((x - 4.558)^2 + 0.566) + b = -2.350 + 1.403 * x + 1.103 / ((x - 4.587)^2 + 0.263) + if 5.9 ≤ x ≤ 8.0 # far-NUV + y = x - 5.9 + a += @evalpoly y 0.0 0.0 -0.0077 -0.0030 + b += @evalpoly y 0.0 0.0 0.2060 0.0550 + end + + return a + b / Rv +end From d152b4294783c1bba5f90b2b916a6c228f819558 Mon Sep 17 00:00:00 2001 From: abhro <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 12:00:54 -0400 Subject: [PATCH 24/34] Update GitHub/Julia actions versions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apply suggestions from code review Co-authored-by: Mosè Giordano --- .github/workflows/ci.yml | 6 +++--- .github/workflows/docs.yml | 11 +++-------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0db138c..cf2b544 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: - x64 steps: - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v1 + - uses: julia-actions/setup-julia@v2 with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} @@ -51,10 +51,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v1 + - uses: julia-actions/setup-julia@v2 with: version: '1' - - uses: julia-actions/cache@v1 + - uses: julia-actions/cache@v2 - uses: julia-actions/julia-buildpkg@v1 - run: julia -e 'using Pkg; Pkg.add("Aqua")' - run: julia --project=@. -e 'using Aqua, DustExtinction; Aqua.test_all(DustExtinction, ambiguities=false)' diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 58a207d..16ab030 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -14,16 +14,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v1 + - uses: julia-actions/setup-julia@v2 with: version: '1' - - uses: julia-actions/cache@v1 - - run: | - julia --project=docs -e ' - using Pkg - Pkg.develop(PackageSpec(path=pwd())) - Pkg.instantiate()' - - run: julia --project=docs docs/make.jl + - uses: julia-actions/cache@v2 + - uses: julia-actions/julia-docdeploy@v1 env: GKSwstype: nul DATADEPS_ALWAYS_ACCEPT: true From 2acbee3d9c05fd14faeb308f93afc38850db7412 Mon Sep 17 00:00:00 2001 From: abhro <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 12:58:03 -0400 Subject: [PATCH 25/34] Add coloring to aqua workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mosè Giordano --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf2b544..5fec738 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,5 +56,5 @@ jobs: version: '1' - uses: julia-actions/cache@v2 - uses: julia-actions/julia-buildpkg@v1 - - run: julia -e 'using Pkg; Pkg.add("Aqua")' - - run: julia --project=@. -e 'using Aqua, DustExtinction; Aqua.test_all(DustExtinction, ambiguities=false)' + - run: julia --color=yes -e 'using Pkg; Pkg.add("Aqua")' + - run: julia --color=yes --project=@. -e 'using Aqua, DustExtinction; Aqua.test_all(DustExtinction, ambiguities=false)' From 96132f68f93ece5a5bf426fc11f956f1c6466cbb Mon Sep 17 00:00:00 2001 From: abhro <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 12:58:45 -0400 Subject: [PATCH 26/34] Update codecov action version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mosè Giordano --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5fec738..147dba9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,9 +42,10 @@ jobs: env: DATADEPS_ALWAYS_ACCEPT: true - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v1 + - uses: codecov/codecov-action@v4 with: file: lcov.info + token: ${{ secrets.CODECOV_TOKEN }} aqua: name: Aqua tests From f6a53b07e8afc7e924f8437282d2166867c07bd5 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:48:17 -0400 Subject: [PATCH 27/34] Encapsulate all tests into larger testset Cleaner output for all passing tests --- test/runtests.jl | 144 ++++++++++++++++++++++++----------------------- 1 file changed, 73 insertions(+), 71 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index f47655a..3557455 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,85 +2,87 @@ using DustExtinction using DustExtinction: bounds, checkbounds using Test, Measurements, Unitful, UnitfulAstro, Random -Random.seed!(9994445781) +@testset "DustExtinction" begin + Random.seed!(9994445781) -include("deprecate.jl") -include("color_laws.jl") -include("dust_maps.jl") -include("fittable_laws.jl") -include("mixture_laws.jl") + include("deprecate.jl") + include("color_laws.jl") + include("dust_maps.jl") + include("fittable_laws.jl") + include("mixture_laws.jl") -@testset "interfaces" begin - for LAW in [CCM89, OD94, CAL00, GCC09, VCG04, FM90, G16, F99, F04, F19, M14] - @test bounds(LAW) == bounds(LAW()) - @test checkbounds(LAW, 1000) == checkbounds(LAW(), 1000) - low, high = bounds(LAW) - @test all(checkbounds.(LAW, rand(low:high, 1000))) - @test all(isfinite.(LAW().(bounds(LAW)))) + @testset "interfaces" begin + for LAW in [CCM89, OD94, CAL00, GCC09, VCG04, FM90, G16, F99, F04, F19, M14] + @test bounds(LAW) == bounds(LAW()) + @test checkbounds(LAW, 1000) == checkbounds(LAW(), 1000) + low, high = bounds(LAW) + @test all(checkbounds.(LAW, rand(low:high, 1000))) + @test all(isfinite.(LAW().(bounds(LAW)))) + end + @test bounds(DustExtinction.ExtinctionLaw) == (0, Inf) end - @test bounds(DustExtinction.ExtinctionLaw) == (0, Inf) -end -@testset "redden/deredden" begin - wave = [3372., 4404., 5428., 6509., 8090., - 3683., 4393., 5519., 6602., 8046., - 12660., 16732., 22152., - 5244., 6707., 7985., 9055., - 6993., - 3502., 4676., 4127., - 4861., 5479., - 3546., 4925., 6335., 7799., 9294., - 3047., 4711., 5498., - 6042., 7068., 8066., - 4814., 6571., 8183.] + @testset "redden/deredden" begin + wave = [3372., 4404., 5428., 6509., 8090., + 3683., 4393., 5519., 6602., 8046., + 12660., 16732., 22152., + 5244., 6707., 7985., 9055., + 6993., + 3502., 4676., 4127., + 4861., 5479., + 3546., 4925., 6335., 7799., 9294., + 3047., 4711., 5498., + 6042., 7068., 8066., + 4814., 6571., 8183.] - # Av=0.3, Rv=3.1, law=ccm89 - ref_values = [ - 0.6376288197244566, 0.6937993158943373, 0.7556003129054399, - 0.7959216081971665, 0.8508142213648981, 0.6517368195297566, - 0.6930246485833793, 0.7596467718783736, 0.7990835963390542, - 0.8493553321733043, 0.9264835715958143, 0.9524307890106202, - 0.9694546832913796, 0.7467375901587614, 0.8026674093639407, - 0.847310247751628, 0.8771971841412943, 0.8125473475954554, - 0.6442645437827309, 0.7127773090414787, 0.6749407318003154, - 0.7249166081334651, 0.7578933014813821, 0.6461535564599767, - 0.7288900774623704, 0.7900092679188825, 0.8409405763429691, - 0.881972061390043, 0.6091986958411011, 0.7151404275193919, - 0.7587309863781261, 0.7798780926274524, 0.8151697825084553, - 0.8500202342098636, 0.7219200730427752, 0.7980286586611023, - 0.8538476253948861 - ] + # Av=0.3, Rv=3.1, law=ccm89 + ref_values = [ + 0.6376288197244566, 0.6937993158943373, 0.7556003129054399, + 0.7959216081971665, 0.8508142213648981, 0.6517368195297566, + 0.6930246485833793, 0.7596467718783736, 0.7990835963390542, + 0.8493553321733043, 0.9264835715958143, 0.9524307890106202, + 0.9694546832913796, 0.7467375901587614, 0.8026674093639407, + 0.847310247751628, 0.8771971841412943, 0.8125473475954554, + 0.6442645437827309, 0.7127773090414787, 0.6749407318003154, + 0.7249166081334651, 0.7578933014813821, 0.6461535564599767, + 0.7288900774623704, 0.7900092679188825, 0.8409405763429691, + 0.881972061390043, 0.6091986958411011, 0.7151404275193919, + 0.7587309863781261, 0.7798780926274524, 0.8151697825084553, + 0.8500202342098636, 0.7219200730427752, 0.7980286586611023, + 0.8538476253948861 + ] - flux = ones(length(wave)) - output = @inferred broadcast((l, w, f)->redden(l, w, f; Av = 0.3), CCM89, wave, flux) - @test output ≈ ref_values - @test @inferred(broadcast((l, w, f)->deredden(l, w, f; Av = 0.3), CCM89, wave, output)) ≈ flux - flux .= redden.(CCM89, wave, flux, Av = 0.3) - @test flux ≈ ref_values + flux = ones(length(wave)) + output = @inferred broadcast((l, w, f)->redden(l, w, f; Av = 0.3), CCM89, wave, flux) + @test output ≈ ref_values + @test @inferred(broadcast((l, w, f)->deredden(l, w, f; Av = 0.3), CCM89, wave, output)) ≈ flux + flux .= redden.(CCM89, wave, flux, Av = 0.3) + @test flux ≈ ref_values - # interfaces - @test redden(CCM89, wave[1], flux[1]) == redden(CCM89(), wave[1], flux[1]) - @test redden(CCM89, wave[1], flux[1], Rv = 2.8) == redden(CCM89(Rv = 2.8), wave[1], flux[1]) - @test redden.(CCM89, wave, flux) == redden.(CCM89(), wave, flux) - @test redden.(CCM89, wave, flux, Rv = 2.8) == redden.(CCM89(Rv = 2.8), wave, flux) + # interfaces + @test redden(CCM89, wave[1], flux[1]) == redden(CCM89(), wave[1], flux[1]) + @test redden(CCM89, wave[1], flux[1], Rv = 2.8) == redden(CCM89(Rv = 2.8), wave[1], flux[1]) + @test redden.(CCM89, wave, flux) == redden.(CCM89(), wave, flux) + @test redden.(CCM89, wave, flux, Rv = 2.8) == redden.(CCM89(Rv = 2.8), wave, flux) - # Measurements - flux = ones(length(wave)) .± 0.1 - output = @inferred broadcast((l, w, f)->redden(l, w, f; Av = 0.3), CCM89, wave, flux) - @test Measurements.value.(output) ≈ ref_values - @test @inferred(broadcast((l, w, f)->deredden(l, w, f; Av = 0.3), CCM89, wave, output)) ≈ flux - flux .= redden.(CCM89, wave, flux, Av = 0.3) - @test flux ≈ ref_values + # Measurements + flux = ones(length(wave)) .± 0.1 + output = @inferred broadcast((l, w, f)->redden(l, w, f; Av = 0.3), CCM89, wave, flux) + @test Measurements.value.(output) ≈ ref_values + @test @inferred(broadcast((l, w, f)->deredden(l, w, f; Av = 0.3), CCM89, wave, output)) ≈ flux + flux .= redden.(CCM89, wave, flux, Av = 0.3) + @test flux ≈ ref_values - # Unitful - flux = ones(length(wave))u"Jy" - wave = wave * u"angstrom" - output = @inferred broadcast((l, w, f)->redden(l, w, f; Av = 0.3), CCM89, wave, flux) - @test redden.(CCM89, wave, ustrip.(u"Jy", flux), Av = 0.3) ≈ ustrip.(u"Jy", output) - @test ustrip.(output) ≈ ref_values - @test @inferred(broadcast((l, w, f)->deredden(l, w, f; Av = 0.3), CCM89, wave, output)) ≈ flux - @test deredden.(CCM89, wave, ustrip.(u"Jy", output), Av = 0.3) ≈ ustrip.(u"Jy", flux) - flux .= redden.(CCM89, wave, flux, Av = 0.3) - @test flux ≈ output + # Unitful + flux = ones(length(wave))u"Jy" + wave = wave * u"angstrom" + output = @inferred broadcast((l, w, f)->redden(l, w, f; Av = 0.3), CCM89, wave, flux) + @test redden.(CCM89, wave, ustrip.(u"Jy", flux), Av = 0.3) ≈ ustrip.(u"Jy", output) + @test ustrip.(output) ≈ ref_values + @test @inferred(broadcast((l, w, f)->deredden(l, w, f; Av = 0.3), CCM89, wave, output)) ≈ flux + @test deredden.(CCM89, wave, ustrip.(u"Jy", output), Av = 0.3) ≈ ustrip.(u"Jy", flux) + flux .= redden.(CCM89, wave, flux, Av = 0.3) + @test flux ≈ output + end end From 07ae89a46d22572487e4b1b77dfa5a21b24fc72f Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:02:02 -0400 Subject: [PATCH 28/34] Add dependabot --- .github/dependabot.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..134d3f5 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" + open-pull-requests-limit: 99 + labels: + - "dependencies" + - "github-actions" From c2c348f7b74b01294acfe15ca0dada20df595ba4 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:10:09 -0400 Subject: [PATCH 29/34] Allow manual triggering of CompatHelper --- .github/workflows/CompatHelper.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml index 7758ba1..de63b85 100644 --- a/.github/workflows/CompatHelper.yml +++ b/.github/workflows/CompatHelper.yml @@ -3,6 +3,7 @@ name: CompatHelper on: schedule: - cron: '05 20 * * *' + workflow_dispatch: jobs: CompatHelper: From c6699d57e33aacc3c9cff63f0f3a770bb123db53 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:13:18 -0400 Subject: [PATCH 30/34] Give CompatHelper pull request permissions --- .github/workflows/CompatHelper.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml index de63b85..001220a 100644 --- a/.github/workflows/CompatHelper.yml +++ b/.github/workflows/CompatHelper.yml @@ -5,6 +5,10 @@ on: - cron: '05 20 * * *' workflow_dispatch: +permissions: + contents: write + pull-requests: write + jobs: CompatHelper: runs-on: ubuntu-latest From 0e39b0175d65cd856ce19f1d7a92a2b15bcaec99 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:14:54 -0400 Subject: [PATCH 31/34] Rename CompatHelper job steps --- .github/workflows/CompatHelper.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml index 001220a..89fb99d 100644 --- a/.github/workflows/CompatHelper.yml +++ b/.github/workflows/CompatHelper.yml @@ -13,9 +13,9 @@ jobs: CompatHelper: runs-on: ubuntu-latest steps: - - name: Pkg.add("CompatHelper") + - name: "Install CompatHelper" run: julia -e 'using Pkg; Pkg.add("CompatHelper")' - - name: CompatHelper.main() + - name: "Run CompatHelper" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: julia -e 'using CompatHelper; CompatHelper.main()' From d7f5da660c2f0bf3048eca4673a7b615dbf948f8 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:15:25 -0400 Subject: [PATCH 32/34] Reformat CompatHelper runner --- .github/workflows/CompatHelper.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml index 89fb99d..e67e93d 100644 --- a/.github/workflows/CompatHelper.yml +++ b/.github/workflows/CompatHelper.yml @@ -18,4 +18,6 @@ jobs: - name: "Run CompatHelper" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: julia -e 'using CompatHelper; CompatHelper.main()' + COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }} + shell: julia --color=yes {0} + run: using CompatHelper; CompatHelper.main() From 0a12509b02b074ec854c6b7225e78b1d27a1e6ad Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:20:48 -0400 Subject: [PATCH 33/34] Add compat entry for DelimitedFiles --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index a72250c..0dd3136 100644 --- a/Project.toml +++ b/Project.toml @@ -14,6 +14,7 @@ UnitfulAstro = "6112ee07-acf9-5e0f-b108-d242c714bf9f" [compat] DataDeps = "0.7" +DelimitedFiles = "1" Dierckx = "0.4, 0.5" FITSIO = "0.13.0, 0.14, 0.15, 0.16.1, 0.17" Parameters = "0.12" From 8935f9ae83c437492c4797371864140d2f6a40a4 Mon Sep 17 00:00:00 2001 From: Abhro R <5664668+abhro@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:29:33 -0400 Subject: [PATCH 34/34] Use separate Project.toml for tests --- Project.toml | 8 -------- test/Project.toml | 12 ++++++++++++ 2 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 test/Project.toml diff --git a/Project.toml b/Project.toml index 0dd3136..9b0f220 100644 --- a/Project.toml +++ b/Project.toml @@ -21,11 +21,3 @@ Parameters = "0.12" Unitful = "0.17.0, 1" UnitfulAstro = "0.3.0, 0.4, 1" julia = "1.6" - -[extras] -Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[targets] -test = ["Measurements", "Random", "Test"] diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 0000000..0bd039d --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,12 @@ +[deps] +DataDeps = "124859b0-ceae-595e-8997-d05f6a7a8dfe" +Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" +UnitfulAstro = "6112ee07-acf9-5e0f-b108-d242c714bf9f" + +[compat] +DataDeps = "0.7" +Unitful = "0.17.0, 1" +UnitfulAstro = "0.3.0, 0.4, 1"