3
3
import glob
4
4
import time
5
5
import re
6
+ import fnmatch
6
7
import numpy as np
7
8
import h5py
8
9
import math
12
13
from combineDataFn import processTimestampsForCombiningData
13
14
14
15
16
+ # find files by ignoreing the case sensitivity
17
+ def find_files (path , glob_path , ignore_case = False ):
18
+ rule = re .compile (fnmatch .translate (glob_path ), re .IGNORECASE ) if ignore_case \
19
+ else re .compile (fnmatch .translate (glob_path ))
20
+ return [os .path .join (path ,n ) for n in os .listdir (os .path .expanduser (path )) if rule .match (n )]
21
+
22
+
15
23
# function to read hdf5 file
16
24
def read_hdf5 (event , filepath , key ):
17
25
if event :
@@ -119,10 +127,14 @@ def applyCorrection(filepath, timeForLightsTurnOn, event, displayName, naming):
119
127
timeRecStart = read_hdf5 ('timeCorrection_' + naming , filepath , 'timeRecStart' )[0 ]
120
128
timestampNew = read_hdf5 ('timeCorrection_' + naming , filepath , 'timestampNew' )
121
129
correctionIndex = read_hdf5 ('timeCorrection_' + naming , filepath , 'correctionIndex' )
130
+
122
131
123
132
if 'control' in displayName .lower () or 'signal' in displayName .lower ():
124
133
arr = read_hdf5 (event , filepath , 'data' )
125
- arr = arr [correctionIndex ]
134
+ if (arr == 0 ).all ()== True :
135
+ arr = arr
136
+ else :
137
+ arr = arr [correctionIndex ]
126
138
write_hdf5 (arr , displayName , filepath , 'data' )
127
139
else :
128
140
arr = read_hdf5 (event , filepath , 'timestamps' )
@@ -211,6 +223,10 @@ def visualize(filepath, x, y1, y2, plot_name, removeArtifacts):
211
223
212
224
213
225
# plotting control and signal data
226
+
227
+ if (y1 == 0 ).all ()== True :
228
+ y1 = np .zeros (x .shape [0 ])
229
+
214
230
name = os .path .basename (filepath )
215
231
fig = plt .figure ()
216
232
ax1 = fig .add_subplot (211 )
@@ -274,9 +290,9 @@ def plt_close_event(event):
274
290
275
291
# function to plot control and signal, also provide a feature to select chunks for artifacts removal
276
292
def visualizeControlAndSignal (filepath , removeArtifacts ):
277
- path_1 = glob .glob (os .path .join (filepath , 'control*' ))
293
+ path_1 = find_files ( filepath , 'control*' , ignore_case = True ) # glob.glob(os.path.join(filepath, 'control*'))
278
294
279
- path_2 = glob .glob (os .path .join (filepath , 'signal*' ))
295
+ path_2 = find_files ( filepath , 'signal*' , ignore_case = True ) # glob.glob(os.path.join(filepath, 'signal*'))
280
296
281
297
282
298
path = sorted (path_1 + path_2 )
@@ -303,9 +319,9 @@ def visualizeControlAndSignal(filepath, removeArtifacts):
303
319
304
320
# functino to check if the naming convention for saving storeslist file was followed or not
305
321
def decide_naming_convention (filepath ):
306
- path_1 = glob .glob (os .path .join (filepath , 'control*' ))
322
+ path_1 = find_files ( filepath , 'control*' , ignore_case = True ) # glob.glob(os.path.join(filepath, 'control*'))
307
323
308
- path_2 = glob .glob (os .path .join (filepath , 'signal*' ))
324
+ path_2 = find_files ( filepath , 'signal*' , ignore_case = True ) # glob.glob(os.path.join(filepath, 'signal*'))
309
325
310
326
path = sorted (path_1 + path_2 )
311
327
if len (path )% 2 != 0 :
@@ -341,6 +357,9 @@ def eliminateData(filepath, timeForLightsTurnOn, event, sampling_rate, naming):
341
357
data = read_hdf5 (event , filepath , 'data' ).reshape (- 1 )
342
358
coords = fetchCoords (filepath , naming , ts )
343
359
360
+ if (data == 0 ).all ()== True :
361
+ data = np .zeros (ts .shape [0 ])
362
+
344
363
arr = np .array ([])
345
364
ts_arr = np .array ([])
346
365
for i in range (coords .shape [0 ]):
@@ -474,6 +493,9 @@ def helper_z_score(control, signal, filepath, name, inputParameters): #helpe
474
493
coords_path = os .path .join (filepath , 'coordsForPreProcessing_' + name + '.npy' )
475
494
476
495
print ("Remove Artifacts : " , removeArtifacts )
496
+
497
+ if (control == 0 ).all ()== True :
498
+ control = np .zeros (tsNew .shape [0 ])
477
499
478
500
z_score_arr , norm_data_arr = np .array ([]), np .array ([])
479
501
@@ -517,8 +539,8 @@ def compute_z_score(filepath, inputParameters):
517
539
remove_artifacts = inputParameters ['removeArtifacts' ]
518
540
519
541
520
- path_1 = glob .glob (os .path .join (filepath , 'control*' ))
521
- path_2 = glob .glob (os .path .join (filepath , 'signal*' ))
542
+ path_1 = find_files ( filepath , 'control*' , ignore_case = True ) # glob.glob(os.path.join(filepath, 'control*'))
543
+ path_2 = find_files ( filepath , 'signal*' , ignore_case = True ) # glob.glob(os.path.join(filepath, 'signal*'))
522
544
523
545
path = sorted (path_1 + path_2 )
524
546
0 commit comments