1
+ import os
2
+ import re
1
3
from pynwb import NWBHDF5IO
2
4
import numpy as np
3
5
import soundfile as sf
4
- import os
5
6
import scipy
6
7
from scipy .fft import fft , ifft , fftfreq , rfftfreq , rfft , irfft
7
8
from scipy .signal import butter , lfilter , filtfilt , hilbert
8
- import re
9
9
# from ripple2nwb.neural_processing import NeuralDataProcessor
10
10
# from prepype import NeuralDataProcessor
11
11
from prepype .neural_processing import NeuralDataProcessor , downsample , downsample_NWB
@@ -49,6 +49,7 @@ def __init__(self, nwb_dir, patient):
49
49
self .nwb_files = [file
50
50
for file in file_list
51
51
if file .startswith (f"{ patient } " )]
52
+ self .nwb_sr = None
52
53
self .target_sr = 100
53
54
54
55
self .bad_electrodes = []
@@ -184,7 +185,7 @@ def make_data(self,
184
185
self .nwb_sr = nwbfile .acquisition ["ElectricalSeries" ].\
185
186
rate
186
187
187
- # indices = np.where(electrode_table["group_name"] ==
188
+ # indices = np.where(electrode_table["group_name"] ==
188
189
# self.electrode_name
189
190
# )[0]
190
191
@@ -197,10 +198,10 @@ def make_data(self,
197
198
print ('High gamma extraction done.' )
198
199
199
200
nwbfile_electrodes = processor .nwb_file .processing ['ecephys' ].\
200
- data_interfaces ['LFP' ].\
201
- electrical_series [f'high gamma \
202
- ({ list (self .config ["referencing" ])[0 ]} )' ].\
203
- data [()][:, self .good_electrodes ]
201
+ data_interfaces ['LFP' ].\
202
+ electrical_series [f'high gamma \
203
+ ({ list (self .config ["referencing" ])[0 ]} )' ].\
204
+ data [()][:, self .good_electrodes ]
204
205
205
206
print (f"Number of good electrodes in { file } : { nwbfile_electrodes .shape [1 ]} " )
206
207
@@ -215,10 +216,10 @@ def make_data(self,
215
216
for start
216
217
in list (nwbfile .trials [:]["stop_time" ] * self .nwb_sr )]
217
218
218
- # Manage the speaking segments only... as an option .
219
+ # Manage the speaking segments only... as an option.
219
220
# Training data for wav2vec as speaking segments only
220
- # will be saved in the `chopped_sentence_dir` directory.
221
- # This block also saves the individual sentences.
221
+ # will be saved in the `chopped_sentence_dir` directory.
222
+ # This block also saves the individual sentences.
222
223
i = 0
223
224
all_speaking_segments = []
224
225
for start , stop in zip (starts , stops ):
@@ -232,7 +233,8 @@ def make_data(self,
232
233
233
234
i = i + 1
234
235
235
- concatenated_speaking_segments = np .concatenate (all_speaking_segments , axis = 0 )
236
+ concatenated_speaking_segments = np .concatenate (all_speaking_segments ,
237
+ axis = 0 )
236
238
237
239
# Training data: speaking segments only
238
240
if create_training_data and chopped_sentence_dir :
@@ -258,7 +260,7 @@ def make_data(self,
258
260
# Training data: silences included
259
261
if create_training_data and chopped_recording_dir :
260
262
261
- _nwbfile_electrodes = nwbfile_electrodes # [starts[0]:stops[-1],:]
263
+ _nwbfile_electrodes = nwbfile_electrodes
262
264
num_full_chunks = len (_nwbfile_electrodes ) // chunk_length
263
265
# last_chunk_size = len(_nwbfile_electrodes) % chunk_size
264
266
@@ -291,8 +293,8 @@ def make_data(self,
291
293
print ('Full recording saved as a WAVE file.' )
292
294
293
295
if (ecog_tfrecords_dir and
294
- ((self .patient in ( 'EFC402' , 'EFC403' ) and (block in self .blocks_ID_demo2 ) or
295
- (self .patient in ( 'EFC400' , 'EFC401' ) and (block in self .blocks_ID_mocha ))))):
296
+ ((self .patient in { 'EFC402' , 'EFC403' } and (block in self .blocks_ID_demo2 ) or
297
+ (self .patient in { 'EFC400' , 'EFC401' } and (block in self .blocks_ID_mocha ))))):
296
298
297
299
# Create TFRecords for the ECoG data
298
300
@@ -399,7 +401,9 @@ def make_data(self,
399
401
print ('In distribution block. TFRecords created.' )
400
402
401
403
except Exception as e :
402
- print (f"An error occured and block { path } is not inluded in the wav2vec training data: { e } " )
404
+ print (f"An error occured \
405
+ and block { path } is not inluded \
406
+ in the wav2vec training data: { e } " )
403
407
404
408
io .close ()
405
409
@@ -425,7 +429,8 @@ def write_to_Protobuf(path, example_dicts):
425
429
feature_example = tfh .make_feature_example (example_dict )
426
430
writer .write (feature_example .SerializeToString ())
427
431
428
- def transcription_to_array (trial_t0 , trial_tF , onset_times , offset_times , transcription , max_length , sampling_rate ):
432
+ def transcription_to_array (trial_t0 , trial_tF , onset_times , offset_times ,
433
+ transcription , max_length , sampling_rate ):
429
434
430
435
# if the transcription is missing (e.g. for covert trials)
431
436
if transcription is None :
@@ -456,4 +461,4 @@ def transcription_to_array(trial_t0, trial_tF, onset_times, offset_times, transc
456
461
transcript = np .insert (transcript , 0 , 'pau' )
457
462
indices = np .sum (indices * (np .arange (1 , len (transcript ))[:, None ]), 0 )
458
463
459
- return transcript [indices ]
464
+ return transcript [indices ]
0 commit comments