Interlacer
interlacer
#
Interlacer Module
This module defines the Interlacer
class, which constructs and queries a hierarchical
forest of DICOM series based on their metadata relationships. It enables efficient
grouping, querying, and visualization of medical imaging series.
The Interlacer provides tools for analyzing complex DICOM relationships, such as connections between different imaging modalities (CT, MR, PT) and derived objects (RTSTRUCT, RTDOSE, SEG). It enables validation of relationships based on DICOM standards and medical imaging workflows.
Classes:
Name | Description |
---|---|
SeriesNode |
Represents an individual DICOM series and its hierarchical relationships. |
Interlacer |
Builds the hierarchy, processes queries, and visualizes the relationships. |
InterlacerQueryError |
Base exception for query validation errors. |
UnsupportedModalityError |
Raised when an unsupported modality is specified in a query. |
MissingDependencyModalityError |
Raised when modalities in a query are missing required dependencies. |
ModalityHighlighter |
Rich text highlighter for pretty-printing DICOM modalities. |
Features
- Hierarchical representation of DICOM relationships
- Query for specific combinations of modalities with dependency validation
- Interactive visualization of DICOM series relationships
- Rich text console display of patient/series hierarchies
- Validation of modality dependencies based on DICOM standards
DuplicateRowError
#
Bases: imgtools.dicom.interlacer.InterlacerQueryError
Raised when the index.csv file contains duplicate rows.
Source code in src/imgtools/dicom/interlacer.py
Interlacer
dataclass
#
Interlacer(
crawl_index: str | pathlib.Path | pandas.DataFrame,
)
Builds and queries a forest of SeriesNode objects from DICOM series data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str | pathlib.Path | pandas.DataFrame
|
Path to the CSV file or DataFrame containing the series data |
required |
Attributes:
Name | Type | Description |
---|---|---|
crawl_df |
pandas.DataFrame
|
DataFrame containing the data loaded from the CSV file or passed in |
series_nodes |
dict[str, imgtools.utils.interlacer_utils.SeriesNode]
|
Maps SeriesInstanceUID to SeriesNode objects |
root_nodes |
list[imgtools.utils.interlacer_utils.SeriesNode]
|
List of root nodes in the forest |
Methods:
Name | Description |
---|---|
print_tree |
Print a representation of the forest. |
query |
Query the forest for specific modalities. |
query_all |
Simply return ALL possible matches |
visualize_forest |
Visualize the forest as an interactive network graph. |
valid_queries
property
#
Compute all valid queries based on the current forest. Mostly for debugging and informing the user of what we have determined what we can query.
Essentially, traverse each possible branch path and add the modalities to a set, afterwards, permutate each element's subpaths that might be valid
print_tree
#
query
#
query(
query_string: str, group_by_root: bool = True
) -> list[list[imgtools.utils.interlacer_utils.SeriesNode]]
Query the forest for specific modalities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
Comma-separated string of modalities to query (e.g., 'CT,MR') |
required |
|
bool
|
If True, group the returned SeriesNodes by their root CT/MR/PT node (i.e., avoid duplicate root nodes across results). |
True
|
Returns:
Type | Description |
---|---|
list[list[dict[str, str]]]
|
List of matched series groups where each series is represented by a dict containing 'Series' and 'Modality' keys |
Notes
Supported modalities: - CT: Computed Tomography - PT: Positron Emission Tomography - MR: Magnetic Resonance Imaging - SEG: Segmentation - RTSTRUCT: Radiotherapy Structure - RTDOSE: Radiotherapy Dose
Source code in src/imgtools/dicom/interlacer.py
query_all
#
query_all() -> (
list[list[imgtools.utils.interlacer_utils.SeriesNode]]
)
Simply return ALL possible matches Note this has a different approach than query, since we dont care about the order of the modalities, just that they exist in the Branch
Source code in src/imgtools/dicom/interlacer.py
visualize_forest
#
visualize_forest(
save_path: str | pathlib.Path,
) -> pathlib.Path
Visualize the forest as an interactive network graph.
Creates an HTML visualization showing nodes for each SeriesNode and edges for parent-child relationships.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str | pathlib.Path
|
Path to save the HTML visualization. |
required |
Returns:
Type | Description |
---|---|
pathlib.Path
|
Path to the saved HTML visualization |
Source code in src/imgtools/dicom/interlacer.py
InterlacerQueryError
#
Bases: Exception
Base exception for Interlacer query errors.
MissingDependencyModalityError
#
Bases: imgtools.dicom.interlacer.InterlacerQueryError
Raised when modalities are missing their required dependencies.
Source code in src/imgtools/dicom/interlacer.py
UnsupportedModalityError
#
Bases: imgtools.dicom.interlacer.InterlacerQueryError
Raised when an unsupported modality is specified in the query.