Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/dr25_gaia_fgk/abc_setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function setup(prior_choice::String, bin_size_factor::Float64)
println("# Finished reading in KOI data")
df_star = setup_star_table_dr25(sim_param_closure)
println("# Finished reading in stellar data")
cat_obs = setup_actual_planet_candidate_catalog(df_star, df_koi, usable_koi, sim_param_closure)
cat_obs = setup_actual_pc_catalog_kepler(df_star, df_koi, usable_koi, sim_param_closure)
println("# Finished setting up true catalog")
###

Expand Down Expand Up @@ -199,7 +199,7 @@ function setup_abc(num_dist::Integer = 0; prior_choice::String = "uniform", bin_

calc_distance_ltd(sum_stat_obs::ExoplanetsSysSim.CatalogSummaryStatistics,sum_stat_sim::ExoplanetsSysSim.CatalogSummaryStatistics) = EvalSysSimModel.calc_distance(sum_stat_obs,sum_stat_sim,num_dist)

global abc_plan = ABC.abc_pmc_plan_type(EvalSysSimModel.gen_data,EvalSysSimModel.calc_summary_stats, calc_distance_ltd, param_prior, make_proposal_dist=make_proposal_dist_multidim_beta, is_valid=EvalSysSimModel.is_valid_uniform, num_part=100, num_max_attempt=200, num_max_times=15, epsilon_init=9.9e99, target_epsilon=1.0e-100, in_parallel=in_parallel, adaptive_quantiles = false, epsilon_reduction_factor=0.9, tau_factor=1.5);
global abc_plan = ABC.abc_pmc_plan_type(EvalSysSimModel.gen_data,EvalSysSimModel.calc_summary_stats, calc_distance_ltd, param_prior, make_proposal_dist=make_proposal_dist_multidim_beta, is_valid=EvalSysSimModel.is_valid_uniform, num_part=200, num_max_attempt=200, num_max_times=15, epsilon_init=9.9e99, target_epsilon=1.0e-100, in_parallel=in_parallel, adaptive_quantiles = false, epsilon_reduction_factor=0.9, tau_factor=1.5);

if prior_choice == "dirichlet" && r_dim > 1
abc_plan.make_proposal_dist = make_proposal_dist_multidim_beta_dirichlet
Expand Down
95 changes: 52 additions & 43 deletions examples/dr25_gaia_fgk/dr25_binrates_func.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ function set_test_param(sim_param_closure::SimParam)
@assert (typeof(stellar_catalog) == String)
add_param_fixed(sim_param_closure,"stellar_catalog",stellar_catalog)
end
if @isdefinedlocal(koi_catalog)
@assert (typeof(koi_catalog) == String)
add_param_fixed(sim_param_closure,"koi_catalog",koi_catalog)
if @isdefinedlocal(planetary_catalog)
@assert (typeof(planetary_catalog) == String)
add_param_fixed(sim_param_closure,"planetary_catalog",planetary_catalog)
end

if @isdefinedlocal(num_targ_sim)
Expand Down Expand Up @@ -120,9 +120,9 @@ function set_test_param_total(sim_param_closure::SimParam)
@assert (typeof(stellar_catalog) == String)
add_param_fixed(sim_param_closure,"stellar_catalog",stellar_catalog)
end
if @isdefinedlocal(koi_catalog)
@assert (typeof(koi_catalog) == String)
add_param_fixed(sim_param_closure,"koi_catalog",koi_catalog)
if @isdefinedlocal(planetary_catalog)
@assert (typeof(planetary_catalog) == String)
add_param_fixed(sim_param_closure,"planetary_catalog",planetary_catalog)
end

if @isdefinedlocal(num_targ_sim)
Expand Down Expand Up @@ -465,7 +465,7 @@ function setup_dr25(filename::String; force_reread::Bool = false)
if occursin(r".jld2$",filename)
try
data = load(filename)
df = data["stellar_catalog"]
df = data["q1q17"]
#usable::Array{Int64,1} = data["stellar_catalog_usable"]
Core.typeassert(df,DataFrame)
StellarTable.set_star_table(df)
Expand Down Expand Up @@ -524,7 +524,7 @@ function setup_dr25(filename::String; force_reread::Bool = false)
df = tmp_df
mast_df = CSV.read(convert(String,joinpath(abspath(joinpath(dirname(Base.find_package("ExoplanetsSysSim")),"..")), "data", "KeplerMAST_TargetProperties.csv")))
delete!(mast_df, [~(x in [:kepid, :contam]) for x in names(mast_df)])
df = join(df, mast_df, on=:kepid)
df = innerjoin(df, mast_df, on=kepid, makeunique=false, validate=(false,false))
StellarTable.set_star_table(df)
end
println("# Removing stars observed <5 quarters.")
Expand Down Expand Up @@ -827,50 +827,59 @@ function cnt_np_bin(cat_obs::KeplerObsCatalog, param::SimParam, verbose::Bool =

pbin = findfirst(x -> ((pper > limitP[x]) && (pper < limitP[x+1])), collect(1:(length(limitP)-1)))
rbin = findfirst(x -> ((prad > limitRp[x]) && (prad < limitRp[x+1])), collect(1:(length(limitRp)-1)))
if (pbin > 0 && rbin > 0)
cnt_bin[(pbin-1)*(length(limitRp)-1) + rbin] += 1
pgeo = ExoplanetsSysSim.calc_transit_prob_single_planet_approx(pper, cat_obs.target[i].star.radius, cat_obs.target[i].star.mass)
pdet = 0.0
for star_id in 1:num_targ

if !(isnothing(pbin) || isnothing(rbin))
if (pbin > 0 && rbin > 0)
cnt_bin[(pbin-1)*(length(limitRp)-1) + rbin] += 1
pgeo = ExoplanetsSysSim.calc_transit_prob_single_planet_approx(pper, cat_obs.target[i].star.radius, cat_obs.target[i].star.mass)
pdet = 0.0
for star_id in 1:num_targ
ld = ExoplanetsSysSim.LimbDarkeningParam4thOrder(ExoplanetsSysSim.StellarTable.star_table(star_id,:limbdark_coeff1), ExoplanetsSysSim.StellarTable.star_table(star_id,:limbdark_coeff2), ExoplanetsSysSim.StellarTable.star_table(star_id,:limbdark_coeff3), ExoplanetsSysSim.StellarTable.star_table(star_id,:limbdark_coeff4) )
star = SingleStar(ExoplanetsSysSim.StellarTable.star_table(star_id,:radius),ExoplanetsSysSim.StellarTable.star_table(star_id,:mass),1.0, ld, star_id)
cdpp_arr = ExoplanetsSysSim.make_cdpp_array_empty(star_id)#(1.0e-6*sqrt(1.0 / 24.0 / ExoplanetsSysSim.LC_duration)) .* [ExoplanetsSysSim.StellarTable.star_table(star_id, :rrmscdpp01p5)*sqrt(1.5), ExoplanetsSysSim.StellarTable.star_table(star_id, :rrmscdpp02p0)*sqrt(2.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp02p5)*sqrt(2.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp03p0)*sqrt(3.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp03p5)*sqrt(3.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp04p5)*sqrt(4.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp05p0)*sqrt(5.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp06p0)*sqrt(6.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp07p5)*sqrt(7.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp09p0)*sqrt(9.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp10p5)*sqrt(10.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp12p0)*sqrt(12.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp12p5)*sqrt(12.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp15p0)*sqrt(15.)]
#cdpp = 1.0e-6 * ExoplanetsSysSim.StellarTable.star_table(star_id, :rrmscdpp04p5) * sqrt(4.5/24.0 / ExoplanetsSysSim.LC_duration )
contam = 0.0
data_span = ExoplanetsSysSim.StellarTable.star_table(star_id, :dataspan)
duty_cycle = ExoplanetsSysSim.StellarTable.star_table(star_id, :dutycycle)
pl_arr = Array{Planet}(undef,1)
orbit_arr = Array{Orbit}(undef,1)
star = SingleStar(ExoplanetsSysSim.StellarTable.star_table(star_id,:radius),ExoplanetsSysSim.StellarTable.star_table(star_id,:mass),1.0, ld, star_id)
cdpp_arr = ExoplanetsSysSim.make_cdpp_array_empty(star_id)#(1.0e-6*sqrt(1.0 / 24.0 / ExoplanetsSysSim.kepler_LC_duration)) .* [ExoplanetsSysSim.StellarTable.star_table(star_id, :rrmscdpp01p5)*sqrt(1.5), ExoplanetsSysSim.StellarTable.star_table(star_id, :rrmscdpp02p0)*sqrt(2.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp02p5)*sqrt(2.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp03p0)*sqrt(3.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp03p5)*sqrt(3.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp04p5)*sqrt(4.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp05p0)*sqrt(5.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp06p0)*sqrt(6.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp07p5)*sqrt(7.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp09p0)*sqrt(9.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp10p5)*sqrt(10.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp12p0)*sqrt(12.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp12p5)*sqrt(12.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp15p0)*sqrt(15.)]
#cdpp = 1.0e-6 * ExoplanetsSysSim.StellarTable.star_table(star_id, :rrmscdpp04p5) * sqrt(4.5/24.0 / ExoplanetsSysSim.kepler_LC_duration )
contam = 0.0
data_span = ExoplanetsSysSim.StellarTable.star_table(star_id, :dataspan)
duty_cycle = ExoplanetsSysSim.StellarTable.star_table(star_id, :dutycycle)
pl_arr = Array{Planet}(undef,1)
orbit_arr = Array{Orbit}(undef,1)
incl = acos(Base.rand()*star.radius*ExoplanetsSysSim.rsol_in_au/ExoplanetsSysSim.semimajor_axis(pper, star.mass))
orbit_arr[1] = Orbit(pper, 0., incl, 0., 0., Base.rand()*2.0*pi)
pl_arr[1] = Planet(prad, 1.0e-6)
orbit_arr[1] = Orbit(pper, 0., incl, 0., 0., Base.rand()*2.0*pi)
pl_arr[1] = Planet(prad, 1.0e-6)
if ExoplanetsSysSim.StellarTable.star_table_has_key(:wf_id)
wf_id = ExoplanetsSysSim.StellarTable.star_table(star_id,:wf_id)
else
wf_id = ExoplanetsSysSim.WindowFunction.get_window_function_id(ExoplanetsSysSim.StellarTable.star_table(star_id,:kepid))
end # if star_table_has_key
kep_targ = KeplerTarget([PlanetarySystem(star, pl_arr, orbit_arr)], repeat(cdpp_arr, outer=[1,1]),contam,data_span,duty_cycle,wf_id)

duration = ExoplanetsSysSim.calc_transit_duration(kep_targ,1,1)
if duration <= 0.
continue
end
kep_targ = KeplerTarget([PlanetarySystem(star, pl_arr, orbit_arr)], repeat(cdpp_arr, outer=[1,1]),contam,data_span,duty_cycle,wf_id)

duration = ExoplanetsSysSim.calc_transit_duration(kep_targ,1,1)
if duration <= 0.
continue
end
ntr = ExoplanetsSysSim.calc_expected_num_transits(kep_targ, 1, 1, param)
depth = ExoplanetsSysSim.calc_transit_depth(kep_targ,1,1)

ntr = ExoplanetsSysSim.calc_expected_num_transits(kep_targ, 1, 1, param)
depth = ExoplanetsSysSim.calc_transit_depth(kep_targ,1,1)
cdpp = ExoplanetsSysSim.interpolate_cdpp_to_duration_lookup_cdpp(kep_targ, duration)
#cdpp = ExoplanetsSysSim.interpolate_cdpp_to_duration(kep_targ, duration)
snr = ExoplanetsSysSim.calc_snr_if_transit_cdpp(kep_targ, depth, duration, cdpp, param, num_transit=ntr)
pdet += ExoplanetsSysSim.calc_prob_detect_if_transit(kep_targ, snr, pper, duration, param, num_transit=ntr)
end
np_bin[(pbin-1)*(length(limitRp)-1) + rbin] += 1.0/pgeo/(pdet/num_targ)
if verbose
println("Planet ",pl_idx," => Bin ", (pbin-1)*(length(limitRp)-1) + rbin, ", C = ", 1.0/pgeo/(pdet/num_targ))
end
pl_idx += 1
end
end
end
return cnt_bin, np_bin
pdet += ExoplanetsSysSim.calc_prob_detect_if_transit(kep_targ, snr, pper, duration, param, num_transit=ntr)
end # for
np_bin[(pbin-1)*(length(limitRp)-1) + rbin] += 1.0/pgeo/(pdet/num_targ)
if verbose
println("Planet ",pl_idx," => Bin ", (pbin-1)*(length(limitRp)-1) + rbin, ", C = ", 1.0/pgeo/(pdet/num_targ))
end
pl_idx += 1
else
pl_idx += 1
if verbose
println("Skipping planet ", pl_idx, ": out of bounds")
end # if verbose
end # if bins > 0
end # !isnothing
end # for j
end # for i
return cnt_bin, np_bin
end

## stellar catalog ess (simple bayesian)
Expand All @@ -887,7 +896,7 @@ function stellar_ess(param::SimParam, verbose::Bool = true)
for star_id in 1:num_targ
ld = ExoplanetsSysSim.LimbDarkeningParam4thOrder(ExoplanetsSysSim.StellarTable.star_table(star_id,:limbdark_coeff1), ExoplanetsSysSim.StellarTable.star_table(star_id,:limbdark_coeff2), ExoplanetsSysSim.StellarTable.star_table(star_id,:limbdark_coeff3), ExoplanetsSysSim.StellarTable.star_table(star_id,:limbdark_coeff4) )
star = SingleStar(ExoplanetsSysSim.StellarTable.star_table(star_id,:radius),ExoplanetsSysSim.StellarTable.star_table(star_id,:mass),1.0, ld, star_id)
cdpp_arr = ExoplanetsSysSim.make_cdpp_array_empty(star_id)#(1.0e-6*sqrt(1.0/24.0/ExoplanetsSysSim.LC_duration)) .* [ExoplanetsSysSim.StellarTable.star_table(star_id, :rrmscdpp01p5)*sqrt(1.5), ExoplanetsSysSim.StellarTable.star_table(star_id, :rrmscdpp02p0)*sqrt(2.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp02p5)*sqrt(2.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp03p0)*sqrt(3.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp03p5)*sqrt(3.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp04p5)*sqrt(4.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp05p0)*sqrt(5.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp06p0)*sqrt(6.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp07p5)*sqrt(7.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp09p0)*sqrt(9.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp10p5)*sqrt(10.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp12p0)*sqrt(12.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp12p5)*sqrt(12.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp15p0)*sqrt(15.)]
cdpp_arr = ExoplanetsSysSim.make_cdpp_array_empty(star_id)#(1.0e-6*sqrt(1.0/24.0/ExoplanetsSysSim.kepler_LC_duration)) .* [ExoplanetsSysSim.StellarTable.star_table(star_id, :rrmscdpp01p5)*sqrt(1.5), ExoplanetsSysSim.StellarTable.star_table(star_id, :rrmscdpp02p0)*sqrt(2.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp02p5)*sqrt(2.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp03p0)*sqrt(3.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp03p5)*sqrt(3.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp04p5)*sqrt(4.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp05p0)*sqrt(5.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp06p0)*sqrt(6.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp07p5)*sqrt(7.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp09p0)*sqrt(9.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp10p5)*sqrt(10.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp12p0)*sqrt(12.), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp12p5)*sqrt(12.5), ExoplanetsSysSim.StellarTable.star_table(star_id,:rrmscdpp15p0)*sqrt(15.)]
contam = 0.0
data_span = ExoplanetsSysSim.StellarTable.star_table(star_id, :dataspan)
duty_cycle = ExoplanetsSysSim.StellarTable.star_table(star_id, :dutycycle)
Expand Down
2 changes: 1 addition & 1 deletion examples/dr25_gaia_fgk/invdet_calc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ df_koi,usable_koi = read_koi_catalog(sim_param_closure)
println("# Finished reading in KOI data")
df_star = setup_star_table_dr25(sim_param_closure)
println("# Finished reading in stellar data")
cat_obs = setup_actual_planet_candidate_catalog(df_star, df_koi, usable_koi, sim_param_closure)
cat_obs = setup_actual_pc_catalog_kepler(df_star, df_koi, usable_koi, sim_param_closure)

#@time inv_det_simp_bayes(cat_obs, sim_param_closure)
@time simp_bayes(cat_obs, sim_param_closure)
18 changes: 9 additions & 9 deletions examples/dr25_gaia_fgk/param.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

#stellar_catalog = "q1_q16_christiansen.jld" # data file for stellar catalog [DEFAULT = "q1_q16_christiansen.jld"]
stellar_catalog = "q1q17_dr25_gaia_fgk.jld2"
#koi_catalog = "q1_q16_koi_cand.csv" # data file for KOI catalog [NO DEFAULT VALUE]
koi_catalog = "q1_q17_dr25_koi.csv"
osd_file = "inputs\\dr25fgk_relaxcut_osds.jld2"
#planetary_catalog = "q1_q16_koi_cand.csv" # data file for KOI catalog [NO DEFAULT VALUE]
planetary_catalog = "q1_q17_dr25_koi.csv"
osd_file = "inputs/dr25fgk_relaxcut_osds.jld2"

num_targ_sim = 1000 # number of planetary systems in simulated catalogs
num_targ_sim = 1000 # number of planetary systems in simulated catalogs
# [DEFAULT = same size as observed catalog]

p_bin_lim = [237., 500.] # bin boundaries for orbital period (days) [NO DEFAULT VALUE]
r_bin_lim = [0.5, 0.75, 1., 1.25, 1.5, 1.75] # bin boundaries for planet radius (R_earth) [NO DEFAULT VALUE]
#p_bin_lim = [0.5, 1., 2., 4., 8., 16., 32., 64., 128., 256., 500.]
#r_bin_lim = [0.5, 0.75, 1., 1.25, 1.5, 1.75, 2., 2.5, 3., 4., 6., 8., 12., 16.]
#p_bin_lim = [237., 500.] # bin boundaries for orbital period (days) [NO DEFAULT VALUE]
#r_bin_lim = [0.5, 0.75, 1., 1.25, 1.5, 1.75] # bin boundaries for planet radius (R_earth) [NO DEFAULT VALUE]
p_bin_lim = [0.1, 0.5, 1., 2., 4., 8., 16., 32., 64., 128., 256., 500.]
r_bin_lim = [0.1, 0.5, 0.75, 1., 1.25, 1.5, 1.75, 2., 2.5, 3., 4., 6., 8., 12., 16., 20.]

#rate_init = 1.0 # initial guess for occurrence rates (percent) [DEFAULT = 1.0 for all bins]
# can be single rate (applied to all bins) or array of rates
# can be single rate (applied to all bins) or array of rates
# (axis 1 = radius; axis 2 = period)
# (1D array reshaped along increasing radius first, then period)
2 changes: 1 addition & 1 deletion examples/dr25_gaia_m/abc_setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function setup(prior_choice::String, bin_size_factor::Float64)
println("# Finished reading in KOI data")
df_star = setup_star_table_dr25(sim_param_closure)
println("# Finished reading in stellar data")
cat_obs = setup_actual_planet_candidate_catalog(df_star, df_koi, usable_koi, sim_param_closure)
cat_obs = setup_actual_pc_catalog_kepler(df_star, df_koi, usable_koi, sim_param_closure)
println("# Finished setting up true catalog")
###

Expand Down
Loading