Skip to main content

Read raw data from Siemens MRI scanners with IDEA VB15.

Project description

Python implementation based on MATLAB version written by Eugene G. Kholmovski, PhD (UCAIR, Department of Radiology, University of Utah).

The name of the project pays homage to the naming convention of the main antagonist in Disney’s hit cartoon “Phineas and Ferb” (see List of Doofenshmirtz’s schemes and inventions).

Installation

This package is known to work with Python 2.7.14 and Python 3.6.3 using Ubuntu 17.10 and Windows 10. requirements.txt contains package dependencies. You can clone the repo and get everything up and running like this:

git clone https://github.com/mckib2/rawdatarinator.git
cd rawdatarinator
pip install -r requirements.txt

or, slightly more easily, you can use pip:

pip install rawdatarinator

readMeasDataVB15

Read raw data from Siemens MRI scanners with IDEA VB15.

Will return an array of measured k-space data from raw data from Siemens MRI scanners using IDEA VB15 (single value). If the option -I is used, then image space data will be returned instead.

Usage:

Call with arguments:

python3 -m rawdatarinator.readMeasDataVB15 filename [ -t ] [ -rfft ]
                                                    [ -r1 ] [ -rp ] [ -rn ]
                                                    [ -skipts ] [ -nnavek ]
                                                    [ -ros ] [ -rosa ]
                                                    [ -I ] [ -w ] [ -npz ]

You can also use an alias for fewer key strokes:

python3 -m rawdatarinator.raw filename [ same args as above ]

Example - Executable

From the terminal:

python3 -m rawdatarinator.raw raw.dat -w

Example - Import

Import into python script:

from rawdatarinator.raw import raw

class DataLoader:
    def __init__(self):
        data = raw('raw.dat')

if __name__ == "__main__":
    DataLoader()

Function Arguments

Function definition:

def readMeasDataVB15(filename,
                     resetFFTscale=False,
                     readOneCoil=False,
                     readPhaseCorInfo=False,
                     readNavigator=False,
                     readTimeStamp=True,
                     nNavEK=False,
                     removeOS=False,
                     removeOSafter=False,
                     transformToImageSpace=False,
                     writeToFile=False,
                     npz=False)

See Command-line Options for more details.

Command-line Options:

Terminal options:

filename
  Filename of file containing raw measurements.

-rfft (resetFFTscale)
  Resets FFTscale and DataCorrection for each coil
  to 1.

-r1 (readOneCoil)
  Read measurement data from from individual coil.

-rp (readPhaseCorInfo)
  _

-rn (readNavigator)
  _

-skipts (skip readTimeStamp)
  _

-nnavek (nNavEK)
  _

-ros (removeOS)
  Flag to remove oversampling (OS) in the x
  direction. removeOS=True is more efficient as it
  processes each readout line independently,
  reducing the required memory space to keep all
  measured data.

-rosa (removeOSafter)
  Flag to remove oversampling (OS) in the x
  direction. This works in image space, cutting FOV.
  Not likely a good idea for radial.

-I (transformToImageSpace)
  Produce image space representation. Note that
  there is no correction for partial Fourier or
  parallel imaging k-space undersampling.  The given
  version of code only uses numpy's FFT operation.

-w (writeToFile)
  Save k-space or image space volume. Currently the
  output filename is auto generated.

-npz (npz)
  Save k-space or image space volume using the .npz
  file extension.  Default is to use hdf5 file
  standard.

-h (help)
  Displays this documentation.

Testing

testsuite.py compares the values generated in the Python implementation to the workspace variables of the MATLAB implementation to ensure correct output.

Quick View

Display processed MRI data from .hdf5, .npz, or .dat files. No arguments displays the IFFT of the k-space data. The type of file is guessed by the file extension (i.e., if extension is .dat then readMeasData15 will be run to get the data).

Command-line Options

Options for QuickView:

-nifft (no IFFT)
  Display k-space data, log magnitude and phase plots.

Examples

To view image domain data:

python3 -m rawdatarinator.quickview processed_data.hdf5

To view log magnitude and phase plots of k-space data:

python3 -m rawdatarinator.quickview processed_data.hdf5 -nifft

To view image domain data of raw data file:

python3 -m rawdatarinator.quickview raw.dat

Lexer and Parser

Siemens raw MRI data comes packaged all in a .dat file. The structure does not follow Siemens’ PLM XML format, but is quasi-XML followed by a dump of the binary data. It is described in the IDEA Documentation.

The game plan I used was to extract the quasi-XML portion of the file, obtain the structure of the document by parsing it, and then reconstructing an equivalent XML document that is easy to traverse using standard libraries. Python Lex-Yacc (PLY) is used to create a lexer (infolex.py) identifying each unique token and a parser (infoparser.py) that builds an XML string as grammar productions are matched. The actual grammar is unknown to me, so the tokens and grammar may not be comprehensive. This functionality is captured in the raw2xml function in infoparser.py.

cleanraw.py sanitizes the raw data by removing illegal characters (such as carriage returns or null characters in the quasi-XML portion of the document) or data not needing to be parsed.

The resultant XML document mirrors the original quasio-XML document and is split into roughly six subtrees/section::
  1. <XProtocol> … </XProtocol>

  2. <XProtocol name=”Dicom”> … </XProtocol>

  3. <XProtocol name=”Meas”> … </XProtocol>

  4. The MeasYaps portion, looks like:

    <value>Key</value>

    <value>Value</value>

  5. <XProtocol name=”Phoenix”> … </XProtocol>

  6. <XProtocol name=”Spice”> … </XProtocol>

MeasYaps is a collection of keys and values whereas each <XProtocol> has a standard tree structure. Every XML document must have a root and is called <doc_root>.

Many measurements come from MeasYaps. A utility function called get_val_by_text() is used to find a value given a key.

Project details


Download files

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

Source Distribution

rawdatarinator-0.1.8.tar.gz (33.2 kB view details)

Uploaded Source

Built Distribution

rawdatarinator-0.1.8-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file rawdatarinator-0.1.8.tar.gz.

File metadata

  • Download URL: rawdatarinator-0.1.8.tar.gz
  • Upload date:
  • Size: 33.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/3.6.5

File hashes

Hashes for rawdatarinator-0.1.8.tar.gz
Algorithm Hash digest
SHA256 9a01efcda2304ed4f00dfcfa1e1544cb8454a0297e752cf35f2a710ce98dc694
MD5 cd9bcc1d66690076cf58d693690dd9db
BLAKE2b-256 7e326bf39d4664c1e701ece89833a890a31b2d5fbd5019e61b21128145893aa8

See more details on using hashes here.

File details

Details for the file rawdatarinator-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: rawdatarinator-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/3.6.5

File hashes

Hashes for rawdatarinator-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 d41b4dbce03c6331e072734d4f40dd66812307a84dda37d7bf23902c16e9bad7
MD5 e9444501113202152b1c70275eee43f8
BLAKE2b-256 c445314ff04c1f77c28992c825c8a5af3f5dd26651a34983eac0c066c45e5f17

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page