Skip to content

Commit 9a6216b

Browse files
author
sprenger
committed
[neuralynx] cleanup and refactoring
1 parent 6d9333b commit 9a6216b

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

neo/rawio/neuralynxrawio/ncssections.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import math
22
import numpy as np
3-
import copy
4-
# from memory_profiler import profile
53

64

75
class NcsSections:
@@ -149,38 +147,38 @@ def _parseGivenActualFrequency(ncsMemMap, ncsSects, chanNum, reqFreq, blkOnePred
149147
NcsSections object with block locations marked
150148
"""
151149
startBlockPredTime = blkOnePredTime
152-
blkLen = 0
150+
blk_len = 0
153151
curBlock = ncsSects.sects[0]
154152
for recn in range(1, ncsMemMap.shape[0]):
155153
timestamp = ncsMemMap['timestamp'][recn]
156154
channel_id = ncsMemMap['channel_id'][recn]
157155
sample_rate = ncsMemMap['sample_rate'][recn]
158156
nb_valid = ncsMemMap['nb_valid'][recn]
159157

160-
# hdr = CscRecordHeader(ncsMemMap, recn)
161158
if channel_id != chanNum or sample_rate != reqFreq:
162159
raise IOError('Channel number or sampling frequency changed in ' +
163160
'records within file')
164161
predTime = NcsSectionsFactory.calc_sample_time(ncsSects.sampFreqUsed,
165-
startBlockPredTime, blkLen)
162+
startBlockPredTime, blk_len)
166163
nValidSamps = nb_valid
167164
if timestamp != predTime:
168165
curBlock.endRec = recn - 1
169166
curBlock.endTime = predTime
167+
curBlock.n_samples = blk_len
170168
curBlock = NcsSection(recn, timestamp, -1, -1, -1)
171169
ncsSects.sects.append(curBlock)
172170
startBlockPredTime = NcsSectionsFactory.calc_sample_time(
173171
ncsSects.sampFreqUsed,
174172
timestamp,
175173
nValidSamps)
176-
blkLen = 0
174+
blk_len = 0
177175
else:
178-
blkLen += nValidSamps
176+
blk_len += nValidSamps
179177

180178
curBlock.endRec = ncsMemMap.shape[0] - 1
181179
endTime = NcsSectionsFactory.calc_sample_time(ncsSects.sampFreqUsed,
182180
startBlockPredTime,
183-
blkLen)
181+
blk_len)
184182
curBlock.endTime = endTime
185183

186184
return ncsSects
@@ -230,7 +228,8 @@ def _buildGivenActualFrequency(ncsMemMap, actualSampFreq, reqFreq):
230228
ncsMemMap['sample_rate'][lastBlkI] == reqFreq and \
231229
lts == predLastBlockStartTime:
232230
lastBlkEndTime = NcsSectionsFactory.calc_sample_time(actualSampFreq, lts, lnb)
233-
curBlock = NcsSection(0, ts0, lastBlkI, lastBlkEndTime, -1)
231+
n_samples = NcsSection._RECORD_SIZE * lastBlkI
232+
curBlock = NcsSection(0, ts0, lastBlkI, lastBlkEndTime, n_samples)
234233

235234
nb.sects.append(curBlock)
236235
return nb
@@ -244,7 +243,6 @@ def _buildGivenActualFrequency(ncsMemMap, actualSampFreq, reqFreq):
244243
blkOnePredTime)
245244

246245
@staticmethod
247-
# @profile
248246
def _parseForMaxGap(ncsMemMap, ncsSects, maxGapLen):
249247
"""
250248
Parse blocks of records from file, allowing a maximum gap in timestamps between records
@@ -307,7 +305,8 @@ def _parseForMaxGap(ncsMemMap, ncsSects, maxGapLen):
307305
n_samples = np.sum(ncsMemMap['nb_valid'][curr_sec.startRec:gap_rec_id + 1])
308306
curr_sec.n_samples = n_samples
309307

310-
next_sec = NcsSection(gap_rec_id + 1, ncsMemMap['timestamp'][gap_rec_id + 1], -1, -1, -1)
308+
next_sec = NcsSection(gap_rec_id + 1,
309+
ncsMemMap['timestamp'][gap_rec_id + 1], -1, -1, -1)
311310
ncsSects.sects.append(next_sec)
312311

313312
curr_sec = ncsSects.sects[-1]
@@ -367,7 +366,7 @@ def _buildForMaxGap(ncsMemMap, nomFreq):
367366
freqInFile = math.floor(nomFreq)
368367
if lts - predLastBlockStartTime == 0 and lcid == chanNum and lsr == freqInFile:
369368
endTime = NcsSectionsFactory.calc_sample_time(nomFreq, lts, lnb)
370-
curBlock = NcsSection(0, ts0, lastBlkI, endTime, -1)
369+
curBlock = NcsSection(0, ts0, lastBlkI, endTime, numSampsForPred)
371370
nb.sects.append(curBlock)
372371
nb.sampFreqUsed = numSampsForPred / (lts - ts0) * 1e6
373372
nb.microsPerSampUsed = NcsSectionsFactory.get_micros_per_samp_for_freq(nb.sampFreqUsed)

neo/rawio/neuralynxrawio/neuralynxrawio.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def _source_name(self):
112112
else:
113113
return self.dirname
114114

115+
# from memory_profiler import profile
116+
#
117+
# @profile()
115118
def _parse_header(self):
116119

117120
stream_channels = []
@@ -376,7 +379,6 @@ def _parse_header(self):
376379
# ~ ev_ann['digital_marker'] =
377380
# ~ ev_ann['analog_marker'] =
378381

379-
380382
def _get_file_map(self, filename):
381383
"""
382384
Create memory maps when needed

0 commit comments

Comments
 (0)