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.

Release files for de-twin 0.1.1

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.1.1
File Size Uploaded
de_twin-0.1.1.tar.gz 321.1 kB Details

Built distribution (wheel)

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

Total release size: 583.0 kB

Release files / de_twin-0.1.1.tar.gz

Download URL de_twin-0.1.1.tar.gz
Size 321.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5cd938d034dc92326ba035dc4c6558174709a1f6ab78309ff27823e17ab9b547
BLAKE2b-256 checksum
How to use checksums
08a12d008491fc8cbed06c6572afbec687f98bc065d11160b0c7873081272da8
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 24, 2026.

Transparency log

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

Download URL de_twin-0.1.1-py3-none-any.whl
Size 261.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b27a824ea05940d147c11a7c52c5346e6380b752833f1b1d10bbff0e6986861
BLAKE2b-256 checksum
How to use checksums
f8e5fdbb77185818602b1240bf438cf64f94497a6027be86d4ca4dd9f72d2fe6
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 24, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

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