@@ -518,9 +518,10 @@ def _iterate_trans_views(function, alpha, **kwargs):
518
518
519
519
try :
520
520
try :
521
- return _itv (function , fig , surfaces = { "head-dense" : alpha }, ** kwargs )
521
+ return _itv (function , fig , ** kwargs )
522
522
except OSError :
523
- return _itv (function , fig , surfaces = {"head" : alpha }, ** kwargs )
523
+ kwargs ["surfaces" ] = {"head" : alpha }
524
+ return _itv (function , fig , ** kwargs )
524
525
finally :
525
526
backend ._close_3d_figure (fig )
526
527
@@ -1597,9 +1598,10 @@ def add_trans(
1597
1598
subject = None ,
1598
1599
subjects_dir = None ,
1599
1600
alpha = None ,
1601
+ coord_frame = "mri" ,
1602
+ plot_kwargs = None ,
1600
1603
tags = ("coregistration" ,),
1601
1604
section = None ,
1602
- coord_frame = "mri" ,
1603
1605
replace = False ,
1604
1606
):
1605
1607
"""Add a coregistration visualization to the report.
@@ -1625,13 +1627,23 @@ def add_trans(
1625
1627
alpha : float | None
1626
1628
The level of opacity to apply to the head surface. If a float, must
1627
1629
be between 0 and 1 (inclusive), where 1 means fully opaque. If
1628
- ``None``, will use the MNE-Python default value.
1630
+ ``None``, will use the MNE-Python default value. See also ``plot_kwargs``.
1631
+ coord_frame : 'auto' | 'head' | 'meg' | 'mri'
1632
+ Coordinate frame used for plotting. See :func:`mne.viz.plot_alignment`
1633
+ and ``plot_kwargs``.
1634
+ plot_kwargs : dict | None
1635
+ Plotting arguments to be passed to :func:`mne.viz.plot_alignment`.
1636
+ If ``alpha`` is not ``None``, it will override a potential
1637
+ ``plot_kwargs["alpha"]``. The ``coord_frame`` key word argument always
1638
+ overrides a potential ``plot_kwargs["coord_frame"]``. If ``None``,
1639
+ this defaults to
1640
+ ``dict(dig=True, meg=("helmet", "sensors"), show_axes=True)``.
1641
+
1642
+ .. versionadded:: 1.10
1629
1643
%(tags_report)s
1630
1644
%(section_report)s
1631
1645
1632
1646
.. versionadded:: 1.9
1633
- coord_frame : 'auto' | 'head' | 'meg' | 'mri'
1634
- Coordinate frame used for plotting. See :func:`mne.viz.plot_alignment`.
1635
1647
%(replace_report)s
1636
1648
1637
1649
Notes
@@ -1645,6 +1657,7 @@ def add_trans(
1645
1657
subject = subject ,
1646
1658
subjects_dir = subjects_dir ,
1647
1659
alpha = alpha ,
1660
+ plot_kwargs = plot_kwargs ,
1648
1661
title = title ,
1649
1662
section = section ,
1650
1663
tags = tags ,
@@ -4220,6 +4233,7 @@ def _add_trans(
4220
4233
subject ,
4221
4234
subjects_dir ,
4222
4235
alpha ,
4236
+ plot_kwargs ,
4223
4237
title ,
4224
4238
section ,
4225
4239
tags ,
@@ -4232,22 +4246,40 @@ def _add_trans(
4232
4246
if not isinstance (info , Info ):
4233
4247
info = read_info (info )
4234
4248
4235
- kwargs = dict (
4236
- info = info ,
4237
- trans = trans ,
4238
- subject = subject ,
4239
- subjects_dir = subjects_dir ,
4240
- dig = True ,
4241
- meg = [ "helmet" , "sensors" ] ,
4242
- show_axes = True ,
4243
- coord_frame = coord_frame ,
4249
+ plot_kwargs = _handle_default ( "report_coreg" , plot_kwargs )
4250
+
4251
+ plot_kwargs . update (
4252
+ dict (
4253
+ info = info ,
4254
+ trans = trans ,
4255
+ subject = subject ,
4256
+ subjects_dir = subjects_dir ,
4257
+ )
4244
4258
)
4259
+
4260
+ # This potentially overwrites information
4261
+ plot_kwargs ["coord_frame" ] = coord_frame
4262
+
4263
+ if alpha is not None :
4264
+ # if not available, fall back to plot_alignment default: 'auto'
4265
+ surfaces = plot_kwargs .get ("surfaces" , "auto" )
4266
+ if isinstance (surfaces , dict ):
4267
+ surfaces = list (surfaces .keys ())
4268
+ elif isinstance (surfaces , list ):
4269
+ pass
4270
+ elif isinstance (surfaces , str ) and surfaces != "auto" :
4271
+ surfaces = [surfaces ]
4272
+ else :
4273
+ surfaces = ["head-dense" ] # "auto"
4274
+
4275
+ surfaces = {surf : alpha for surf in surfaces }
4276
+
4245
4277
img , caption = _iterate_trans_views (
4246
4278
function = plot_alignment ,
4247
4279
alpha = alpha ,
4248
4280
max_width = self .img_max_width ,
4249
4281
max_res = self .img_max_res ,
4250
- ** kwargs ,
4282
+ ** plot_kwargs ,
4251
4283
)
4252
4284
self ._add_image (
4253
4285
img = img ,
0 commit comments