Repository navigation
Fill the view corners in the COMSOL cut-plane field plot - #808
Conversation
draw_cut_plane_field Delaunay-triangulated only a strided subset of the nodes inside the window, so the corners outside that subset's hull drew blank. Triangulate every finite node within one window size of the view and crop with the axis limits; coincident nodes keep their largest value. Drop the stride parameter. Fixes gdsfactory#807 Co-authored-by: Niko Savola <niko@gdsfactory.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Niko Savola <niko@gdsfactory.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reviewer's GuideAPIUpdate the function contract and docstring to describe margin-based triangulation and remove the stride argument.
ImplementationFilter invalid and distant export rows, merge coincident positions by maximum field value, and select the crop nodes.
Use all prepared nodes for contouring, update the diagnostic output, and retain the requested axis limits.
DocumentationAdd the changelog fragment for the corner-filling field-plot fix.
TestsUpdate existing plotting tests for the removed stride parameter and add coverage for filled corners, NaN filtering, distant nodes, and duplicate positions.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Linked issuesChecked at commit 1fac22a #807 COMSOL draw_cut_plane_field leaves the view corners blank · 4 of 4 met
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="gplugins/comsol/plotting.py" line_range="97-102" />
<code_context>
+ field = field[np.isfinite(field[:, [0, 1, 3]]).all(axis=1)]
+ xmin, xmax, ymin, ymax = view_um
+ margin = max(xmax - xmin, ymax - ymin)
+ near = (
+ (field[:, 0] >= xmin - margin)
+ & (field[:, 0] <= xmax + margin)
+ & (field[:, 1] >= ymin - margin)
+ & (field[:, 1] <= ymax + margin)
+ )
+ # The triangulation keeps one node per position and would drop the rest
+ # silently, in export order.
</code_context>
<issue_to_address>
**Some window corners remain blank**
When the finite cut-plane nodes within the expanded box do not surround `view_um`, such as near a truncated or non-convex simulation domain, `margin` only selects nodes inside an axis-aligned expanded box; it does not ensure their convex hull contains the view corners, so `tricontourf` still leaves those corners blank.
Ensure the triangulated coverage contains the view corners, or explicitly handle corners outside the selected nodes' convex hull.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: gplugins/comsol/plotting.py:102
| near = ( | ||
| (field[:, 0] >= xmin - margin) | ||
| & (field[:, 0] <= xmax + margin) | ||
| & (field[:, 1] >= ymin - margin) | ||
| & (field[:, 1] <= ymax + margin) | ||
| ) |
There was a problem hiding this comment.
🟡 Medium · Some window corners remain blank
When the finite cut-plane nodes within the expanded box do not surround view_um, such as near a truncated or non-convex simulation domain, margin only selects nodes inside an axis-aligned expanded box; it does not ensure their convex hull contains the view corners, so tricontourf still leaves those corners blank.
Ensure the triangulated coverage contains the view corners, or explicitly handle corners outside the selected nodes' convex hull.
Prompt for AI agents
In `gplugins/comsol/plotting.py` at lines 97-102:
**Some window corners remain blank**
When the finite cut-plane nodes within the expanded box do not surround `view_um`, such as near a truncated or non-convex simulation domain, `margin` only selects nodes inside an axis-aligned expanded box; it does not ensure their convex hull contains the view corners, so `tricontourf` still leaves those corners blank.
Ensure the triangulated coverage contains the view corners, or explicitly handle corners outside the selected nodes' convex hull.The corner fix now lives in gplugins.comsol.plotting.draw_cut_plane_field (gdsfactory/gplugins#808), so drop the notebook's local copy and its test, call the helper without the removed stride argument, and pin gplugins to the merge commit. Co-authored-by: Niko Savola <niko@gdsfactory.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The corner fix now lives in gplugins.comsol.plotting.draw_cut_plane_field (gdsfactory/gplugins#808), which main already pins, so drop the notebook's local copy and its test and call the helper without the removed stride argument. Co-authored-by: Niko Savola <niko@gdsfactory.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #807.
draw_cut_plane_fieldDelaunay-triangulated only every 4th node insideview_um. The view corners fell outside that subset's convex hull and drew blank, not even in the lowest colour. Seen in the QPDK COMSOL CPW resonator notebook.Changes
view_umon each side, then crop with the axis limits. The margin keeps the corners inside the hull. A 1M-node export with a 10 µm view takes about 1.6 s locally; triangulating the full export took about 7 s.stride.gplugins.comsolis unreleased; QPDK's notebook will drop the argument when it bumps its gplugins pin.Tests
test_field_plot_fills_the_view_corners: nodes on a circle inside the view plus a frame outside it, a NaN node, a far node and a duplicate node. It asserts that the filled contours reach all four corners. It fails onmainand passes here.stride=removed from two existing tests; their assertions are unchanged.gplugins.comsol.plotting, because the uv venv's Python isn't available in my container. CI is the full check.pre-commit run --fileson the changed files is green.Changelog fragment:
.changelog.d/808.fixed.Requested by @nikosavola
A human must review this before merge.
🤖 Generated with Claude Code
Summary by Sourcery
Fix COMSOL cut-plane field plotting so cropped views render completely and consistently across mesh edge cases.
Bug Fixes:
Enhancements:
Tests: