Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
752854d
Add EvokedField.plotter
wmvanvliet Sep 20, 2023
d9b2e07
Merge branch 'main' of github.com:mne-tools/mne-python
wmvanvliet Sep 27, 2023
55edc31
Merge branch 'main' of github.com:mne-tools/mne-python
wmvanvliet Oct 2, 2023
bb7e229
Merge branch 'main' of github.com:mne-tools/mne-python
wmvanvliet Oct 4, 2023
1178ebc
BUG: Fix bug with sensor_colors
larsoner Oct 4, 2023
7556823
Update devel.rst
larsoner Oct 4, 2023
cb5a520
Add foreground/background parameters to EvokedField plot
wmvanvliet Oct 4, 2023
d4015d4
Set foreground automatically
wmvanvliet Oct 4, 2023
2c307fe
First working version of lasso select in plot_evoked_topo
wmvanvliet Oct 4, 2023
3b37ea3
Add slider to control contour line thickness
wmvanvliet Oct 4, 2023
6245c0a
Merge branch 'main' into evoked-field-colors
wmvanvliet Oct 4, 2023
4f43e50
Merge branch 'colors' into xfit
wmvanvliet Oct 4, 2023
9779843
Merge branch 'evoked-field-colors' into xfit
wmvanvliet Oct 4, 2023
9747338
Merge branch 'sensorselect' into xfit
wmvanvliet Oct 4, 2023
8268315
fix
wmvanvliet Oct 5, 2023
7dd77d9
Some initial stuff
wmvanvliet Oct 6, 2023
10c2b2a
Merge branch 'main' into xfit
wmvanvliet Oct 13, 2023
f0a92da
Merge branch 'main' of github.com:mne-tools/mne-python into xfit
wmvanvliet Oct 13, 2023
8ef1179
Small steps
wmvanvliet Oct 18, 2023
ca46e1a
Merge remote-tracking branch 'upstream/main' into xfit
wmvanvliet Oct 18, 2023
458c509
Continue work on the "fit dipole" button
wmvanvliet Oct 19, 2023
3c91d05
More progress
wmvanvliet Oct 31, 2023
6d2496c
Merge branch 'main' into xfit
wmvanvliet Nov 4, 2023
8fc904d
Merge branch 'main' of github.com:mne-tools/mne-python into xfit
wmvanvliet Nov 11, 2023
6170c63
Merge branch 'main' of github.com:mne-tools/mne-python into sensorselect
wmvanvliet Nov 11, 2023
41087bb
Fix divide by zero
wmvanvliet Nov 14, 2023
568560b
Fix sensor picking
wmvanvliet Nov 14, 2023
f6738e7
Fix bug
wmvanvliet Nov 14, 2023
a83b8fd
Fix more renames
wmvanvliet Nov 14, 2023
3bfe2a5
Don't draw patches for channels that do not exist
wmvanvliet Nov 14, 2023
2e94752
Move the ChannelsSelect ui-event one abstraction layer higher
wmvanvliet Nov 14, 2023
3c6b73c
Some more fixes
wmvanvliet Nov 14, 2023
9b6bd60
select_many should not notify()
wmvanvliet Nov 14, 2023
8796836
Merge branch 'main' into sensorselect
wmvanvliet Nov 14, 2023
573cb40
Add "select" parameter to enable/disable the lasso selection tool
wmvanvliet Nov 14, 2023
facd394
Add select parameter to relevant methods
wmvanvliet Nov 14, 2023
a0069d8
Update test
wmvanvliet Nov 15, 2023
76aebb3
Merge branch 'sensorselect' into xfit
wmvanvliet Nov 27, 2023
1cbdb96
Merge branch 'main' into xfit
wmvanvliet Dec 11, 2023
b0e6cb2
Enable sensor selection again
wmvanvliet Dec 11, 2023
474f184
Merge branch 'main' of github.com:mne-tools/mne-python into xfit
wmvanvliet Dec 18, 2023
bc54c3a
Merge branch 'main' into xfit
wmvanvliet Apr 19, 2024
aa25982
Merge branch 'main' into xfit
wmvanvliet May 17, 2024
bb4fd2c
Implement toggling fixed orientation with MNE solution
wmvanvliet May 17, 2024
b498c15
small fixes
wmvanvliet Jun 4, 2024
c2eed61
Merge branch 'xfit' of github.com:wmvanvliet/mne-python into xfit
wmvanvliet Jun 4, 2024
f7005a5
Merge branch 'main' into xfit
wmvanvliet Jun 7, 2024
b47792e
Merge branch 'xfit' of github.com:wmvanvliet/mne-python into xfit
wmvanvliet Jun 7, 2024
fda59e8
Merge branch 'main' into xfit
wmvanvliet Jul 12, 2024
ca1b99e
Remove features not for v1
wmvanvliet Jul 14, 2024
1b877df
Work more on xfit
wmvanvliet Jul 18, 2024
f7bd8cc
Fixes
wmvanvliet Jul 18, 2024
5f594dd
more fixes
wmvanvliet Jul 19, 2024
263b99f
Merge branch 'main' into xfit
wmvanvliet Jul 22, 2024
eaa081e
fix multi-dipole model
wmvanvliet Jul 24, 2024
ffb2fe1
Add save option
wmvanvliet Jul 24, 2024
2f801a4
style tweaks
wmvanvliet Jul 24, 2024
56ebda7
Merge branch 'main' into sensorselect
wmvanvliet Jul 24, 2024
d913fff
fix bugs (thanks vulture!)
wmvanvliet Jul 24, 2024
13877b4
Add rank parameter
wmvanvliet Jul 29, 2024
74e80d6
Merge branch 'xfit' of github.com:wmvanvliet/mne-python into xfit
wmvanvliet Jul 29, 2024
4039603
Merge branch 'main' into xfit
wmvanvliet Jul 29, 2024
43e145f
Merge branch 'main' into xfit
wmvanvliet Aug 9, 2024
b2bdbe2
Merge branch 'xfit' of github.com:wmvanvliet/mne-python into xfit
wmvanvliet Aug 9, 2024
e342e43
start work on dipole deletion
wmvanvliet Aug 21, 2024
5c8e337
Merge branch 'main' into xfit
wmvanvliet Oct 2, 2024
5bdb9e1
Finish dipole deletion, add occlusion mesh
wmvanvliet Oct 2, 2024
2aa51d6
set rank
wmvanvliet Oct 8, 2024
65fb86b
Merge branch 'main' of github.com:mne-tools/mne-python into sensorselect
wmvanvliet Oct 8, 2024
9b6b06a
Merge branch 'sensorselect' of github.com:wmvanvliet/mne-python into …
wmvanvliet Oct 8, 2024
bcef66e
attempt to fix tests
wmvanvliet Oct 8, 2024
8efcb8c
further attempts to fix tests
wmvanvliet Oct 22, 2024
87f72e2
Add what's new entry
wmvanvliet Oct 22, 2024
6601235
Merge branch 'main' into sensorselect
wmvanvliet Oct 22, 2024
871e15a
Merge branch 'sensorselect' of github.com:wmvanvliet/mne-python into …
wmvanvliet Oct 22, 2024
8ebd885
Merge branch 'main' into xfit
wmvanvliet Nov 15, 2024
5f5666a
also show field strength input fields when not plotting density
wmvanvliet Jan 7, 2025
0277981
Update unit tests for lasso select
wmvanvliet Jan 7, 2025
bea101d
Update unit tests for lasso select
wmvanvliet Jan 7, 2025
2ae07bf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 7, 2025
f55028d
Merge branch 'main' into sensorselect
wmvanvliet Jan 20, 2025
49c9d0b
Merge branch 'sensorselect' of github.com:wmvanvliet/mne-python into …
wmvanvliet Jan 20, 2025
e857a2e
Move large lasso test to test_utils.py and have smaller tests in test…
wmvanvliet Jan 20, 2025
822f761
select from proper list of channels
wmvanvliet Jan 20, 2025
51efe6c
fix version
wmvanvliet Jan 20, 2025
e806634
more versionadded annotations
wmvanvliet Jan 20, 2025
23b5c23
Merge branch 'sensorselect' into xfit
wmvanvliet Jan 20, 2025
8b1a014
Save and load dipoles Xfit style. Fix legend when hiding dipoles.
wmvanvliet Jan 21, 2025
0066f0b
cleanup
wmvanvliet Jan 21, 2025
f1a0364
more cleanup
wmvanvliet Jan 21, 2025
727fa29
Fix single dipole fitting with loose orientation
wmvanvliet Jan 21, 2025
710b77d
[autofix.ci] apply automated fixes
autofix-ci[bot] Jan 21, 2025
4b71df0
fixes proposed by vulture
wmvanvliet Jan 21, 2025
dbabf05
Properly implement and test single channel picking
wmvanvliet Jan 22, 2025
e90887d
Add logging message
wmvanvliet Jan 22, 2025
df0737f
Merge branch 'sensorselect' into xfit
wmvanvliet Jan 22, 2025
1e67acc
Merge branch 'xfit' of github.com:wmvanvliet/mne-python into xfit
wmvanvliet Jan 22, 2025
622ff54
small fix
wmvanvliet Jan 22, 2025
64b0ed1
Merge branch 'main' into xfit
wmvanvliet Jan 22, 2025
0841c88
Merge branch 'main' into xfit
wmvanvliet Jan 24, 2025
0f3239a
Merge branch 'xfit' of github.com:wmvanvliet/mne-python into xfit
wmvanvliet Jan 24, 2025
17e28b0
Merge branch 'main' into xfit
wmvanvliet Jan 26, 2025
b4467c9
Merge branch 'main' into xfit
wmvanvliet Jan 29, 2025
d878f60
fix to dipole
wmvanvliet Jan 31, 2025
b1ee63a
Add possibility to show an stc with the fieldmap
wmvanvliet Feb 4, 2025
15519eb
Take units (m or mm) into account when showing fieldmaps on top of br…
wmvanvliet Feb 4, 2025
5108607
Add unit test and towncrier
wmvanvliet Feb 4, 2025
e243310
Don't make unnecessary copy
wmvanvliet Feb 4, 2025
a1f5328
Fix
wmvanvliet Feb 4, 2025
4e7270a
Merge branch 'evoked-field-units' into xfit
wmvanvliet Feb 4, 2025
c703e32
some checks on inputs and doc
wmvanvliet Feb 5, 2025
08e28e6
Merge branch 'main' into xfit
wmvanvliet Feb 24, 2025
b01cfdf
Merge branch 'main' of github.com:mne-tools/mne-python into xfit
wmvanvliet Apr 7, 2025
35a2b64
Merge branch 'xfit' of github.com:wmvanvliet/mne-python into xfit
wmvanvliet Apr 7, 2025
8f26350
Merge branch 'main' of github.com:wmvanvliet/mne-python into xfit
wmvanvliet Jun 30, 2025
a92aead
Merge branch 'xfit' of github.com:wmvanvliet/mne-python into xfit
wmvanvliet Jun 30, 2025
f4d879d
work on dipolefitui
wmvanvliet Jul 18, 2025
648ac5b
properly transform dipole orientations for plotting
wmvanvliet Aug 18, 2025
9e27f35
change lambda2
wmvanvliet Aug 18, 2025
952a196
handle n_jobs
wmvanvliet Aug 18, 2025
d0cae85
Merge branch 'main' into xfit
wmvanvliet Aug 18, 2025
8c7c1b5
Add "dipolefit" command line utility
wmvanvliet Aug 19, 2025
2a888bb
add --hide-density parameter to command line script
wmvanvliet Aug 19, 2025
e5a3605
Add ability to specify names when adding Dipole objects to the GUI
wmvanvliet Aug 20, 2025
9874bbd
fix for eeg
wmvanvliet Aug 20, 2025
0abefff
fix for vectorsourceestiamte
wmvanvliet Aug 20, 2025
8838aca
update metavars for command line tool
wmvanvliet Aug 20, 2025
aab8aaa
Fix arrow meshes when adding multiple dipoles
wmvanvliet Aug 20, 2025
67ab49c
Add tutorial that will at some point replace the current dipole fitti…
wmvanvliet Aug 20, 2025
a8fe912
revert multi_dipole_model.py example
wmvanvliet Aug 21, 2025
a23182b
Merge branch 'main' of github.com:mne-tools/mne-python into xfit
wmvanvliet Aug 21, 2025
fbc3d10
restore missing line
wmvanvliet Aug 21, 2025
3d49fe8
fix import nesting
wmvanvliet Aug 21, 2025
003ba92
vulture fixes
wmvanvliet Aug 21, 2025
b8892d1
avoid duplicate tag
wmvanvliet Aug 21, 2025
bf0ec5b
numpydoc style
wmvanvliet Aug 21, 2025
67006a8
Don't redo forward computations unnecessarily
wmvanvliet Aug 28, 2025
eff0b58
Use _CheckInside in more places in mne/dipole.py
wmvanvliet Aug 29, 2025
cba5ddd
small bugfix
wmvanvliet Aug 29, 2025
0f8629c
Merge branch 'main' of github.com:mne-tools/mne-python into xfit
wmvanvliet Aug 29, 2025
f6a2943
Document return value.
wmvanvliet Aug 29, 2025
f8b5884
Touch 40_sensor_locations.py
wmvanvliet Aug 29, 2025
d1f53d7
Revert "Touch 40_sensor_locations.py"
wmvanvliet Aug 29, 2025
73a35c3
Fix up unit tests
wmvanvliet Sep 1, 2025
056521c
Add towncrier
wmvanvliet Sep 1, 2025
de9e836
add gui.dipolefit to API docs
wmvanvliet Sep 1, 2025
51c6494
Merge branch 'main' of github.com:mne-tools/mne-python into xfit
wmvanvliet Sep 1, 2025
046dd22
Ignore linking to DipoleFitUI
wmvanvliet Sep 4, 2025
a602932
Merge remote-tracking branch 'upstream/main' into xfit
wmvanvliet Sep 9, 2025
084841e
Merge branch 'main' into xfit
wmvanvliet Sep 9, 2025
b0adaeb
refactor dipole fitting a little
wmvanvliet Sep 9, 2025
dff558d
put back changes
wmvanvliet Sep 9, 2025
152f135
Merge branch 'main' of github.com:mne-tools/mne-python into xfit
wmvanvliet Sep 11, 2025
e717069
Use new _ForwardModeler
wmvanvliet Sep 11, 2025
5060f70
Make _ForwardModeler fill out the complete forward object
wmvanvliet Sep 11, 2025
a897369
Merge branch 'main' into xfit
wmvanvliet Sep 13, 2025
228bba7
Merge branch 'main' into xfit
wmvanvliet Sep 13, 2025
e74bbc0
Merge branch 'xfit' of github.com:wmvanvliet/mne-python into xfit
wmvanvliet Sep 13, 2025
d77dd02
Don't have fit_dipole require pyvista
wmvanvliet Sep 15, 2025
a12ce5e
Use testing data during XFit tests
wmvanvliet Sep 16, 2025
a863853
Merge branch 'xfit' of github.com:wmvanvliet/mne-python into xfit
wmvanvliet Sep 16, 2025
c8d70b8
Merge branch 'main' of github.com:mne-tools/mne-python into xfit
wmvanvliet Sep 16, 2025
ab2c39a
remove print()
wmvanvliet Sep 16, 2025
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/api/inverse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Inverse Solutions
Dipole
DipoleFixed
fit_dipole
gui.dipolefit

