Skip to content

Commit be8459e

Browse files
author
BptGrm
authored
black formatting
1 parent 97afdab commit be8459e

File tree

4 files changed

+55
-46
lines changed

4 files changed

+55
-46
lines changed

neo/rawio/biocamrawio.py

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

201-
if 'EventsBasedRawRanges' in experiment_settings['DataSettings']:
201+
if "EventsBasedRawRanges" in experiment_settings["DataSettings"]:
202202
for key in rf:
203203
if key[:5] == "Well_":
204204
num_channels = len(rf[key]["StoredChIdxs"])
205-
num_frames = np.array(rf['TOC'])[-1][-1]
205+
num_frames = np.array(rf["TOC"])[-1][-1]
206206
break
207207
read_function = readHDF5t_brw4_event_based
208-
208+
209209
else:
210210
for key in rf:
211211
if key[:5] == "Well_":
@@ -226,7 +226,6 @@ def open_biocam_file_header(filename):
226226

227227
gain = scale_factor * (max_uv - min_uv) / (max_digital - min_digital)
228228
offset = min_uv
229-
230229

231230
return dict(
232231
file_handle=rf,
@@ -239,10 +238,11 @@ def open_biocam_file_header(filename):
239238
offset=offset,
240239
)
241240

241+
242242
def GenerateSyntheticNoise_arr(file, wellID, startFrame, endFrame, numFrames, n_channels):
243243
# collect the TOCs
244-
toc = np.array(file['TOC'])
245-
noiseToc = np.array(file[wellID + '/NoiseTOC'])
244+
toc = np.array(file["TOC"])
245+
noiseToc = np.array(file[wellID + "/NoiseTOC"])
246246
# from the given start position in frames, localize the corresponding noise positions
247247
# using the TOC
248248
tocStartIdx = np.searchsorted(toc[:, 1], startFrame)
@@ -262,9 +262,9 @@ def GenerateSyntheticNoise_arr(file, wellID, startFrame, endFrame, numFrames, n_
262262
break
263263

264264
# obtain the noise info at the start position
265-
noiseChIdxs = file[wellID + '/NoiseChIdxs'][noiseStartPosition:noiseEndPosition]
266-
noiseMean = file[wellID + '/NoiseMean'][noiseStartPosition:noiseEndPosition]
267-
noiseStdDev = file[wellID + '/NoiseStdDev'][noiseStartPosition:noiseEndPosition]
265+
noiseChIdxs = file[wellID + "/NoiseChIdxs"][noiseStartPosition:noiseEndPosition]
266+
noiseMean = file[wellID + "/NoiseMean"][noiseStartPosition:noiseEndPosition]
267+
noiseStdDev = file[wellID + "/NoiseStdDev"][noiseStartPosition:noiseEndPosition]
268268
noiseLength = noiseEndPosition - noiseStartPosition
269269

270270
noiseInfo = {}
@@ -285,60 +285,65 @@ def GenerateSyntheticNoise_arr(file, wellID, startFrame, endFrame, numFrames, n_
285285

286286
for chIdx in range(n_channels):
287287
if chIdx in noiseInfo:
288-
arr[:,chIdx] = np.array(np.random.normal(noiseInfo[chIdx][0], noiseInfo[chIdx][1],numFrames), dtype=np.int16)
288+
arr[:, chIdx] = np.array(
289+
np.random.normal(noiseInfo[chIdx][0], noiseInfo[chIdx][1], numFrames), dtype=np.int16
290+
)
289291
else:
290-
arr[:,chIdx] = np.array(np.random.normal(dataMean, dataStdDev, numFrames),dtype=np.int16)
292+
arr[:, chIdx] = np.array(np.random.normal(dataMean, dataStdDev, numFrames), dtype=np.int16)
291293

292294
return arr
293295

296+
294297
def DecodeEventBasedRawData_arr(rf, wellID, t0, t1, nch):
295298

296-
toc = np.array(rf['TOC']) # Main table of contents
297-
eventsToc = np.array(rf[wellID + '/EventsBasedSparseRawTOC']) # Events table of contents
299+
toc = np.array(rf["TOC"]) # Main table of contents
300+
eventsToc = np.array(rf[wellID + "/EventsBasedSparseRawTOC"]) # Events table of contents
298301

299302
# Only select the chunks in the desired range
300303
tocStartIdx = np.searchsorted(toc[:, 1], t0)
301-
tocEndIdx = min(np.searchsorted(toc[:, 1], t1, side='right') + 1, len(toc) - 1)
304+
tocEndIdx = min(np.searchsorted(toc[:, 1], t1, side="right") + 1, len(toc) - 1)
302305
eventsStartPosition = eventsToc[tocStartIdx]
303306
eventsEndPosition = eventsToc[tocEndIdx]
304307

305308
numFrames = t1 - t0
306309

307-
binaryData = rf[wellID + '/EventsBasedSparseRaw'][eventsStartPosition:eventsEndPosition]
310+
binaryData = rf[wellID + "/EventsBasedSparseRaw"][eventsStartPosition:eventsEndPosition]
308311
binaryDataLength = len(binaryData)
309312

310313
synth = True
311314

312315
if synth:
313316
arr = GenerateSyntheticNoise_arr(rf, wellID, t0, t1, numFrames, nch)
314-
317+
315318
else:
316319
arr = np.zeros((numFrames, nch))
317320

318321
pos = 0
319322
while pos < binaryDataLength:
320-
chIdx = int.from_bytes(binaryData[pos:pos + 4], byteorder='little', signed=True)
323+
chIdx = int.from_bytes(binaryData[pos : pos + 4], byteorder="little", signed=True)
321324
pos += 4
322-
chDataLength = int.from_bytes(binaryData[pos:pos + 4], byteorder='little', signed=True)
325+
chDataLength = int.from_bytes(binaryData[pos : pos + 4], byteorder="little", signed=True)
323326
pos += 4
324327
chDataPos = pos
325328
while pos < chDataPos + chDataLength:
326-
fromInclusive = int.from_bytes(binaryData[pos:pos + 8], byteorder='little', signed=True)
329+
fromInclusive = int.from_bytes(binaryData[pos : pos + 8], byteorder="little", signed=True)
327330
pos += 8
328-
toExclusive = int.from_bytes(binaryData[pos:pos + 8], byteorder='little', signed=True)
331+
toExclusive = int.from_bytes(binaryData[pos : pos + 8], byteorder="little", signed=True)
329332
pos += 8
330333
rangeDataPos = pos
331334
for j in range(fromInclusive, toExclusive):
332-
if j >= t0 + numFrames:
335+
if j >= t0 + numFrames:
333336
break
334337
if j >= t0:
335-
arr[j - t0,chIdx] = int.from_bytes(
336-
binaryData[rangeDataPos:rangeDataPos + 2], byteorder='little', signed=True)
338+
arr[j - t0, chIdx] = int.from_bytes(
339+
binaryData[rangeDataPos : rangeDataPos + 2], byteorder="little", signed=True
340+
)
337341
rangeDataPos += 2
338342
pos += (toExclusive - fromInclusive) * 2
339343

340344
return arr
341345

346+
342347
def readHDF5t_100(rf, t0, t1, nch):
343348
return rf["3BData/Raw"][t0:t1]
344349

@@ -359,7 +364,8 @@ def readHDF5t_brw4(rf, t0, t1, nch):
359364
for key in rf:
360365
if key[:5] == "Well_":
361366
return rf[key]["Raw"][nch * t0 : nch * t1].reshape((t1 - t0, nch), order="C")
362-
367+
368+
363369
def readHDF5t_brw4_event_based(rf, t0, t1, nch):
364370
for key in rf:
365371
if key[:5] == "Well_":

neo/rawio/neuralynxrawio/ncssections.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,19 @@ def _buildNcsSections(ncsMemMap, sampFreq, gapTolerance=0):
190190
and ncsMemMap["sample_rate"][0] == ncsMemMap["sample_rate"][-1]
191191
and ncsMemMap["timestamp"][-1] == predLastBlockStartTime
192192
):
193-
lastBlkEndTime = NcsSectionsFactory.calc_sample_time(sampFreq, ncsMemMap["timestamp"][-1], ncsMemMap["nb_valid"][-1])
193+
lastBlkEndTime = NcsSectionsFactory.calc_sample_time(
194+
sampFreq, ncsMemMap["timestamp"][-1], ncsMemMap["nb_valid"][-1]
195+
)
194196
n_samples = NcsSection._RECORD_SIZE * (ncsMemMap.size - 1) + ncsMemMap["nb_valid"][-1]
195197
section0 = NcsSection(
196-
startRec=0,
197-
startTime=ncsMemMap["timestamp"][0],
198-
endRec=ncsMemMap.size - 1,
199-
endTime=lastBlkEndTime,
200-
n_samples=n_samples
201-
)
198+
startRec=0,
199+
startTime=ncsMemMap["timestamp"][0],
200+
endRec=ncsMemMap.size - 1,
201+
endTime=lastBlkEndTime,
202+
n_samples=n_samples,
203+
)
202204
ncsSects.sects.append(section0)
203-
205+
204206
else:
205207
# need to parse all data block to detect gaps
206208
# check when the predicted timestamp is outside the tolerance
@@ -210,19 +212,19 @@ def _buildNcsSections(ncsMemMap, sampFreq, gapTolerance=0):
210212
gap_inds = np.flatnonzero(np.abs(delta - delta_prediction) > gapTolerance)
211213
gap_inds += 1
212214

