Skip to main content

de-twin

Tests Docs PyPI Python License: MIT

A digital twin of a Direct Electron camera on a TEM: the column, the specimen, the in-situ holder and the detector, advancing on one clock. Develop and test automated microscope control without a microscope, a camera or DE-Server, and plug the same twin into the real software when you have it.

Documentation: https://cssfrancis.github.io/de-twin/

pip install de-twin            # numpy, scipy, diffsims, orix
pip install "de-twin[deapi]"   # + a deapi-compatible DE-Server stand-in

Quick start

from de_twin import DigitalTwin

twin = DigitalTwin("Dense Au on holey C", camera="DE16", holder="sim-heating")
twin.column.set("Magnification", 50_000)
twin.column.move_stage(x=12.5, y=-3.0)        # um, waits for the stage
twin.column.set_defocus_um(-1.5)

img = twin.snap(1.0)                          # dark/gain-corrected electrons, like DE-Server
raw = twin.raw_frame(0.025)                   # one raw uint16 frame: offset, noise, defects
truth = twin.flux(twin.request())             # noiseless e-/px/s, for scoring automation

What is simulated

  • Column: JEOL/TFS-style modes, magnification and camera-length ladders, stage motion, beam current and illumination, defocus, astigmatism, shifts and tilts, axial aberrations (C1 to C5), and an optional CEOS-like probe/image corrector with drift and tuning.
  • Specimen: seeded grids, thin films, proteins in ice, FIB lamellae and an in-situ heating chip; every grain is a real crystal (diffsims + orix) that responds to tilt.
  • Image formation: wave-optical TEM with a CTF, kinematic SAED/NBD/CBED, coherent 4D-STEM for ptychography and tcBF, and physical dose.
  • Detector: every DE camera model, with dark, gain, noise, defects, saturation, binning and counting, so references are needed and work.
  • Holder: a simulated DENS-style heating chip, or a real DENS Impulse holder.

Plug it into real software

de-twin serve --soap 5002 --deapi 13240 --shm
Face Who talks to it
DE-TEM-Channel SOAP (--soap) DE-Server, de_microscope, de_autopilot, de_ground_crew
deapi fake DE-Server (--deapi) any deapi client
shared memory (--shm) a real DE-Server with the test pattern External Frame Source (Shared Memory)

Each part can also follow real hardware instead of simulating it: --mirror-temchannel HOST for a real (or Dummy) DE-TEM-Channel, --holder impulse for a DENS Impulse holder.

DE-Server's side of the shared-memory frame source is two small files in cpp/.

Contributing and releases

See CONTRIBUTING.md. Changes are recorded as towncrier fragments in upcoming_changes/, and releases follow the procedure in the development docs.

MIT licensed.

Metadata

Release files for de-twin 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for de-twin 0.2.0
File Size Uploaded
de_twin-0.2.0.tar.gz 957.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for de-twin 0.2.0
File Interpreter ABI Platform
de_twin-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.8 MB

Release files / de_twin-0.2.0.tar.gz

Download URL de_twin-0.2.0.tar.gz
Size 957.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0974edbd70c0387eb33e76cd0289110bea8ecec746cf7dbe8ffdd78f19c630e4
BLAKE2b-256 checksum
How to use checksums
981246828df72d4304e5a584dedb19bd45426af4bdd30760d1747409d4a29ff3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / de_twin-0.2.0-py3-none-any.whl

Download URL de_twin-0.2.0-py3-none-any.whl
Size 870.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df4c3d4b3d260b87b934a6135bcddb32b6ce995bdb8e54350fefd2312028ea6e
BLAKE2b-256 checksum
How to use checksums
8b5890985170caf3b4589bf842799f262b237b73b94d2dff23ae0bdbc2a3621c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page