Skip to content

Add grid module, .grid_finder, and .grid_monitor tools - #169

Open
Baharis wants to merge 7 commits into
instamatic-dev:mainfrom
Baharis:grid
Open

Add grid module, .grid_finder, and .grid_monitor tools#169
Baharis wants to merge 7 commits into
instamatic-dev:mainfrom
Baharis:grid

Conversation

@Baharis

@Baharis Baharis commented Sep 1, 2026

Copy link
Copy Markdown
Member

Context

Instamatic has already some tools to deal with the "grid" i.e. the copper scaffolding used to hold thin carbon film with the samples. Most of the routines deal with its presence in a occasional rather than exhaustive manner: by looking at the grid in imaging mode, one can quickly realize that some part of detector is shadowed and simply ignore it from further analysis. However, the grid is never treated as an object of investigation itself, as none of the methods currently present require this.

This PR introduces a new small module, instamatic.grid. It exists to collect all functionality, where the grid rather than a crystal sample is a target of investigation itself. The new module stores functionality used to: find grid position (currently using two methods: beam scanning/shadowing and manually), refine grid parameters against points on the edge, read or write its geometry from file, draw current grid model, predict available area and new window positions, and many more.

The functionality is available via two new tools that can be used in tandem: instamatic.grid_finder and instamatic.grid_monitor. The following can be ran in manual or automated mode and looks for intercepts i.e. points on the edge between "window" and "grid", while the latter watches a file updated by the finder to draw the most recent progress to a small GUI window:

image

On this image, the grid geometry is defined and plotted based on fitting intercept points from four windows, indexed 0 to 3. Position of window 0 has been determined manually by traversing along the stage edge while regularly adding new points. Windows 1-3 were fit from 2nd-order 3-arms star search (3+3 points per window), with some-angular offset per window.

The new functionality may find some use by itself, but it is predominantly great as a prerequisite for long automated experiments that are a matter of ongoing development. Since the automated grid geometry determination relies on scanning with a beam only, it can be performed by a experiment that has no information about "imaging" config. The continuous-serial electron diffraction routine implemented in incoming patches uses this information to easily define areas where it can scan for new data, without any need to change detector config or any imaging data.

Additions

  • programs.md: Added new programs to list, added new programs' documentation;
  • pyproject.toml: Added instamatic.grid_finder and .grid_monitor entry points;
  • grid/__init__.py: A few common type hints and utils used in the module;
  • grid/artist.py: Function plot_grid that draws grid details onto provided axes.
  • grid/finder.py: High-level tools to locate, read, write grid & intercept information;
  • grid/grid.py: Definitions, registry, fitting of grids: square, rectangular, hexagonal;
  • grid/monitor.py: GUI utility, standalone or embed-able, auto-plots grid geometry;
  • grid/sweeping.py: Sweepers used to find grid edges within the star_sweep function;
  • grid/window.py: Definition of individual windows used by higher-level grid.py;
  • tests/test_grid.py: Test suite covering 70% of new functionality (not GUI, scripts).

Notes

This is a direct prerequisite to a new experiment routine that is already ready, functional, tested, proved to give good 3D ED data. In order to merge this new routine before October, I'd like to merge this PR before the end of the next week.

@Baharis
Baharis requested a review from stefsmeets September 1, 2026 18:54
@Baharis Baharis self-assigned this Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant