Skip to content

Commit cf6a986

Browse files
committed
fixed tests
1 parent 16a0486 commit cf6a986

File tree

2 files changed

+37
-56
lines changed

2 files changed

+37
-56
lines changed

tests/test_basic.py

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333
for i, t_c in enumerate(t_component):
3434
p[i] = s_component * t_c
3535

36-
# Let's take a look at the dimension of our data
37-
# to make sure it is compatible with pyspod
38-
print('p.shape = ', p.shape)
39-
4036
# Let's define the required parameters into a dictionary
4137
params = dict()
4238

@@ -58,7 +54,7 @@
5854
params['n_modes_save'] = 3 # modes to be saved
5955
params['normvar' ] = False # normalize data by data variance
6056
params['conf_level' ] = 0.95 # calculate confidence level
61-
params['savefft' ] = True # save FFT blocks to reuse them in the future (saves time)
57+
params['savefft' ] = False # save FFT blocks to reuse them in the future (saves time)
6258

6359

6460

@@ -68,7 +64,7 @@ def test_basic_spod_low_storage():
6864
# Initialize libraries for the low_storage algorithm
6965
spod_ls = SPOD_low_storage(p, params=params, data_handler=False, variables=['p'])
7066
spod_ls.fit()
71-
67+
7268
# Let's plot the data
7369
spod_ls.plot_2D_data(time_idx=[1,2], filename='tmp.png')
7470
spod_ls.plot_data_tracers(coords_list=[(5,2.5)], time_limits=[0,t.shape[0]], filename='tmp.png')
@@ -77,13 +73,13 @@ def test_basic_spod_low_storage():
7773
bashCmd = ["ffmpeg", " --version"]
7874
sbp = subprocess.Popen(bashCmd, stdin=subprocess.PIPE)
7975
spod_ls.generate_2D_data_video(
80-
sampling=10,
81-
time_limits=[0,t.shape[0]],
76+
sampling=10,
77+
time_limits=[0,t.shape[0]],
8278
filename='video.mp4')
8379
except:
84-
print('[test_basic_file_spod_low_storage]: ',
80+
print('[test_basic_file_spod_low_storage]: ',
8581
'Skipping video making as `ffmpeg` not present.')
86-
82+
8783
# Show results
8884
T_approx = 10 # approximate period = 10 days (in days)
8985
freq = spod_ls.freq
@@ -100,15 +96,15 @@ def test_basic_spod_low_storage():
10096
modes_idx=[0,1],
10197
vars_idx=[0],
10298
filename='tmp.png')
103-
104-
10599

106-
@pytest.mark.order2
107-
def test_basic_spod_low_ram():
100+
101+
102+
@pytest.mark.order2
103+
def test_basic_spod_low_ram():
108104
# Let's try the low_ram algorithm
109105
spod_ram = SPOD_low_ram(p, params=params, data_handler=False, variables=['p'])
110106
spod_ram.fit()
111-
107+
112108
# Show results
113109
T_approx = 10 # approximate period = 10 days (in days)
114110
freq = spod_ram.freq
@@ -126,16 +122,16 @@ def test_basic_spod_low_ram():
126122
vars_idx=[0],
127123
filename='tmp.png')
128124
tol = 1e-10
129-
assert((np.abs(modes_at_freq[5,10,0,0]) < 0.010068515759308167 +tol) & \
130-
(np.abs(modes_at_freq[5,10,0,0]) > 0.010068515759308167 -tol))
131-
assert((np.abs(modes_at_freq[0,0,0,0]) < 0.012180208154393609 +tol) & \
132-
(np.abs(modes_at_freq[0,0,0,0]) > 0.012180208154393609 -tol))
133-
assert((np.abs(modes_at_freq[5,10,0,1]) < 5.117415619566953e-09+tol) & \
134-
(np.abs(modes_at_freq[5,10,0,1]) > 5.117415619566953e-09-tol))
135-
assert((np.abs(modes_at_freq[5,10,0,2]) < 6.929706983609628e-09+tol) & \
136-
(np.abs(modes_at_freq[5,10,0,2]) > 6.929706983609628e-09-tol))
137-
assert((np.max(np.abs(modes_at_freq)) < 0.029919118328162627 +tol) & \
138-
(np.max(np.abs(modes_at_freq)) > 0.029919118328162627 -tol))
125+
assert((np.abs(modes_at_freq[5,10,0,0]) < 0.010068515759308162 +tol) & \
126+
(np.abs(modes_at_freq[5,10,0,0]) > 0.010068515759308162 -tol))
127+
assert((np.abs(modes_at_freq[0,0,0,0]) < 0.01218020815439358 +tol) & \
128+
(np.abs(modes_at_freq[0,0,0,0]) > 0.01218020815439358 -tol))
129+
assert((np.abs(modes_at_freq[5,10,0,1]) < 2.7677058004877376e-09+tol) & \
130+
(np.abs(modes_at_freq[5,10,0,1]) > 2.7677058004877376e-09-tol))
131+
assert((np.abs(modes_at_freq[5,10,0,2]) < 4.204229641776651e-09 +tol) & \
132+
(np.abs(modes_at_freq[5,10,0,2]) > 4.204229641776651e-09 -tol))
133+
assert((np.max(np.abs(modes_at_freq)) < 0.02991911832816271 +tol) & \
134+
(np.max(np.abs(modes_at_freq)) > 0.02991911832816271 -tol))
139135

140136

141137

