-
Notifications
You must be signed in to change notification settings - Fork 3
/
process_object.py
executable file
·59 lines (46 loc) · 1.33 KB
/
process_object.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
#!/usr/bin/env python
import argparse
import sys
import json
import pickle
import traceback
import numpy as np
from curve_fit import fitcurve
from matplotlib.mlab import PCA
def loadMagData(mag, phase):
magPeak = 100
phasePeak = -1
for i in range(len(mag)):
if mag[i] < magPeak:
magPeak = mag[i]
phasePeak = phase[i]
magScaled = mag - np.mean(mag)
shift = phasePeak - 0.3
for i in range(len(phase)):
phase[i] = phase[i] - shift
if phase[i] > 1:
phase[i] = phase[i] - 1
elif phase[i] < 0:
phase[i] = phase[i] + 1
mag_phase_scaled = {}
for i in range(len(mag)):
mag_phase_scaled[phase[i]] = magScaled[i]
sort_data = sorted(mag_phase_scaled.items())
result_mag = []
for i in sort_data:
result_mag.append(i[1])
row_length = 50
for i in range(row_length - len(result_mag)):
result_mag.append(result_mag[0])
return result_mag
def project(lc, p):
lcdata = lc
period = p
sampled = fitcurve(lcdata, period)
shifted_mag = loadMagData(sampled[0]['mag'], sampled[0]['phase'])
with open('./static/data_ogle/pca_model.dat', 'rb') as f:
pca_result = pickle.load(f)
result = pca_result.project(shifted_mag)
pos = {'x':result[0], 'y':result[1]}
f.close()
return pos