Skip to content

Commit 371462a

Browse files
committed
tweaks for pipeline
1 parent 737bd95 commit 371462a

File tree

3 files changed

+37
-29
lines changed

3 files changed

+37
-29
lines changed

Project.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ MultivariateStats = "6f286f6a-111f-5878-ab1e-185364afe411"
2929
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
3030
NeidArchive = "b2c48323-12ae-41a0-acdb-062d24b276bc"
3131
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
32+
PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150"
3233
PkgVersion = "eebad327-c553-4316-9ea0-9fa01ccd7688"
3334
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
3435
Pluto = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
@@ -50,7 +51,7 @@ SunAsAStar = "1bd1a468-645d-4223-8813-48273918c0e0"
5051
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
5152

5253
[compat]
53-
CSV = "0.7, 0.8"
54+
CSV = "0.7, 0.8, 0.9.11"
5455
DataFrames = "0.20, 0.21, 0.22, 0.23, 0.24, 1, 1.1"
5556
EchelleInstruments = ">=0.2.5"
5657
FileIO = "1.4"

examples/calc_order_ccfs_using_continuum_1.1.jl

+26-20
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ pipeline_plan = PipelinePlan()
500500
end
501501

502502

503-
if args["apply_continuum_normalization"]==true && args["continuum_normalization_individually"]==true
503+
if args["apply_continuum_normalization"] && args["continuum_normalization_individually"]
504+
println("Applying continuum normalization to each spectrum individually.")
504505
local anchors, continuum, f_filtered
505506
if args["anchors_filename"] != nothing
506507
@assert isfile(args["anchors_filename"]) && filesize(args["anchors_filename"])>0
@@ -525,19 +526,24 @@ pipeline_plan = PipelinePlan()
525526
mean_clean_flux_continuum_normalized .+= f_norm # .*weight
526527
mean_clean_var_continuum_normalized .+= var_norm # .*weight
527528
global mean_clean_flux_continuum_normalized_weight_sum += weight
528-
end
529+
end
529530
spec.flux .= f_norm
530531
spec.var .= var_norm
531532

532533
end
533534
push!(all_spectra,spec)
534535
end
535536
GC.gc()
537+
mean_lambda ./= mean_clean_flux_weight_sum
538+
mean_clean_flux ./= mean_clean_flux_weight_sum
539+
mean_clean_var ./= mean_clean_flux_weight_sum
540+
mean_clean_flux_sed_normalized ./= mean_clean_flux_sed_normalized_weight_sum
541+
mean_clean_var_sed_normalized ./= mean_clean_flux_sed_normalized_weight_sum
536542
dont_need_to!(pipeline_plan,:read_spectra);
537543

538544

