-
Notifications
You must be signed in to change notification settings - Fork 10
/
exonailer.py
70 lines (58 loc) · 2.65 KB
/
exonailer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
import sys
sys.path.append('utilities')
import os
import data_utils
import general_utils
import numpy as np
################# OPTIONS ######################
options = general_utils.read_input_parameters()
################################################
# ---------- DATA PRE-PROCESSING ------------- #
# First, get the transit and RV data:
t_tr,f,f_err,transit_instruments,t_rv,rv,rv_err,rv_instruments = general_utils.read_data(options)
# Sort transit data if there is any:
# Initialize the parameters:
parameters = general_utils.read_priors(options['TARGET'],options['MODE'])
# Pre-process the transit data if available:
if options['MODE'] != 'rvs':
t_tr,phases,f, f_err,transit_instruments = data_utils.pre_process(t_tr,f,f_err,options,transit_instruments,parameters)
idx = np.argsort(t_tr)
t_tr = t_tr[idx]
f = f[idx]
f_err = f_err[idx]
phases = phases[idx]
transit_instruments = transit_instruments[idx]
idx_resampling = {}
for instrument in options['photometry'].keys():
idx = np.where(transit_instruments==instrument)[0]
if options['photometry'][instrument]['RESAMPLING']:
# Define indexes between which data will be resampled:
idx_resampling[instrument] = np.where((phases[idx]>-options['photometry'][instrument]['PHASE_MAX_RESAMPLING'])&\
(phases[idx]<options['photometry'][instrument]['PHASE_MAX_RESAMPLING']))[0]
else:
idx_resampling[instrument] = []
else:
idx_resampling = []
# Create results folder if not already created:
if not os.path.exists('results'):
os.mkdir('results')
mode = options['MODE']
target = options['TARGET']
fname = target+'_'+mode+'_'
if options['MODE'] != 'rvs':
for instrument in options['photometry'].keys():
fname = fname + instrument +'_'+options['photometry'][instrument]['PHOT_NOISE_MODEL']+\
'_'+options['photometry'][instrument]['LD_LAW']+'_'
out_dir = 'results/'+fname[:-1]+'/'
# If chains not ran, run the MCMC and save results:
if not os.path.exists(out_dir):
print '\t Starting MCMC...'
data_utils.exonailer_mcmc_fit(t_tr, f, f_err, transit_instruments, t_rv, rv, rv_err, rv_instruments,\
parameters, idx_resampling, options)
general_utils.save_results(target,options,parameters)
else:
parameters = general_utils.read_results(target,options,transit_instruments,rv_instruments)
if options['MODE'] != 'transit_noise':
data_utils.plot_transit_and_rv(t_tr, f, f_err, transit_instruments, t_rv, rv, rv_err, rv_instruments,\
parameters, idx_resampling, options)