diff --git a/Project.toml b/Project.toml index 61ad85e..eb41c5d 100644 --- a/Project.toml +++ b/Project.toml @@ -7,7 +7,6 @@ version = "0.11.2" BSplineKit = "093aae92-e908-43d7-9660-e50ee39d5a0a" DataDeps = "124859b0-ceae-595e-8997-d05f6a7a8dfe" FITSIO = "525bcba6-941b-5504-bd06-fd0dc1a4d2eb" -Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" UnitfulAstro = "6112ee07-acf9-5e0f-b108-d242c714bf9f" @@ -15,7 +14,6 @@ UnitfulAstro = "6112ee07-acf9-5e0f-b108-d242c714bf9f" BSplineKit = "0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19" DataDeps = "0.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.6" diff --git a/src/DustExtinction.jl b/src/DustExtinction.jl index 1f2d116..01702c2 100644 --- a/src/DustExtinction.jl +++ b/src/DustExtinction.jl @@ -3,7 +3,6 @@ module DustExtinction import Unitful as U using UnitfulAstro: UnitfulAstro import DataDeps -import Parameters import FITSIO as FITS import BSplineKit as BSK @@ -40,8 +39,7 @@ The abstract supertype for dust extinction laws. See the 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 +* Create your struct. We strongly recommend using keyword arguments if your model is parameterized, which allows convenient usage with [`redden`](@ref) and [`deredden`](@ref). ```julia struct MyLaw <: DustExtinction.ExtinctionLaw end diff --git a/src/color_laws.jl b/src/color_laws.jl index d7fcc83..e747583 100644 --- a/src/color_laws.jl +++ b/src/color_laws.jl @@ -18,7 +18,7 @@ for different coefficients used in the optical (3030.3 Å to 9090.9 Å). # See Also [`CCM89`](@ref) """ -Parameters.@with_kw struct OD94 <: ExtinctionLaw +Base.@kwdef struct OD94 <: ExtinctionLaw Rv::Float64 = 3.1 end @@ -47,7 +47,7 @@ fit value for such galaxies was 4.05±0.80. # References [Calzetti et al. (2000)](https://ui.adsabs.harvard.edu/abs/2000ApJ...533..682C) """ -Parameters.@with_kw struct CAL00 <: ExtinctionLaw +Base.@kwdef struct CAL00 <: ExtinctionLaw Rv::Float64 = 4.05 end function (law::CAL00)(wave::T) where T diff --git a/src/color_laws/ccm89.jl b/src/color_laws/ccm89.jl index 0261d24..f8d67bb 100644 --- a/src/color_laws/ccm89.jl +++ b/src/color_laws/ccm89.jl @@ -18,7 +18,7 @@ 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) """ -Parameters.@with_kw struct CCM89 <: ExtinctionLaw +Base.@kwdef struct CCM89 <: ExtinctionLaw Rv::Float64 = 3.1 end diff --git a/src/color_laws/fitzpatrick.jl b/src/color_laws/fitzpatrick.jl index 9ec9a72..2354adb 100644 --- a/src/color_laws/fitzpatrick.jl +++ b/src/color_laws/fitzpatrick.jl @@ -72,7 +72,7 @@ A typical value for the Milky Way is 3.1. # References [Fitzpatrick (1999)](https://ui.adsabs.harvard.edu/abs/1999PASP..111...63F/) """ -Parameters.@with_kw struct F99 <: ExtinctionLaw +Base.@kwdef struct F99 <: ExtinctionLaw Rv::Float64 = 3.1 end @@ -165,7 +165,7 @@ See also Fitzpatrick & Massa (2007, ApJ, 663, 320) # References [Fitzpatrick (2004)](https://ui.adsabs.harvard.edu/abs/2004ASPC..309...33F/) """ -Parameters.@with_kw struct F04 <: ExtinctionLaw +Base.@kwdef struct F04 <: ExtinctionLaw Rv::Float64 = 3.1 end @@ -242,7 +242,7 @@ sample of stars observed spectroscopically in the optical with HST/STIS. # References [Fitzpatrick (2019)](https://ui.adsabs.harvard.edu/abs/2019ApJ...886..108F/) """ -Parameters.@with_kw struct F19 <: ExtinctionLaw +Base.@kwdef struct F19 <: ExtinctionLaw Rv::Float64 = 3.1 end diff --git a/src/color_laws/gcc09.jl b/src/color_laws/gcc09.jl index 2a3bddf..f0677ec 100644 --- a/src/color_laws/gcc09.jl +++ b/src/color_laws/gcc09.jl @@ -9,7 +9,7 @@ This model was not derived for the optical or NIR. # References [Gordon, Cartledge, & Clayton (2009)](https://ui.adsabs.harvard.edu/abs/2009ApJ...705.1320G/) """ -Parameters.@with_kw struct GCC09 <: ExtinctionLaw +Base.@kwdef struct GCC09 <: ExtinctionLaw Rv::Float64 = 3.1 end diff --git a/src/color_laws/m14.jl b/src/color_laws/m14.jl index 019e474..b2e16be 100644 --- a/src/color_laws/m14.jl +++ b/src/color_laws/m14.jl @@ -65,7 +65,7 @@ equivalent to photometric R(V). # References [Maiz Apellaniz et al. (2014)](https://ui.adsabs.harvard.edu/abs/2014A%26A...564A..63M/) """ -Parameters.@with_kw struct M14 <: ExtinctionLaw +Base.@kwdef struct M14 <: ExtinctionLaw Rv::Float64 = 3.1 end diff --git a/src/color_laws/vcg04.jl b/src/color_laws/vcg04.jl index 55fc99f..c0f35c6 100644 --- a/src/color_laws/vcg04.jl +++ b/src/color_laws/vcg04.jl @@ -9,7 +9,7 @@ This model was not derived for the optical or NIR. # References [Valencic, Clayton, & Gordon (2004)](https://ui.adsabs.harvard.edu/abs/2004ApJ...616..912V/) """ -Parameters.@with_kw struct VCG04 <: ExtinctionLaw +Base.@kwdef struct VCG04 <: ExtinctionLaw Rv::Float64 = 3.1 end diff --git a/src/fittable_laws.jl b/src/fittable_laws.jl index 61b8f5b..e9e05d5 100644 --- a/src/fittable_laws.jl +++ b/src/fittable_laws.jl @@ -46,18 +46,20 @@ changing the expected behavior of reddening via the parameter ``A_V``. ## References [Fitzpatrick & Massa (1990)](https://ui.adsabs.harvard.edu/abs/1990ApJS...72..163F) """ -Parameters.@with_kw struct FM90{T<:Number} <: ExtinctionLaw @deftype T - c1 = 0.10 - c2 = 0.70 - c3 = 3.23 - c4 = 0.41 - x0 = 4.60 - gamma = 0.99 - @assert x0 ≥ 0 "`x0` must be ≥ 0, got $x0" - @assert gamma ≥ 0 "`gamma` must be ≥ 0, got $gamma" +Base.@kwdef struct FM90{T<:Number} <: ExtinctionLaw + c1::T = 0.10 + c2::T = 0.70 + c3::T = 3.23 + c4::T = 0.41 + x0::T = 4.60 + gamma::T = 0.99 + function FM90(c1, c2, c3, c4, x0, gamma) + x0 < 0 && error("`x0` must be ≥ 0, got ", x0) + gamma < 0 && error("`gamma` must be ≥ 0, got ", gamma) + params = promote(c1, c2, c3, c4, x0, gamma) + return new{eltype(params)}(params...) + end end - -FM90(c1, c2, c3, c4, x0, gamma) = FM90(promote(c1, c2, c3, c4, x0, gamma)...) FM90(coeffs, x0=4.60, gamma=0.99) = FM90(coeffs..., x0, gamma) bounds(::Type{<:FM90}) = (912, 3200) diff --git a/src/mixture_laws.jl b/src/mixture_laws.jl index ec56d56..2d6f3d2 100644 --- a/src/mixture_laws.jl +++ b/src/mixture_laws.jl @@ -67,7 +67,7 @@ provide smooth interpolation as noted in Gordon et al. (2016, ApJ, 826, 104) # Reference [Gordon et al. (2003)](https://ui.adsabs.harvard.edu/abs/2003ApJ...594..279G/) """ -Parameters.@with_kw struct G03_SMCBar <: ExtinctionLaw +Base.@kwdef struct G03_SMCBar <: DustExtinction.ExtinctionLaw Rv::Float64 = 2.74 obsdata_x = g03_obsdata_x obsdata_axav = g03_obsdata_axav @@ -82,7 +82,7 @@ Gordon et al. (2003) LMCAve Average Extinction Curve. # Reference [Gordon et al. (2003)](https://ui.adsabs.harvard.edu/abs/2003ApJ...594..279G/) """ -Parameters.@with_kw struct G03_LMCAve <: ExtinctionLaw +Base.@kwdef struct G03_LMCAve <: DustExtinction.ExtinctionLaw Rv::Float64 = 3.41 obsdata_x = g03lmc_obsdata_x obsdata_axav = g03lmc_obsdata_axav @@ -170,9 +170,9 @@ A typical value for the Milky Way is 3.1. # References [Gordon et al. (2016)](https://ui.adsabs.harvard.edu/abs/2016ApJ...826..104G/) """ -Parameters.@with_kw struct G16{T<:Number} <: ExtinctionLaw @deftype T +Base.@kwdef struct G16{T<:Number} <: ExtinctionLaw Rv::Float64 = 3.1 - f_A = 1.0 + f_A::T = 1.0 end #G16(Rv, f_A) = G16(promote(Rv, f_A)...) diff --git a/test/fittable_laws.jl b/test/fittable_laws.jl index f3e6117..843b6f8 100644 --- a/test/fittable_laws.jl +++ b/test/fittable_laws.jl @@ -3,8 +3,11 @@ x_inv_microns = [3.5, 4.0, 4.5, 5.0, 6.0, 7.0, 9.0, 10.0] wave = 1e4 ./ x_inv_microns + # Construction model = FM90() model1 = FM90([0.10 0.70 3.23 0.41]) + @test_throws ErrorException("`x0` must be ≥ 0, got -2.0") FM90(x0=-2.0) + @test_throws ErrorException("`gamma` must be ≥ 0, got -2.0") FM90(gamma=-2.0) # Test out of bounds bad_waves = [100, 4e4]