539-
if args["apply_continuum_normalization"]==true && !(args["continuum_normalization_individually"] == true)
540-
println("# Computing continuum normalization from mean spectra.")
545+
if args["apply_continuum_normalization"] && !args["continuum_normalization_individually"]
546+
println("Applying continuum normalization based on mean of clean spectra.")
541547
local anchors, continuum, f_filtered
542548
if args["anchors_filename"] !=nothing
543549
@assert isfile(args["anchors_filename"]) && filesize(args["anchors_filename"])>0
@@ -549,15 +555,20 @@ pipeline_plan = PipelinePlan()
549555
(anchors, continuum, f_filtered) = Continuum.calc_continuum(spec.λ, mean_clean_flux_sed_normalized, mean_clean_var_sed_normalized; fwhm = args["fwhm_continuum"]*1000, ν = args["nu_continuum"],
550556
stretch_factor = args["stretch_factor"], merging_threshold = args["merging_threshold"], smoothing_half_width = args["smoothing_half_width"], min_R_factor = args["min_rollingpin_r"],
551557
orders_to_use = orders_to_use_for_continuum, verbose = false )
552-
save(args["anchors_filename_output"], Dict("anchors" => anchors) )
558+
if !isnothing(args["anchors_filename_output"])
559+
println("# Storing anchors used for continuum model in ",args["anchors_filename_output"], ".")
560+
save(args["anchors_filename_output"], Dict("anchors" => anchors) )
561+
end
553562
else
554563
(anchors, continuum, f_filtered) = Continuum.calc_continuum(spec.λ, mean_clean_flux, mean_clean_var; fwhm = args["fwhm_continuum"]*1000, ν = args["nu_continuum"],
555564
stretch_factor = args["stretch_factor"], merging_threshold = args["merging_threshold"], smoothing_half_width = args["smoothing_half_width"], min_R_factor = args["min_rollingpin_r"],
556565
orders_to_use = orders_to_use_for_continuum, verbose = false )
557-
save(args["anchors_filename_output"], Dict("anchors" => anchors) )
558-
end
559-
println("# Stored anchors used for continuum model.")
560-
end
566+
if !isnothing(args["anchors_filename_output"])
567+
println("# Storing anchors used for continuum model in ",args["anchors_filename_output"], ".")
568+
save(args["anchors_filename_output"], Dict("anchors" => anchors) )
569+
end
570+
end # @isdefined sed
571+
end # args["anchors_filename"]
561572
normalization_anchors_list = anchors
562573

563574
weight = 1
@@ -573,13 +584,8 @@ pipeline_plan = PipelinePlan()
573584
end
574585
end
575586
end
576-
mean_lambda ./= mean_clean_flux_weight_sum
577-
mean_clean_flux ./= mean_clean_flux_weight_sum
578-
mean_clean_var ./= mean_clean_flux_weight_sum
579-
mean_clean_flux_sed_normalized ./= mean_clean_flux_sed_normalized_weight_sum
580-
mean_clean_var_sed_normalized ./= mean_clean_flux_sed_normalized_weight_sum
581-
mean_clean_flux_continuum_normalized ./= mean_clean_flux_continuum_normalized_weight_sum
582-
mean_clean_var_continuum_normalized ./= mean_clean_flux_continuum_normalized_weight_sum
587+
mean_clean_flux_continuum_normalized ./= mean_clean_flux_continuum_normalized_weight_sum
588+
mean_clean_var_continuum_normalized ./= mean_clean_flux_continuum_normalized_weight_sum
583589

584590
order_list_timeseries = extract_orders(all_spectra, pipeline_plan, orders_to_use=orders_to_use, remove_bad_chunks=false, recalc=true )
585591

