Skip to content

Commit 80cd7eb

Browse files
bug fix for case-sensitive file search
1 parent a0f666a commit 80cd7eb

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

GuPPy/preprocess.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import glob
44
import time
55
import re
6+
import fnmatch
67
import numpy as np
78
import h5py
89
import math
@@ -12,6 +13,13 @@
1213
from combineDataFn import processTimestampsForCombiningData
1314

1415

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+
1523
# function to read hdf5 file
1624
def read_hdf5(event, filepath, key):
1725
if event:
@@ -119,10 +127,14 @@ def applyCorrection(filepath, timeForLightsTurnOn, event, displayName, naming):
119127
timeRecStart = read_hdf5('timeCorrection_'+naming, filepath, 'timeRecStart')[0]
120128
timestampNew = read_hdf5('timeCorrection_'+naming, filepath, 'timestampNew')
121129
correctionIndex = read_hdf5('timeCorrection_'+naming, filepath, 'correctionIndex')
130+
122131

123132
if 'control' in displayName.lower() or 'signal' in displayName.lower():
124133
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]
126138
write_hdf5(arr, displayName, filepath, 'data')
127139
else:
128140
arr = read_hdf5(event, filepath, 'timestamps')
@@ -211,6 +223,10 @@ def visualize(filepath, x, y1, y2, plot_name, removeArtifacts):
211223

212224

213225
# plotting control and signal data
226+
227+
if (y1==0).all()==True:
228+
y1 = np.zeros(x.shape[0])
229+
214230
name = os.path.basename(filepath)
215231
fig = plt.figure()
216232
ax1 = fig.add_subplot(211)
@@ -274,9 +290,9 @@ def plt_close_event(event):
274290

275291
# function to plot control and signal, also provide a feature to select chunks for artifacts removal
276292
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*'))
278294

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*'))
280296

281297

282298
path = sorted(path_1 + path_2)
@@ -303,9 +319,9 @@ def visualizeControlAndSignal(filepath, removeArtifacts):
303319

304320
# functino to check if the naming convention for saving storeslist file was followed or not
305321
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*'))
307323

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*'))
309325

310326
path = sorted(path_1 + path_2)
311327
if len(path)%2 != 0:
@@ -341,6 +357,9 @@ def eliminateData(filepath, timeForLightsTurnOn, event, sampling_rate, naming):
341357
data = read_hdf5(event, filepath, 'data').reshape(-1)
342358
coords = fetchCoords(filepath, naming, ts)
343359

360+
if (data==0).all()==True:
361+
data = np.zeros(ts.shape[0])
362+
344363
arr = np.array([])
345364
ts_arr = np.array([])
346365
for i in range(coords.shape[0]):
@@ -474,6 +493,9 @@ def helper_z_score(control, signal, filepath, name, inputParameters): #helpe
474493
coords_path = os.path.join(filepath, 'coordsForPreProcessing_'+name+'.npy')
475494

476495
print("Remove Artifacts : ", removeArtifacts)
496+
497+
if (control==0).all()==True:
498+
control = np.zeros(tsNew.shape[0])
477499

478500
z_score_arr, norm_data_arr = np.array([]), np.array([])
479501

@@ -517,8 +539,8 @@ def compute_z_score(filepath, inputParameters):
517539
remove_artifacts = inputParameters['removeArtifacts']
518540

519541

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*'))
522544

523545
path = sorted(path_1 + path_2)
524546

0 commit comments

Comments
 (0)