Skip to content

Commit

Permalink
adding Delta FWHM functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
eford committed Apr 23, 2021
1 parent 6d44319 commit 6c17923
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/ccf/plan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ function increase_mask_fwhm!(p::PlanT, Δfwhm::Real ) where { PlanT<:BasicCCFPla
end
return p
end

function copy(plan::BasicCCFPlan{MST, LLT} ) where { MST<:AbstractCCFMaskShape, LLT<:AbstractLineList }
BasicCCFPlan(plan.v_center, plan.v_step, plan.v_max, plan.v_range_no_mask_change, deepcopy(plan.mask_shape), plan.line_list, plan.allow_nans)
end
32 changes: 25 additions & 7 deletions src/convenience/ccf_chunk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,21 @@ Convenience function to compute CCF for one chunk of spectrum.
- CCF for one chunk of spectrum, evaluated using mask_shape and line list from ccf plan
"""
function calc_ccf_chunk(chunk::AbstractChunkOfSpectrum, plan::PlanT = BasicCCFPlan()
; var::AbstractVector{T} = chunk.var, ccf_var_scale::Real = 1.0,
; var::AbstractVector{T} = chunk.var, ccf_var_scale::Real = 1.0, Δfwhm::Real = 0,
assume_sorted::Bool = false, calc_ccf_var::Bool = false ) where { T<:Real, PlanT<:AbstractCCFPlan }
if Δfwhm > 0
this_plan_for_chunk = copy(plan)
increase_mask_fwhm!(this_plan_for_chunk,Δfwhm)
else
this_plan_for_chunk = plan
end
len_v_grid = calc_length_ccf_v_grid(plan)
ccf_out = zeros(len_v_grid)
if calc_ccf_var
ccf_var_out = zeros(len_v_grid)
return calc_ccf_and_var_chunk!(ccf_out, ccf_var_out, chunk, plan, var=var, ccf_var_scale=ccf_var_scale, assume_sorted=assume_sorted )
return calc_ccf_and_var_chunk!(ccf_out, ccf_var_out, chunk, this_plan_for_chunk, var=var, ccf_var_scale=ccf_var_scale, assume_sorted=assume_sorted )
else
return calc_ccf_chunk!(ccf_out, chunk, plan, var=var, assume_sorted=assume_sorted )
return calc_ccf_chunk!(ccf_out, chunk, this_plan_for_chunk, var=var, assume_sorted=assume_sorted )
end
end

Expand All @@ -114,13 +120,19 @@ Convenience function to compute CCF and variance of each "CCF pixel" for one chu
- `ccf_var_out`:
"""
function calc_ccf_and_var_chunk(chunk::AbstractChunkOfSpectrum, plan::PlanT = BasicCCFPlan()
; var::AbstractVector{T} = chunk.var, ccf_var_scale::Real = 1.0,
; var::AbstractVector{T} = chunk.var, ccf_var_scale::Real = 1.0, Δfwhm::Real = 0,
assume_sorted::Bool = false ) where { T<:Real, PlanT<:AbstractCCFPlan }
@assert assume_sorted || issorted( plan.line_list.λ )
if Δfwhm > 0
this_plan_for_chunk = copy(plan)
increase_mask_fwhm!(this_plan_for_chunk,Δfwhm)
else
this_plan_for_chunk = plan
end
len_v_grid = calc_length_ccf_v_grid(plan)
ccf_out = zeros(len_v_grid)
ccf_var_out = zeros(len_v_grid)
calc_ccf_and_var_chunk!(ccf_out, ccf_var_out, chunk, plan, var=var, ccf_var_scale=ccf_var_scale, assume_sorted=true )
calc_ccf_and_var_chunk!(ccf_out, ccf_var_out, chunk, this_plan_for_chunk, var=var, ccf_var_scale=ccf_var_scale, assume_sorted=true )
return (ccf=ccf_out, ccf_var=ccf_var_out)
end

Expand All @@ -139,12 +151,18 @@ Convenience function to compute CCF and covariance of each pair of "CCF pixels"
- `ccf_covar_out`:
"""
function calc_ccf_and_covar_chunk(chunk::AbstractChunkOfSpectrum, plan::PlanT = BasicCCFPlan()
; var::AbstractVector{T} = chunk.var, ccf_var_scale::Real = 1.0,
; var::AbstractVector{T} = chunk.var, ccf_var_scale::Real = 1.0, Δfwhm::Real = 0,
assume_sorted::Bool = false ) where { T<:Real, PlanT<:AbstractCCFPlan }
@assert assume_sorted || issorted( plan.line_list.λ )
if Δfwhm > 0
this_plan_for_chunk = copy(plan)
increase_mask_fwhm!(this_plan_for_chunk,Δfwhm)
else
this_plan_for_chunk = plan
end
len_v_grid = calc_length_ccf_v_grid(plan)
ccf_out = zeros(len_v_grid)
ccf_covar_out = zeros(len_v_grid,len_v_grid)
calc_ccf_and_covar_chunk!(ccf_out, ccf_covar_out, chunk, plan, var=var, ccf_var_scale=ccf_var_scale, assume_sorted=true )
calc_ccf_and_covar_chunk!(ccf_out, ccf_covar_out, chunk, this_plan_for_chunk, var=var, ccf_var_scale=ccf_var_scale, assume_sorted=true )
return (ccf=ccf_out, ccf_covar=ccf_covar_out)
end
26 changes: 22 additions & 4 deletions src/convenience/order_ccf_chunklist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,23 @@ CCF is evaluated using line list and mask_shape provided by the ccf plan for eac
A 2-d array containing the CCF at each (velocity, chunk)
"""
function calc_order_ccfs_chunklist(chunk_list::AbstractChunkList,
plan_for_chunk::AbstractVector{PlanT} = BasicCCFPlan(); assume_sorted::Bool = false ) where {
plan_for_chunk::AbstractVector{PlanT} = BasicCCFPlan();
Δfwhm::Real = 0, assume_sorted::Bool = false ) where {
PlanT<:AbstractCCFPlan }
num_chunks = length(chunk_list)
@assert length(plan_for_chunk) == num_chunks
@assert assume_sorted || issorted( first(plan_for_chunk).line_list.λ )
num_vels = maximum(map(chid->calc_length_ccf_v_grid(plan_for_chunk[chid]), 1:num_chunks ))
if Δfwhm > 0
this_plan_for_chunk = copy(plan_for_chunk)
#increase_mask_fwhm!(this_plan_for_chunk,Δfwhm)
map(chid->increase_mask_fwhm!(this_plan_for_chunk[chid],Δfwhm), 1:num_chunks )
else
this_plan_for_chunk = plan_for_chunk
end

chunk_ccfs_out = zeros( num_vels, num_chunks )
calc_order_ccfs_chunklist!(chunk_ccfs_out, chunk_list, plan_for_chunk, assume_sorted=assume_sorted )
calc_order_ccfs_chunklist!(chunk_ccfs_out, chunk_list, this_plan_for_chunk, Δfwhm=Δfwhm, assume_sorted=assume_sorted )
return chunk_ccfs_out
end

Expand Down Expand Up @@ -97,16 +106,25 @@ CCF is evaluated using line list and mask_shape provided by the ccf plan for eac
A 2-d array containing the CCF at each (velocity, chunk)
"""
function calc_order_ccf_and_vars_chunklist(chunk_list::AbstractChunkList,
plan_for_chunk::AbstractVector{PlanT} = BasicCCFPlan(); assume_sorted::Bool = false ) where {
plan_for_chunk::AbstractVector{PlanT} = BasicCCFPlan();
Δfwhm::Real = 0, assume_sorted::Bool = false ) where {
PlanT<:AbstractCCFPlan }
num_chunks = length(chunk_list)
@assert length(plan_for_chunk) == num_chunks
@assert assume_sorted || issorted( first(plan_for_chunk).line_list.λ )

if Δfwhm > 0
this_plan_for_chunk = copy(plan_for_chunk)
#increase_mask_fwhm!(this_plan_for_chunk,Δfwhm)
map(chid->increase_mask_fwhm!(this_plan_for_chunk[chid],Δfwhm), 1:num_chunks )
else
this_plan_for_chunk = plan_for_chunk
end

num_vels = maximum(map(chid->calc_length_ccf_v_grid(plan_for_chunk[chid]), 1:num_chunks ))
chunk_ccfs_out = zeros( num_vels, num_chunks )
chunk_ccf_vars_out = zeros( num_vels, num_chunks )

calc_order_ccf_and_vars_chunklist!(chunk_ccfs_out, chunk_ccf_vars_out, chunk_list, plan_for_chunk, assume_sorted=assume_sorted )
calc_order_ccf_and_vars_chunklist!(chunk_ccfs_out, chunk_ccf_vars_out, chunk_list, this_plan_for_chunk, assume_sorted=assume_sorted )
return (ccfs=chunk_ccfs_out, ccf_vars=chunk_ccf_vars_out)
end
21 changes: 14 additions & 7 deletions src/convenience/order_ccf_chunklist_timeseries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ Note that the ccf_plan provided is used as a template for creating a custom ccf_
only includes lines that reliably appear in that order for all spectra in the chunklist_timeseries.
"""
function calc_order_ccf_chunklist_timeseries(clt::AbstractChunkListTimeseries,
plan::PlanT = BasicCCFPlan(); verbose::Bool = false ) where {
PlanT<:AbstractCCFPlan }
plan::PlanT = BasicCCFPlan(); verbose::Bool = false ,
Δfwhm::AbstractVector{T} = zeros(0)
) where { PlanT<:AbstractCCFPlan, T<:Real }