@@ -600,7 +606,6 @@ line_width = line_width_50_default
600606
@assert all(map(k->k names(line_list_espresso), ["lambda","weight","order"]))
601607
dont_need_to!(pipeline_plan,:clean_line_list_tellurics)
602608
else
603-
println("# Can't find ", line_list_filename, ". Trying ESPRESSO line list.")
604609
#orders_to_use = good_orders
605610
#order_list_timeseries = extract_orders(all_spectra,pipeline_plan, orders_to_use=orders_to_use, recalc=true )
606611
touch(line_list_filename)
@@ -609,6 +614,7 @@ line_width = line_width_50_default
609614
else
610615
line_list_input_filename = joinpath(pkgdir(EchelleCCFs),"data","masks","espresso+neid_mask_97_to_108.mas")
611616
end
617+
println("# Recreating line list weights from ", line_list_input_filename)
612618
line_list_espresso = prepare_line_list(line_list_input_filename, all_spectra, pipeline_plan, v_center_to_avoid_tellurics=ccf_mid_velocity,
613619
Δv_to_avoid_tellurics = 2*max_bc+range_no_mask_change*line_width_50_default+max_mask_scale_factor*default_ccf_mask_v_width(NEID2D()), orders_to_use=#=orders_to_use=#56:108, recalc=true, verbose=true)
614620
if args["recompute_line_weights"] && !isnothing(args["line_list_output_filename"])
@@ -651,7 +657,7 @@ if verbose println(now()) end
651657
println("# Saving results to ", daily_ccf_filename, ".")
652658
stop_processing_time = now()
653659
jldopen(daily_ccf_filename, "w") do f
654-
f["v_grid"] = v_grid_order_ccfs
660+
f["v_grid"] = collect(v_grid_order_ccfs)
655661
f["order_ccfs"] = order_ccfs
656662
f["order_ccf_vars"] = order_ccf_vars
657663
f["Δfwhm"] = Δfwhm
@@ -690,7 +696,7 @@ for (i,row) in enumerate(eachrow(df_files_use))
690696
#ccf_filename = joinpath(neid_data_path,target_subdir,"output","ccfs", m[1] * "_ccfs=default.jld2")
691697
ccf_filename = joinpath(neid_data_path,target_subdir,"ccfs", m[1] * "_ccfs=default.jld2")
692698
jldopen(ccf_filename, "w") do f
693-
f["v_grid"] = v_grid_order_ccfs
699+
f["v_grid"] = collect(v_grid_order_ccfs)
694700
f["order_ccfs"] = order_ccfs[:,:,i]
695701
f["order_ccf_vars"] = order_ccf_vars[:,:,i]
696702
f["orders_to_use"] = orders_to_use
@@ -807,7 +813,7 @@ msf = lsf_width/default_ccf_mask_v_width(NEID2D()); fwtf = 0.5 # using LSF widt
807813
mask_type=:gaussian, Δfwhm=Δfwhm,
808814
mask_scale_factor=msf, range_no_mask_change=5*line_width_50, ccf_mid_velocity=ccf_mid_velocity, v_step=100, #155,
809815
v_max=max(5*line_width_50,2*max_bc), allow_nans=true, calc_ccf_var=true, recalc=true)
810-
outputs["v_grid"] = v_grid
816+
outputs["v_grid"] = collect(v_grid)
811817
outputs["ccfs_espresso"] = ccfs_espresso
812818
outputs["ccf_vars_espresso"] = ccf_vars_espresso
813819

examples/daily_rvs_v1.2.jl

+9-8
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,9 @@ println("# Found ", length(obs_to_use), " files of ", size(manifest,1), " to us
250250
:mean_pyroflux=>:pyrflux_mean, :rms_pyroflux=>:pyrflux_rms ) |> DataFrame
251251
df_out[!,"mask"] = mask
252252

253-
ccf_sum = reshape(sum(order_ccfs,dims=2),num_vels,num_obs)
254-
ccf_var_sum = reshape(sum(input_data["order_ccf_vars"],dims=2),num_vels,num_obs)
253+
orders_to_use_for_rvs = 56:78 # TODO: Implement, make parameter, generalize, etc.
254+
ccf_sum = reshape(sum(view(order_ccfs,:,orders_to_use_for_rvs,:),dims=2),num_vels,num_obs)
255+
ccf_var_sum = reshape(sum(view(input_data["order_ccf_vars"],:,orders_to_use_for_rvs,:),dims=2),num_vels,num_obs)
255256

