dicom_parser.utils.siemens.csa package¶
Module contents¶
CSA headers are Siemens-specific private data elements that are embedded in some DICOM headers, specifically as the (0029, 1010)/”CSA Image Header Info” and (0029, 1020)/”CSA Series Header Info” tags. For more information see this NiBabel article.
Submodules¶
dicom_parser.utils.siemens.csa.data_element module¶
Definition of a single CSA header data element. These elements are parsed from the full string header using new line characters.
-
class
dicom_parser.utils.siemens.csa.data_element.CsaDataElement(raw_element: str)¶ Bases:
objectRepresents a single CSA header data element as extracted from the raw header information.
-
CLEAN_PART_PATTERN= '[A-Z].*'¶
-
LIST_PART_PATTERN= '\\[\\d+\\]'¶
-
key_to_list(chained_key: str) → list¶ The string data elements represents nested keys using a ‘.’ character. Returns a clean (prefix-omitted) list of the nested key structure.
-
dicom_parser.utils.siemens.csa.header module¶
Definition of the CsaHeader
class which handles the parsing of
CSA header values
returned by pydicom as bytes.
-
class
dicom_parser.utils.siemens.csa.header.CsaHeader(header: bytes)¶ Bases:
objectRepresents a full CSA header data element, i.e. either (0029, 1010)/”CSA Image Header Info” or (0029, 1020)/”CSA Series Header Info”, and provides access to the header as a parsed dictionary. This implementation is heavily based on dicom2nifti’s code (particularly this module).
-
CSA_HEADER_PATTERN= '### ASCCONV BEGIN(.*?)### ASCCONV END ###'¶
-
ELEMENT_PATTERN= '([A-Z][^\\n]*)'¶
-
ENCODING= 'ISO-8859-1'¶
-
create_csa_data_elements(raw_elements: list = None) → list¶ Creates
CsaDataElementinstances that parse the key and the value.- Parameters
raw_elements (list) – Raw (string) CSA header elements
- Returns
CsaDataElementinstances.- Return type
-
property
csa_data_elements¶ Caches the
CsaDataElementinstances representing the entire header information.- Returns
CsaDataElementinstances- Return type
-
decode() → str¶ Decodes the raw (ASCII) information to string.
- Returns
Decoded information
- Return type
-
get_header_information() → str¶ Returns the decoded and extracted header information from the full data element’s value.
- Returns
Decoded clean header information
- Return type
-
get_raw_data_elements() → list¶ Splits the decoded header information into a list of raw (string) data elements, each containing a key-value pair. The first item is skipped because it is an unrequired heading.
- Returns
CSA data elements in raw string format
- Return type
-
property
n_slices¶ Returns the number of slices (tiles) in a mosaic.
- Returns
Number of slices encoded as a 2D mosaic
- Return type
-
parse(csa_data_elements: list = None) → dict¶ Parses a list of
CsaDataElementinstances (or all if left None) as a dictionary.- Parameters
csa_data_elements (list, optional) –
CsaDataElementinstances, by default None- Returns
Header information as a dictionary
- Return type
-
property
parsed¶ Caches the parsed dictionary as a private attribute.
- Returns
Header information as dictionary
- Return type
-
dicom_parser.utils.siemens.csa.parser module¶
Definition of parser that accepts
CsaDataElement
instances to be parsed and keeps a pointer to a dictionary that
may aggregate the results.
-
class
dicom_parser.utils.siemens.csa.parser.CsaParser(destination: dict = None)¶ Bases:
objectParses CSA header data elements given as
CsaDataElementinstances into a public dictionary.-
assign_list_element(part: str, value, destination: dict)¶ Appends to an existing list value or creates a new list instance for it.
- Parameters
part (str) – Last part’s name
value (Any) – The
CsaDataElement’s valuedestination (dict) – A pointer to the appropriate destination with the parsed dictionary
-
assign_listed_element(csa_data_element: dicom_parser.utils.siemens.csa.data_element.CsaDataElement, destination: dict)¶ Once the destination for the
CsaDataElement’s value has been retrieved or created, this method assigns the value at that destination.- Parameters
csa_data_element (CsaDataElement) – The instance from which to assign the value
destination (dict) – The appropriate destination within the parsed values dictionary
-
create_new_element_list(part_name: str, destination: dict) → dict¶ If an array part (part containing the [<index>] pattern) exists as any part of the listed key except for the last, it indicates a list of dictionary instances. This method creates a new list with a single dict instances and returns a pointer to it.
-
fix_value(value)¶ Covert a CSA header element’s value to float or int if possible. Also cleans up redundant quotation marks and decodes hexadecimal values.
-
parse(csa_data_element: dicom_parser.utils.siemens.csa.data_element.CsaDataElement)¶ Parses a raw CSA header element into the provided dictionary or creates a new one.
- Parameters
csa_data_element (CsaDataElement) – CSA header element to be parsed
-
scaffold_dict_part(part: str, destination: dict) → dict¶ Returns the destination of a given key’s dict part within the parsed dictionary.
-
scaffold_list_part(part: str, index: int, destination: dict) → dict¶ Returns the destination of a given key’s list part within the parsed dictionary.
-
scaffold_listed_key(csa_data_element: dicom_parser.utils.siemens.csa.data_element.CsaDataElement, destination: dict = None) → dict¶ Creates a scaffolding within the parsed values dictionary. This means that it runs over the data elements nested key structure (LevelA.ListLevelB[5].LevelC = ‘value’) and returns a pointer to the appropriate destination for the value within the parsed values dictionary.
- Parameters
csa_data_element (CsaDataElement) – Instance to scaffold a destination for
destination (dict, optional) – An existing destination dictionary, by default None
- Returns
A pointer to the appropriate destination for the
CsaDataElement’s value- Return type
-
scaffold_part(csa_data_element: dicom_parser.utils.siemens.csa.data_element.CsaDataElement, part: str, destination: dict) → dict¶ Returns the destination of a given key’s part within the parsed dictionary.
- Parameters
csa_data_element (CsaDataElement) – The source instance
part (str) – List part’s name
destination (dict) – The current level of scaffolding within the parsed dictionary
- Returns
The next level of the key’s scaffolding within the parsed dictionary
- Return type
-
update_existing_element_list(part_name: str, index: int, destination: dict) → dict¶ If an array part (part containing the [<index>] pattern) exists as any part of the listed key except for the last, it indicates a list of dictionary instances. This method check whether a dictionary exists already at the given list’s index. If it does, returns that dict instance, otherwise, creates a new one and returns it.
-