Skip to content

Commit

Permalink
Merge pull request #1403 from PeterNSteinmetz/IsolateFileMap
Browse files Browse the repository at this point in the history
NeuralynxIO: get_file_map as static method
  • Loading branch information
samuelgarcia authored Feb 27, 2024
2 parents 1b0f1ef + aed56d2 commit c33de92
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions neo/rawio/neuralynxrawio/neuralynxrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ def _parse_header(self):
internal_ids = []
else:
data = self._get_file_map(filename)
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:
if internal_event_id not in self.internal_event_ids:
Expand Down Expand Up @@ -519,7 +521,8 @@ def min_max_tuple(tuple1, tuple2):
# ~ ev_ann['digital_marker'] =
# ~ ev_ann['analog_marker'] =

def _get_file_map(self, filename):
@staticmethod
def _get_file_map(filename):
"""
Create memory maps when needed
see also https://github.com/numpy/numpy/issues/19340
Expand All @@ -528,15 +531,14 @@ def _get_file_map(self, filename):
suffix = filename.suffix.lower()[1:]

if suffix == "ncs":
return np.memmap(filename, dtype=self._ncs_dtype, mode="r", offset=NlxHeader.HEADER_SIZE)
return np.memmap(filename, dtype=NeuralynxRawIO._ncs_dtype, mode="r", offset=NlxHeader.HEADER_SIZE)

elif suffix in ["nse", "ntt"]:
info = NlxHeader(filename)
dtype = get_nse_or_ntt_dtype(info, suffix)

# return empty map if file does not contain data
if os.path.getsize(filename) <= NlxHeader.HEADER_SIZE:
self._empty_nse_ntt.append(filename)
return np.zeros((0,), dtype=dtype)

return np.memmap(filename, dtype=dtype, mode="r", offset=NlxHeader.HEADER_SIZE)
Expand Down

0 comments on commit c33de92

Please sign in to comment.