ChooseLattice#

Pick an ordered origin and two lattice-vector points on a 2D image. Displays a single image, lets you wheel-zoom and drag-pan to inspect a region, and lets you click 3 ordered points whose pixel coordinates (in the ORIGINAL, un-zoomed image) are exposed for downstream lattice-vector calculations.

import numpy as np
from quantem.widget import ChooseLattice

widget = ChooseLattice(image, cmap="gray")

After clicking the origin, then the two lattice points on the image:

widget.origin   # (row, col) or None
widget.u        # second point - origin, or None until both are placed
widget.v        # third point - origin, or None until both are placed
widget.points   # the picked (row, col) pairs so far; assign to set them from Python

Reference#

class quantem.widget.choose_lattice.ChooseLattice(*args: Any, **kwargs: Any)#

Bases: AnyWidget

Interactive picker for an ordered origin plus two lattice-vector points.

Parameters:
  • data (array_like or Dataset2d) – A single 2D image (NumPy, PyTorch or CuPy); a Dataset2d supplies its name as the default title.

  • cmap (str, default "gray") – Colormap used to render the image.

  • title (str, default "") – Title shown above the image.

Notes

Click on the image to place points in order; once 3 are placed, drag a point to adjust it, or press “Clear Points” to start over. Coordinates are always reported in the original image’s (row, col) space regardless of zoom. The display range is the robust 1st to 99th percentile of the image.

property origin: tuple[float, float] | None#

First picked point (row, col), or None if not yet placed.

property u: tuple[float, float] | None#

Lattice vector from the origin to the second point, or None until both are placed.

property v: tuple[float, float] | None#

Lattice vector from the origin to the third point, or None until both are placed.

Interactive controls#

Control

Trait

Expected effect

Click on the image (fewer than 3 points placed)

points

Appends the next ordered point

Drag an existing point

points

Adjusts that point’s pixel coordinates in place

Clear Points button

points

Resets to no points

Pan (drag) / zoom (wheel)

view transform

Image translates / zooms about the cursor

Double-click

view transform

Resets zoom/pan