Commit 82adbcdf authored by Gabriel Couture's avatar Gabriel Couture

In write_dicom_rt function, each dataset has its layer

parent 7918761f
......@@ -2,14 +2,10 @@
# author: Gabriel Couture
from typing import Dict
from pydicom import FileDataset
from pydicom import Dataset
def apply_layer(layer: Dict, dataset: FileDataset) -> FileDataset:
# for item in dataset:
# print(item)
def apply_layer(layer: Dict, dataset: Dataset) -> Dataset:
for key, value in layer.items():
if type(value) is dict:
for dataset_item in eval(f'dataset.{key}'):
......
......@@ -34,7 +34,9 @@ def write_dicom_rt(
spacing: float,
dose_gradient: str,
roi: str,
layer: Dict = {}):
rtplan_layer: Dict = {},
rtdose_layer: Dict = {},
rtstruct_layer: Dict = {}):
"""Write the DICOM-RT files (RTDOSE, RTSTRUCT, RTPLAN).
Parameters
......@@ -49,8 +51,12 @@ def write_dicom_rt(
Dose gradient: {'AP', 'SI'}.
roi
Roi: {'axial', 'right'}.
layer
Dictionary of DICOM field to edit.
rtplan_layer
Dictionary of DICOM field to edit on RTPLAN dataset.
rtdose_layer
Dictionary of DICOM field to edit on RTDOSE dataset.
rtstruct_layer
Dictionary of DICOM field to edit on RTSTRUCT dataset.
Returns
-------
......@@ -63,19 +69,18 @@ def write_dicom_rt(
rtstruct = dao.get_rtstruct(geometry, spacing)
dvh_data = dao.get_analytic_dvhs(geometry, spacing, dose_gradient, roi)
# Applying desired layers
rtplan = apply_layer(layer, rtplan)
rtdose = apply_layer(layer, rtdose)
rtstruct = apply_layer(layer, rtstruct)
# Applying layers
apply_layer(rtplan_layer, rtplan)
apply_layer(rtdose_layer, rtdose)
apply_layer(rtstruct_layer, rtstruct)
# Writing results
os.makedirs(target_directory)
pydicom.dcmwrite(join(target_directory, 'RTPLAN-1.dcm'), rtplan)
pydicom.dcmwrite(join(target_directory, 'RTDOSE-1.dcm'), rtdose)
pydicom.dcmwrite(join(target_directory, 'RTSTRUCT-1.dcm'), rtstruct)
dvh_data.columns = ['Dose [cGy]', 'Volume [cc]']
dvh_data.to_csv(
join(target_directory, 'DVH.csv'),
index=False
)
dvh_data.to_csv(join(target_directory, 'DVH.csv'), index=False)
write_metadata(target_directory, geometry, spacing, dose_gradient, roi)
......@@ -5,7 +5,7 @@ import unittest
from dicomgenerator import dao, layer
A_LAYER_NAME = 'HDQID'
A_COMPLEX_LAYER_NAME = 'OCP_HDR_live_prostate'
A_COMPLEX_LAYER_NAME = 'RTPLAN_OCP_HDR_live_prostate'
class TestLayer(unittest.TestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment