-
Notifications
You must be signed in to change notification settings - Fork 6
Merge Kristo's work #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eford
wants to merge
4
commits into
RvSpectML:master
Choose a base branch
from
kment:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using FITSIO | ||
using DataInterpolations | ||
|
||
teldir = "/home/kment/RV/telluric" # Directory containing telluric model spectra | ||
|
||
get_h2o_spectrum(λ_values) = interp_telluric_file("$teldir/kpno_telluric_4.0_0.0_h2o_only.fits", λ_values) | ||
get_oxy_spectrum(λ_values) = interp_telluric_file("$teldir/kpno_telluric_4.0_0.0_oxy_only.fits", λ_values) | ||
get_tel_spectrum(λ_values) = interp_telluric_file("$teldir/kpno_telluric_4.0_0.0.fits", λ_values) | ||
|
||
""" | ||
get_telluric_model(λ_values, pwv, z_angle; verbose=true) | ||
Estimate the telluric spectrum at a range of wavelenths (λ_values) for a specific zenith angle | ||
(z_angle, in degrees) and precipitable water vapor (pwv) value. | ||
""" | ||
function get_telluric_model(λ_values, pwv, z_angle; verbose::Bool=true) | ||
|
||
@assert pwv <= 16 "Precipitable water vapor cannot exceed 16." | ||
@assert z_angle < 60 "Zenith angle must be below 60." | ||
|
||
pwv_files = [1, 2, 4, 8, 16] | ||
z_files = [0, 34, 44, 51, 60] | ||
i_pwv = 1 # Index of PWV file | ||
i_z = 1 # Index of zenith angle file | ||
|
||
for (i, x) in enumerate(pwv_files) | ||
if pwv > x | ||
i_pwv = i + 1 | ||
end | ||
end | ||
for (i, x) in enumerate(z_files) | ||
if z_angle >= x | ||
i_z = i | ||
end | ||
end | ||
|
||
fn_model1 = "$teldir/kpno_telluric_$(pwv_files[i_pwv-1]).0_$(z_files[i_z]).0.fits" | ||
fn_model2 = "$teldir/kpno_telluric_$(pwv_files[i_pwv]).0_$(z_files[i_z]).0.fits" | ||
fn_model3 = "$teldir/kpno_telluric_$(pwv_files[i_pwv-1]).0_$(z_files[i_z+1]).0.fits" | ||
fn_model4 = "$teldir/kpno_telluric_$(pwv_files[i_pwv]).0_$(z_files[i_z+1]).0.fits" | ||
if verbose | ||
println("Using models: $fn_model1 $fn_model2 $fn_model3 $fn_model4") | ||
end | ||
|
||
t_model1 = interp_telluric_file(fn_model1, λ_values) | ||
t_model2 = interp_telluric_file(fn_model2, λ_values) | ||
t_model3 = interp_telluric_file(fn_model3, λ_values) | ||
t_model4 = interp_telluric_file(fn_model4, λ_values) | ||
|
||
X = sec(z_angle * π / 180) # Airmass | ||
X_model12 = sec(z_files[i_z] * π / 180) | ||
X_model34 = sec(z_files[i_z+1] * π / 180) | ||
X_power12 = X / X_model12 | ||
X_power34 = X / X_model34 | ||
pwv_power12 = (pwv - pwv_files[i_pwv-1]) / (pwv_files[i_pwv] - pwv_files[i_pwv-1]) * X_power12 | ||
t_scaled12 = t_model1 .^ (X_power12 - pwv_power12) .* t_model2 .^ pwv_power12 | ||
pwv_power34 = (pwv - pwv_files[i_pwv-1]) / (pwv_files[i_pwv] - pwv_files[i_pwv-1]) * X_power34 | ||
t_scaled34 = t_model3 .^ (X_power34 - pwv_power34) .* t_model4 .^ pwv_power34 | ||
|
||
weight = (X - X_model12) / (X_model34 - X_model12) | ||
t_scaled = t_scaled12 .* weight .+ t_scaled34 .* (1 - weight) | ||
|
||
return t_scaled | ||
|
||
end | ||
|
||
""" | ||
get_telluric_prior_spectrum(λ_values, species::Symbol=:all) | ||
Evaluate the spectrum used as a telluric prior at a range of wavelenths (λ_values). | ||
""" | ||
function get_telluric_prior_spectrum(λ_values, species::Symbol=:all) | ||
|
||
if species == :all | ||
return get_tel_spectrum(λ_values) | ||
elseif species == :h2o | ||
return get_h2o_spectrum(λ_values) | ||
elseif species == :oxy | ||
return get_oxy_spectrum(λ_values) | ||
end | ||
|
||
end | ||
|
||
""" | ||
interp_telluric_file(filename, λ_values) | ||
Estimate the telluric spectrum at a range of wavelenths (λ_values) by interpolating a model spectrum | ||
in a given FITS file. | ||
""" | ||
function interp_telluric_file(filename, λ_values) | ||
|
||
f = FITS(filename) | ||
λ_all = reverse(read(f[2], "wavelength")) .* 10 | ||
t_all = reverse(read(f[2], "transmittance")) | ||
|
||
interp = LinearInterpolation(t_all, λ_all) | ||
t_model = interp.(λ_values) | ||
t_model[t_model .< 0] .= 0 | ||
|
||
return t_model | ||
|
||
end | ||
|
||
""" | ||
simulate_telluric_data(λ_values, pwv_values, z_values) | ||
Simulate the telluric spectrum at a range of wavelenths (λ_values) for a list of precipitable water | ||
vapor values (pwv_values) and zenith angle values (z_values, in degrees). | ||
""" | ||
function simulate_telluric_data(λ_values, pwv_values, z_values) | ||
|
||
@assert length(pwv_values) == length(z_values) "Must provide an equal number of PWV and zenith angle values." | ||
|
||
t_all = Matrix{Float64}(undef, length(λ_values), length(pwv_values)) | ||
|
||
for i in range(1, length(pwv_values)) | ||
t_all[:,i] = get_telluric_model(λ_values, pwv_values[i], z_values[i]; verbose=false) | ||
end | ||
|
||
return t_all | ||
|
||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kment Please replace this path with something more general. We could create a data directory and then we can access it with
joinpath(pkgdir(StellarSpectraObservationFitting, "data"), filename)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the files are small, we can just stick them in this repository. If they're large then we can add a script in 'deps/build.jl' that downloads the files into the data subdirectory. It could be from a separate GitHub repository (maybe TelluricModels or SSOFTelluricModels?) or a Zenodo url.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is to take the directory from a
LocalPreferences.toml
file in the same directory as theProject.toml
.