Skip to content

Implement SimuMicroscope stage speed and generalize motion calibration#161

Merged
Baharis merged 4 commits into
instamatic-dev:mainfrom
Baharis:calib_motion_fixed_speed
May 4, 2026
Merged

Implement SimuMicroscope stage speed and generalize motion calibration#161
Baharis merged 4 commits into
instamatic-dev:mainfrom
Baharis:calib_motion_fixed_speed

Conversation

@Baharis
Copy link
Copy Markdown
Member

@Baharis Baharis commented Apr 21, 2026

Context

I am working on the instamatic TEM emulator, removing bugs and making it as functional as a physical TEM. The emulator is mostly its own thing, however, to avoid code duplication, it does use Instamatic as a dependency; for example, the TEM object used to store the state of the microscope is simply the default SimuMicroscope class from src/instamatic/microscope/interface/simu_microscope.py.

The aim of the SimuMicroscope class is first and foremost to provide an elegant fallback or test case when attempting to connect one's machine, accessing camera only, debugging etc. Therefore, it should be as simple as possible. However, it still should behave consistently, which now is not the case. For example, current SimuMicroscope implements setRotationSpeed, but ignores speed in setStagePosition. As a result, tilting the stage using stage.set(speed=x) vs with stage.rotation_speed(x): stage.set behaves completely differently.

This PR implements a long-missing functionality to move stage with speed. This is done via a new context manager stage._speed_setting, which temporarily changes the speed and speed_setting for given axis. Implementation of setStagePosition is updated to reflect this change:

def setStagePosition(...):
    if z is not None:
        self.setStageZ(z, wait=wait)
        with nullcontext() if speed is None else self._speed_setting('z', speed):
            self.setStageZ(z, wait=wait)
    ...

While at it, I have unified the speed of the stage to behave consistently. Previously, fresh stage would start up with tilt speed of 20.0 deg / second and tilt speed_setting of 12; however, as soon as the speed_setting was "updated" to the same value of 12, the speed would fall to 10 because the equations were inconsistent. I unified the default translation speed to 100 000 nm/s and rotation speed to 20 deg/s, given setting 12.
Resulting simulated stage can now properly interpret stage.set_with_speed, and thus can be calibrated:

instamatic_trans_calib

The calib_stage_translation_x.yaml produced by the instamatic.calibrate_stage_translation executed on the instamatic-TEM-emulator importing the updated SimuMicroscope can look something like this:

delay: 0.04263976740884395
pace: 0.00012027886971854111
speed_options:
  lower_lim: 0.0
  upper_lim: 12.0
windup: -0.058916610257381694

Finally, I am working on compatibility with JEOL microscopes. Without goniotool, their stage translation and rotation speed can not be set, but it should still be calculable. Calibrating without setting speed is now done automatically by the updated scripts if setting speed is not possible. Same behavior can be also enforced: a lone -s added to any of the motion calibration scripts will force it to calibrate at the default speed, using set instead of set_with_speed. This way rotation speed can be calibrated, and FastADT run, on goniotool-less JEOL TEMs.

Changes

  • Stage can now be translated and rotated with speed via stage.set(speed=...).
  • Simulated stage translation and rotating speed have been unified and made consistent`.
  • Default stage x- and y-translation speed were lowered from "instant" 1mm/s to 100um/s.
  • instamatic.calibrate_rotation_speed and instamatic.calibrate_rotation_speed can now both calculate motion speed, even if speed is constant and not settable; this is detected automatically or can be forced via -s.

This PR could use some tests; however, I'm leaving for a secondment soon and prefer to merge it before Friday.

@Baharis Baharis requested a review from stefsmeets April 21, 2026 18:53
@Baharis Baharis self-assigned this Apr 21, 2026
@Baharis Baharis changed the title Calib motion fixed speed Implement SimuMicroscope stage speed and generalize motion calibration Apr 21, 2026
@Baharis Baharis merged commit a711839 into instamatic-dev:main May 4, 2026
6 checks passed
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