de-twin
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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| de_twin-0.1.0.tar.gz | 320.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| de_twin-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 581.6 kB
Release files / de_twin-0.1.0.tar.gz
| Download URL | de_twin-0.1.0.tar.gz |
|---|---|
| Size | 320.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
381094a6fb398fccf22208ac6595c11199cfd8fafa9994282d76fa2b3528eb17
|
|
BLAKE2b-256 checksum How to use checksums |
a27aa306e613b1b4883ff2e50e188bfacd939580f97d4e311f72826cef4b9c88
|
| 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 logRelease files / de_twin-0.1.0-py3-none-any.whl
| Download URL | de_twin-0.1.0-py3-none-any.whl |
|---|---|
| Size | 261.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef3941fa4ecfbacd5f7a3e9709578df1360e7a8bfe6dc93d191bb0b1f7c1ca27
|
|
BLAKE2b-256 checksum How to use checksums |
af9d08ef4bd354b5ab54e0d420c745dba793fc189a70830c6a1a876780ec30ca
|
| 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