@@ -144,7 +140,7 @@ def test_basic_spod_streaming():
144140
# Finally, we can try the streaming algorithm
145141
spod_st = SPOD_streaming(p, params=params, data_handler=False, variables=['p'])
146142
spod_st.fit()
147-
143+
148144
# Show results
149145
T_approx = 10 # approximate period = 10 days (in days)
150146
freq = spod_st.freq
@@ -178,10 +174,6 @@ def test_basic_spod_streaming():
178174
shutil.rmtree(os.path.join(CWD,'results'))
179175
except OSError as e:
180176
print("Error: %s : %s" % (os.path.join(CWD,'results'), e.strerror))
181-
try:
182-
shutil.rmtree(os.path.join(CFD,'__pycache__'))
183-
except OSError as e:
184-
print("Error: %s : %s" % (os.path.join(CFD,'__pycache__'), e.strerror))
185177

186178

187179

@@ -190,5 +182,3 @@ def test_basic_spod_streaming():
190182
test_basic_spod_low_storage()
191183
test_basic_spod_low_ram ()
192184
test_basic_spod_streaming ()
193-
194-

tests/test_basic_file.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def read_data_netCDF(data, t_0, t_end, variables):
8686
params['n_modes_save'] = 3 # modes to be saved
8787
params['normvar' ] = False # normalize data by data variance
8888
params['conf_level' ] = 0.95 # calculate confidence level
89-
params['savefft' ] = True # save FFT blocks to reuse them in the future (saves time)
89+
params['savefft' ] = False # save FFT blocks to reuse them in the future (saves time)
9090

9191

9292

@@ -109,11 +109,11 @@ def test_basic_file_spod_low_storage():
109109
bashCmd = ["ffmpeg", " --version"]
110110
sbp = subprocess.Popen(bashCmd, stdin=subprocess.PIPE)
111111
spod_ls.generate_2D_data_video(
112-
sampling=20,
113-
time_limits=[0,t.shape[0]],
112+
sampling=20,
113+
time_limits=[0,t.shape[0]],
114114
filename='video.mp4')
115115
except:
116-
print('[test_basic_file_spod_low_storage]: ',
116+
print('[test_basic_file_spod_low_storage]: ',
117117
'Skipping video making as `ffmpeg` not present.')
118118

119119

@@ -174,20 +174,20 @@ def test_basic_file_spod_low_ram():
174174
vars_idx=[0],
175175
filename='tmp.png')
176176
tol = 1e-10
177-
assert((np.abs(modes_at_freq[5,10,0,0]) < 0.010068515759308167 +tol) & \
178-
(np.abs(modes_at_freq[5,10,0,0]) > 0.010068515759308167 -tol))
179-
assert((np.abs(modes_at_freq[0,0,0,0]) < 0.012180208154393609 +tol) & \
180-
(np.abs(modes_at_freq[0,0,0,0]) > 0.012180208154393609 -tol))
181-
assert((np.abs(modes_at_freq[5,10,0,1]) < 5.117415619566953e-09+tol) & \
182-
(np.abs(modes_at_freq[5,10,0,1]) > 5.117415619566953e-09-tol))
183-
assert((np.abs(modes_at_freq[5,10,0,2]) < 6.929706983609628e-09+tol) & \
184-
(np.abs(modes_at_freq[5,10,0,2]) > 6.929706983609628e-09-tol))
185-
assert((np.max(np.abs(modes_at_freq)) < 0.029919118328162627 +tol) & \
186-
(np.max(np.abs(modes_at_freq)) > 0.029919118328162627 -tol))
177+
assert((np.abs(modes_at_freq[5,10,0,0]) < 0.010068515759308162 +tol) & \
178+
(np.abs(modes_at_freq[5,10,0,0]) > 0.010068515759308162 -tol))
179+
assert((np.abs(modes_at_freq[0,0,0,0]) < 0.01218020815439358 +tol) & \
180+
(np.abs(modes_at_freq[0,0,0,0]) > 0.01218020815439358 -tol))
181+
assert((np.abs(modes_at_freq[5,10,0,1]) < 2.7677058004877376e-09+tol) & \
182+
(np.abs(modes_at_freq[5,10,0,1]) > 2.7677058004877376e-09-tol))
183+
assert((np.abs(modes_at_freq[5,10,0,2]) < 4.204229641776651e-09 +tol) & \
184+
(np.abs(modes_at_freq[5,10,0,2]) > 4.204229641776651e-09 -tol))
185+
assert((np.max(np.abs(modes_at_freq)) < 0.02991911832816271 +tol) & \
186+
(np.max(np.abs(modes_at_freq)) > 0.02991911832816271 -tol))
187187

188188

189189

190-
@pytest.mark.order3
190+
@pytest.mark.order3
191191
def test_basic_file_spod_streaming():
192192
# Finally, we can try the streaming algorithm
193193
spod_st = SPOD_streaming(
@@ -233,19 +233,10 @@ def test_basic_file_spod_streaming():
233233
os.remove(os.path.join(CWD,'data.nc'))
234234
except OSError as e:
235235
print("Error: %s : %s" % (os.path.join(CWD,'data.nc'), e.strerror))
236-
try:
237-
shutil.rmtree(os.path.join(CFD,'__pycache__'))
238-
except OSError as e:
239-
print("Error: %s : %s" % (os.path.join(CFD,'__pycache__'), e.strerror))
240236

241237

242238

243239
if __name__ == "__main__":
244240
test_basic_file_spod_low_storage()
245241
test_basic_file_spod_low_ram ()
246242
test_basic_file_spod_streaming ()
247-
248-
249-
250-
251-

0 commit comments

Comments
 (0)