Skip to content

Commit 384c5ac

Browse files
author
BptGrm
authored
black formatting
1 parent f9b1803 commit 384c5ac

File tree

4 files changed

+66
-44
lines changed

4 files changed

+66
-44
lines changed

neo/rawio/biocamrawio.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,14 @@ def open_biocam_file_header(filename):
200200
scale_factor = experiment_settings["ValueConverter"]["ScaleFactor"]
201201
sampling_rate = experiment_settings["TimeConverter"]["FrameRate"]
202202

203-
if 'EventsBasedRawRanges' in experiment_settings['DataSettings']:
203+
if "EventsBasedRawRanges" in experiment_settings["DataSettings"]:
204204
for key in rf:
205205
if key[:5] == "Well_":
206206
num_channels = len(rf[key]["StoredChIdxs"])
207-
num_frames = np.array(rf['TOC'])[-1][-1]
207+
num_frames = np.array(rf["TOC"])[-1][-1]
208208
break
209209
read_function = readHDF5t_brw4_event_based
210-
210+
211211
else:
212212
for key in rf:
213213
if key[:5] == "Well_":
@@ -228,7 +228,6 @@ def open_biocam_file_header(filename):
228228

229229
gain = scale_factor * (max_uv - min_uv) / (max_digital - min_digital)
230230
offset = min_uv
231-
232231

233232
return dict(
234233
file_handle=rf,
@@ -241,10 +240,11 @@ def open_biocam_file_header(filename):
241240
offset=offset,
242241
)
243242

