-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_library.py
executable file
·288 lines (193 loc) · 10.4 KB
/
test_library.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/usr/bin/env python
from Feature import FeatureSpace
import numpy as np
from import_lc_cluster import ReadLC_MACHO
from PreprocessLC import Preprocess_LC
from alignLC import Align_LC
import os.path
import tarfile
import sys
import pandas as pd
import pytest
@pytest.fixture
def white_noise():
data = np.random.normal(size=10000)
mjd=np.arange(10000)
error = np.random.normal(loc=0.01, scale =0.8, size=10000)
second_data = np.random.normal(size=10000)
mjd2=np.arange(10000)
error2 = np.random.normal(loc=0.01, scale =0.8, size=10000)
aligned_data = data
aligned_second_data = second_data
aligned_mjd = mjd
lc = np.array([data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd])
return lc
@pytest.fixture
def periodic_lc():
N=100
mjd_periodic = np.arange(N)
Period = 20
cov = np.zeros([N,N])
mean = np.zeros(N)
for i in np.arange(N):
for j in np.arange(N):
cov[i,j] = np.exp( -(np.sin( (np.pi/Period) *(i-j))**2))
data_periodic=np.random.multivariate_normal(mean, cov)
lc = np.array([data_periodic, mjd_periodic])
return lc
@pytest.fixture
def uniform_lc():
mjd_uniform=np.arange(1000000)
data_uniform=np.random.uniform(size=1000000)
lc = np.array([data_uniform, mjd_uniform])
return lc
# def test_Amplitude(white_noise):
# # data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
# a = FeatureSpace(featureList=['Amplitude'])
# a=a.calculateFeature(white_noise[0])
# assert(a.result(method='array') >= 0.043 and a.result(method='array') <= 0.046)
# def test_Autocor(white_noise):
# # data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
# a = FeatureSpace(featureList=['Autocor'] )
# a=a.calculateFeature(white_noise[0])
# assert(a.result(method='array') >= 0.043 and a.result(method='array') <= 0.046)
# def test_Automean(white_noise):
# # data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
# a = FeatureSpace(featureList=['Automean'] , Automean=[0,0])
# a=a.calculateFeature(white_noise[0])
# assert(a.result(method='array') >= 0.043 and a.result(method='array') <= 0.046)
# def test_B_R(white_noise):
# # data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
# a = FeatureSpace(featureList=['B_R'] , B_R=second_data)
# a=a.calculateFeature(white_noise[0])
# assert(a.result(method='array') >= 0.043 and a.result(method='array') <= 0.046)
def test_Beyond1Std(white_noise):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['Beyond1Std'])
a=a.calculateFeature(white_noise)
assert(a.result(method='array') >= 0.30 and a.result(method='array') <= 0.40)
def test_Mean(white_noise):
a = FeatureSpace(featureList=['Mean'])
a=a.calculateFeature(white_noise)
assert(a.result(method='array') >= -0.1 and a.result(method='array') <= 0.1)
# def test_CAR(white_noise):
# # data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
# a = FeatureSpace(featureList=['CAR_sigma', 'CAR_tau', 'CAR_tmean'] , CAR_sigma=[mjd, error])
# a=a.calculateFeature(white_noise[0])
# assert(a.result(method='array') >= 0.043 and a.result(method='array') <= 0.046)
def test_Con(white_noise):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['Con'] , Con=1)
a=a.calculateFeature(white_noise)
assert(a.result(method='array') >= 0.04 and a.result(method='array') <= 0.05)
def test_Eta_color(white_noise):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['Eta_color'])
a=a.calculateFeature(white_noise)
assert(a.result(method='array') >= 1.9 and a.result(method='array') <= 2.1)
def test_Eta_e(white_noise):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['Eta_e'])
a=a.calculateFeature(white_noise)
assert(a.result(method='array') >= 1.9 and a.result(method='array') <= 2.1)
def test_FluxPercentile(white_noise):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['FluxPercentileRatioMid20','FluxPercentileRatioMid35','FluxPercentileRatioMid50','FluxPercentileRatioMid65','FluxPercentileRatioMid80'] )
a=a.calculateFeature(white_noise)
assert(a.result(method='array')[0] >= 0.145 and a.result(method='array')[0] <= 0.160)
assert(a.result(method='array')[1] >= 0.260 and a.result(method='array')[1] <= 0.290)
assert(a.result(method='array')[2] >= 0.350 and a.result(method='array')[2] <= 0.450)
assert(a.result(method='array')[3] >= 0.540 and a.result(method='array')[3] <= 0.580)
assert(a.result(method='array')[4] >= 0.760 and a.result(method='array')[4] <= 0.800)
def test_LinearTrend(white_noise):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['LinearTrend'])
a=a.calculateFeature(white_noise)
assert(a.result(method='array') >= -0.1 and a.result(method='array') <= 0.1)
# def test_MaxSlope(white_noise):
# # data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
# a = FeatureSpace(featureList=['MaxSlope'] , MaxSlope=mjd)
# a=a.calculateFeature(white_noise[0])
# assert(a.result(method='array') >= 0.043 and a.result(method='array') <= 0.046)
def test_Meanvariance(uniform_lc):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['Meanvariance'])
a=a.calculateFeature(uniform_lc)
assert(a.result(method='array') >= 0.575 and a.result(method='array') <= 0.580)
def test_MedianAbsDev(white_noise):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['MedianAbsDev'])
a=a.calculateFeature(white_noise)
assert(a.result(method='array') >= 0.630 and a.result(method='array') <= 0.700)
# def test_MedianBRP(white_noise):
# # data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
# a = FeatureSpace(featureList=['MedianBRP'] , MaxSlope=mjd)
# a=a.calculateFeature(white_noise[0])
# assert(a.result(method='array') >= 0.043 and a.result(method='array') <= 0.046)
def test_PairSlopeTrend(white_noise):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['PairSlopeTrend'])
a=a.calculateFeature(white_noise)
assert(a.result(method='array') >= -0.25 and a.result(method='array') <= 0.25)
# def test_PercentAmplitude(white_noise):
# # data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
# a = FeatureSpace(featureList=['PercentAmplitude'])
# a=a.calculateFeature(white_noise[0])
# assert(a.result(method='array') >= 0.043 and a.result(method='array') <= 0.046)
# def test_PercentDifferenceFluxPercentile(white_noise):
# # data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
# a = FeatureSpace(featureList=['PercentDifferenceFluxPercentile'])
# a=a.calculateFeature(white_noise[0])
# assert(a.result(method='array') >= 0.043 and a.result(method='array') <= 0.046)
def test_Period_Psi(periodic_lc):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['PeriodLS', 'Period_fit','Psi_CS','Psi_eta'])
a=a.calculateFeature(periodic_lc)
# print a.result(method='array'), len(periodic_lc[0])
assert(a.result(method='array')[0] >= 19 and a.result(method='array')[0] <= 21)
def test_Q31(white_noise):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['Q31'])
a=a.calculateFeature(white_noise)
assert(a.result(method='array') >= 1.30 and a.result(method='array') <= 1.38)
# def test_Q31B_R(white_noise):
# # data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
# a = FeatureSpace(featureList=['Q31B_R'], Q31B_R = [aligned_second_data, aligned_data])
# a=a.calculateFeature(white_noise[0])
def test_Rcs(white_noise):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['Rcs'])
a=a.calculateFeature(white_noise)
assert(a.result(method='array') >= 0 and a.result(method='array') <= 0.1)
def test_Skew(white_noise):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['Skew'])
a=a.calculateFeature(white_noise)
assert(a.result(method='array') >= -0.1 and a.result(method='array') <= 0.1)
# def test_SlottedA(white_noise):
# # data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
# a = FeatureSpace(featureList=['SlottedA'], SlottedA = [mjd, 1])
# a=a.calculateFeature(white_noise[0])
def test_SmallKurtosis(white_noise):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['SmallKurtosis'])
a=a.calculateFeature(white_noise)
assert(a.result(method='array') >= -0.2 and a.result(method='array') <= 0.2)
def test_Std(white_noise):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['Std'])
a=a.calculateFeature(white_noise)
assert(a.result(method='array') >= 0.9 and a.result(method='array') <= 1.1)
def test_Stetson(white_noise):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['SlottedA_length','StetsonK', 'StetsonK_AC', 'StetsonJ', 'StetsonL'])
a=a.calculateFeature(white_noise)
assert(a.result(method='array')[1] >= 0.790 and a.result(method='array')[1] <= 0.85)
assert(a.result(method='array')[2] >= 0.20 and a.result(method='array')[2] <= 0.45)
assert(a.result(method='array')[3] >= -0.1 and a.result(method='array')[3] <= 0.1)
assert(a.result(method='array')[4] >= -0.1 and a.result(method='array')[4] <= 0.1)
def test_Gskew(white_noise):
# data, mjd, error, second_data, aligned_data, aligned_second_data, aligned_mjd = white_noise()
a = FeatureSpace(featureList=['Gskew'])
a=a.calculateFeature(white_noise)
assert(a.result(method='array') >= -0.2 and a.result(method='array') <= 0.2)