-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
124 lines (97 loc) · 5.33 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
### File: ./main.py
from lvtlaw.utils import colors,data_dir, data_file, data_out, disg, disi
import pandas as pd
from lvtlaw.pl_pw import pl_reg #pl_reg(data,'_g','_i') -> PLW, residue, prediction
from lvtlaw.data_transform import transformation, extinction_law
from lvtlaw.residue import residue_analysis
from lvtlaw.error_estimation import all_bands_reddening, find_rms, error_correction, find_error_pair
import os
clear_screen= lambda: os.system('clear')
clear_screen()
print('Master Thesis Project: Calibration of Galactic Leavitt Law by determining distance and reddening errors of individual Cepheid \n Author: Shubham Mamgain (smamgain@aip.de) \n Supervisor II: Dr. Jesper Storm \n Supervisor I: Prof. Dr. Maria Rosa Cioni \n ')
input(' To start the analysis, store the cleaned_data.csv file in ./data/input/ directory. \n Press enter to continue')
print('###'*30)
#####################################################################################################
cleaned_data = pd.read_csv(data_dir+data_file)
x = cleaned_data[['plx','RA_ICRS', 'DE_ICRS']]
print(x.head())
input('sdf')
print(' \n Data Loaded from: \t', data_dir+data_file)
print( cleaned_data.info())
input('\n \n Raw data will be transformed into absolute magnitude and weseheit magnitude using the extinction law.')
print('###'*30)
extinction_law()
input(' \n These values will be multiplied with E(B-V) values to calculate extinction in each band for individual Cepheid toward the respective line-of-sight.')
print('###'*30)
#####################################################################################################
name=cleaned_data['ID']
absolute, extinction, true_absolute, wesenheit = transformation(cleaned_data)
absolute.to_csv(data_out+str(len(absolute))+ '_abs_data'+'.csv')
extinction.to_csv(data_out+ str(len(extinction))+ '_ext_data'+'.csv')
true_absolute.to_csv(data_out+str(len(true_absolute))+ '_true_abs_data'+'.csv')
wesenheit.to_csv(data_out+str(len(wesenheit))+ '_wes_data'+'.csv')
print('Calculated absolute magnitude: \n', absolute.head())
print('Calculated true-Absolute magnitude: \n', true_absolute.head())
print('Calculated Wesenheit magnitude: \n', wesenheit.head())
input(' \n Using these results the raw PL, PL_0 and PW relations can be deduced. \n')
print('###'*30)
#####################################################################################################
#v_plt('Raw_data', data,ap_bands, 1, disg='', disi='')
#v_plt('absolute_data', abs_data, bands, 1)
#v_plt('extinction_data', ext_data, bands, 1, disg='', disi='')
#v_plt('true_absolute_data', tabs_data, bands, 1, disg = '0_g', disi='0_i')
#####################################################################################################
merg1= pd.merge(absolute, true_absolute, on="logP")
prepared_regression_data = pd.merge(merg1, wesenheit, on = 'logP')
prepared_regression_data['name'] = name
prepared_regression_data.to_csv(data_out+str(len(prepared_regression_data))+ '_prepared_PLdata'+'.csv')
print(prepared_regression_data.head())
input('\n This prepared dataset will be used for deriving PL and PW relations with their respective residues \n')
print('###'*30)
#####################################################################################################
PLW, residue, prediction= pl_reg(prepared_regression_data)
input('\n Press enter to see the PL and PW relation data \n')
print('###'*30)
residue.to_csv('%s%i_residue.csv'%(data_out,len(residue)))
prediction.to_csv('%s%i_prediction.csv'%(data_out,len(prediction)))
PLW.to_csv('./%s%i_regression.csv'%(data_out,len(PLW)))
for i in range(0,17):
print('\n \t %i \t Relation Slope, intercept, respective error in Gaia (g) and IRSB (i) cases \n '%(i), PLW[i*6:6*i+6])
input('\n Model Residues: \n')
print('###'*30)
print(residue.head())
#####################################################################################################
input('\n'*3 + 'Following begins the residual analysis'+ '\n')
print('###'*30)
dres , dpre, del_mc, dres_M, dpre_M, del_mc_M = residue_analysis(residue,colors,s=1)
input('See residue')
print('###'*30)
print('My approach \n', dres.head())
print(del_mc.head())
input('see Madore approach')
print('###'*30)
print('Madore Approach \n', dres_M.head())
print(del_mc_M.head())
input(' \n \n Press Enter to decouple distance reddening error')
print('###'*30)
####################################################################################################
del_mu, red_g, red_i = all_bands_reddening(data = residue ,slope_data=del_mc)
rms_df_g, avg_EBV_g = find_rms(residue.name, red_g, del_mu)
rms_df_i, avg_EBV_i = find_rms(residue.name, red_i, del_mu)
rms_df_g.to_csv('%s%i_rms_g.csv'%(data_out,len(rms_df_g)))
rms_df_i.to_csv('%s%i_rms_i.csv'%(data_out,len(rms_df_i)))
print('\n',rms_df_g)
print('\n',rms_df_i)
errorpair_g = find_error_pair(rms_df_g, avg_EBV_g)
errorpair_i = find_error_pair(rms_df_i, avg_EBV_i)
print('\n',errorpair_g)
print('\n',errorpair_i)
errorpair_g.to_csv('%s%i_errorpair_g.csv'%(data_out,len(errorpair_g)))
errorpair_i.to_csv('%s%i_errorpair_i.csv'%(data_out,len(errorpair_i)))
result_g = error_correction(errorpair_g, absolute, disg)
result_i = error_correction(errorpair_i, absolute, disi)
result_g.to_csv('%s%i_result_g.csv'%(data_out,len(result_g)))
result_i.to_csv('%s%i_result_i.csv'%(data_out,len(result_i)))
print('\n',result_g)
print('\n',result_i)
input('Enter to exit!!')