Skip to content

Commit

Permalink
Merge pull request #288 from ajwheeler/LSF-synth-wls
Browse files Browse the repository at this point in the history
check arguments to `fit_spectrum`
  • Loading branch information
ajwheeler committed Apr 2, 2024
2 parents 4bd818a + ec1dbc5 commit 7983ac4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ function fit_spectrum(obs_wls, obs_flux, obs_err, linelist, initial_guesses, fix
Korg.compute_LSF_matrix(synthesis_wls, obs_wls, R)
end,
wl_buffer=1.0, precision=1e-3, synthesis_kwargs...)
if length(obs_wls) != length(obs_flux) || length(obs_wls) != length(obs_err)
throw(ArgumentError("obs_wls, obs_flux, and obs_err must all have the same length."))
end
if length(obs_wls) != size(LSF_matrix, 1)
throw(ArgumentError("the first dimension of LSF_matrix must be the length of obs_wls."))
end
if (length(synthesis_wls) != size(LSF_matrix, 2))
throw(ArgumentError("the second dimension of LSF_matrix must be the length of synthesis_wls " *
"If you provided one as a keyword argument, you must also provide the other."))
end

initial_guesses, fixed_params = validate_params(initial_guesses, fixed_params)
ps = collect(pairs(scale(initial_guesses)))
Expand Down
8 changes: 8 additions & 0 deletions test/fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ using Random

# check that best-fit flux is within 1% of the true flux at all pixels
@test assert_allclose(spectrum, result.best_fit_flux, rtol=0.01)

# test argument checks
@test_throws "must all have the same length" Korg.Fit.fit_spectrum(obs_wls[1:end-1], spectrum, err, linelist, p0, fixed;
synthesis_wls=synth_wls, LSF_matrix=LSF)
@test_throws "the first dimension of LSF_matrix" Korg.Fit.fit_spectrum(obs_wls, spectrum, err, linelist, p0, fixed;
synthesis_wls=synth_wls, LSF_matrix=LSF[1:end-1, :])
@test_throws "the second dimension of LSF_matrix" Korg.Fit.fit_spectrum(obs_wls, spectrum, err, linelist, p0, fixed;
synthesis_wls=synth_wls, LSF_matrix=LSF[:, 1:end-1])
end

@testset "ews_to_abundances" begin
Expand Down

0 comments on commit 7983ac4

Please sign in to comment.