:py:mod:`mne.dipole`:

Expand Down
1 change: 1 addition & 0 deletions doc/changes/dev/13074.newfeature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a GUI for interactive guided dipole fitting (:func:`mne.gui.dipolefit`), by `Marijn van Vliet`_
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@
"default",
# unlinkable
"CoregistrationUI",
"DipoleFitUI",
"mne_qt_browser.figure.MNEQtBrowser",
# pooch, since its website is unreliable and users will rarely need the links
"pooch.Unzip",
Expand Down
161 changes: 161 additions & 0 deletions mne/commands/mne_dipolefit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Authors: The MNE-Python contributors.
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.

"""Open the dipole fitting GUI.

Examples
--------
.. code-block:: console

$ mne dipolefit

"""

import os.path as op

import mne


def run():
"""Run command."""
from mne.commands.utils import _add_verbose_flag, get_optparser

parser = get_optparser(__file__)

parser.add_option(
"-e",
"--evoked",
default=None,
metavar="EVOKED_FILE",
help='The evoked file ("-ave.fif") containing the data to fit dipoles to.',
)
parser.add_option(
"--condition",
default=0,
help="The condition to use.",
)
parser.add_option(
"--baseline-from",
default=None,
type=float,
metavar="TIME",
help="The earliest timepoint to use as baseline.",
)
parser.add_option(
"--baseline-to",
default=None,
type=float,
metavar="TIME",
help="The latest timepoint to use as baseline.",
)
parser.add_option(
"-c",
"--cov",
default=None,
metavar="COV_FILE",
help='The noise covariance ("-cov.fif") to use.',
)
parser.add_option(
"-b",
"--bem",
default=None,
metavar="BEM_FILE",
help='The BEM model ("-bem-sol.fif") to use.',
)
parser.add_option(
"-t",
"--initial-time",
default=None,
type=float,
metavar="TIME",
help="The initial time to show",
)
parser.add_option(
"--trans",
default=None,
metavar="TRANS_FILE",
help='Head<->MRI transform FIF file ("-trans.fif")',
)
parser.add_option(
"--stc",
default=None,
metavar="STC_FILE",
help="An optional distributed source estimate to show during dipole fitting.",
)
parser.add_option(
"-s", "--subject", dest="subject", default=None, help="Subject name"
)
parser.add_option(
"-d",
"--subjects-dir",
default=None,
help="Subjects directory",
)
parser.add_option(
"--hide-density",
action="store_true",
default=False,
help="Prevent showing the magnetic field density as blobs of color.",
)
parser.add_option(
"--channel-type",
default=None,
help=(
'Restrict channel types to either "meg" or "eeg". By default both are used '
"if present."
),
)
parser.add_option(
"-j", "--cpus", default=-1, type=int, help="Number of CPUs to use."
)
_add_verbose_flag(parser)

