From c16c836bd2711357846b5fc55ca14be3dedcfa49 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Tue, 3 Jan 2023 13:37:28 -0500 Subject: [PATCH] MAINT: Allow no dig --- mne/_fiff/_digitization.py | 3 +++ mne/coreg.py | 10 ++++++---- mne/gui/_coreg.py | 13 ++++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/mne/_fiff/_digitization.py b/mne/_fiff/_digitization.py index e70a9410af5..c95078f3a3a 100644 --- a/mne/_fiff/_digitization.py +++ b/mne/_fiff/_digitization.py @@ -294,6 +294,7 @@ def _get_data_as_dict_from_dig(dig, exclude_ref_channel=True): # Split up the dig points by category hsp, hpi, elp = list(), list(), list() fids, dig_ch_pos_location = dict(), list() + dig = [] if dig is None else dig for d in dig: if d["kind"] == FIFF.FIFFV_POINT_CARDINAL: @@ -308,6 +309,8 @@ def _get_data_as_dict_from_dig(dig, exclude_ref_channel=True): dig_ch_pos_location.append(d["r"]) dig_coord_frames = set([d["coord_frame"] for d in dig]) + if len(dig_coord_frames) == 0: + dig_coord_frames = set([FIFF.FIFFV_COORD_HEAD]) if len(dig_coord_frames) != 1: raise RuntimeError( "Only single coordinate frame in dig is supported, " diff --git a/mne/coreg.py b/mne/coreg.py index cd9158b7cba..e5de1709cff 100644 --- a/mne/coreg.py +++ b/mne/coreg.py @@ -1551,7 +1551,9 @@ def _setup_bem(self): low_res_path = _find_head_bem(self._subject, self._subjects_dir, high_res=False) if high_res_path is None and low_res_path is None: raise RuntimeError( - "No standard head model was " f"found for subject {self._subject}" + "No standard head model was " + f"found for subject {self._subject} in " + f"{self._subjects_dir}" ) if high_res_path is not None: self._bem_high_res = _read_surface( @@ -1988,9 +1990,9 @@ def fit_fiducials( return self def _setup_icp(self, n_scale_params): - head_pts = list() - mri_pts = list() - weights = list() + head_pts = [np.zeros((0, 3))] + mri_pts = [np.zeros((0, 3))] + weights = [np.zeros(0)] if self._has_dig_data and self._hsp_weight > 0: # should be true head_pts.append(self._filtered_extra_points) mri_pts.append( diff --git a/mne/gui/_coreg.py b/mne/gui/_coreg.py index c44bd71dd75..6cad5233504 100644 --- a/mne/gui/_coreg.py +++ b/mne/gui/_coreg.py @@ -1063,11 +1063,14 @@ def _update_distance_estimation(self): ) dists = self.coreg.compute_dig_mri_distances() * 1e3 if self._hsp_weight > 0: - value += ( - "\nHSP <-> MRI (mean/min/max): " - f"{np.mean(dists):.2f} " - f"/ {np.min(dists):.2f} / {np.max(dists):.2f} mm" - ) + if len(dists) == 0: + value += "\nNo head shape points found." + else: + value += ( + "\nHSP <-> MRI (mean/min/max): " + f"{np.mean(dists):.2f} " + f"/ {np.min(dists):.2f} / {np.max(dists):.2f} mm" + ) self._forward_widget_command("fit_label", "set_value", value) def _update_parameters(self):