243+
244244
def GenerateSyntheticNoise_arr(file, wellID, startFrame, endFrame, numFrames, n_channels):
245245
# collect the TOCs
246-
toc = np.array(file['TOC'])
247-
noiseToc = np.array(file[wellID + '/NoiseTOC'])
246+
toc = np.array(file["TOC"])
247+
noiseToc = np.array(file[wellID + "/NoiseTOC"])
248248
# from the given start position in frames, localize the corresponding noise positions
249249
# using the TOC
250250
tocStartIdx = np.searchsorted(toc[:, 1], startFrame)
@@ -264,9 +264,9 @@ def GenerateSyntheticNoise_arr(file, wellID, startFrame, endFrame, numFrames, n_
264264
break
265265

266266
# obtain the noise info at the start position
267-
noiseChIdxs = file[wellID + '/NoiseChIdxs'][noiseStartPosition:noiseEndPosition]
268-
noiseMean = file[wellID + '/NoiseMean'][noiseStartPosition:noiseEndPosition]
269-
noiseStdDev = file[wellID + '/NoiseStdDev'][noiseStartPosition:noiseEndPosition]
267+
noiseChIdxs = file[wellID + "/NoiseChIdxs"][noiseStartPosition:noiseEndPosition]
268+
noiseMean = file[wellID + "/NoiseMean"][noiseStartPosition:noiseEndPosition]
269+
noiseStdDev = file[wellID + "/NoiseStdDev"][noiseStartPosition:noiseEndPosition]
270270
noiseLength = noiseEndPosition - noiseStartPosition
271271

272272
noiseInfo = {}
@@ -287,60 +287,65 @@ def GenerateSyntheticNoise_arr(file, wellID, startFrame, endFrame, numFrames, n_
287287

288288
for chIdx in range(n_channels):
289289
if chIdx in noiseInfo:
290-
arr[:,chIdx] = np.array(np.random.normal(noiseInfo[chIdx][0], noiseInfo[chIdx][1],numFrames), dtype=np.int16)
290+
arr[:, chIdx] = np.array(
291+
np.random.normal(noiseInfo[chIdx][0], noiseInfo[chIdx][1], numFrames), dtype=np.int16
292+
)
291293
else:
292-
arr[:,chIdx] = np.array(np.random.normal(dataMean, dataStdDev, numFrames),dtype=np.int16)
294+
arr[:, chIdx] = np.array(np.random.normal(dataMean, dataStdDev, numFrames), dtype=np.int16)
293295

294296
return arr
295297

298+
296299
def DecodeEventBasedRawData_arr(rf, wellID, t0, t1, nch):
297300

298-
toc = np.array(rf['TOC']) # Main table of contents
299-
eventsToc = np.array(rf[wellID + '/EventsBasedSparseRawTOC']) # Events table of contents
301+
toc = np.array(rf["TOC"]) # Main table of contents
302+
eventsToc = np.array(rf[wellID + "/EventsBasedSparseRawTOC"]) # Events table of contents
300303

301304
# Only select the chunks in the desired range
302305
tocStartIdx = np.searchsorted(toc[:, 1], t0)
303-
tocEndIdx = min(np.searchsorted(toc[:, 1], t1, side='right') + 1, len(toc) - 1)
306+
tocEndIdx = min(np.searchsorted(toc[:, 1], t1, side="right") + 1, len(toc) - 1)
304307
eventsStartPosition = eventsToc[tocStartIdx]
305308
eventsEndPosition = eventsToc[tocEndIdx]
306309

307310
numFrames = t1 - t0
308311

309-
binaryData = rf[wellID + '/EventsBasedSparseRaw'][eventsStartPosition:eventsEndPosition]
312+
binaryData = rf[wellID + "/EventsBasedSparseRaw"][eventsStartPosition:eventsEndPosition]
310313
binaryDataLength = len(binaryData)
311314

312315
synth = True
313316

314317
if synth:
315318
arr = GenerateSyntheticNoise_arr(rf, wellID, t0, t1, numFrames, nch)
316-
319+
317320
else:
318321
arr = np.zeros((numFrames, nch))
319322

320323
pos = 0
321324
while pos < binaryDataLength:
322-
chIdx = int.from_bytes(binaryData[pos:pos + 4], byteorder='little', signed=True)
325+
chIdx = int.from_bytes(binaryData[pos : pos + 4], byteorder="little", signed=True)
323326
pos += 4
324-
chDataLength = int.from_bytes(binaryData[pos:pos + 4], byteorder='little', signed=True)
327+
chDataLength = int.from_bytes(binaryData[pos : pos + 4], byteorder="little", signed=True)
325328
pos += 4
326329
chDataPos = pos
327330
while pos < chDataPos + chDataLength:
328-
fromInclusive = int.from_bytes(binaryData[pos:pos + 8], byteorder='little', signed=True)
331+
fromInclusive = int.from_bytes(binaryData[pos : pos + 8], byteorder="little", signed=True)
329332
pos += 8
330-
toExclusive = int.from_bytes(binaryData[pos:pos + 8], byteorder='little', signed=True)
333+
toExclusive = int.from_bytes(binaryData[pos : pos + 8], byteorder="little", signed=True)
331334
pos += 8
332335
rangeDataPos = pos
333336
for j in range(fromInclusive, toExclusive):
334-
if j >= t0 + numFrames:
337+
if j >= t0 + numFrames:
335338
break
336339
if j >= t0:
337-
arr[j - t0,chIdx] = int.from_bytes(
338-
binaryData[rangeDataPos:rangeDataPos + 2], byteorder='little', signed=True)
340+
arr[j - t0, chIdx] = int.from_bytes(
341+
binaryData[rangeDataPos : rangeDataPos + 2], byteorder="little", signed=True
342+
)
339343
rangeDataPos += 2
340344
pos += (toExclusive - fromInclusive) * 2
341345

342346
return arr
343347

348+
344349
def readHDF5t_100(rf, t0, t1, nch):
345350
return rf["3BData/Raw"][t0:t1]
346351

@@ -361,7 +366,8 @@ def readHDF5t_brw4(rf, t0, t1, nch):
361366
for key in rf:
362367
if key[:5] == "Well_":
363368
return rf[key]["Raw"][nch * t0 : nch * t1].reshape((t1 - t0, nch), order="C")
364-
369+
370+
365371
def readHDF5t_brw4_event_based(rf, t0, t1, nch):
366372
for key in rf:
367373
if key[:5] == "Well_":

neo/rawio/intanrawio.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class IntanRawIO(BaseRawIO):
4646
ignore_integrity_checks: bool, default: False
4747
If True, data that violates integrity assumptions will be loaded. At the moment the only integrity
4848
check we perform is that timestamps are continuous. Setting this to True will ignore this check and set
49-
the attribute `discontinuous_timestamps` to True if the timestamps are not continous. This attribute can be checked
49+
the attribute `discontinuous_timestamps` to True if the timestamps are not continous. This attribute can be checked
5050
after parsing the header to see if the timestamps are continuous or not.
5151
Notes
5252
-----
@@ -83,7 +83,7 @@ class IntanRawIO(BaseRawIO):
8383
11: 'Stim channel',
8484
8585
* For the "header-attached" and "one-file-per-signal" formats, the structure of the digital input and output channels is
86-
one long vector, which must be post-processed to extract individual digital channel information.
86+
one long vector, which must be post-processed to extract individual digital channel information.
8787
See the intantech website for more information on performing this post-processing.
8888
8989
Examples
@@ -108,7 +108,6 @@ def __init__(self, filename="", ignore_integrity_checks=False):
108108
self.ignore_integrity_checks = ignore_integrity_checks
109109
self.discontinuous_timestamps = False
110110

111-
112111
def _source_name(self):
113112
return self.filename
114113

@@ -207,7 +206,7 @@ def _parse_header(self):
207206
elif self.file_format == "one-file-per-channel":
208207
time_stream_index = max(self._raw_data.keys())
209208
timestamp = self._raw_data[time_stream_index][0]
210-
209+
211210
discontinuous_timestamps = np.diff(timestamp) != 1
212211
timestamps_are_not_contiguous = np.any(discontinuous_timestamps)
213212
if timestamps_are_not_contiguous:
@@ -267,7 +266,7 @@ def _parse_header(self):
267266
# are in a list we just take the first channel in each list of channels
268267
else:
269268
self._max_sigs_length = max([raw_data[0].size for raw_data in self._raw_data.values()])
270-
269+
271270
# No events
272271
event_channels = []
273272
event_channels = np.array(event_channels, dtype=_event_channel_dtype)

neo/test/iotest/test_intanio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ class TestIntanIO(
1515
ioclass = IntanIO
1616
entities_to_download = ["intan"]
1717
entities_to_test = [
18-
"intan/intan_rhs_test_1.rhs", # Format header-attached
18+
"intan/intan_rhs_test_1.rhs", # Format header-attached
1919
"intan/intan_rhd_test_1.rhd", # Format header-attached
2020
"intan/rhs_fpc_multistim_240514_082243/rhs_fpc_multistim_240514_082243.rhs", # Format header-attached newer version
2121
"intan/intan_fpc_test_231117_052630/info.rhd", # Format one-file-per-channel
2222
"intan/intan_fps_test_231117_052500/info.rhd", # Format one file per signal
2323
"intan/intan_fpc_rhs_test_240329_091637/info.rhs", # Format one-file-per-channel
24-
"intan/intan_fps_rhs_test_240329_091536/info.rhs", # Format one-file-per-signal
24+
"intan/intan_fps_rhs_test_240329_091536/info.rhs", # Format one-file-per-signal
2525
"intan/rhd_fpc_multistim_240514_082044/info.rhd", # Multiple digital channels one-file-per-channel rhd
2626
]
2727

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
import numpy as np
2+
import numpy as np
33

44
from neo.rawio.intanrawio import IntanRawIO
55
from neo.test.rawiotest.common_rawio_test import BaseTestRawIO
@@ -12,32 +12,46 @@ class TestIntanRawIO(
1212
rawioclass = IntanRawIO
1313
entities_to_download = ["intan"]
1414
entities_to_test = [
15-
"intan/intan_rhs_test_1.rhs", # Format header-attached
15+
"intan/intan_rhs_test_1.rhs", # Format header-attached
1616
"intan/intan_rhd_test_1.rhd", # Format header-attached
1717
"intan/rhs_fpc_multistim_240514_082243/rhs_fpc_multistim_240514_082243.rhs", # Format header-attached newer version
1818
"intan/intan_fpc_test_231117_052630/info.rhd", # Format one-file-per-channel
1919
"intan/intan_fps_test_231117_052500/info.rhd", # Format one file per signal
2020
"intan/intan_fpc_rhs_test_240329_091637/info.rhs", # Format one-file-per-channel
21-
"intan/intan_fps_rhs_test_240329_091536/info.rhs", # Format one-file-per-signal
21+
"intan/intan_fps_rhs_test_240329_091536/info.rhs", # Format one-file-per-signal
2222
"intan/rhd_fpc_multistim_240514_082044/info.rhd", # Multiple digital channels one-file-per-channel rhd
2323
]
2424

25-
2625
def test_annotations(self):
27-
26+
2827
intan_reader = IntanRawIO(filename=self.get_local_path("intan/intan_rhd_test_1.rhd"))
2928
intan_reader.parse_header()
30-
29+
3130
raw_annotations = intan_reader.raw_annotations
3231
annotations = raw_annotations["blocks"][0]["segments"][0] # Intan is mono segment
3332
signal_annotations = annotations["signals"][0] # As in the other exmaples, annotaions are duplicated
34-
35-
33+
3634
# Scalar annotations
37-
exepcted_annotations = {'intan_version': '1.5', 'desired_impedance_test_frequency': 1000.0, 'desired_upper_bandwidth': 7500.0, 'note1': '', 'notch_filter_mode': 1, 'notch_filter': False, 'nb_signal_group': 7,
38-
'dsp_enabled': 1, 'actual_impedance_test_frequency': 1000.0, 'desired_lower_bandwidth': 0.1, 'note3': '', 'actual_dsp_cutoff_frequency': 1.165828,
39-
'desired_dsp_cutoff_frequency': 1.0, 'actual_lower_bandwidth': 0.0945291, 'eval_board_mode': 0, 'note2': '', 'num_temp_sensor_channels': 0}
40-
35+
exepcted_annotations = {
36+
"intan_version": "1.5",
37+
"desired_impedance_test_frequency": 1000.0,
38+
"desired_upper_bandwidth": 7500.0,
39+
"note1": "",
40+
"notch_filter_mode": 1,
41+
"notch_filter": False,
42+
"nb_signal_group": 7,
43+
"dsp_enabled": 1,
44+
"actual_impedance_test_frequency": 1000.0,
45+
"desired_lower_bandwidth": 0.1,
46+
"note3": "",
47+
"actual_dsp_cutoff_frequency": 1.165828,
48+
"desired_dsp_cutoff_frequency": 1.0,
49+
"actual_lower_bandwidth": 0.0945291,
50+
"eval_board_mode": 0,
51+
"note2": "",
52+
"num_temp_sensor_channels": 0,
53+
}
54+
4155
for key in exepcted_annotations:
4256
if isinstance(exepcted_annotations[key], float):
4357
self.assertAlmostEqual(signal_annotations[key], exepcted_annotations[key], places=2)
@@ -47,8 +61,11 @@ def test_annotations(self):
4761
# Array annotations
4862
signal_array_annotations = signal_annotations["__array_annotations__"]
4963
np.testing.assert_array_equal(signal_array_annotations["native_order"][:10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
50-
np.testing.assert_array_equal(signal_array_annotations["spike_scope_digital_edge_polarity"][:10], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
64+
np.testing.assert_array_equal(
65+
signal_array_annotations["spike_scope_digital_edge_polarity"][:10], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
66+
)
5167
np.testing.assert_array_equal(signal_array_annotations["board_stream_num"][:10], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
5268

69+
5370
if __name__ == "__main__":
5471
unittest.main()

0 commit comments

Comments
 (0)