utils

Module contents

Utilities for the dicom_parser package.

Submodules

dicom_parser.utils.choice_enum module

Definition of the ChoiceEnum class.

class dicom_parser.utils.choice_enum.ChoiceEnum(value)

Bases: enum.Enum

An Enum with a custom class method that facilitates integration with a Django Field’s choices attribute.

classmethod choices() Tuple[Tuple[str, str], ...]

Returns the contained items as a tuple of tuples.

Returns

Tuple of (name, value) tuples

Return type

Tuple[Tuple[str, str], …]

dicom_parser.utils.peek module

Based on this StackOverflow answer.

dicom_parser.utils.peek.peek(iterable: generator) tuple

From Wikipedia: “peek is an operation which returns the value of the top of the collection without removing the value from the data.”

Parameters

iterable (GeneratorType) – A generator object to peek into

Returns

A tuple containing the first item and the original generator, unless it is empty, then (None, None)

Return type

tuple

dicom_parser.utils.read_file module

Definition of the read_file() function.

dicom_parser.utils.read_file.read_file(raw_input: Union[pydicom.dataset.FileDataset, str, pathlib.Path], read_data: bool = False) pydicom.dataset.FileDataset

Return pydicom’s FileDataset instance based on the provided input.

Parameters
  • raw_input (Union[FileDataset, str, Path]) – The DICOM image to be parsed

  • read_data (bool) – Whether to include the pixel data or not

Returns

Image data

Return type

FileDataset

dicom_parser.utils.value_representation module

This file contains an Enum with the two-character codes of the various DICOM value-representations (VRs).

class dicom_parser.utils.value_representation.ValueRepresentation(value)

Bases: dicom_parser.utils.choice_enum.ChoiceEnum

DICOM value-representations (VRs).

AE = 'Application Entity'
AS = 'Age String'
AT = 'Attribute Tag'
CS = 'Code String'
DA = 'Date'
DS = 'Decimal String'
DT = 'Date Time'
FD = 'Floating Point Double'
FL = 'Floating Point Single'
IS = 'Integer String'
LO = 'Long String'
LT = 'Long Text'
OB = 'Other Byte'
OD = 'Other Double'
OF = 'Other Float'
OL = 'Other Long'
OV = 'Other 64-bit Very Long'
OW = 'Other Word'
PN = 'Person Name'
SH = 'Short String'
SL = 'Signed Long'
SQ = 'Sequence of Items'
SS = 'Signed Short'
ST = 'Short Text'
SV = 'Signed 64-bit Very Long'
TM = 'Time'
UC = 'Unlimited Characters'
UI = 'Unique Identifer'
UL = 'Unsigned Long'
UN = 'Unknown'
UR = 'Universal Resource'
US = 'Unsigned Short'
UT = 'Unlimited Text'
UV = 'Unsigned 64-bit Very Long'
exception dicom_parser.utils.value_representation.ValueRepresentationError

Bases: Exception

Custom execption indicating a data element has an invalid VR value.

dicom_parser.utils.value_representation.get_value_representation(key: str) dicom_parser.utils.value_representation.ValueRepresentation

Utility function to match the VR key in pydicom’s data elements with the appropriate Enum value.

Parameters

key (str) – Value representation key

Returns

Enum value

Return type

ValueRepresentation

Raises

ValueRepresentationError – Invalid value representation