forked from NatashaBertaina/multimodal-analysis-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lightcurve2.py
178 lines (159 loc) · 6.07 KB
/
lightcurve2.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"""
Created on 2022
@author: sonounoteam (view licence)
"""
# General imports
import pandas as pd
import argparse
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import numpy as np
# Local imports
from data_transform import predef_math_functions as _math
from sound_module.simple_sound import simpleSound
# Instanciate the sonoUno clases needed
_simplesound = simpleSound()
# Sound configurations, predefined at the moment
_simplesound.reproductor.set_continuous()
_simplesound.reproductor.set_waveform('sine') # piano; sine
_simplesound.reproductor.set_time_base(0.03)
_simplesound.reproductor.set_min_freq(380)
_simplesound.reproductor.set_max_freq(800)
parser = argparse.ArgumentParser()
# Receive the directory path from the arguments
parser.add_argument("-d", "--directory", type=str,
help="Indicate a directory to process as batch.")
# Indicate the star type
parser.add_argument("-s", "--star-type", type=str,
help="Indicate the star type to plot (RWPhe, V0748Cep, ZLep, CGCas, HWPup, MNCam)",
choices=['RWPhe', 'V0748Cep', 'ZLep', 'CGCas', 'HWPup', 'MNCam'])
args = parser.parse_args()
path = args.directory
starType = args.star_type
data = pd.read_csv(path)
toplot = data.copy()
# Constantes de algunas estrellas variables
if starType == 'CGCas':
"""https://asas-sn.osu.edu/variables/753bdd73-38a7-5e43-b6c0-063292c7f28d"""
periodo = 4.3652815
t0 = 2457412.70647
BPRP = 0.719
elif starType == 'RWPhe':
"""https://asas-sn.osu.edu/variables/dfa51488-c6b7-5a03-abd4-df3c28273250"""
periodo = 5.4134367
t0 = 2458053.49761
BPRP = 0.586
elif starType == 'V0748Cep':
"""https://asas-sn.osu.edu/variables/dfcbcf52-8a62-542f-9383-1c712d7c042c"""
periodo = 2.5093526
t0 = 2458024.93242
elif starType == 'ZLep':
"""https://asas-sn.osu.edu/variables/70cc7024-5027-52f9-a834-75c51f4a5064"""
periodo = 0.9937068
t0 = 2457699.6236
elif starType == 'MNCam':
"""https://asas-sn.osu.edu/variables/c3faa9d0-6e10-5775-8bb0-075defcd2578"""
periodo = 8.1796049
t0 = 2458046.08639
elif starType == 'HWPup':
"""https://asas-sn.osu.edu/variables/2083f661-73f5-512f-aee5-fd7ad26d5b30"""
periodo = 13.4590914
t0 = 2457786.63153
else:
print('Error en el tipo de estrella.')
toplot['hjd'] = ((data['hjd'] - t0) / periodo)
toplot['hjd'] = (toplot['hjd'] - toplot['hjd'].astype(int))# + BPRP + 1
count = 0
for i in toplot['hjd']:
if i < 0:
toplot.loc[count,'hjd'] = i + 1
count = count + 1
toplot['hjd'] = toplot['hjd'] + BPRP
count = 0
for i in toplot['hjd']:
if i > 1:
toplot.loc[count,'hjd'] = i - 1
count = count + 1
toplotlength = count
for i in toplot['hjd']:
toplot.loc[count,'hjd'] = i + 1
toplot.loc[count, 'camera'] = toplot.loc[count-toplotlength, 'camera']
toplot.loc[count, 'mag'] = toplot.loc[count-toplotlength, 'mag']
toplot.loc[count, 'mag_err'] = toplot.loc[count-toplotlength, 'mag_err']
toplot.loc[count, 'flux'] = toplot.loc[count-toplotlength, 'flux']
toplot.loc[count, 'flux_err'] = toplot.loc[count-toplotlength, 'flux_err']
count = count + 1
groups = toplot.groupby('camera')
if starType == 'CGCas':
bd_toplot = groups.get_group('bd')
bc_toplot = groups.get_group('bc')
elif starType == 'RWPhe':
be_toplot = groups.get_group('be')
bf_toplot = groups.get_group('bf')
else:
print('Error en el tipo de estrella para separar por grupos.')
fig = plt.figure()
ax = plt.axes()
ax.set_xlabel('Phase')
ax.set_ylabel('Mag')
ax.invert_yaxis()
rep = True
def reproduction(camera1, camera2, camera1text, camera2text, wav_path):
alldata = pd.concat([camera1, camera2])
alldata = alldata.sort_values('hjd')
x_norm, y_norm, status, Error = _math.normalize(alldata['hjd'], alldata['mag'])
y_norm = y_norm.reset_index()
if rep:
ordenada = np.array([alldata['mag'].min(), alldata['mag'].max()])
count = 0
value = _simplesound.invert_values_to_sound(y_norm['mag'])
for index, row in alldata.iterrows():
abscisa = np.array([row['hjd'], row['hjd']])
red_line = ax.plot(abscisa, ordenada, 'r')
plt.pause(0.05)
# Make the sound
if row['camera'] == camera1text:
_simplesound.reproductor.set_waveform('sine')
_simplesound.make_sound(value[count])
elif row['camera'] == camera2text:
_simplesound.reproductor.set_waveform('square')
_simplesound.make_sound(value[count])
else:
print('Error en la cámara')
count = count + 1
line = red_line.pop(0)
line.remove()
_simplesound.save_invert_freq_sound(wav_path, alldata['hjd'], y_norm['mag'])
if starType == 'CGCas':
ax.set_title('CG-Cas-Cepheid')
ax.scatter(bd_toplot['hjd'], bd_toplot['mag'], marker='.', c='#CF3476', label='bd')
ax.scatter(bc_toplot['hjd'], bc_toplot['mag'], marker='.', c='#E59866', label='bc')
plot_path = 'data/galaxy-stars/light-curves/Cefeida/CGCas/cepheid_sonouno.png'
wav_path = 'data/galaxy-stars/light-curves/Cefeida/CGCas/cepheid_sonouno.wav'
reproduction(bd_toplot, bc_toplot, 'bd', 'bc', wav_path)
elif starType == 'RWPhe':
ax.set_title('RW-Phe-Eclipsing Binary')
ax.scatter(be_toplot['hjd'], be_toplot['mag'], marker='.', c='k', label='be')
ax.scatter(bf_toplot['hjd'], bf_toplot['mag'], marker='.', c='g', label='bf')
plot_path = 'data/galaxy-stars/light-curves/BEclipsante/RWPhe/eclipsante_sonouno.png'
wav_path = 'data/galaxy-stars/light-curves/BEclipsante/RWPhe/eclipsante_sonouno.wav'
reproduction(be_toplot, bf_toplot, 'be', 'bf', wav_path)
elif starType == 'V0748Cep':
ax.set_title('V0748-Cep-Eclipsing Binary')
elif starType == 'ZLep':
ax.set_title('Z-Lep-Eclipsing Binary')
elif starType == 'MNCam':
ax.set_title('MN-Cam-Cepheid')
elif starType == 'HWPup':
ax.set_title('HW-Pup-Cepheid')
else:
ax.set_title(' ')
ax.legend()
# Save the plot
fig.savefig(plot_path)
if rep:
plt.pause(0.5)
# Showing the above plot
plt.show()
plt.close()