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/improve documentation for functions #55

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

add/improve documentation for functions #55

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

Comments

@hematthi
Copy link
Collaborator

function filter_line_list(df::DataFrame, inst::IT ; λmin::Real = default_λmin, λmax::Real = default_λmax ) where { IT<:NEID.AnyNEID }
df |> @filter(λmin <= _.lambda <= λmax) |>
# @filter( _.lambda < 6000.0 ) |> # Avoid tellurics at redder wavelengths
# @filter( _.lambda >6157 || _.lambda < 6155 ) |> # Avoid "line" w/ large variability
DataFrame
end
""" read_telluric_ranges( filename )
Return DataFrame (keys lambda_lo and lambda_hi) with wavelength ranges to be avoided as containing tellurics
based on provided CSV file. Assumes path is included in filename.
"""
function read_telluric_ranges(fn::String)
@assert occursin(r"\.csv$",fn)
#println("Trying to read from >",fn,"<.")
@assert isfile(fn)
df = CSV.read(fn, DataFrame)
@assert size(df,1) >= 1
@assert hasproperty(df,:lambda_lo)
@assert hasproperty(df,:lambda_hi)
return df
end
function make_λ_list_for_bad_columns(line_list::DataFrame, neid_data::DT ) where {
T1<:Real, A1<:AbstractArray{T1}, T2<:Real, A2<:AbstractArray{T2}, T3<:Real, A3<:AbstractArray{T3},
IT<:NEID.AnyNEID, ST<:Spectra2DBasic{T1,T2,T3,A1,A2,A3,IT}, DT<:AbstractArray{ST,1} }
order_list = 1:size(first(neid_data).λ,2)
df_bad_col_λs = DataFrame(:order=>Int[], :lambda_lo=>Float64[], :lambda_hi=>Float64[])
for order in order_list
λ_extrema = NaNMath.extrema(first(neid_data).λ[:,order])
if isnan(first(λ_extrema)) || isnan(last(λ_extrema)) continue end
for bcr in bad_col_ranges(NEID2D(), order)
pixlo = first(bcr)
pixhi = pixlo + 1
if pixhi > size(first(neid_data).λ,1)
pixhi -= 1
pixlo -= 1
end
doppler_factors = map(obsid-> haskey(neid_data[obsid].metadata,:doppler_factor) ? neid_data[obsid].metadata[:doppler_factor] : 1 , 1:length(neid_data))
Δλ_pixel = (first(neid_data).λ[pixhi,order] - first(neid_data).λ[pixlo,order]) * doppler_factors[1]
(λ_lo, λ_hi) = mapreduce(obsid->extrema(neid_data[obsid].λ[bcr,order]) .* doppler_factors[obsid],
(a,b) -> (min(a[1],b[1]), max(a[2],b[2])), 1:length(neid_data) )
λ_lo -= Δλ_pixel/2
λ_hi += Δλ_pixel/2
push!(df_bad_col_λs, Dict(:order=>order, :lambda_lo=>λ_lo, :lambda_hi=>λ_hi) )
end
end
return df_bad_col_λs
end
function make_good_orders_pixels_df(neid_data::DT ; orders::A4 = orders_to_use_default(first(neid_data).inst) ) where {
T1<:Real, A1<:AbstractArray{T1}, T2<:Real, A2<:AbstractArray{T2}, T3<:Real, A3<:AbstractArray{T3},
IT<:NEID.AnyNEID, ST<:Spectra2DBasic{T1,T2,T3,A1,A2,A3,IT}, DT<:AbstractArray{ST,1},
T4 <: Integer, A4<:AbstractArray{T4} }
@warn "Deprecated use make_good_orders_pixels_df(inst) instead."
df = DataFrame(order=Int[],pixels=UnitRange[])
for ord in orders
pixel_array = EchelleInstruments.calc_complement_index_ranges(get_pixel_range(NEID2D(),ord),EchelleInstruments.NEID.bad_col_ranges(NEID2D(),ord))
order_array = repeat([ord],length(pixel_array))
df_tmp = DataFrame(:order=>order_array,:pixels=>pixel_array)
append!(df,df_tmp)
end
return df
end
function make_good_orders_pixels_df(inst::IT ; orders::A4 = orders_to_use_default(inst) ) where {
IT<:NEID.AnyNEID, T4 <: Integer, A4<:AbstractArray{T4} }
df = DataFrame(order=Int[],pixels=UnitRange[])
for ord in orders
pixel_array = EchelleInstruments.calc_complement_index_ranges(get_pixel_range(NEID2D(),ord),EchelleInstruments.NEID.bad_col_ranges(NEID2D(),ord))
order_array = repeat([ord],length(pixel_array))
df_tmp = DataFrame(:order=>order_array,:pixels=>pixel_array)
append!(df,df_tmp)
end
return df
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