options, args = parser.parse_args()

# expanduser allows ~ for paths
subjects_dir = options.subjects_dir
if subjects_dir is not None:
subjects_dir = op.expanduser(subjects_dir)
bem = options.bem
if bem is not None:
bem = op.expanduser(bem)
trans = options.trans
if trans is not None:
trans = op.expanduser(trans)
stc = options.stc
if stc is not None:
stc = op.expanduser(stc)
import faulthandler

# Condition can be specified as integer index or string comment.
if options.condition is not None:
try:
condition = int(options.condition)
except ValueError:
condition = options.condition
else:
condition = None

faulthandler.enable()
mne.gui.dipolefit(
evoked=options.evoked,
condition=condition,
baseline=(options.baseline_from, options.baseline_to),
cov=options.cov,
bem=bem,
subject=options.subject,
subjects_dir=subjects_dir,
stc=stc,
ch_type=options.channel_type,
initial_time=options.initial_time,
trans=trans,
n_jobs=options.cpus,
show_density=not options.hide_density,
show=True,
block=True,
verbose=options.verbose,
)


mne.utils.run_command_if_main()
106 changes: 58 additions & 48 deletions mne/dipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
)
from .parallel import parallel_func
from .source_space._source_space import SourceSpaces, _make_volume_source_space
from .surface import _compute_nearest, _points_outside_surface, transform_surface_to
from .surface import (
_CheckInside,
_compute_nearest,
_DistanceQuery,
transform_surface_to,
)
from .transforms import _coord_frame_name, _print_coord_trans, apply_trans
from .utils import (
ExtendedTimeMixin,
Expand Down Expand Up @@ -911,7 +916,7 @@ def _write_dipole_bdip(fname, dip):
fid.write(np.array(has_errors, ">i4").tobytes()) # has_errors
fid.write(np.zeros(1, ">f4").tobytes()) # noise level
for key in _BDIP_ERROR_KEYS:
val = dip.conf[key][ti] if key in dip.conf else 0.0
val = dip.conf[key][ti] if key in dip.conf else np.array(0.0)
assert val.shape == ()
fid.write(np.array(val, ">f4").tobytes())
fid.write(np.zeros(25, ">f4").tobytes())
Expand Down Expand Up @@ -1050,7 +1055,7 @@ def _fit_Q(*, sensors, fwd_data, whitener, B, B2, B_orig, rd, ori=None):

def _fit_dipoles(
fun,
min_dist_to_inner_skull,
constraint,
data,
times,
guess_rrs,
Expand All @@ -1069,7 +1074,7 @@ def _fit_dipoles(
# parallel over time points
res = parallel(
p_fun(
min_dist_to_inner_skull,
constraint,
B,
t,
guess_rrs,
Expand Down Expand Up @@ -1267,26 +1272,41 @@ def _fit_confidence(*, rd, Q, ori, whitener, fwd_data, sensors):
return conf


def _surface_constraint(rd, surf, min_dist_to_inner_skull):
"""Surface fitting constraint."""
dist = _compute_nearest(surf["rr"], rd[np.newaxis, :], return_dists=True)[1][0]
if _points_outside_surface(rd[np.newaxis, :], surf, 1)[0]:
dist *= -1.0
# Once we know the dipole is below the inner skull,
# let's check if its distance to the inner skull is at least
# min_dist_to_inner_skull. This can be enforced by adding a
# constrain proportional to its distance.
dist -= min_dist_to_inner_skull
return dist
def _surface_constraint(surf, min_dist_to_inner_skull):
"""Create a surface fitting constraint function."""
distance_checker = _DistanceQuery(surf["rr"], method="BallTree")
try:
import pyvista # noqa F401

inside_checker = _CheckInside(surf, mode="pyvista")
except ImportError:
inside_checker = _CheckInside(surf, mode="old")

def constraint(rd):
dist = distance_checker.query(rd[np.newaxis, :])[0][0]
if not inside_checker(rd[np.newaxis, :])[0]:
dist *= -1.0
# Once we know the dipole is below the inner skull,
# let's check if its distance to the inner skull is at least
# min_dist_to_inner_skull. This can be enforced by adding a
# constrain proportional to its distance.
dist -= min_dist_to_inner_skull
return dist

return constraint


def _sphere_constraint(r0, R_adj):
"""Create a sphere fitting constraint function."""

def constraint(rd):
return R_adj - np.sqrt(np.sum((rd - r0) ** 2))

def _sphere_constraint(rd, r0, R_adj):
"""Sphere fitting constraint."""
return R_adj - np.sqrt(np.sum((rd - r0) ** 2))
return constraint


def _fit_dipole(
min_dist_to_inner_skull,
constraint,
B_orig,
t,
guess_rrs,
Expand All @@ -1303,22 +1323,6 @@ def _fit_dipole(
"""Fit a single bit of data."""
B = np.dot(whitener, B_orig)

# make constraint function to keep the solver within the inner skull
if "rr" in fwd_data["inner_skull"]: # bem
surf = fwd_data["inner_skull"]
constraint = partial(
_surface_constraint,
surf=surf,
min_dist_to_inner_skull=min_dist_to_inner_skull,
)
else: # sphere
surf = None
constraint = partial(
_sphere_constraint,
r0=fwd_data["inner_skull"]["r0"],
R_adj=fwd_data["inner_skull"].radius - min_dist_to_inner_skull,
)

# Find a good starting point (find_best_guess in C)
B2 = np.dot(B, B)
if B2 == 0:
Expand Down Expand Up @@ -1388,9 +1392,9 @@ def _fit_dipole(
)

msg = "---- Fitted : %7.1f ms" % (1000.0 * t)
if surf is not None:
if "rr" in fwd_data["inner_skull"]: # bem
dist_to_inner_skull = _compute_nearest(
surf["rr"], rd_final[np.newaxis, :], return_dists=True
fwd_data["inner_skull"]["rr"], rd_final[np.newaxis, :], return_dists=True
)[1][0]
msg += ", distance to inner skull : %2.4f mm" % (dist_to_inner_skull * 1000.0)

Expand All @@ -1399,7 +1403,7 @@ def _fit_dipole(


def _fit_dipole_fixed(
min_dist_to_inner_skull,
constraint,
B_orig,
t,
guess_rrs,
Expand Down Expand Up @@ -1703,17 +1707,23 @@ def fit_dipole(
logger.info("Go through all guess source locations...")

# inner_skull goes from mri to head frame
if "rr" in inner_skull:
if not bem["is_sphere"]:
transform_surface_to(inner_skull, "head", mri_head_t)

# make constraint function to keep the solver within the inner skull
if bem["is_sphere"]:
constraint = _sphere_constraint(
r0=inner_skull["r0"],
R_adj=inner_skull.radius - min_dist_to_inner_skull,
)
else:
constraint = _surface_constraint(
surf=inner_skull,
min_dist_to_inner_skull=min_dist_to_inner_skull,
)

if fixed_position:
if "rr" in inner_skull:
check = _surface_constraint(pos, inner_skull, min_dist_to_inner_skull)
else:
check = _sphere_constraint(
pos,
inner_skull["r0"],
R_adj=inner_skull.radius - min_dist_to_inner_skull,
)
check = constraint(pos)
if check <= 0:
raise ValueError(
f"fixed position is {-1000 * check:0.1f}mm outside the inner skull "
Expand Down Expand Up @@ -1753,7 +1763,7 @@ def fit_dipole(
fun = _fit_dipole_fixed if fixed_position else _fit_dipole
out = _fit_dipoles(
fun,
min_dist_to_inner_skull,
constraint,
data,
times,
guess_src["rr"],
Expand Down
4 changes: 2 additions & 2 deletions mne/gui/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__all__ = ["_GUIScraper", "coregistration"]
from ._gui import _GUIScraper, coregistration
__all__ = ["_GUIScraper", "coregistration", "dipolefit"]
from ._gui import _GUIScraper, coregistration, dipolefit
Loading
Loading