Skip to content

Commit

Permalink
FIX: Pip pre
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Oct 25, 2023
1 parent 660203e commit 4524869
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
12 changes: 9 additions & 3 deletions mne/io/bti/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
17 changes: 16 additions & 1 deletion mne/io/ctf/res4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand All @@ -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
2 changes: 1 addition & 1 deletion mne/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 4524869

Please sign in to comment.