#@assert issorted( plan.line_list.λ )
#nvs = length(calc_ccf_v_grid(plan))
nvs = calc_length_ccf_v_grid(plan)
Expand Down Expand Up @@ -93,13 +95,14 @@ function calc_order_ccf_chunklist_timeseries(clt::AbstractChunkListTimeseries,
# order_ccfs[:,:,i] .= calc_order_ccfs_chunklist(clt.chunk_list[i], plan)
#end
Threads.@threads for i in 1:nobs
order_ccfs[:,:,i] .= calc_order_ccfs_chunklist(clt.chunk_list[i], plan_for_chunk, assume_sorted=true )
this_Δfwhm = length(Δfwhm) == nobs ? Δfwhm[i] : 0.0
order_ccfs[:,:,i] .= calc_order_ccfs_chunklist(clt.chunk_list[i], plan_for_chunk, Δfwhm=this_Δfwhm, assume_sorted=true )
end

return order_ccfs
end

""" `calc_order_ccf_chunklist_timeseries( chunklist_timeseries, ccf_plan )`
""" `calc_order_ccf_and_var_chunklist_timeseries( chunklist_timeseries, ccf_plan )`
Convenience function to compute separate CCFs for each chunk (potentially an order or view around one or two lines) of each spectrum in a timeseries.
CCF is evaluated using line list and mask_shape provided by the ccf plan for each chunk.
Uses multiple threads if avaliable.
Expand All @@ -113,8 +116,10 @@ Note that the ccf_plan provided is used as a template for creating a custom ccf_
only includes lines that reliably appear in that order for all spectra in the chunklist_timeseries.
"""
function calc_order_ccf_and_var_chunklist_timeseries(clt::AbstractChunkListTimeseries,
plan::PlanT = BasicCCFPlan(); verbose::Bool = false ) where {
PlanT<:AbstractCCFPlan }
plan::PlanT = BasicCCFPlan(); verbose::Bool = false,
ccf_var_scale::Real = 1.0, Δfwhm::AbstractVector{T} = zeros(0)
) where {
PlanT<:AbstractCCFPlan, T<:Real }
#@assert issorted( plan.line_list.λ )
#nvs = length(calc_ccf_v_grid(plan))
nvs = calc_length_ccf_v_grid(plan)
Expand Down Expand Up @@ -186,8 +191,10 @@ function calc_order_ccf_and_var_chunklist_timeseries(clt::AbstractChunkListTimes
# order_ccfs[:,:,i] .= calc_order_ccfs_chunklist(clt.chunk_list[i], plan)
#end
Threads.@threads for i in 1:nobs
this_Δfwhm = length(Δfwhm) == nobs ? Δfwhm[i] : 0.0
for j in 1:num_chunks(clt)
( ccf_tmp, ccf_var_tmp ) = calc_ccf_and_var_chunk(clt.chunk_list[i][j], plan_for_chunk[j], assume_sorted=true )
( ccf_tmp, ccf_var_tmp ) = calc_ccf_and_var_chunk(clt.chunk_list[i][j], plan_for_chunk[j],
ccf_var_scale=ccf_var_scale, Δfwhm=this_Δfwhm, assume_sorted=true )
order_ccfs[:,j,i] .= ccf_tmp
order_ccf_vars[:,j,i] .= ccf_var_tmp
end
Expand Down

0 comments on commit 6c17923

Please sign in to comment.