213-
sections_limits = [ 0 ] + gap_inds.tolist() + [len(ncsMemMap)]
215+
sections_limits = [0] + gap_inds.tolist() + [len(ncsMemMap)]
214216

215217
for i in range(len(gap_inds) + 1):
216218
start = sections_limits[i]
217219
stop = sections_limits[i + 1]
218-
duration = np.uint64(1e6 / sampFreq * ncsMemMap["nb_valid"][stop-1])
220+
duration = np.uint64(1e6 / sampFreq * ncsMemMap["nb_valid"][stop - 1])
219221
ncsSects.sects.append(
220222
NcsSection(
221223
startRec=start,
222224
startTime=ncsMemMap["timestamp"][start],
223-
endRec=stop-1,
224-
endTime=ncsMemMap["timestamp"][stop-1] + duration,
225-
n_samples=np.sum(ncsMemMap["nb_valid"][start:stop])
225+
endRec=stop - 1,
226+
endTime=ncsMemMap["timestamp"][stop - 1] + duration,
227+
n_samples=np.sum(ncsMemMap["nb_valid"][start:stop]),
226228
)
227229
)
228230

@@ -274,7 +276,6 @@ def build_for_ncs_file(ncsMemMap, nlxHdr, gapTolerance=None, strict_gap_mode=Tru
274276
# quarter of paquet size is tolerate
275277
gapTolerance = round(0.25 * NcsSection._RECORD_SIZE * 1e6 / freq)
276278
ncsSects = NcsSectionsFactory._buildNcsSections(ncsMemMap, freq, gapTolerance=gapTolerance)
277-
278279

279280
# take longer data block to compute reaal sampling rate
280281
# ind_max = np.argmax([section.n_samples for section in ncsSects.sects])
@@ -292,7 +293,6 @@ def build_for_ncs_file(ncsMemMap, nlxHdr, gapTolerance=None, strict_gap_mode=Tru
292293
ncsSects.sampFreqUsed = sampFreqUsed
293294
ncsSects.microsPerSampUsed = NcsSectionsFactory.get_micros_per_samp_for_freq(sampFreqUsed)
294295

295-
296296
elif acqType == "BML" or acqType == "ATLAS":
297297
# BML & ATLAS style with fractional frequency and micros per samp
298298
if strict_gap_mode:
@@ -305,7 +305,6 @@ def build_for_ncs_file(ncsMemMap, nlxHdr, gapTolerance=None, strict_gap_mode=Tru
305305
ncsSects.sampFreqUsed = freq
306306
ncsSects.microsPerSampUsed = NcsSectionsFactory.get_micros_per_samp_for_freq(freq)
307307

308-
309308
else:
310309
raise TypeError("Unknown Ncs file type from header.")
311310

neo/rawio/neuralynxrawio/neuralynxrawio.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ class NeuralynxRawIO(BaseRawIO):
8787
Otherwise set 0 of time to first time in dataset
8888
strict_gap_mode: bool, default: True
8989
Detect gaps using strict mode or not.
90-
* strict_gap_mode = True then a gap is consider when timstamp difference between two
90+
* strict_gap_mode = True then a gap is consider when timstamp difference between two
9191
consequtive data packet is more than one sample interval.
9292
* strict_gap_mode = False then a gap has an increased tolerance. Some new system with different clock need this option
9393
otherwise, too many gaps are detected
94-
94+
9595
Notes
9696
-----
9797
* This IO supports NCS, NEV, NSE and NTT file formats (not NVT or NRD yet)
@@ -131,7 +131,9 @@ class NeuralynxRawIO(BaseRawIO):
131131
("samples", "int16", (NcsSection._RECORD_SIZE)),
132132
]
133133

134-
def __init__(self, dirname="", filename="", exclude_filename=None, keep_original_times=False, strict_gap_mode=True, **kargs):
134+
def __init__(
135+
self, dirname="", filename="", exclude_filename=None, keep_original_times=False, strict_gap_mode=True, **kargs
136+
):
135137

136138
if dirname != "":
137139
self.dirname = dirname
@@ -797,7 +799,9 @@ def scan_stream_ncs_files(self, ncs_filenames):
797799

798800
verify_sec_struct = NcsSectionsFactory._verifySectionsStructure
799801
if not chanSectMap or (not verify_sec_struct(data, chan_ncs_sections)):
800-
chan_ncs_sections = NcsSectionsFactory.build_for_ncs_file(data, nlxHeader, strict_gap_mode=self.strict_gap_mode)
802+
chan_ncs_sections = NcsSectionsFactory.build_for_ncs_file(
803+
data, nlxHeader, strict_gap_mode=self.strict_gap_mode
804+
)
801805

802806
# register file section structure for all contained channels
803807
for chan_uid in zip(nlxHeader["channel_names"], np.asarray(nlxHeader["channel_ids"], dtype=str)):

neo/test/rawiotest/test_neuralynxrawio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def test_build_given_actual_frequency(self):
228228
ncsBlocks = NcsSections()
229229
ncsBlocks.sampFreqUsed = 1 / (35e-6)
230230
ncsBlocks.microsPerSampUsed = 35
231-
231+
232232
ncsBlocks = NcsSectionsFactory._buildNcsSections(data0, ncsBlocks.sampFreqUsed)
233233

234234
self.assertEqual(len(ncsBlocks.sects), 1)
@@ -324,7 +324,7 @@ class TestNcsSections(TestNeuralynxRawIO, unittest.TestCase):
324324
"""
325325
Test building NcsBlocks for files of different revisions.
326326
"""
327-
327+
328328
entities_to_test = []
329329

330330
def test_equality(self):

0 commit comments

Comments
 (0)