From 452486960681b6124e2daa8f1d59609d8d4c4440 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 25 Oct 2023 14:11:19 -0400 Subject: [PATCH] FIX: Pip pre --- mne/io/bti/read.py | 12 +++++++++--- mne/io/ctf/res4.py | 17 ++++++++++++++++- mne/surface.py | 2 +- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/mne/io/bti/read.py b/mne/io/bti/read.py index 4af53112ae8..d05e2d9d941 100644 --- a/mne/io/bti/read.py +++ b/mne/io/bti/read.py @@ -48,12 +48,12 @@ def read_int8(fid): def read_uint16(fid): """Read unsigned 16bit integer from bti file.""" - return _unpack_simple(fid, ">u2", np.uint16) + return _unpack_simple(fid, ">u2", np.uint32) def read_int16(fid): """Read 16bit integer from bti file.""" - return _unpack_simple(fid, ">i2", np.int16) + return _unpack_simple(fid, ">i2", np.int32) def read_uint32(fid): @@ -88,7 +88,13 @@ def read_double(fid): def read_int16_matrix(fid, rows, cols): """Read 16bit integer matrix from bti file.""" - return _unpack_matrix(fid, rows, cols, dtype=">i2", out_dtype=np.int16) + return _unpack_matrix( + fid, + rows, + cols, + dtype=">i2", + out_dtype=np.int32, + ) def read_float_matrix(fid, rows, cols): diff --git a/mne/io/ctf/res4.py b/mne/io/ctf/res4.py index b5c0f884c99..2ea2f619bcc 100644 --- a/mne/io/ctf/res4.py +++ b/mne/io/ctf/res4.py @@ -43,7 +43,7 @@ def _read_ustring(fid, n_bytes): def _read_int2(fid): """Read int from short.""" - return np.fromfile(fid, ">i2", 1)[0] + return _auto_cast(np.fromfile(fid, ">i2", 1)[0]) def _read_int(fid): @@ -208,6 +208,9 @@ def _read_res4(dsdir): coil["area"] *= 1e-4 # convert to dict chs = [dict(zip(chs.dtype.names, x)) for x in chs] + for ch in chs: + for key, val in ch.items(): + ch[key] = _auto_cast(val) res["chs"] = chs for k in range(res["nchan"]): res["chs"][k]["ch_name"] = res["ch_names"][k] @@ -216,3 +219,15 @@ def _read_res4(dsdir): _read_comp_coeff(fid, res) logger.info(" res4 data read.") return res + + +def _auto_cast(x): + # Upcast scalars + if isinstance(x, np.ScalarType): + if x.dtype.kind == "i": + if x.dtype != np.int64: + x = x.astype(np.int64) + elif x.dtype.kind == "f": + if x.dtype != np.float64: + x = x.astype(np.float64) + return x diff --git a/mne/surface.py b/mne/surface.py index b042361305a..d0aac3abe0d 100644 --- a/mne/surface.py +++ b/mne/surface.py @@ -772,7 +772,7 @@ def _call_old(self, rr, n_jobs): def _fread3(fobj): """Read 3 bytes and adjust.""" - b1, b2, b3 = np.fromfile(fobj, ">u1", 3) + b1, b2, b3 = np.fromfile(fobj, ">u1", 3).astype(np.int64) return (b1 << 16) + (b2 << 8) + b3