dbdicom.as_series#

dbdicom.as_series(array: ndarray, coords: dict | None = None, dtype='mri', in_study: Study | None = None, in_database: Database | None = None, **kwargs) Series[source]#

Create a DICOM series from a numpy array.

Parameters:
  • array (np.ndarray) – numpy.ndarray with image data

  • coords (dict, optional) – Dictionary with coordinate labels and values. For 3- or 4-dimensional arrays this is optional but for arrays with more than 4 dimensions this is required. The coordinate values can be one-dimensions for regularly gridded data, or n-dimensional for irregularly gridded data.

  • dtype (str, optional) – The type of the series to create. Defaults to ‘mri’.

  • in_study (Study, optional) – If provided, the series is created in this study. Defaults to None.

  • in_database (Database, optional) – If provided, the series is created in this database. Defaults to None.

  • kwargs – Any valid DICOM (tag, value) pair to set properties of the new patient

Returns:

DICOM series containing the provided array as image data and defaults for all other parameters.

Return type:

Series

Raises:
  • ValueError – if a dtype is requested that is currently not yet implemented

  • ValueError – If the coords do not match up with the shape of the array.

See also

series() zeros()

Example

Create a series containing a 4-dimensional array. Since the default format is single-frame MRImage, this produces 6 separate files.

>>> array = np.zeros((128, 128, 3, 2))
>>> zeros = db.as_series(array)
>>> zeros.print()
---------- SERIES --------------
Series 001 [New Series]
    Nr of instances: 6
        MRImage 000001
        MRImage 000002
        MRImage 000003
        MRImage 000004
        MRImage 000005
        MRImage 000006
--------------------------------

Since no coordinates are provided, these are assumed to be SliceLocation and AcquisitionTime with default values:

>>> print(zeros.SliceLocation)
[0.0, 1.0, 2.0]
>>> print(zeros.AcquisitionTime)
[0.0, 1.0]

To override these defaults, set coordinates explicitly using a dictionary. For instance, for an MRI series of images acquired at a single slice location for 3 flip angles and 2 repetition times, the coordinates of the series are:

>>> coords = {
...    'FlipAngle': [2, 15, 30],
...    'RepetitionTime': [2.5, 5.0],
... }

Now create another series, providing coordinates, and list the unique values of flip angle and repetition time: >>> zeros = db.as_series(array, coords) >>> print(zeros.FlipAngle) [2.0, 15.0, 30.0] >>> print(zeros.RepetitionTime) [2.5, 5.0]