tfmri.io.parse_twix

parse_twix(contents)[source]

Parses the contents of a TWIX RAID file (Siemens raw data).

Warning

This function does not support graph execution.

Example

>>> # Read bytes from file.
>>> contents = tf.io.read_file("/path/to/file.dat")
>>> # Parse the contents.
>>> twix = tfmri.io.parse_twix(contents)
>>> # Access the first measurement.
>>> meas = twix.measurements[0]
>>> # Get the protocol...
>>> protocol = meas.protocol
>>> # You can index the protocol to access any of the protocol buffers,
>>> # e.g., the measurement protocol.
>>> meas_prot = protocol['Meas']
>>> # Protocol buffers are nested structures accessible with "dot notation"
>>> # or "bracket notation". The following are equivalent:
>>> base_res = meas_prot.MEAS.sKSpace.lBaseResolution.value
>>> base_res = meas_prot['MEAS']['sKSpace']['lBaseResolution'].value
>>> # The measurement object also contains the scan data.
>>> scans = meas.scans
>>> # Each scan has a header and the list of channels.
>>> scan_header = scans[0].header
>>> channels = scans[0].channels
>>> # Each channel also has its own header as well as the raw measurement
>>> # data.
>>> channel_header = channels[0].header
>>> data = channels[0].data
Parameters

contents – A scalar tf.Tensor of type string. The encoded contents of a TWIX RAID file.

Returns

A TwixRaidFile object containing the measurements, including protocol buffers, scan headers and scan data.

Raises

RuntimeError – If called with eager execution disabled.