From 1bcbc16bab8a69649805b3ecb0f8abd2c42246f6 Mon Sep 17 00:00:00 2001 From: Chris Kerr Date: Sat, 16 Mar 2019 13:41:49 +0100 Subject: [PATCH 1/3] Use `np.frombuffer` instead of `np.fromstring` Fixes #22 --- galvani/BioLogic.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/galvani/BioLogic.py b/galvani/BioLogic.py index 0fa07f0..c63342d 100644 --- a/galvani/BioLogic.py +++ b/galvani/BioLogic.py @@ -275,7 +275,7 @@ def read_VMP_modules(fileobj, read_module_data=True): if len(hdr_bytes) < VMPmodule_hdr.itemsize: raise IOError("Unexpected end of file while reading module header") - hdr = np.fromstring(hdr_bytes, dtype=VMPmodule_hdr, count=1) + hdr = np.frombuffer(hdr_bytes, dtype=VMPmodule_hdr, count=1) hdr_dict = dict(((n, hdr[n][0]) for n in VMPmodule_hdr.names)) hdr_dict['offset'] = fileobj.tell() if read_module_data: @@ -326,17 +326,17 @@ class MPRfile: data_module, = (m for m in modules if m['shortname'] == b'VMP data ') maybe_log_module = [m for m in modules if m['shortname'] == b'VMP LOG '] - n_data_points = np.fromstring(data_module['data'][:4], dtype=' 40000 and ole_timestamp1 < 50000: From b08c2f44350d29c5d6335f5b6ac4aa3dddd5bb14 Mon Sep 17 00:00:00 2001 From: Chris Kerr Date: Sat, 16 Mar 2019 13:43:26 +0100 Subject: [PATCH 2/3] Use `array.item()` instead of `np.asscalar()` --- galvani/BioLogic.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/galvani/BioLogic.py b/galvani/BioLogic.py index c63342d..df954d2 100644 --- a/galvani/BioLogic.py +++ b/galvani/BioLogic.py @@ -327,8 +327,7 @@ class MPRfile: maybe_log_module = [m for m in modules if m['shortname'] == b'VMP LOG '] n_data_points = np.frombuffer(data_module['data'][:4], dtype=' Date: Sat, 16 Mar 2019 13:50:50 +0100 Subject: [PATCH 3/3] Fix 'invalid escape sequence' warnings --- galvani/BioLogic.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/galvani/BioLogic.py b/galvani/BioLogic.py index df954d2..a34ad13 100644 --- a/galvani/BioLogic.py +++ b/galvani/BioLogic.py @@ -70,7 +70,8 @@ def MPTfile(file_or_path): if magic != b'EC-Lab ASCII FILE\r\n': raise ValueError("Bad first line for EC-Lab file: '%s'" % magic) - nb_headers_match = re.match(b'Nb header lines : (\d+)\s*$', next(mpt_file)) + # TODO use rb'string' here once Python 2 is no longer supported + nb_headers_match = re.match(b'Nb header lines : (\\d+)\\s*$', next(mpt_file)) nb_headers = int(nb_headers_match.group(1)) if nb_headers < 3: raise ValueError("Too few header lines: %d" % nb_headers) @@ -107,7 +108,7 @@ def MPTfileCSV(file_or_path): if magic.rstrip() != 'EC-Lab ASCII FILE': raise ValueError("Bad first line for EC-Lab file: '%s'" % magic) - nb_headers_match = re.match('Nb header lines : (\d+)\s*$', next(mpt_file)) + nb_headers_match = re.match(r'Nb header lines : (\d+)\s*$', next(mpt_file)) nb_headers = int(nb_headers_match.group(1)) if nb_headers < 3: raise ValueError("Too few header lines: %d" % nb_headers)