Skip to content

Commit 006c460

Browse files
chore: linter 2/2
1 parent 3c97c43 commit 006c460

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

packages/ecog2vec/ecog2vec/data_generator.py

+22-17
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import os
2+
import re
13
from pynwb import NWBHDF5IO
24
import numpy as np
35
import soundfile as sf
4-
import os
56
import scipy
67
from scipy.fft import fft, ifft, fftfreq, rfftfreq, rfft, irfft
78
from scipy.signal import butter, lfilter, filtfilt, hilbert
8-
import re
99
# from ripple2nwb.neural_processing import NeuralDataProcessor
1010
# from prepype import NeuralDataProcessor
1111
from prepype.neural_processing import NeuralDataProcessor, downsample, downsample_NWB
@@ -49,6 +49,7 @@ def __init__(self, nwb_dir, patient):
4949
self.nwb_files = [file
5050
for file in file_list
5151
if file.startswith(f"{patient}")]
52+
self.nwb_sr = None
5253
self.target_sr = 100
5354

5455
self.bad_electrodes = []
@@ -184,7 +185,7 @@ def make_data(self,
184185
self.nwb_sr = nwbfile.acquisition["ElectricalSeries"].\
185186
rate
186187

187-
# indices = np.where(electrode_table["group_name"] ==
188+
# indices = np.where(electrode_table["group_name"] ==
188189
# self.electrode_name
189190
# )[0]
190191

@@ -197,10 +198,10 @@ def make_data(self,
197198
print('High gamma extraction done.')
198199

199200
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]
204205

205206
print(f"Number of good electrodes in {file}: {nwbfile_electrodes.shape[1]}")
206207

@@ -215,10 +216,10 @@ def make_data(self,
215216
for start
216217
in list(nwbfile.trials[:]["stop_time"] * self.nwb_sr)]
217218

218-
# Manage the speaking segments only... as an option .
219+
# Manage the speaking segments only... as an option.
219220
# 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.
222223
i = 0
223224
all_speaking_segments = []
224225
for start, stop in zip(starts, stops):
@@ -232,7 +233,8 @@ def make_data(self,
232233

233234
i = i + 1
234235

235-
concatenated_speaking_segments = np.concatenate(all_speaking_segments, axis=0)
236+
concatenated_speaking_segments = np.concatenate(all_speaking_segments,
237+
axis=0)
236238

237239
# Training data: speaking segments only
238240
if create_training_data and chopped_sentence_dir:
@@ -258,7 +260,7 @@ def make_data(self,
258260
# Training data: silences included
259261
if create_training_data and chopped_recording_dir:
260262

261-
_nwbfile_electrodes = nwbfile_electrodes # [starts[0]:stops[-1],:]
263+
_nwbfile_electrodes = nwbfile_electrodes
262264
num_full_chunks = len(_nwbfile_electrodes) // chunk_length
263265
# last_chunk_size = len(_nwbfile_electrodes) % chunk_size
264266

@@ -291,8 +293,8 @@ def make_data(self,
291293
print('Full recording saved as a WAVE file.')
292294

293295
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))))):
296298

297299
# Create TFRecords for the ECoG data
298300

@@ -399,7 +401,9 @@ def make_data(self,
399401
print('In distribution block. TFRecords created.')
400402

401403
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}")
403407

404408
io.close()
405409

@@ -425,7 +429,8 @@ def write_to_Protobuf(path, example_dicts):
425429
feature_example = tfh.make_feature_example(example_dict)
426430
writer.write(feature_example.SerializeToString())
427431

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):
429434

430435
# if the transcription is missing (e.g. for covert trials)
431436
if transcription is None:
@@ -456,4 +461,4 @@ def transcription_to_array(trial_t0, trial_tF, onset_times, offset_times, transc
456461
transcript = np.insert(transcript, 0, 'pau')
457462
indices = np.sum(indices*(np.arange(1, len(transcript))[:, None]), 0)
458463

459-
return transcript[indices]
464+
return transcript[indices]

packages/ecog2vec/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
install_requires=[
88
# Add any other required packages here
99
],
10-
)
10+
)

0 commit comments

Comments
 (0)