From b1d61fc15f8924605c88ef7f6d0a1831b0e14c90 Mon Sep 17 00:00:00 2001 From: apdavison Date: Sun, 3 Mar 2024 12:10:26 +0000 Subject: [PATCH] black formatting --- neo/rawio/neuralynxrawio/ncssections.py | 27 ++++++++------- neo/rawio/neuralynxrawio/neuralynxrawio.py | 2 +- neo/rawio/neuralynxrawio/nlxheader.py | 39 +++++++++++----------- neo/test/rawiotest/test_neuralynxrawio.py | 2 +- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/neo/rawio/neuralynxrawio/ncssections.py b/neo/rawio/neuralynxrawio/ncssections.py index 4da0be177..f3280c2ca 100644 --- a/neo/rawio/neuralynxrawio/ncssections.py +++ b/neo/rawio/neuralynxrawio/ncssections.py @@ -33,6 +33,7 @@ The challenge addressed by the NcsSectionsFactory of this module is to separate those intended gaps from those introduced by a quirk of the hardware, recording software, or file format. """ + import math import numpy as np @@ -87,12 +88,12 @@ class NcsSection: _RECORD_SIZE = 512 # nb sample per signal record def __init__(self, startRec, startTime, endRec, endTime, n_samples): - self.startRec = startRec # index of starting record - self.startTime = startTime # starttime of first record - self.endRec = endRec # index of last record (inclusive) - self.endTime = endTime # end time of last record, that is, the end time of the last - # sampling period contained in the last record of the section - self.n_samples = n_samples # number of samples in record which are valid + self.startRec = startRec # index of starting record + self.startTime = startTime # starttime of first record + self.endRec = endRec # index of last record (inclusive) + self.endTime = endTime # end time of last record, that is, the end time of the last + # sampling period contained in the last record of the section + self.n_samples = n_samples # number of samples in record which are valid def __eq__(self, other): return ( @@ -200,7 +201,7 @@ def _parseGivenActualFrequency(ncsMemMap, ncsSects, chanNum, reqFreq, blkOnePred delta_prediction = ((ncsMemMap["nb_valid"][:-1] / ncsSects.sampFreqUsed) * 1e6).astype(np.int64) gap_inds = np.flatnonzero((delta - delta_prediction) != 0) gap_inds += 1 - sections_limits = [ 0 ] + gap_inds.tolist() + [len(ncsMemMap)] + sections_limits = [0] + gap_inds.tolist() + [len(ncsMemMap)] for i in range(len(gap_inds) + 1): start = sections_limits[i] @@ -209,9 +210,10 @@ def _parseGivenActualFrequency(ncsMemMap, ncsSects, chanNum, reqFreq, blkOnePred NcsSection( startRec=start, startTime=ncsMemMap["timestamp"][start], - endRec=stop-1, - endTime=ncsMemMap["timestamp"][stop-1] + np.uint64(ncsMemMap["nb_valid"][stop-1] / ncsSects.sampFreqUsed * 1e6), - n_samples=np.sum(ncsMemMap["nb_valid"][start:stop]) + endRec=stop - 1, + endTime=ncsMemMap["timestamp"][stop - 1] + + np.uint64(ncsMemMap["nb_valid"][stop - 1] / ncsSects.sampFreqUsed * 1e6), + n_samples=np.sum(ncsMemMap["nb_valid"][start:stop]), ) ) @@ -272,13 +274,14 @@ def _buildGivenActualFrequency(ncsMemMap, actualSampFreq, reqFreq): ncsSects.sects.append(curBlock) return ncsSects - else: # otherwise need to scan looking for data gaps blkOnePredTime = NcsSectionsFactory.calc_sample_time(actualSampFreq, ts0, nb0) # curBlock = NcsSection(0, ts0, -1, -1, -1) # ncsSects.sects.append(curBlock) - ncsSects = NcsSectionsFactory._parseGivenActualFrequency(ncsMemMap, ncsSects, chanNum, reqFreq, blkOnePredTime) + ncsSects = NcsSectionsFactory._parseGivenActualFrequency( + ncsMemMap, ncsSects, chanNum, reqFreq, blkOnePredTime + ) return ncsSects @staticmethod diff --git a/neo/rawio/neuralynxrawio/neuralynxrawio.py b/neo/rawio/neuralynxrawio/neuralynxrawio.py index f4c2b27bf..70306ff29 100644 --- a/neo/rawio/neuralynxrawio/neuralynxrawio.py +++ b/neo/rawio/neuralynxrawio/neuralynxrawio.py @@ -319,7 +319,7 @@ def _parse_header(self): internal_ids = [] else: data = self._get_file_map(filename) - if data.shape[0] == 0: # empty file + if data.shape[0] == 0: # empty file self._empty_nse_ntt.append(filename) internal_ids = np.unique(data[["event_id", "ttl_input"]]).tolist() for internal_event_id in internal_ids: diff --git a/neo/rawio/neuralynxrawio/nlxheader.py b/neo/rawio/neuralynxrawio/nlxheader.py index baf343c00..8d1de1ca2 100644 --- a/neo/rawio/neuralynxrawio/nlxheader.py +++ b/neo/rawio/neuralynxrawio/nlxheader.py @@ -81,52 +81,53 @@ def _to_bool(txt): "bml": dict( datetime1_regex=r"## Time Opened: \(m/d/y\): (?P\S+)" r" At Time: (?P