File I/O

File I/O#

bartorch.io reads and writes the files a reconstruction starts from and ends in: BART’s CFL arrays, ISMRMRD raw data, and DICOM and NIfTI images. Every reader returns tensors in bartorch’s layout (Data layout and conventions) and plain containers beside them: the ISMRMRD header as ismrmrd parses it, a dictionary of per-readout or per-contrast values, and the image geometry as one (4, 4) affine from voxel indices (x, y, z) – the last three axes of an image tensor, reversed – to RAS coordinates in millimetres, the convention of NIfTI. The image writers take the same affine, so an image read from one format is written to the other in the same place. ISMRMRD, DICOM and NIfTI need the io extra: pip install 'bartorch[io]'.

CFL arrays are NumPy arrays in BART’s dimension order, the reverse of a C-order tensor shape, so array.T converts between the two.

Object

Description

read_mrd

Read one encoding space of an ISMRMRD file into k-space placed by its counters, with the mask, trajectory, noise readouts and affine

read_dicom

Read a DICOM MR series, or several as one, into images sorted by contrast and slice, with their timings and affine

to_dicom

Convert a real image and its affine to the datasets of one DICOM MR series

write_dicom

Write a real image and its affine as a DICOM MR series

read_nifti

Read NIfTI files and their BIDS sidecars into images, timings and affine

write_nifti

Write an image and its affine as NIfTI, and its timings as a BIDS sidecar

readcfl

Read name.hdr and name.cfl into a NumPy array in BART’s dimension order

writecfl

Write a NumPy array in BART’s dimension order as name.hdr and name.cfl

Parameter maps from scanner images reads a multi-echo series from DICOM, fits a \(T_2\) map to it and writes the map back.