Skip to content
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

add documentation for function #37

Open
hematthi opened this issue May 20, 2022 · 0 comments
Open

add documentation for function #37

hematthi opened this issue May 20, 2022 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@hematthi
Copy link
Collaborator

function find_ranges_with_tellurics_in_order(spectrum::ST, order::Integer; telluric_threshold::Real = 1, min_Δv_clean::Real = default_min_Δv_clean, verbose::Bool = false) where { T1<:Real, A1<:AbstractArray{T1}, T2<:Real, A2<:AbstractArray{T2}, T3<:Real, A3<:AbstractArray{T3}, IT<:EXPRES.AnyEXPRES, ST<:Spectra2DBasic{T1,T2,T3,A1,A2,A3,IT} }
@assert haskey(spectrum.metadata,:tellurics)
telluric_ranges = Vector{Tuple{Int64,Int64}}(undef,0)
c = RvSpectMLBase.speed_of_light_mps
all_wavelengths = range(first(spectrum.λ[:,order]),stop=last(spectrum.λ[:,order]),length=size(spectrum.λ,1) )
tellurics = spectrum.metadata[:tellurics]
start = findfirst(x->!isnan(x),view(tellurics,:,order) )
stop = findlast(x->!isnan(x),view(tellurics,:,order) )
if isnothing(start) || isnothing(stop)
if verbose println("# The entire order ", order, " was NaNs!?!") end
return Vector{Tuple{eltype(spectrum.λ), eltype(spectrum.λ)} }(undef,0)
end
@assert stop >= start +1
in_telluric = tellurics[start,order] < telluric_threshold
idx_start_this_telluric = in_telluric ? start : 0
idx_stop_this_telluric = 0
for i in start+1:stop
if in_telluric
if !(tellurics[i,order] < telluric_threshold) # exitted telluric
idx_stop_this_telluric = i-1
#println("# Order = " , order, " Adding pixels = ", idx_start_this_telluric, " - ", idx_stop_this_telluric, " λ = ", spectrum.λ[idx_start_this_telluric,order], " - ", spectrum.λ[idx_stop_this_telluric,order] )
push!(telluric_ranges, (idx_start_this_telluric,idx_stop_this_telluric) )
#push!(telluric_ranges,(spectrum.λ[idx_start_this_telluric,order], spectrum.λ[idx_stop_this_telluric,order]) )
in_telluric = false
end
else
if (tellurics[i,order] < telluric_threshold) # entered telluric
idx_start_this_telluric = i
if length(telluric_ranges) >= 1
idx_last_start = last(telluric_ranges)[1]
idx_last_stop = last(telluric_ranges)[2]
if spectrum.λ[idx_start_this_telluric,order] - spectrum.λ[idx_last_stop,order] <= min_Δv_clean/c * spectrum.λ[idx_start_this_telluric,order]
idx_start_this_telluric = first(last(telluric_ranges))
pop!(telluric_ranges)
end
end
in_telluric = true
end
end
end
if in_telluric
idx_stop_this_telluric = stop
#println("# Order = " , order, " Adding pixels = ", idx_start_this_telluric, " - ", idx_stop_this_telluric, " λ = ", spectrum.λ[idx_start_this_telluric,order], " - ", spectrum.λ[idx_stop_this_telluric,order] )
push!(telluric_ranges,(idx_start_this_telluric,idx_stop_this_telluric) )
end
#lambda_range = map(r->(spectrum.λ[first(r),order], spectrum.λ[last(r),order] ), telluric_ranges)
DataFrame(:lambda_lo=>map(r->spectrum.λ[first(r),order], telluric_ranges), :lambda_hi=>map(r->spectrum.λ[last(r),order], telluric_ranges) )
end

@hematthi hematthi added the documentation Improvements or additions to documentation label May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant