From klayoutclaw
Transforms per-material detections into full_stack coordinates, generates unified traces.json, and draws contour overlays on raw/LUT images. Use after align and detect steps in nanodevice flake pipelines.
npx claudepluginhub caidish/klayoutclaw --plugin klayoutclawThis skill uses the workspace's default tool permissions.
Transforms all per-material detections into the full_stack coordinate system, produces the unified `traces.json`, and draws contour overlays on raw/LUT images.
Detects van der Waals heterostructure flake boundaries from microscope images and maps to KLayout polygons via 5-step agent-orchestrated pipeline (align, detect, combine, commit, review). Use for multi-image flake detection, alignment, or stack segmentation.
Processes microscopy and bioimage images with scikit-image: read/write, filter (Gaussian, median, LoG), segment (thresholding, watershed, active contours), measure regions, detect features. NumPy/SciPy integration.
Segments cells in fluorescence microscopy images using Cellpose/cpsam (Cellpose 4.0). Outputs segmentation masks, per-cell metrics (area, diameter, centroid, eccentricity), overlay figures, and report.md.
Share bugs, ideas, or general feedback.
Transforms all per-material detections into the full_stack coordinate system, produces the unified traces.json, and draws contour overlays on raw/LUT images.
instrMCPdev with opencv, numpy, shapely (rank_candidate_pairs.py uses shapely)conda run -n instrMCPdev python <script>conda run -n instrMCPdev python skills/nanodevice_flakedetect_combine/scripts/ecc_register.py \
--raw <full_stack_raw_image> \
--lut <full_stack_lut_image> \
--output-dir <path>
--raw — Full stack raw image--lut — Full stack LUT (color-enhanced) image--output-dir — Output directoryComputes ECC translation alignment between raw and LUT images. The LUT image typically has a spatial offset (~71px dx, ~56px dy) from raw.
Outputs:
combine_report.json with raw2lut section: dx, dy, ecc_correlationNote: If no LUT image is available, skip this script. The overlay script handles the absence gracefully.
conda run -n instrMCPdev python skills/nanodevice_flakedetect_combine/scripts/transform.py \
--detections <detect/detections.json> \
--align-dir <align/> \
--image <full_stack_raw_image> \
--pixel-size <um_per_px> \
--output-dir <path>
--detections — Path to detections.json from detect step--align-dir — Directory containing warp matrices and footprint from align step--image — Full stack raw image (for size reference)--pixel-size — Microns per pixel--output-dir — Output directoryTransform rules by material:
| Material | Coordinate System | Transform |
|---|---|---|
| graphite | bottom_part | Invert warp_sift_bottom.npy, apply to contour |
| graphene | top_part (mirrored) | Apply warp_top.npy to mask (INTER_NEAREST), clip to footprint, morph clean, re-extract contour |
| bottom_hBN | full_stack | Pass through (already in target coords) |
| top_hBN | full_stack | Pass through (= footprint) |
All materials get smooth_material() applied after transform.
Input files read from --align-dir:
warp_sift_bottom.npy — inverted before use (bottom_part→full_stack)warp_top.npy — applied directly (top_part→full_stack)footprint_mask.png — for graphene clippingOutputs:
traces.json — unified traces with all contours in full_stack pixel coordinatesgraphite_full.png, graphene_full.png, bottom_hbn_full.png, top_hbn_full.png — transformed maskstransform_summary section to combine_report.jsonconda run -n instrMCPdev python skills/nanodevice_flakedetect_combine/scripts/overlay.py \
--traces <combine/traces.json> \
--raw <full_stack_raw_image> \
[--lut <full_stack_lut_image>] \
[--combine-report <combine/combine_report.json>] \
--output-dir <path>
--traces — Path to traces.json from transform step--raw — Full stack raw image--lut — (optional) Full stack LUT image--combine-report — (optional) Path to combine_report.json (for raw→LUT shift)--output-dir — Output directoryDraws material contours on desaturated background images using the BGR color palette:
For LUT overlay: reads dx, dy from combine_report.json and shifts contours before drawing.
Outputs:
overlay_raw.png — all material contours on raw imageoverlay_lut.png — all material contours on LUT image (if --lut provided)mask_composite.png — all material masks color-coded at 50% alphaoverlay_files section to combine_report.jsonRanks every pair across two detected material lists by intersection area. Useful whenever a downstream design step requires a material pair with non-trivial overlap and the rank-0 detections do not always satisfy that constraint. Defaults to --material-a graphene --material-b graphite for the vdW-Hall-bar workflow, but any two material keys that exist in traces.json will work (e.g. --material-a top_hBN --material-b bottom_hBN to rank encapsulation pairs).
conda run -n instrMCPdev python skills/nanodevice_flakedetect_combine/scripts/rank_candidate_pairs.py \
--traces <combine/traces.json> \
[--output candidate_ranking.json] \
[--top-k 5] \
[--material-a graphene] [--material-b graphite]
--traces — Path to traces.json (works on both pre- and post-gdsalign traces: uses contour_gds if present, falls back to contour_um)--output — Path to the ranking JSON (default: alongside traces.json)--top-k — How many top pairs to echo on stdout (default 5). The JSON file always contains all pairs.--material-a, --material-b — Material keys to pair (default graphene × graphite)Computes polygon intersection area between every (material_a, material_b) candidate pair, ranks by overlap area descending, and writes an ordered list.
Outputs:
candidate_ranking.json — ordered list with fields: {rank, graphene_id, graphite_id, overlap_um2, graphene_area_um2, graphite_area_um2, centroid_distance_um}When to run: When a first-pass design session discovers the auto-picked material-A × material-B pair has overlap_um2 ≈ 0. The ranking surfaces a pair with non-trivial overlap without brute-force iteration. (Observed failure mode: ml09 / ml11 benchmarks where default graphene × graphite had no overlap.)
Run in order:
ecc_register.py (if LUT image available)transform.pyoverlay.pyrank_candidate_pairs.py — only when the auto-picked pair has zero overlap; otherwise skip.The combine_report.json is a multi-writer file: ecc_register creates it, transform adds to it, overlay adds to it. Each script reads the existing file and appends its section. rank_candidate_pairs.py writes a separate candidate_ranking.json and does not touch combine_report.json.
All outputs go in the combine output directory:
traces.json — the main pipeline output consumed by review and commitcombine_report.json — metadata for diagnosticscandidate_ranking.json — (optional) ranking of candidate material pairs