io.read_series

Contents

io.read_series#

bartorch.io.read_series()#

Read a DICOM or NIfTI image series, pairing magnitude with phase or real with imaginary.

Each image is assigned to a part – magnitude, phase, real or imaginary – by, in order, DICOM’s ComplexImageComponent, GE’s private image-type tag, Philips’s private one, and the values of ImageType; a NIfTI file by its sidecar’s ImageType, then a BIDS part- entity, then phase, real or imag in its name. An image none of these place is magnitude. The parts have to cover the same contrasts and slices, and agree on every timing both state; a timing one part does not state is taken from another.

Phase is scaled to radians from the span of stored values that stands for one turn. Given phase_range, that span is used. Otherwise it is the narrowest of radians, degrees, milliradians, [0, 4096) and [-4096, 4096) that holds every value, else the span of the stored integer type after its rescale, else the values’ own span. Wrapped phase fills its span, so a warning is issued when the values fill less than 80% of the span used, or fall outside a given one: a reconstruction of one’s own may scale phase in a way no rule can guess. A warning is also issued when the phase takes fewer than 256 distinct values: phase rounded on export (to whole radians, say) carries no field.

Parameters:
  • path (str or sequence of str) – A DICOM directory, searched recursively, or DICOM files; or .nii and .nii.gz files, one per part and contrast or with contrasts along the fourth axis, each with an optional JSON sidecar of the same name.

  • series (int, str or sequence, default=None) – DICOM only: SeriesNumber or SeriesInstanceUID of the series to read, or several, read as one. None reads every series the files hold, provided no two hold the same part, as a scanner that stores magnitude and phase as series of their own does.

  • phase_range (tuple of float, default=None) – Stored phase values (low, high) that stand for -pi and pi.

Returns:

A named tuple of

image

complex64 when the series holds phase or real and imaginary parts, float32 when it holds magnitude only; (contrasts, z, y, x). Phase without magnitude reads as unit magnitude.

affine

float64 (4, 4), from voxel indices (x, y, z) to RAS millimetres.

acquisition

The Acquisition the files describe.

header

The first DICOM dataset or NIfTI header read, a template for the writers.

Return type:

Series

Raises:
  • ValueError – If two series hold the same part and series is not given, the parts cover different contrasts, slices or geometry, a part is missing its counterpart (real without imaginary), or phase_range is empty.

  • ImportError – If pydicom or nibabel is not installed.