Skip to content

Commit 4d079ef

Browse files
authored
Merge pull request NeuralEnsemble#1590 from NeuralEnsemble/black-formatting
Black formatting
2 parents 96a28af + 35256ce commit 4d079ef

18 files changed

+162
-170
lines changed

neo/rawio/axonrawio.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ def _parse_header(self):
158158
# Get raw data by segment
159159
# self._raw_signals = {}
160160
self._t_starts = {}
161-
self._buffer_descriptions = {0 :{}}
162-
self._stream_buffer_slice = {stream_id : None}
161+
self._buffer_descriptions = {0: {}}
162+
self._stream_buffer_slice = {stream_id: None}
163163
pos = 0
164164
for seg_index in range(nb_segment):
165165
length = episode_array[seg_index]["len"]
@@ -174,12 +174,12 @@ def _parse_header(self):
174174

175175
self._buffer_descriptions[0][seg_index] = {}
176176
self._buffer_descriptions[0][seg_index][buffer_id] = {
177-
"type" : "raw",
178-
"file_path" : str(self.filename),
179-
"dtype" : str(sig_dtype),
177+
"type": "raw",
178+
"file_path": str(self.filename),
179+
"dtype": str(sig_dtype),
180180
"order": "C",
181-
"file_offset" : head_offset + pos * sig_dtype.itemsize,
182-
"shape" : (int(length // nbchannel), int(nbchannel)),
181+
"file_offset": head_offset + pos * sig_dtype.itemsize,
182+
"shape": (int(length // nbchannel), int(nbchannel)),
183183
}
184184
pos += length
185185

@@ -239,7 +239,9 @@ def _parse_header(self):
239239
else:
240240
gain, offset = 1.0, 0.0
241241

242-
signal_channels.append((name, str(chan_id), self._sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id))
242+
signal_channels.append(
243+
(name, str(chan_id), self._sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id)
244+
)
243245

244246
signal_channels = np.array(signal_channels, dtype=_signal_channel_dtype)
245247

@@ -313,7 +315,6 @@ def _get_signal_t_start(self, block_index, seg_index, stream_index):
313315
def _get_analogsignal_buffer_description(self, block_index, seg_index, buffer_id):
314316
return self._buffer_descriptions[block_index][seg_index][buffer_id]
315317

316-
317318
def _event_count(self, block_index, seg_index, event_channel_index):
318319
return self._raw_ev_timestamps.size
319320

neo/rawio/baserawio.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,6 @@ def _get_analogsignal_buffer_description(self, block_index, seg_index, buffer_id
13751375
raise (NotImplementedError)
13761376

13771377

1378-
13791378
class BaseRawWithBufferApiIO(BaseRawIO):
13801379
"""
13811380
Generic class for reader that support "buffer api".
@@ -1402,7 +1401,7 @@ def _get_signal_size(self, block_index, seg_index, stream_index):
14021401
buffer_desc = self.get_analogsignal_buffer_description(block_index, seg_index, buffer_id)
14031402
# some hdf5 revert teh buffer
14041403
time_axis = buffer_desc.get("time_axis", 0)
1405-
return buffer_desc['shape'][time_axis]
1404+
return buffer_desc["shape"][time_axis]
14061405

14071406
def _get_analogsignal_chunk(
14081407
self,
@@ -1413,57 +1412,63 @@ def _get_analogsignal_chunk(
14131412
stream_index: int,
14141413
channel_indexes: list[int] | None,
14151414
):
1416-
1415+
14171416
stream_id = self.header["signal_streams"][stream_index]["id"]
14181417
buffer_id = self.header["signal_streams"][stream_index]["buffer_id"]
1419-
1420-
buffer_slice = self._stream_buffer_slice[stream_id]
14211418

1419+
buffer_slice = self._stream_buffer_slice[stream_id]
14221420

14231421
buffer_desc = self.get_analogsignal_buffer_description(block_index, seg_index, buffer_id)
14241422

14251423
i_start = i_start or 0
1426-
i_stop = i_stop or buffer_desc['shape'][0]
1424+
i_stop = i_stop or buffer_desc["shape"][0]
14271425

1428-
if buffer_desc['type'] == "raw":
1426+
if buffer_desc["type"] == "raw":
14291427

1430-
# open files on demand and keep reference to opened file
1431-
if not hasattr(self, '_memmap_analogsignal_buffers'):
1428+
# open files on demand and keep reference to opened file
1429+
if not hasattr(self, "_memmap_analogsignal_buffers"):
14321430
self._memmap_analogsignal_buffers = {}
14331431
if block_index not in self._memmap_analogsignal_buffers:
14341432
self._memmap_analogsignal_buffers[block_index] = {}
14351433
if seg_index not in self._memmap_analogsignal_buffers[block_index]:
14361434
self._memmap_analogsignal_buffers[block_index][seg_index] = {}
14371435
if buffer_id not in self._memmap_analogsignal_buffers[block_index][seg_index]:
1438-
fid = open(buffer_desc['file_path'], mode='rb')
1436+
fid = open(buffer_desc["file_path"], mode="rb")
14391437
self._memmap_analogsignal_buffers[block_index][seg_index][buffer_id] = fid
14401438
else:
14411439
fid = self._memmap_analogsignal_buffers[block_index][seg_index][buffer_id]
1442-
1443-
num_channels = buffer_desc['shape'][1]
1444-
1445-
raw_sigs = get_memmap_chunk_from_opened_file(fid, num_channels, i_start, i_stop, np.dtype(buffer_desc['dtype']), file_offset=buffer_desc['file_offset'])
14461440

1447-
1448-
elif buffer_desc['type'] == 'hdf5':
1441+
num_channels = buffer_desc["shape"][1]
1442+
1443+
raw_sigs = get_memmap_chunk_from_opened_file(
1444+
fid,
1445+
num_channels,
1446+
i_start,
1447+
i_stop,
1448+
np.dtype(buffer_desc["dtype"]),
1449+
file_offset=buffer_desc["file_offset"],
1450+
)
1451+
1452+
elif buffer_desc["type"] == "hdf5":
14491453

1450-
# open files on demand and keep reference to opened file
1451-
if not hasattr(self, '_hdf5_analogsignal_buffers'):
1454+
# open files on demand and keep reference to opened file
1455+
if not hasattr(self, "_hdf5_analogsignal_buffers"):
14521456
self._hdf5_analogsignal_buffers = {}
14531457
if block_index not in self._hdf5_analogsignal_buffers:
14541458
self._hdf5_analogsignal_buffers[block_index] = {}
14551459
if seg_index not in self._hdf5_analogsignal_buffers[block_index]:
14561460
self._hdf5_analogsignal_buffers[block_index][seg_index] = {}
14571461
if buffer_id not in self._hdf5_analogsignal_buffers[block_index][seg_index]:
14581462
import h5py
1459-
h5file = h5py.File(buffer_desc['file_path'], mode="r")
1463+
1464+
h5file = h5py.File(buffer_desc["file_path"], mode="r")
14601465
self._hdf5_analogsignal_buffers[block_index][seg_index][buffer_id] = h5file
14611466
else:
14621467
h5file = self._hdf5_analogsignal_buffers[block_index][seg_index][buffer_id]
14631468

14641469
hdf5_path = buffer_desc["hdf5_path"]
14651470
full_raw_sigs = h5file[hdf5_path]
1466-
1471+
14671472
time_axis = buffer_desc.get("time_axis", 0)
14681473
if time_axis == 0:
14691474
raw_sigs = full_raw_sigs[i_start:i_stop, :]
@@ -1475,31 +1480,28 @@ def _get_analogsignal_chunk(
14751480
if buffer_slice is not None:
14761481
raw_sigs = raw_sigs[:, buffer_slice]
14771482

1478-
1479-
14801483
else:
14811484
raise NotImplementedError()
14821485

14831486
# this is a pre slicing when the stream do not contain all channels (for instance spikeglx when load_sync_channel=False)
14841487
if buffer_slice is not None:
14851488
raw_sigs = raw_sigs[:, buffer_slice]
1486-
1489+
14871490
# channel slice requested
14881491
if channel_indexes is not None:
14891492
raw_sigs = raw_sigs[:, channel_indexes]
14901493

1491-
14921494
return raw_sigs
14931495

14941496
def __del__(self):
1495-
if hasattr(self, '_memmap_analogsignal_buffers'):
1497+
if hasattr(self, "_memmap_analogsignal_buffers"):
14961498
for block_index in self._memmap_analogsignal_buffers.keys():
14971499
for seg_index in self._memmap_analogsignal_buffers[block_index].keys():
14981500
for buffer_id, fid in self._memmap_analogsignal_buffers[block_index][seg_index].items():
14991501
fid.close()
15001502
del self._memmap_analogsignal_buffers
15011503

1502-
if hasattr(self, '_hdf5_analogsignal_buffers'):
1504+
if hasattr(self, "_hdf5_analogsignal_buffers"):
15031505
for block_index in self._hdf5_analogsignal_buffers.keys():
15041506
for seg_index in self._hdf5_analogsignal_buffers[block_index].keys():
15051507
for buffer_id, h5_file in self._hdf5_analogsignal_buffers[block_index][seg_index].items():

neo/rawio/brainvisionrawio.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,18 @@ def _parse_header(self):
8080

8181
sig_dtype = np.dtype(fmts[fmt])
8282

83-
8483
stream_id = "0"
8584
buffer_id = "0"
86-
self._buffer_descriptions = {0 :{0 : {}}}
85+
self._buffer_descriptions = {0: {0: {}}}
8786
self._stream_buffer_slice = {}
8887
shape = get_memmap_shape(binary_filename, sig_dtype, num_channels=nb_channel, offset=0)
8988
self._buffer_descriptions[0][0][buffer_id] = {
90-
"type" : "raw",
91-
"file_path" : binary_filename,
92-
"dtype" : str(sig_dtype),
89+
"type": "raw",
90+
"file_path": binary_filename,
91+
"dtype": str(sig_dtype),
9392
"order": "C",
94-
"file_offset" : 0,
95-
"shape" : shape,
93+
"file_offset": 0,
94+
"shape": shape,
9695
}
9796
self._stream_buffer_slice[stream_id] = None
9897

neo/rawio/edfrawio.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,17 @@ def _parse_header(self):
173173
for array_key in array_keys:
174174
array_anno = {array_key: [h[array_key] for h in self.signal_headers]}
175175
seg_ann["signals"].append({"__array_annotations__": array_anno})
176-
176+
177177
# We store the following attributes for rapid access without needing the reader
178-
178+
179179
self._t_stop = self.edf_reader.datarecord_duration * self.edf_reader.datarecords_in_file
180180
# use sample count of first signal in stream
181-
self._stream_index_samples = {stream_index : self.edf_reader.getNSamples()[chidx][0] for stream_index, chidx in self.stream_idx_to_chidx.items()}
181+
self._stream_index_samples = {
182+
stream_index: self.edf_reader.getNSamples()[chidx][0]
183+
for stream_index, chidx in self.stream_idx_to_chidx.items()
184+
}
182185
self._number_of_events = len(self.edf_reader.readAnnotations()[0])
183-
186+
184187
self.close()
185188

186189
def _get_stream_channels(self, stream_index):

neo/rawio/elanrawio.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def _parse_header(self):
163163
buffer_id = "0"
164164
signal_buffers = np.array([("Signals", buffer_id)], dtype=_signal_buffer_dtype)
165165
signal_streams = np.array([("Signals", stream_id, buffer_id)], dtype=_signal_stream_dtype)
166-
166+
167167
sig_channels = []
168168
for c, chan_info in enumerate(channel_infos):
169169
chan_name = chan_info["label"]
@@ -197,16 +197,16 @@ def _parse_header(self):
197197
sig_channels = np.array(sig_channels, dtype=_signal_channel_dtype)
198198

199199
# raw data
200-
self._buffer_descriptions = {0 :{0 : {}}}
200+
self._buffer_descriptions = {0: {0: {}}}
201201
self._stream_buffer_slice = {}
202202
shape = get_memmap_shape(self.filename, sig_dtype, num_channels=nb_channel + 2, offset=0)
203203
self._buffer_descriptions[0][0][buffer_id] = {
204-
"type" : "raw",
205-
"file_path" : self.filename,
206-
"dtype" : sig_dtype,
204+
"type": "raw",
205+
"file_path": self.filename,
206+
"dtype": sig_dtype,
207207
"order": "C",
208-
"file_offset" : 0,
209-
"shape" : shape,
208+
"file_offset": 0,
209+
"shape": shape,
210210
}
211211
self._stream_buffer_slice["0"] = slice(0, -2)
212212

neo/rawio/maxwellrawio.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ def _parse_header(self):
119119

120120
# create signal channels
121121
max_sig_length = 0
122-
self._buffer_descriptions = {0 :{0 :{}}}
122+
self._buffer_descriptions = {0: {0: {}}}
123123
self._stream_buffer_slice = {}
124124
sig_channels = []
125125
well_indices_to_remove = []
126126
for stream_index, stream_id in enumerate(signal_streams["id"]):
127-
127+
128128
if int(version) == 20160704:
129129
sr = 20000.0
130130
settings = h5file["settings"]
@@ -163,14 +163,14 @@ def _parse_header(self):
163163
continue
164164

165165
self._stream_buffer_slice[stream_id] = None
166-
166+
167167
buffer_id = stream_id
168168
shape = h5file[hdf5_path].shape
169169
self._buffer_descriptions[0][0][buffer_id] = {
170-
"type" : "hdf5",
171-
"file_path" : str(self.filename),
172-
"hdf5_path" : hdf5_path,
173-
"shape" : shape,
170+
"type": "hdf5",
171+
"file_path": str(self.filename),
172+
"hdf5_path": hdf5_path,
173+
"shape": shape,
174174
"time_axis": 1,
175175
}
176176
self._stream_buffer_slice[stream_id] = slice(None)
@@ -232,7 +232,9 @@ def _get_signal_t_start(self, block_index, seg_index, stream_index):
232232

233233
def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, stream_index, channel_indexes):
234234
try:
235-
return super()._get_analogsignal_chunk(block_index, seg_index, i_start, i_stop, stream_index, channel_indexes)
235+
return super()._get_analogsignal_chunk(
236+
block_index, seg_index, i_start, i_stop, stream_index, channel_indexes
237+
)
236238
except OSError as e:
237239
print("*" * 10)
238240
print(_hdf_maxwell_error)

neo/rawio/micromedrawio.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,13 @@ class MicromedRawIO(BaseRawWithBufferApiIO):
4646
extensions = ["trc", "TRC"]
4747
rawmode = "one-file"
4848

49-
5049
def __init__(self, filename=""):
5150
BaseRawWithBufferApiIO.__init__(self)
5251
self.filename = filename
5352

5453
def _parse_header(self):
5554

56-
self._buffer_descriptions = {0 :{ 0: {}}}
55+
self._buffer_descriptions = {0: {0: {}}}
5756

5857
with open(self.filename, "rb") as fid:
5958
f = StructFile(fid)
@@ -106,16 +105,14 @@ def _parse_header(self):
106105
buffer_id = "0"
107106
stream_id = "0"
108107
self._buffer_descriptions[0][0][buffer_id] = {
109-
"type" : "raw",
110-
"file_path" : str(self.filename),
111-
"dtype" : sig_dtype,
108+
"type": "raw",
109+
"file_path": str(self.filename),
110+
"dtype": sig_dtype,
112111
"order": "C",
113-
"file_offset" : 0,
114-
"shape" : signal_shape,
112+
"file_offset": 0,
113+
"shape": signal_shape,
115114
}
116115

117-
118-
119116
# Reading Code Info
120117
zname2, pos, length = zones["ORDER"]
121118
f.seek(pos)
@@ -144,12 +141,12 @@ def _parse_header(self):
144141
sampling_rate *= Rate_Min
145142
chan_id = str(c)
146143

147-
148-
signal_channels.append((chan_name, chan_id, sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id))
149-
144+
signal_channels.append(
145+
(chan_name, chan_id, sampling_rate, sig_dtype, units, gain, offset, stream_id, buffer_id)
146+
)
150147

151148
signal_channels = np.array(signal_channels, dtype=_signal_channel_dtype)
152-
149+
153150
self._stream_buffer_slice = {"0": slice(None)}
154151
signal_buffers = np.array([("Signals", buffer_id)], dtype=_signal_buffer_dtype)
155152
signal_streams = np.array([("Signals", stream_id, buffer_id)], dtype=_signal_stream_dtype)

neo/rawio/neuronexusrawio.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ def _parse_header(self):
136136

137137
# the will cretae a memory map with teh generic mechanism
138138
buffer_id = "0"
139-
self._buffer_descriptions = {0 :{0 :{}}}
139+
self._buffer_descriptions = {0: {0: {}}}
140140
self._buffer_descriptions[0][0][buffer_id] = {
141-
"type" : "raw",
142-
"file_path" : str(binary_file),
143-
"dtype" : BINARY_DTYPE,
141+
"type": "raw",
142+
"file_path": str(binary_file),
143+
"dtype": BINARY_DTYPE,
144144
"order": "C",
145-
"file_offset" : 0,
146-
"shape" : (self._n_samples, self._n_channels),
145+
"file_offset": 0,
146+
"shape": (self._n_samples, self._n_channels),
147147
}
148148
# Make the memory map for timestamp
149149
self._timestamps = np.memmap(

0 commit comments

Comments
 (0)