diff --git a/neo/rawio/neuralynxrawio/ncssections.py b/neo/rawio/neuralynxrawio/ncssections.py index 462913f72..cf3da6113 100644 --- a/neo/rawio/neuralynxrawio/ncssections.py +++ b/neo/rawio/neuralynxrawio/ncssections.py @@ -190,17 +190,19 @@ def _buildNcsSections(ncsMemMap, sampFreq, gapTolerance=0): and ncsMemMap["sample_rate"][0] == ncsMemMap["sample_rate"][-1] and ncsMemMap["timestamp"][-1] == predLastBlockStartTime ): - lastBlkEndTime = NcsSectionsFactory.calc_sample_time(sampFreq, ncsMemMap["timestamp"][-1], ncsMemMap["nb_valid"][-1]) + lastBlkEndTime = NcsSectionsFactory.calc_sample_time( + sampFreq, ncsMemMap["timestamp"][-1], ncsMemMap["nb_valid"][-1] + ) n_samples = NcsSection._RECORD_SIZE * (ncsMemMap.size - 1) + ncsMemMap["nb_valid"][-1] section0 = NcsSection( - startRec=0, - startTime=ncsMemMap["timestamp"][0], - endRec=ncsMemMap.size - 1, - endTime=lastBlkEndTime, - n_samples=n_samples - ) + startRec=0, + startTime=ncsMemMap["timestamp"][0], + endRec=ncsMemMap.size - 1, + endTime=lastBlkEndTime, + n_samples=n_samples, + ) ncsSects.sects.append(section0) - + else: # need to parse all data block to detect gaps # check when the predicted timestamp is outside the tolerance @@ -210,19 +212,19 @@ def _buildNcsSections(ncsMemMap, sampFreq, gapTolerance=0): gap_inds = np.flatnonzero(np.abs(delta - delta_prediction) > gapTolerance) 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] stop = sections_limits[i + 1] - duration = np.uint64(1e6 / sampFreq * ncsMemMap["nb_valid"][stop-1]) + duration = np.uint64(1e6 / sampFreq * ncsMemMap["nb_valid"][stop - 1]) ncsSects.sects.append( NcsSection( startRec=start, startTime=ncsMemMap["timestamp"][start], - endRec=stop-1, - endTime=ncsMemMap["timestamp"][stop-1] + duration, - n_samples=np.sum(ncsMemMap["nb_valid"][start:stop]) + endRec=stop - 1, + endTime=ncsMemMap["timestamp"][stop - 1] + duration, + n_samples=np.sum(ncsMemMap["nb_valid"][start:stop]), ) ) @@ -274,7 +276,6 @@ def build_for_ncs_file(ncsMemMap, nlxHdr, gapTolerance=None, strict_gap_mode=Tru # quarter of paquet size is tolerate gapTolerance = round(0.25 * NcsSection._RECORD_SIZE * 1e6 / freq) ncsSects = NcsSectionsFactory._buildNcsSections(ncsMemMap, freq, gapTolerance=gapTolerance) - # take longer data block to compute reaal sampling rate # 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 ncsSects.sampFreqUsed = sampFreqUsed ncsSects.microsPerSampUsed = NcsSectionsFactory.get_micros_per_samp_for_freq(sampFreqUsed) - elif acqType == "BML" or acqType == "ATLAS": # BML & ATLAS style with fractional frequency and micros per samp if strict_gap_mode: @@ -305,7 +305,6 @@ def build_for_ncs_file(ncsMemMap, nlxHdr, gapTolerance=None, strict_gap_mode=Tru ncsSects.sampFreqUsed = freq ncsSects.microsPerSampUsed = NcsSectionsFactory.get_micros_per_samp_for_freq(freq) - else: raise TypeError("Unknown Ncs file type from header.") diff --git a/neo/rawio/neuralynxrawio/neuralynxrawio.py b/neo/rawio/neuralynxrawio/neuralynxrawio.py index 16ee1860e..1f6367ee5 100644 --- a/neo/rawio/neuralynxrawio/neuralynxrawio.py +++ b/neo/rawio/neuralynxrawio/neuralynxrawio.py @@ -87,11 +87,11 @@ class NeuralynxRawIO(BaseRawIO): Otherwise set 0 of time to first time in dataset strict_gap_mode: bool, default: True Detect gaps using strict mode or not. - * strict_gap_mode = True then a gap is consider when timstamp difference between two + * strict_gap_mode = True then a gap is consider when timstamp difference between two consequtive data packet is more than one sample interval. * strict_gap_mode = False then a gap has an increased tolerance. Some new system with different clock need this option otherwise, too many gaps are detected - + Notes ----- * This IO supports NCS, NEV, NSE and NTT file formats (not NVT or NRD yet) @@ -131,7 +131,9 @@ class NeuralynxRawIO(BaseRawIO): ("samples", "int16", (NcsSection._RECORD_SIZE)), ] - def __init__(self, dirname="", filename="", exclude_filename=None, keep_original_times=False, strict_gap_mode=True, **kargs): + def __init__( + self, dirname="", filename="", exclude_filename=None, keep_original_times=False, strict_gap_mode=True, **kargs + ): if dirname != "": self.dirname = dirname @@ -797,7 +799,9 @@ def scan_stream_ncs_files(self, ncs_filenames): verify_sec_struct = NcsSectionsFactory._verifySectionsStructure if not chanSectMap or (not verify_sec_struct(data, chan_ncs_sections)): - chan_ncs_sections = NcsSectionsFactory.build_for_ncs_file(data, nlxHeader, strict_gap_mode=self.strict_gap_mode) + chan_ncs_sections = NcsSectionsFactory.build_for_ncs_file( + data, nlxHeader, strict_gap_mode=self.strict_gap_mode + ) # register file section structure for all contained channels for chan_uid in zip(nlxHeader["channel_names"], np.asarray(nlxHeader["channel_ids"], dtype=str)): diff --git a/neo/test/rawiotest/test_neuralynxrawio.py b/neo/test/rawiotest/test_neuralynxrawio.py index c8a8cdc6c..c294cd4d5 100644 --- a/neo/test/rawiotest/test_neuralynxrawio.py +++ b/neo/test/rawiotest/test_neuralynxrawio.py @@ -228,7 +228,7 @@ def test_build_given_actual_frequency(self): ncsBlocks = NcsSections() ncsBlocks.sampFreqUsed = 1 / (35e-6) ncsBlocks.microsPerSampUsed = 35 - + ncsBlocks = NcsSectionsFactory._buildNcsSections(data0, ncsBlocks.sampFreqUsed) self.assertEqual(len(ncsBlocks.sects), 1) @@ -324,7 +324,7 @@ class TestNcsSections(TestNeuralynxRawIO, unittest.TestCase): """ Test building NcsBlocks for files of different revisions. """ - + entities_to_test = [] def test_equality(self):