Skip to content

Commit

Permalink
Pull addition of empty file to static method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter N. Steinmetz authored and Peter N. Steinmetz committed Feb 13, 2024
1 parent 0c175b4 commit aed56d2
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 @@ -303,6 +303,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 @@ -503,7 +505,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 @@ -512,15 +515,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 aed56d2

Please sign in to comment.