Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black formatting #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions neo/rawio/neuralynxrawio/ncssections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]),
)
)

Expand Down Expand Up @@ -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])
Expand All @@ -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:
Expand All @@ -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.")

Expand Down
12 changes: 8 additions & 4 deletions neo/rawio/neuralynxrawio/neuralynxrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)):
Expand Down
4 changes: 2 additions & 2 deletions neo/test/rawiotest/test_neuralynxrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -324,7 +324,7 @@ class TestNcsSections(TestNeuralynxRawIO, unittest.TestCase):
"""
Test building NcsBlocks for files of different revisions.
"""

entities_to_test = []

def test_equality(self):
Expand Down