From 971f501a56f56dd726ebb54c7a58f4791567f1db Mon Sep 17 00:00:00 2001 From: olivier Date: Mon, 19 Jun 2023 11:32:02 +0100 Subject: [PATCH] spikeglx.Reader(): add option to specify meta-data file --- release_notes.md | 3 +++ setup.py | 2 +- src/spikeglx.py | 12 ++++++------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/release_notes.md b/release_notes.md index 82bd7b4..760a839 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,4 +1,7 @@ # 0.6.0 +## 0.6.2 2023-06-19 +- add option to specify meta-data file for spikeglx.Reader + ## 0.6.1 2023-06-06 - Fix bug in ADC cycles sampling for Neuropixel 1.0 probes - diff --git a/setup.py b/setup.py index 94223c9..a2ab78c 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setuptools.setup( name="ibl-neuropixel", - version="0.6.1", + version="0.6.2", author="The International Brain Laboratory", description="Collection of tools for Neuropixel 1.0 and 2.0 probes data", long_description=long_description, diff --git a/src/spikeglx.py b/src/spikeglx.py index 5f9fbc7..fa955c9 100644 --- a/src/spikeglx.py +++ b/src/spikeglx.py @@ -39,7 +39,7 @@ class Reader: """ def __init__(self, sglx_file, open=True, nc=None, ns=None, fs=None, dtype='int16', s2v=None, - nsync=None, ignore_warnings=False): + nsync=None, ignore_warnings=False, meta_file=None): """ An interface for reading data from a SpikeGLX file :param sglx_file: Path to a SpikeGLX file (compressed or otherwise), or to a meta-data file @@ -47,8 +47,8 @@ def __init__(self, sglx_file, open=True, nc=None, ns=None, fs=None, dtype='int16 """ self.ignore_warnings = ignore_warnings sglx_file = Path(sglx_file) - file_meta_data = sglx_file.with_suffix('.meta') - if file_meta_data == sglx_file: + meta_file = meta_file or sglx_file.with_suffix('.meta') + if meta_file == sglx_file: # if a meta-data file is provided, try to get the binary file self.file_bin = sglx_file.with_suffix('.cbin') if sglx_file.with_suffix('.cbin').exists() else None self.file_bin = sglx_file.with_suffix('.bin') if sglx_file.with_suffix('.bin').exists() else None @@ -57,7 +57,7 @@ def __init__(self, sglx_file, open=True, nc=None, ns=None, fs=None, dtype='int16 self.nbytes = self.file_bin.stat().st_size if self.file_bin else None self.dtype = np.dtype(dtype) - if not file_meta_data.exists(): + if not meta_file.exists(): # if no meta-data file is provided, try to get critical info from the binary file # by seeing if filesize checks out with neuropixel 384 channels if self.file_bin.stat().st_size / 384 % 2 == 0: @@ -85,8 +85,8 @@ def __init__(self, sglx_file, open=True, nc=None, ns=None, fs=None, dtype='int16 self.channel_conversion_sample2v['samples'][-nsync:] = 1 else: # normal case we continue reading and interpreting the metadata file - self.file_meta_data = file_meta_data - self.meta = read_meta_data(file_meta_data) + self.file_meta_data = meta_file + self.meta = read_meta_data(meta_file) self.channel_conversion_sample2v = _conversion_sample2v_from_meta(self.meta) self._raw = None if open and self.file_bin: