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://directelectron.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, SEM EBSD (kinematic Kikuchi patterns of bulk polycrystals, with ground-truth orientations), 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.4.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.4.1
File Size Uploaded Provenance Actions
de_twin-0.4.1.tar.gz 1.1 MB With provenance Details for de_twin-0.4.1.tar.gz

Built distribution (wheel)

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

Total release size: 2.2 MB

Release files / de_twin-0.4.1.tar.gz

Download URL de_twin-0.4.1.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
2905afd2daa57dbdcf525f76f55a0eb9333d1984bd9ac5a10d1d4667bc7e54a8
BLAKE2b-256 checksum
How to use checksums
88646951b9c553be3ca83cac263e19a55591221e8526432a0a08b3f6520c2433
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 12, 2026.

Transparency log

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

Download URL de_twin-0.4.1-py3-none-any.whl
Size 1.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
cf746398cdcc2bddd43c61eb26c219880e89f9413fab13adeb3bf27158f4d96a
BLAKE2b-256 checksum
How to use checksums
fd5060c11c744c42db1fb71425ac5881cea407c4b13d9e58ef1cfff44b7f5aac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 12, 2026.

Transparency log

Security for de-twin 0.4.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for de_twin-0.4.1.tar.gz

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 Nov 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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