Skip to main content

SIEMENSFile

SIEMENSFile is a Python package for previewing, reading and processing Siemens .dat raw MRI files, and for reconstructing MR images. It extracts the raw k-space data and the scan metadata, and performs image reconstruction with centered inverse Fourier transforms. The Cartesian reconstruction pipeline supports 2D multi-slice, 2D multi-stack (e.g. sag+cor+tra localizers) and 3D acquisitions (e.g. MPRAGE), including Partial Fourier handling. Non-Cartesian reconstruction (radial/spiral via NUFFT) is planned.

Features

  • Reads Siemens VD/VE raw data files (.dat, twix format) through the bundled twixtools.
  • Cartesian reconstruction of:
    • 3D acquisitions: each partition (cPar) is treated as an individual slice — a 3D MPRAGE volume yields one image per partition.
    • 2D multi-stack acquisitions: stacks sharing the same slice counter are separated by spatial position from the acquisition header.
    • Partial Fourier 6/8: phase lines are mapped onto the full acquisition matrix using CenterLin; missing lines are zero-filled.
    • Partial Fourier 1/2 (interleaved): odd phase lines are interpolated from their even neighbours to remove the Nyquist ghost produced by zero-filling.
    • Readout centering: the echo peak (k-space center) is re-centered using CenterCol with an exact circular roll.
  • Root-sum-of-squares (RMS) coil combination over all channels.
  • Outputs per acquisition: k-space preview (PNG), reconstruction mosaic (PNG), one standard-compliant DICOM MR file per slice (MRImageStorage), and full metadata (JSON).
  • Robust metadata extraction from the Siemens Phoenix protocol: TR/TE (ms), FOV, pixel spacing, slice thickness/spacing, 3D flag.

Installation

Install from PyPI:

pip install siemensfile

For a development setup with conda (see requirements.txt for pinned versions):

conda create -n siemensfile python=3.12 -y --override-channels -c conda-forge
conda activate siemensfile
pip install -r requirements.txt
pip install -e .

Requires Python 3.12+.

Usage

from siemensfile import siemensfile

metadata, kspace = siemensfile(r"path/to/meas_MID00068_FID09111_t1_mprage_tra.dat",
                               reconstruction="Cartesian")

kspace.shape   # [line, channel, column, slice] (complex k-space)

reconstruction accepts "Cartesian" (implemented) or "NonCartesian" (not yet implemented — raises NotImplementedError).

API change in 0.2.0: the keyword argument and its values were renamed from reconstruccion="Cartesiana"/"NoCartesiana" to reconstruction="Cartesian"/"NonCartesian", and all module-level functions were renamed to English (e.g. lectura_twixread_twix_pipeline, extraer_metadata_recursivamenteextract_metadata_recursively).

Outputs

Results are written to an output folder next to the input .dat file. The folder is deleted and recreated on every run.

File Content
<name>_kspace.png k-space magnitude preview (log scale), one panel per slice
<name>_reconstruction.png mosaic with the reconstructed magnitude image of every slice
<name>_slice_NNN.dcm reconstruction as DICOM MR (MRImageStorage), one file per slice
<name>_metadata.json flattened twix headers (protocol, geometry, acquisition parameters)

Example: 3D MPRAGE

metadata, kspace = siemensfile(r"meas_MID00068_FID09111_t1_mprage_tra.dat")
kspace.shape    # (224, 15, 352, 102) -> 102 axial partitions reconstructed

Example: multi-stack localizer

metadata, kspace = siemensfile(r"meas_MID00062_FID09105_localizer_sag+cor+tra.dat")
kspace.shape    # (288, 15, 512, 26) -> 26 slices (8 cor + 8 sag + 10 tra), ghost-free

Tests

python -m pytest tests/ -q

Known limitations

  • No coil intensity inhomogeneity correction: sum-of-squares images keep the coil sensitivity profile (brighter periphery than the vendor reconstruction).
  • Partial Fourier 6/8 is zero-filled (slight blur); homodyne reconstruction is not implemented.
  • No parallel imaging (GRAPPA/R) support.
  • No non-Cartesian (radial/spiral) reconstruction yet.
  • ismrmrd_formato.py (ISMRMRD HDF5 export) is experimental and untested.

Credits and acknowledgements

This project builds on twixtools by Philipp Ehses, bundled under src/twixtools, which provides the core Siemens .dat reading functionality. This package extends it with image reconstruction. If you need a more complete tool for reading/writing Siemens raw data, check twixtools directly.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

siemensfile-0.3.0.tar.gz (56.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

siemensfile-0.3.0-py3-none-any.whl (60.8 kB view details)

Uploaded Python 3

File details

Details for the file siemensfile-0.3.0.tar.gz.

File metadata

  • Download URL: siemensfile-0.3.0.tar.gz
  • Upload date:
  • Size: 56.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for siemensfile-0.3.0.tar.gz
Algorithm Hash digest
SHA256 93c34d57f61581bab7aae1588e35cc867a745acbb700faee24d9150fe08de3f1
MD5 d08215db42aeb23365c600fefbae0436
BLAKE2b-256 93517fb3b03b95a6f3286eee20299434cfe09a0099ee1fb6297968517c179a85

See more details on using hashes here.

File details

Details for the file siemensfile-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: siemensfile-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 60.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for siemensfile-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6583793094b8dd1f4637189522b68f30b45373b710cbc751da6e94473f5b42c2
MD5 840ef7b9cd329a41b8b6f2121e6a8a69
BLAKE2b-256 5a1d4618fbb5d0d725ee655c23f69166bc098272554580a681a5923bcf98cf92

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.1

2 files

This release

0.3.0 This release

2 files

0.2.0

2 files

0.1.33

2 files

0.1.32

2 files

0.1.30

2 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