-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
ENH: Add hpi_colors and hpi_labels for clear visualization #13533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
drona-gyawali
wants to merge
6
commits into
mne-tools:main
Choose a base branch
from
drona-gyawali:feature/hpi_visualization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+136
−26
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e70b72b
ENH: Add hpi_colors and hpi_labels for clear visualization
drona-gyawali 0f95ae4
fixed/plot_aligment
drona-gyawali 838cc6b
Merge branch 'main' into feature/hpi_visualization
drona-gyawali 45f167d
refactor/testcase
drona-gyawali 6fea7ce
refactor: testcase
drona-gyawali 973883a
refactor case
drona-gyawali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -553,6 +553,8 @@ def plot_alignment( | |
| interaction="terrain", | ||
| sensor_colors=None, | ||
| *, | ||
| hpi_colors="auto", | ||
| hpi_labels=False, | ||
| sensor_scales=None, | ||
| verbose=None, | ||
| ): | ||
|
|
@@ -644,7 +646,18 @@ def plot_alignment( | |
| %(sensor_colors)s | ||
|
|
||
| .. versionchanged:: 1.6 | ||
| Support for passing a ``dict`` was added. | ||
| Support for passing a ``dict`` was added. | ||
| hpi_colors : 'auto' | list | dict | ||
| Colors for HPI coils when ``dig=True``. | ||
| ``'auto'`` (default): use official MEGIN/Elekta cable colors | ||
| (1=red, 2=blue, 3=green, 4=yellow, 5=magenta, 6=cyan). | ||
| Can also be a list of colors or ``{ident: color}`` dict. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These need |
||
|
|
||
| .. versionadded:: 1.11 | ||
| hpi_labels : bool | ||
| If ``True``, show the HPI coil ident number as 3D text above each coil. | ||
|
|
||
| .. versionadded:: 1.11 | ||
| %(sensor_scales)s | ||
|
|
||
| .. versionadded:: 1.9 | ||
|
|
@@ -900,7 +913,9 @@ def plot_alignment( | |
| _check_option("dig", dig, (True, False, "fiducials")) | ||
| if dig: | ||
| if dig is True: | ||
| _plot_hpi_coils(renderer, info, to_cf_t) | ||
| _plot_hpi_coils( | ||
| renderer, info, to_cf_t, hpi_colors=hpi_colors, hpi_labels=hpi_labels | ||
| ) | ||
| _plot_head_shape_points(renderer, info, to_cf_t) | ||
| _plot_head_fiducials(renderer, info, to_cf_t, fid_colors) | ||
|
|
||
|
|
@@ -1292,34 +1307,90 @@ def _plot_hpi_coils( | |
| surf=None, | ||
| check_inside=None, | ||
| nearest=None, | ||
| hpi_colors="auto", | ||
| hpi_labels=False, | ||
| ): | ||
| from matplotlib.colors import to_rgba | ||
|
|
||
| defaults = DEFAULTS["coreg"] | ||
| scale = defaults["hpi_scale"] if scale is None else scale | ||
| hpi_loc = np.array( | ||
| [ | ||
| d["r"] | ||
| for d in (info["dig"] or []) | ||
| if ( | ||
| d["kind"] == FIFF.FIFFV_POINT_HPI | ||
| and d["coord_frame"] == FIFF.FIFFV_COORD_HEAD | ||
| ) | ||
|
|
||
| hpi_digs = [ | ||
| d | ||
| for d in (info["dig"] or []) | ||
| if ( | ||
| d["kind"] == FIFF.FIFFV_POINT_HPI | ||
| and d["coord_frame"] == FIFF.FIFFV_COORD_HEAD | ||
| ) | ||
| ] | ||
| if not hpi_digs: | ||
| return [] | ||
|
|
||
| hpi_idents = [d["ident"] for d in hpi_digs] | ||
| hpi_locs = apply_trans(to_cf_t["head"], [d["r"] for d in hpi_digs]) | ||
|
|
||
| if hpi_colors == "auto": | ||
| # MEGIN/Elekta HPI coil cable colors(MNE community convention from user reports) | ||
| # 1 = red, 2 = blue, 3 = green, 4 = yellow, 5 = magenta, 6 = cyan | ||
| # Coil 1 is confirmed as "red" in Elekta TRIUX manual | ||
| # Full mapping is standard practice in MNE; no official 6-color list. | ||
| megin_colors = { | ||
| 1: "red", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For future ref can you add a code comment about where you got this color mapping? |
||
| 2: "blue", | ||
| 3: "green", | ||
| 4: "yellow", | ||
| 5: "magenta", | ||
| 6: "cyan", | ||
| } | ||
| colors = [ | ||
| megin_colors.get(ident, defaults["hpi_color"]) for ident in hpi_idents | ||
| ] | ||
| ) | ||
| hpi_loc = apply_trans(to_cf_t["head"], hpi_loc) | ||
| actor, _ = _plot_glyphs( | ||
| renderer=renderer, | ||
| loc=hpi_loc, | ||
| color=defaults["hpi_color"], | ||
| scale=scale, | ||
| opacity=opacity, | ||
| orient_glyphs=orient_glyphs, | ||
| scale_by_distance=scale_by_distance, | ||
| surf=surf, | ||
| backface_culling=True, | ||
| check_inside=check_inside, | ||
| nearest=nearest, | ||
| ) | ||
| return actor | ||
| elif isinstance(hpi_colors, dict): | ||
| colors = [hpi_colors.get(ident, defaults["hpi_color"]) for ident in hpi_idents] | ||
| elif isinstance(hpi_colors, (list, tuple)): | ||
| if len(hpi_colors) != len(hpi_digs): | ||
| raise ValueError( | ||
| f"""hpi_colors list length | ||
| {len(hpi_colors)} != number of HPI coils {len(hpi_digs)} | ||
| """ | ||
| ) | ||
| colors = hpi_colors | ||
| else: | ||
| colors = [hpi_colors] * len(hpi_digs) | ||
|
|
||
| actors = [] | ||
|
|
||
| for loc, color, ident in zip(hpi_locs, colors, hpi_idents): | ||
| color_rgba = to_rgba(color) | ||
|
|
||
| result = _plot_glyphs( | ||
| renderer=renderer, | ||
| loc=np.array([loc]), | ||
| color=color_rgba, | ||
| scale=scale, | ||
| opacity=opacity, | ||
| orient_glyphs=orient_glyphs, | ||
| scale_by_distance=scale_by_distance, | ||
| surf=surf, | ||
| backface_culling=True, | ||
| check_inside=check_inside, | ||
| nearest=nearest, | ||
| ) | ||
|
|
||
| actors.append(result) | ||
|
|
||
| if hpi_labels: | ||
| offset = np.array([0, 0, scale * 1.3]) | ||
| renderer.text3d( | ||
| x=loc[0], | ||
| y=loc[1], | ||
| z=loc[2] + offset[2], | ||
| text=str(ident), | ||
| scale=scale * 0.7, | ||
| color=color_rgba, | ||
| ) | ||
|
|
||
| return actors | ||
|
|
||
|
|
||
| def _get_nearest(nearest, check_inside, project_to_trans, proj_rr): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should come after
*