256257
println("# Measuring RVs from RvSpectML's CCFs.")
257258
v_grid = collect(input_data["v_grid"])
@@ -276,20 +277,20 @@ if occursin("template",args["rv_alg"])
276277
template_obs_to_use = template_data["clean_obs_mask"]
277278
template_num_obs = sum(template_obs_to_use)
278279
@assert template_num_obs >= 1
279-
template_ccf = reshape(sum(view(template_order_ccfs,:,:,template_obs_to_use),dims=2),num_vels,template_num_obs)
280-
template_ccf_var = reshape(sum(view(template_order_ccf_vars,:,:,template_obs_to_use),dims=2),num_vels,template_num_obs)
280+
template_ccf = reshape(sum(view(template_order_ccfs,:,orders_to_use_for_rvs,template_obs_to_use),dims=2),num_vels,template_num_obs)
281+
template_ccf_var = reshape(sum(view(template_order_ccf_vars,:,orders_to_use_for_rvs,template_obs_to_use),dims=2),num_vels,template_num_obs)
281282
end
282283
#ccf_template = EchelleCCFs.calc_ccf_template(view(ccf_sum,:,obs_to_use), view(ccf_var_sum,:,obs_to_use) )
283-
ccf_template = EchelleCCFs.calc_ccf_template(template_ccf, template_ccf_var,frac_of_width_to_fit=args["frac_of_width_to_fit"], measure_width_at_frac_depth=args["measure_width_at_frac_depth"])
284-
alg_template = MeasureRvFromCCFTemplate(v_grid=collect(v_grid),template=ccf_template)
284+
ccf_template = EchelleCCFs.calc_ccf_template(template_ccf, template_ccf_var)
285+
alg_template = MeasureRvFromCCFTemplate(v_grid=collect(v_grid),template=ccf_template,frac_of_width_to_fit=args["frac_of_width_to_fit"], measure_width_at_frac_depth=args["measure_width_at_frac_depth"])
285286
rvs_template = DataFrame(map(i->any(isnan.(view(ccf_sum,:,i))) ? (rv=NaN, σ_rv=NaN) : measure_rv_from_ccf(v_grid,view(ccf_sum,:,i),view(ccf_var_sum,:,i),alg=alg_template),1:num_obs))
286287
df_out[!,Symbol("rv_template")] = rvs_template.rv
287288
df_out[!,Symbol("σrv_template")] = rvs_template.σ_rv
288289
end
289290
if occursin("gaussian",args["rv_alg"])
290291
alg_gauss = MeasureRvFromCCFGaussian(frac_of_width_to_fit=args["frac_of_width_to_fit"], measure_width_at_frac_depth=args["measure_width_at_frac_depth"])
291292
rvs_gauss = DataFrame(map(i->any(isnan.(view(ccf_sum,:,i))) ? (rv=NaN, σ_rv=NaN) : measure_rv_from_ccf(v_grid,view(ccf_sum,:,i),view(ccf_var_sum,:,i),alg=alg_gauss),1:num_obs))
292-
df_out[!,Symbol("rv_template")]= rvs_gauss.rv
293+
df_out[!,Symbol("rv_gaussian")]= rvs_gauss.rv
293294
df_out[!,Symbol("σrv_gaussian")] = rvs_gauss.σ_rv
294295
end
295296
if occursin("quadratic",args["rv_alg"])
@@ -315,7 +316,7 @@ for j in 1:num_orders_to_use
315316
#local ccf_template = EchelleCCFs.calc_ccf_template(view(order_ccfs,:,j,obs_to_use), view(order_ccf_vars,:,j,obs_to_use) )
316317
local ccf_template = EchelleCCFs.calc_ccf_template(template_ccf, template_ccf_var)
317318
local alg_template = MeasureRvFromCCFTemplate(v_grid=collect(v_grid),template=ccf_template, frac_of_width_to_fit=args["frac_of_width_to_fit"], measure_width_at_frac_depth=args["measure_width_at_frac_depth"])
318-
order_rvs_template = DataFrame(map(i->any(isnan.(view(order_ccfs,:,j,i))) ? (rv=NaN, σ_rv=NaN) : measure_rv_from_ccf(v_grid,view(order_ccfs,:,j,i),view(order_ccf_vars,:,j,i),alg=alg_template),1:num_obs))
319+
order_rvs_template = DataFrame(map(i->measure_rv_from_ccf(v_grid,view(order_ccfs,:,j,i),view(order_ccf_vars,:,j,i),alg=alg_template),1:num_obs))
319320
df_out[!,Symbol("rv_" * string(orders_physical[j]) * "_template")] = order_rvs_template.rv
320321
df_out[!,Symbol("σrv_" * string(orders_physical[j]) * "_template")] = order_rvs_template.σ_rv
321322
end

0 commit comments

Comments
 (0)