How neurotechnology-at-eth-zurich/implant works
Purpose and entry points
IMPLAnT is a Linux/Python 3.10 desktop GUI for rat intracranial electrode workflows: MRI-to-atlas planning, intraoperative coordinate correction, post-implant electrode localisation, and anatomy-linked ephys viewing. The application starts at main_window.py; Qt UI definitions are form.ui, generated bindings ui_form.py, and 3D planning UI form_tp_3d.ui.
Application shell and shared imaging state
main_window.py is the integration boundary for file/menu actions and launches the major workflows. MRI loading, layer state, cursor interaction, and measurements are concentrated in core/load_MRI_file.py, core/image_layer.py, and core/interactor_style.py. This shared imaging context is the handoff point between registration, planning, painting/localisation, and visualization.
MRI ingestion, rendering, and annotation
MRI files and metadata enter through file_handling/loader.py, file_handling/mri_volume.py, and file_handling/metadata.py. The GUI supports 3D/4D volume viewing and editing, including image resampling and manual segmentation/painting: file_handling/resample_data.py, segmentation/segmentation_utils.py, and core/paintbrush.py. These stages produce persistent NIfTI-derived images/masks and session-folder artifacts rather than a server-side datastore.
Atlas registration and coordinate transforms
Subject MRI is registered to the Waxholm Space atlas through the bundled SAMRI code and ANTs binaries. Registration-facing modules include core/registration.py, samri/samri/optimization/registration.py, and samri/samri/pipelines/preprocess.py. Atlas acquisition/caching is isolated in mrid_utils/atlas_fetch.py and registry/path logic in mrid_utils/atlas_registry.py. ANTs is an external executable dependency under ants/bin; the atlas is downloaded once or read from configured local storage.
Pre-surgical trajectory planning
Trajectory planning consumes a registered pre-surgical MRI and atlas-space geometry to position shanks and targets in multi-planar/3D views. Its domain model and UI are in trajectory_planning/trajectory_planning.py, trajectory_planning/shank.py, and trajectory_planning/visualisation3D.py. Coordinate conversion and registration interoperability sit in trajectory_planning/coord_transform.py and trajectory_planning/registration.py. Planning output includes shank data and a report PDF, intended as the contract for surgery and later localisation.
Intraoperative correction
The surgery workflow loads a prior plan/report, resolves the associated scan, and recalculates target positions from measured bregma/lambda coordinates. Control/UI is centered on during_surgery/surgery_controller.py, with plan loading in during_surgery/load_surgery_plan.py and spatial reprojection in during_surgery/reprojection.py. This is a distinct correction layer over the planned trajectory, not a replacement for atlas registration.
Post-implant localisation and region assignment
Post-implant data is resampled and registered to pre-surgical MRI before semi-supervised MRID tag localisation. Core pipeline modules are core/electrode_localization.py, core/mrid_tags.py, and core/dfx_geometry_panel.py; channel-to-atlas mapping utilities live in mrid_utils/channel_mapper.py, mrid_utils/point_mapper.py, and mrid_utils/roi.py. Inputs include painted anatomy/electrode traces, the registration transform, atlas registration, implanted-shank data, and the experiment-specific mrid_library.pkl; outputs are channel coordinates and atlas-region labels under the session’s analysis directories.
Ephys visualization and operational boundaries
Ephys loading and anatomy-linked viewing are implemented in ephys/init_ephys.py, ephys/ephysrecording.py, and ephys/visualisationEphys.py, with 3D electrode context in ephys/visualisation3D.py. The main supported flow is recording data plus localisation-derived channel metadata into curated, region-colored traces; advanced analysis utilities are present but README marks preprocessing/analysis as future scope. Runtime configuration is local paths_config.json, including raw-data root, atlas location, and optional MRID library path. Optional Bruker acquisition integration exists in the vendored SAMRI package (samri/samri/fetch/local.py); standalone packaging is defined by MRID_GUI.spec.
Main entry points: main_window.py Main window · load_MRI_file.py Shared imaging context · registration.py MRI-to-atlas registration · electrode_localization.py Electrode localisation
Components 19
Desktop shell
- Main window · Integration boundary for menus and workflow launch.
main_window.py - Qt UI definitions
form.ui
Imaging workspace
- MRI ingestion
file_handling/loader.py - MRI volume & metadata
file_handling/mri_volume.py - Shared imaging context · Owns loaded layers, cursor interaction, and measurements.
core/load_MRI_file.py - Image layers
core/image_layer.py - Painting & segmentation
core/paintbrush.py - Session images & masks · NIfTI-derived images, masks, and session outputs.
Atlas & registration
- Atlas cache · Downloads once or reads configured local atlas storage.
mrid_utils/atlas_fetch.py - MRI-to-atlas registration · Registers subject MRI to Waxholm Space.
core/registration.py - SAMRI preprocessing
samri/samri/pipelines/preprocess.py - ANTs binaries
Clinical workflows
- Trajectory planning · Positions shanks and targets in multi-planar and 3D views.
trajectory_planning/trajectory_planning.py - Plan & surgery report · Shank data and PDF contract for surgery and localisation.
- Intraoperative correction · Reprojects planned targets using measured bregma and lambda.
during_surgery/surgery_controller.py - Electrode localisation · Semi-supervised MRID tag localisation after post-implant registration.
core/electrode_localization.py - Channel-to-atlas mapping · Produces channel coordinates and atlas-region labels.
mrid_utils/channel_mapper.py
Ephys viewing
- Ephys recording loader
ephys/ephysrecording.py - Anatomy-linked ephys viewer · Displays curated region-colored traces with electrode context.
ephys/visualisationEphys.py
Connections 25
- Main window → Qt UI definitions: renders
- Main window → Shared imaging context: loads MRI into
- Main window → Trajectory planning: launches
- Main window → Intraoperative correction: launches
- Main window → Electrode localisation: launches
- Main window → Anatomy-linked ephys viewer: launches
- MRI ingestion → MRI volume & metadata: creates
- MRI volume & metadata → Shared imaging context: supplies volumes
- Shared imaging context → Image layers: manages
- Shared imaging context → Painting & segmentation: provides editing context
- Painting & segmentation → Session images & masks: writes masks
- Shared imaging context → MRI-to-atlas registration: supplies subject MRI
- Atlas cache → MRI-to-atlas registration: supplies atlas
- MRI-to-atlas registration → SAMRI preprocessing: uses
- SAMRI preprocessing → ANTs binaries: executes
- MRI-to-atlas registration → Trajectory planning: provides atlas transform
- Trajectory planning → Plan & surgery report: writes
- Plan & surgery report → Intraoperative correction: loads prior plan
- Plan & surgery report → Electrode localisation: supplies implanted shanks
- Session images & masks → Electrode localisation: supplies traces and anatomy
- MRI-to-atlas registration → Electrode localisation: supplies transforms
- Electrode localisation → Channel-to-atlas mapping: localises tags
- Channel-to-atlas mapping → Session images & masks: writes channel metadata
- Ephys recording loader → Anatomy-linked ephys viewer: supplies recordings
- Channel-to-atlas mapping → Anatomy-linked ephys viewer: supplies region labels