Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/devel/13112.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug with :func:`mne.io.read_raw_egi` where ``info["dev_head_t"]`` was an identity matrix instead of ``None``, by `Eric Larson`_.
4 changes: 1 addition & 3 deletions mne/_fiff/meas_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3326,13 +3326,12 @@ def create_info(ch_names, sfreq, ch_types="misc", verbose=None):

def _empty_info(sfreq):
"""Create an empty info dictionary."""
from ..transforms import Transform

_none_keys = (
"acq_pars",
"acq_stim",
"ctf_head_t",
"description",
"dev_head_t",
"dev_ctf_t",
"dig",
"experimenter",
Expand Down Expand Up @@ -3373,7 +3372,6 @@ def _empty_info(sfreq):
info["highpass"] = 0.0
info["sfreq"] = float(sfreq)
info["lowpass"] = info["sfreq"] / 2.0
info["dev_head_t"] = Transform("meg", "head")
info._update_redundant()
info._check_consistency()
return info
Expand Down
3 changes: 3 additions & 0 deletions mne/chpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
_sss_basis,
)
from .transforms import (
Transform,
_angle_between_quats,
_fit_matched_points,
_quat_to_affine,
Expand Down Expand Up @@ -1274,6 +1275,7 @@ def compute_chpi_locs(
t_step_max=1.0,
too_close="raise",
adjust_dig=False,
*,
verbose=None,
):
"""Compute locations of each cHPI coils over time.
Expand Down Expand Up @@ -1323,6 +1325,7 @@ def compute_chpi_locs(
_check_option("too_close", too_close, ["raise", "warning", "info"])
_check_chpi_param(chpi_amplitudes, "chpi_amplitudes")
_validate_type(info, Info, "info")
_validate_type(info["dev_head_t"], Transform, "info['dev_head_t']")
sin_fits = chpi_amplitudes # use the old name below
del chpi_amplitudes
proj = sin_fits["proj"]
Expand Down
3 changes: 2 additions & 1 deletion mne/forward/_make_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ def _prepare_for_forward(
info = Info(
chs=info["chs"],
comps=info["comps"],
dev_head_t=info["dev_head_t"],
# The forward-writing code always wants a dev_head_t, so give an identity one
dev_head_t=info["dev_head_t"] or Transform("meg", "head"),
mri_file=info_trans,
mri_id=mri_id,
meas_file=info_extra,
Expand Down
3 changes: 0 additions & 3 deletions mne/forward/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ def _get_tag_int(fid, node, name, id_):
"""Check we have an appropriate tag."""
tag = find_tag(fid, node, id_)
if tag is None:
fid.close()
raise ValueError(name + " tag not found")
return int(tag.data.item())

Expand Down Expand Up @@ -649,7 +648,6 @@ def read_forward_solution(fname, include=(), exclude=(), *, ordered=True, verbos
mri_head_t["from"] != FIFF.FIFFV_COORD_MRI
or mri_head_t["to"] != FIFF.FIFFV_COORD_HEAD
):
fid.close()
raise ValueError("MRI/head coordinate transformation not found")
fwd["mri_head_t"] = mri_head_t

Expand Down Expand Up @@ -1124,7 +1122,6 @@ def write_forward_meas_info(fid, info):
# get transformation from CTF and DEVICE to HEAD coordinate frame
meg_head_t = info.get("dev_head_t", info.get("ctf_head_t"))
if meg_head_t is None:
fid.close()
raise ValueError("Head<-->sensor transform not found")
write_coord_trans(fid, meg_head_t)

Expand Down
1 change: 1 addition & 0 deletions mne/forward/tests/test_make_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ def test_use_coil_def(tmp_path):
info = create_info(1, 1000.0, "mag")
info["chs"][0]["coil_type"] = 9999
info["chs"][0]["loc"][:] = [0, 0, 0.02, 1, 0, 0, 0, 1, 0, 0, 0, 1]
info["dev_head_t"] = Transform("meg", "head")
sphere = make_sphere_model((0.0, 0.0, 0.0), 0.01)
src = setup_volume_source_space(pos=5, sphere=sphere)
trans = Transform("head", "mri", None)
Expand Down
2 changes: 2 additions & 0 deletions mne/io/artemis123/artemis123.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ def __init__(
self, tmin=0, tmax=0.25, t_window=0.25, t_step_min=0.25
)
assert len(coil_amplitudes["times"]) == 1
# Need an ititial dev_head_t to compute coil locations
self.info["dev_head_t"] = Transform("meg", "head")
coil_locs = compute_chpi_locs(self.info, coil_amplitudes)
with info._unlock():
info["hpi_results"] = None
Expand Down
1 change: 1 addition & 0 deletions mne/io/artemis123/tests/test_artemis123.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def test_dev_head_t():
"""Test dev_head_t computation for Artemis123."""
# test a random selected point
raw = read_raw_artemis123(short_hpi_1kz_fname, preload=True, add_head_trans=False)
assert raw.info["dev_head_t"] is None
meg_picks = pick_types(raw.info, meg=True, eeg=False)

# checked against matlab reader.
Expand Down
1 change: 1 addition & 0 deletions mne/io/egi/tests/test_egi.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def test_egi_mff_pause(fname, skip_times, event_times):
events_as_annotations=False,
)
assert raw.info["sfreq"] == 250.0 # true for all of these files
assert raw.info["dev_head_t"] is None # no MEG data
assert len(raw.annotations) == len(skip_times)

# assert event onsets match expected times
Expand Down
4 changes: 3 additions & 1 deletion mne/io/fiff/tests/test_raw_fiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from mne.filter import filter_data
from mne.io import RawArray, base, concatenate_raws, match_channel_orders, read_raw_fif
from mne.io.tests.test_raw import _test_concat, _test_raw_reader
from mne.transforms import Transform
from mne.utils import (
_dt_to_stamp,
_record_warnings,
Expand Down Expand Up @@ -1642,7 +1643,8 @@ def test_add_channels():

# Testing force updates
raw_arr_info = create_info(["1", "2"], raw_meg.info["sfreq"], "eeg")
orig_head_t = raw_arr_info["dev_head_t"]
assert raw_arr_info["dev_head_t"] is None
orig_head_t = Transform("meg", "head")
raw_arr = rng.randn(2, raw_eeg.n_times)
raw_arr = RawArray(raw_arr, raw_arr_info)
# This should error because of conflicts in Info
Expand Down
3 changes: 2 additions & 1 deletion mne/io/kit/kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from ..._fiff.utils import _mult_cal_one
from ...epochs import BaseEpochs
from ...event import read_events
from ...transforms import als_ras_trans, apply_trans
from ...transforms import Transform, als_ras_trans, apply_trans
from ...utils import (
_check_fname,
_check_option,
Expand Down Expand Up @@ -831,6 +831,7 @@ def get_kit_info(rawfile, allow_unknown_format, standardize_names=None, verbose=
highpass=sqd["highpass"],
kit_system_id=sysid,
description=description,
dev_head_t=Transform("meg", "head"),
)

# Creates a list of dicts of meg channels for raw.info
Expand Down
4 changes: 4 additions & 0 deletions mne/io/tests/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ def _test_raw_reader(
meas_date = raw.info["meas_date"]
assert meas_date is None or meas_date >= _stamp_to_dt((0, 0))

# gh-13112
if "meg" not in raw:
assert raw.info["dev_head_t"] is None, "dev_head_t should be None if no MEG"

# test repr_html
assert "Channels" in raw._repr_html_()

Expand Down
2 changes: 2 additions & 0 deletions mne/tests/test_chpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,8 @@ def test_calculate_head_pos_kit():
# plotting works
plot_head_positions(quats, info=raw.info)
raw_berlin = read_raw_kit(berlin_fname)
assert "meg" in raw_berlin
assert raw_berlin.info["dev_head_t"] is not None
assert_allclose(raw_berlin.info["dev_head_t"]["trans"], np.eye(4))
assert len(raw_berlin.info["hpi_results"]) == 0
with pytest.raises(ValueError, match="Invalid value"):
Expand Down
Loading