Loading src/Recipe_multi.jl +11 −70 Original line number Diff line number Diff line Loading @@ -37,7 +37,9 @@ function multi_fit(source::QSO{TRecipe}; ref_id=1) where TRecipe <: q1927p654 model[:galaxy].norm.val = Spline1D(λ, source.data[id].val, k=1, bc="error")(5500.) if id != ref_id model[:galaxy].norm.fixed = true @patch! multi m -> m[id][:galaxy].norm = m[ref_id][:galaxy].norm @patch! multi m -> begin m[id][:galaxy].norm = m[ref_id][:galaxy].norm end end end Loading Loading @@ -73,7 +75,7 @@ function multi_fit(source::QSO{TRecipe}; ref_id=1) where TRecipe <: q1927p654 (count(residuals .< 0) / length(residuals) > 0.9) && break (c.norm.val < initialnorm / 5) && break # give up c.norm.val *= 0.99 evaluate!(multi) evaluate!(model) end println(source.log, "$id : Cont. norm. (after) : ", c.norm.val) else Loading Loading @@ -129,7 +131,7 @@ function multi_fit(source::QSO{TRecipe}; ref_id=1) where TRecipe <: q1927p654 if length(iron_components) > 0 model[:Iron] = SumReducer(iron_components) model[:main] = SumReducer([:Continuum, :Iron]) evaluate!(multi) evaluate!(model) bestfit = fit!(model, source.data[id], minimizer=mzer); show(source.log, bestfit) else model[:Iron] = @expr m -> [0.] Loading Loading @@ -199,34 +201,11 @@ function multi_fit(source::QSO{TRecipe}; ref_id=1) where TRecipe <: q1927p654 # Patch parameters if haskey(model, :OIII_4959) && haskey(model, :OIII_5007) model[:OIII_4959].norm.fixed = true model[:OIII_4959].voff.fixed = true @patch! model m -> begin m[:OIII_4959].norm = m[:OIII_5007].norm / 3 m[:OIII_4959].voff = m[:OIII_5007].voff end end if haskey(model, :NII_6549) && haskey(model, :NII_6583) model[:NII_6549].voff.fixed = true @patch! model m -> m[:NII_6549].voff = m[:NII_6583].voff end if haskey(model, :OIII_5007_bw) && haskey(model, :OIII_5007) @patch! model m -> begin m[:OIII_5007_bw].voff += m[:OIII_5007].voff m[:OIII_5007_bw].fwhm += m[:OIII_5007].fwhm end end if haskey(model, :OI_6300) && haskey(model, :OI_6364) # model[:OI_6300].norm.fixed = true model[:OI_6300].voff.fixed = true @patch! model m -> begin # m[:OI_6300].norm = m[:OI_6364].norm / 3 m[:OI_6300].voff = m[:OI_6364].voff end end if haskey(model, :NII_6549) && haskey(model, :NII_6583) # model[:NII_6549].norm.fixed = true Loading @@ -236,49 +215,11 @@ function multi_fit(source::QSO{TRecipe}; ref_id=1) where TRecipe <: q1927p654 m[:NII_6549].voff = m[:NII_6583].voff end end if haskey(model, :SII_6716) && haskey(model, :SII_6731) # model[:SII_6716].norm.fixed = true model[:SII_6716].voff.fixed = true @patch! model m -> begin # m[:SII_6716].norm = m[:SII_6731].norm / 1.5 m[:SII_6716].voff = m[:SII_6731].voff end end if haskey(model, :na_Ha) && haskey(model, :na_Hb) model[:na_Hb].voff.fixed = true @patch! model m -> m[:na_Hb].voff = m[:na_Ha].voff end # The following are required to avoid degeneracy with iron # template if haskey(model, :Hg) && haskey(model, :br_Hb) model[:Hg].voff.fixed = true model[:Hg].fwhm.fixed = true @patch! model m -> begin m[:Hg].voff = m[:br_Hb].voff m[:Hg].fwhm = m[:br_Hb].fwhm end end if haskey(model, :br_Hg) && haskey(model, :br_Hb) model[:br_Hg].voff.fixed = true model[:br_Hg].fwhm.fixed = true @patch! model m -> begin m[:br_Hg].voff = m[:br_Hb].voff m[:br_Hg].fwhm = m[:br_Hb].fwhm end end if haskey(model, :na_Hg) && haskey(model, :na_Hb) model[:na_Hg].voff.fixed = true model[:na_Hg].fwhm.fixed = true if haskey(model, :OIII_5007_bw) && haskey(model, :OIII_5007) @patch! model m -> begin m[:na_Hg].voff = m[:na_Hb].voff m[:na_Hg].fwhm = m[:na_Hb].fwhm m[:OIII_5007_bw].voff += m[:OIII_5007].voff m[:OIII_5007_bw].fwhm += m[:OIII_5007].fwhm end end Loading Loading @@ -367,7 +308,7 @@ function multi_fit(source::QSO{TRecipe}; ref_id=1) where TRecipe <: q1927p654 end model[:UnkLines] = SumReducer(collect(keys(tmp))) model[:main] = SumReducer([:Continuum, :Iron, line_groups[id]..., :UnkLines]) evaluate!(multi) evaluate!(model) for j in 1:source.options[:n_unk] freeze(model, Symbol(:unk, j)) end Loading @@ -390,7 +331,7 @@ function multi_fit(source::QSO{TRecipe}; ref_id=1) where TRecipe <: q1927p654 λunk = Vector{Float64}() while true (length(λunk) >= source.options[:n_unk]) && break evaluate!(multi) evaluate!(model) Δ = (source.data[id].val - model()) ./ source.data[id].unc # Avoid considering again the same region (within 1A) TODO: within resolution Loading src/Recipe_single.jl +6 −68 Original line number Diff line number Diff line Loading @@ -148,7 +148,6 @@ function fit(source::QSO{TRecipe}; id=1) where TRecipe <: q1927p654 # Guess values evaluate!(model) y = source.data[id].val - model() for cname in line_names c = model[cname] resid_at_line = Spline1D(λ, resid, k=1, bc="nearest")(c.center.val) Loading @@ -174,34 +173,11 @@ function fit(source::QSO{TRecipe}; id=1) where TRecipe <: q1927p654 # Patch parameters if haskey(model, :OIII_4959) && haskey(model, :OIII_5007) model[:OIII_4959].norm.fixed = true model[:OIII_4959].voff.fixed = true @patch! model m -> begin m[:OIII_4959].norm = m[:OIII_5007].norm / 3 m[:OIII_4959].voff = m[:OIII_5007].voff end end if haskey(model, :NII_6549) && haskey(model, :NII_6583) model[:NII_6549].voff.fixed = true @patch! model m -> m[:NII_6549].voff = m[:NII_6583].voff end if haskey(model, :OIII_5007_bw) && haskey(model, :OIII_5007) @patch! model m -> begin m[:OIII_5007_bw].voff += m[:OIII_5007].voff m[:OIII_5007_bw].fwhm += m[:OIII_5007].fwhm end end if haskey(model, :OI_6300) && haskey(model, :OI_6364) # model[:OI_6300].norm.fixed = true model[:OI_6300].voff.fixed = true @patch! model m -> begin # m[:OI_6300].norm = m[:OI_6364].norm / 3 m[:OI_6300].voff = m[:OI_6364].voff end end if haskey(model, :NII_6549) && haskey(model, :NII_6583) # model[:NII_6549].norm.fixed = true Loading @@ -211,49 +187,11 @@ function fit(source::QSO{TRecipe}; id=1) where TRecipe <: q1927p654 m[:NII_6549].voff = m[:NII_6583].voff end end if haskey(model, :SII_6716) && haskey(model, :SII_6731) # model[:SII_6716].norm.fixed = true model[:SII_6716].voff.fixed = true @patch! model m -> begin # m[:SII_6716].norm = m[:SII_6731].norm / 1.5 m[:SII_6716].voff = m[:SII_6731].voff end end if haskey(model, :na_Ha) && haskey(model, :na_Hb) model[:na_Hb].voff.fixed = true @patch! model m -> m[:na_Hb].voff = m[:na_Ha].voff end # The following are required to avoid degeneracy with iron # template if haskey(model, :Hg) && haskey(model, :br_Hb) model[:Hg].voff.fixed = true model[:Hg].fwhm.fixed = true @patch! model m -> begin m[:Hg].voff = m[:br_Hb].voff m[:Hg].fwhm = m[:br_Hb].fwhm end end if haskey(model, :br_Hg) && haskey(model, :br_Hb) model[:br_Hg].voff.fixed = true model[:br_Hg].fwhm.fixed = true @patch! model m -> begin m[:br_Hg].voff = m[:br_Hb].voff m[:br_Hg].fwhm = m[:br_Hb].fwhm end end if haskey(model, :na_Hg) && haskey(model, :na_Hb) model[:na_Hg].voff.fixed = true model[:na_Hg].fwhm.fixed = true if haskey(model, :OIII_5007_bw) && haskey(model, :OIII_5007) @patch! model m -> begin m[:na_Hg].voff = m[:na_Hb].voff m[:na_Hg].fwhm = m[:na_Hb].fwhm m[:OIII_5007_bw].voff += m[:OIII_5007].voff m[:OIII_5007_bw].fwhm += m[:OIII_5007].fwhm end end Loading Loading
src/Recipe_multi.jl +11 −70 Original line number Diff line number Diff line Loading @@ -37,7 +37,9 @@ function multi_fit(source::QSO{TRecipe}; ref_id=1) where TRecipe <: q1927p654 model[:galaxy].norm.val = Spline1D(λ, source.data[id].val, k=1, bc="error")(5500.) if id != ref_id model[:galaxy].norm.fixed = true @patch! multi m -> m[id][:galaxy].norm = m[ref_id][:galaxy].norm @patch! multi m -> begin m[id][:galaxy].norm = m[ref_id][:galaxy].norm end end end Loading Loading @@ -73,7 +75,7 @@ function multi_fit(source::QSO{TRecipe}; ref_id=1) where TRecipe <: q1927p654 (count(residuals .< 0) / length(residuals) > 0.9) && break (c.norm.val < initialnorm / 5) && break # give up c.norm.val *= 0.99 evaluate!(multi) evaluate!(model) end println(source.log, "$id : Cont. norm. (after) : ", c.norm.val) else Loading Loading @@ -129,7 +131,7 @@ function multi_fit(source::QSO{TRecipe}; ref_id=1) where TRecipe <: q1927p654 if length(iron_components) > 0 model[:Iron] = SumReducer(iron_components) model[:main] = SumReducer([:Continuum, :Iron]) evaluate!(multi) evaluate!(model) bestfit = fit!(model, source.data[id], minimizer=mzer); show(source.log, bestfit) else model[:Iron] = @expr m -> [0.] Loading Loading @@ -199,34 +201,11 @@ function multi_fit(source::QSO{TRecipe}; ref_id=1) where TRecipe <: q1927p654 # Patch parameters if haskey(model, :OIII_4959) && haskey(model, :OIII_5007) model[:OIII_4959].norm.fixed = true model[:OIII_4959].voff.fixed = true @patch! model m -> begin m[:OIII_4959].norm = m[:OIII_5007].norm / 3 m[:OIII_4959].voff = m[:OIII_5007].voff end end if haskey(model, :NII_6549) && haskey(model, :NII_6583) model[:NII_6549].voff.fixed = true @patch! model m -> m[:NII_6549].voff = m[:NII_6583].voff end if haskey(model, :OIII_5007_bw) && haskey(model, :OIII_5007) @patch! model m -> begin m[:OIII_5007_bw].voff += m[:OIII_5007].voff m[:OIII_5007_bw].fwhm += m[:OIII_5007].fwhm end end if haskey(model, :OI_6300) && haskey(model, :OI_6364) # model[:OI_6300].norm.fixed = true model[:OI_6300].voff.fixed = true @patch! model m -> begin # m[:OI_6300].norm = m[:OI_6364].norm / 3 m[:OI_6300].voff = m[:OI_6364].voff end end if haskey(model, :NII_6549) && haskey(model, :NII_6583) # model[:NII_6549].norm.fixed = true Loading @@ -236,49 +215,11 @@ function multi_fit(source::QSO{TRecipe}; ref_id=1) where TRecipe <: q1927p654 m[:NII_6549].voff = m[:NII_6583].voff end end if haskey(model, :SII_6716) && haskey(model, :SII_6731) # model[:SII_6716].norm.fixed = true model[:SII_6716].voff.fixed = true @patch! model m -> begin # m[:SII_6716].norm = m[:SII_6731].norm / 1.5 m[:SII_6716].voff = m[:SII_6731].voff end end if haskey(model, :na_Ha) && haskey(model, :na_Hb) model[:na_Hb].voff.fixed = true @patch! model m -> m[:na_Hb].voff = m[:na_Ha].voff end # The following are required to avoid degeneracy with iron # template if haskey(model, :Hg) && haskey(model, :br_Hb) model[:Hg].voff.fixed = true model[:Hg].fwhm.fixed = true @patch! model m -> begin m[:Hg].voff = m[:br_Hb].voff m[:Hg].fwhm = m[:br_Hb].fwhm end end if haskey(model, :br_Hg) && haskey(model, :br_Hb) model[:br_Hg].voff.fixed = true model[:br_Hg].fwhm.fixed = true @patch! model m -> begin m[:br_Hg].voff = m[:br_Hb].voff m[:br_Hg].fwhm = m[:br_Hb].fwhm end end if haskey(model, :na_Hg) && haskey(model, :na_Hb) model[:na_Hg].voff.fixed = true model[:na_Hg].fwhm.fixed = true if haskey(model, :OIII_5007_bw) && haskey(model, :OIII_5007) @patch! model m -> begin m[:na_Hg].voff = m[:na_Hb].voff m[:na_Hg].fwhm = m[:na_Hb].fwhm m[:OIII_5007_bw].voff += m[:OIII_5007].voff m[:OIII_5007_bw].fwhm += m[:OIII_5007].fwhm end end Loading Loading @@ -367,7 +308,7 @@ function multi_fit(source::QSO{TRecipe}; ref_id=1) where TRecipe <: q1927p654 end model[:UnkLines] = SumReducer(collect(keys(tmp))) model[:main] = SumReducer([:Continuum, :Iron, line_groups[id]..., :UnkLines]) evaluate!(multi) evaluate!(model) for j in 1:source.options[:n_unk] freeze(model, Symbol(:unk, j)) end Loading @@ -390,7 +331,7 @@ function multi_fit(source::QSO{TRecipe}; ref_id=1) where TRecipe <: q1927p654 λunk = Vector{Float64}() while true (length(λunk) >= source.options[:n_unk]) && break evaluate!(multi) evaluate!(model) Δ = (source.data[id].val - model()) ./ source.data[id].unc # Avoid considering again the same region (within 1A) TODO: within resolution Loading
src/Recipe_single.jl +6 −68 Original line number Diff line number Diff line Loading @@ -148,7 +148,6 @@ function fit(source::QSO{TRecipe}; id=1) where TRecipe <: q1927p654 # Guess values evaluate!(model) y = source.data[id].val - model() for cname in line_names c = model[cname] resid_at_line = Spline1D(λ, resid, k=1, bc="nearest")(c.center.val) Loading @@ -174,34 +173,11 @@ function fit(source::QSO{TRecipe}; id=1) where TRecipe <: q1927p654 # Patch parameters if haskey(model, :OIII_4959) && haskey(model, :OIII_5007) model[:OIII_4959].norm.fixed = true model[:OIII_4959].voff.fixed = true @patch! model m -> begin m[:OIII_4959].norm = m[:OIII_5007].norm / 3 m[:OIII_4959].voff = m[:OIII_5007].voff end end if haskey(model, :NII_6549) && haskey(model, :NII_6583) model[:NII_6549].voff.fixed = true @patch! model m -> m[:NII_6549].voff = m[:NII_6583].voff end if haskey(model, :OIII_5007_bw) && haskey(model, :OIII_5007) @patch! model m -> begin m[:OIII_5007_bw].voff += m[:OIII_5007].voff m[:OIII_5007_bw].fwhm += m[:OIII_5007].fwhm end end if haskey(model, :OI_6300) && haskey(model, :OI_6364) # model[:OI_6300].norm.fixed = true model[:OI_6300].voff.fixed = true @patch! model m -> begin # m[:OI_6300].norm = m[:OI_6364].norm / 3 m[:OI_6300].voff = m[:OI_6364].voff end end if haskey(model, :NII_6549) && haskey(model, :NII_6583) # model[:NII_6549].norm.fixed = true Loading @@ -211,49 +187,11 @@ function fit(source::QSO{TRecipe}; id=1) where TRecipe <: q1927p654 m[:NII_6549].voff = m[:NII_6583].voff end end if haskey(model, :SII_6716) && haskey(model, :SII_6731) # model[:SII_6716].norm.fixed = true model[:SII_6716].voff.fixed = true @patch! model m -> begin # m[:SII_6716].norm = m[:SII_6731].norm / 1.5 m[:SII_6716].voff = m[:SII_6731].voff end end if haskey(model, :na_Ha) && haskey(model, :na_Hb) model[:na_Hb].voff.fixed = true @patch! model m -> m[:na_Hb].voff = m[:na_Ha].voff end # The following are required to avoid degeneracy with iron # template if haskey(model, :Hg) && haskey(model, :br_Hb) model[:Hg].voff.fixed = true model[:Hg].fwhm.fixed = true @patch! model m -> begin m[:Hg].voff = m[:br_Hb].voff m[:Hg].fwhm = m[:br_Hb].fwhm end end if haskey(model, :br_Hg) && haskey(model, :br_Hb) model[:br_Hg].voff.fixed = true model[:br_Hg].fwhm.fixed = true @patch! model m -> begin m[:br_Hg].voff = m[:br_Hb].voff m[:br_Hg].fwhm = m[:br_Hb].fwhm end end if haskey(model, :na_Hg) && haskey(model, :na_Hb) model[:na_Hg].voff.fixed = true model[:na_Hg].fwhm.fixed = true if haskey(model, :OIII_5007_bw) && haskey(model, :OIII_5007) @patch! model m -> begin m[:na_Hg].voff = m[:na_Hb].voff m[:na_Hg].fwhm = m[:na_Hb].fwhm m[:OIII_5007_bw].voff += m[:OIII_5007].voff m[:OIII_5007_bw].fwhm += m[:OIII_5007].fwhm end end Loading