예제 #1
0
def rtdose2dvh():
    """
    Gets DVH data from an RT Dose file.
    """
    # Get RT Dose
    patient_dict_container = PatientDictContainer()
    rtss = patient_dict_container.dataset['rtss']
    rt_dose = patient_dict_container.dataset['rtdose']
    dvh_seq = {"diff": False}

    # Get ROI numbers
    rois = []
    for roi in rtss['StructureSetROISequence']:
        rois.append(roi.ROINumber)
    rois.sort()

    # Try DVH referenced ROI numbers
    dvhs = []
    try:
        for dvh in rt_dose['DVHSequence']:
            dvhs.append(dvh.DVHReferencedROISequence[0].ReferencedROINumber)
        dvhs.sort()
    # RTDOSE has no DVHSequence attribute. Return.
    except KeyError:
        dvh_seq["diff"] = True
        return dvh_seq

    # If there are a different amount of ROIs to DVH sequences
    if rois != dvhs:
        # Size of ROI and DVH sequence is different.
        # alert user, ask to recalculate.
        dvh_seq["diff"] = True

    # Try to get the DVHs for each ROI
    for item in rtss["StructureSetROISequence"]:
        try:
            name = item.ROIName
            dvh = DVH.from_dicom_dvh(rt_dose, item.ROINumber, name=name)
            dvh_seq[item.ROINumber] = dvh
        except AttributeError as e:
            pass

    return dvh_seq
예제 #2
0
 def test_dvh_calculation_empty_structure_no_dose(self):
     """Test if a DVH returns an empty histogram for invalid data."""
     dvh = self.calc_dvh(2)
     self.assertEqual(dvh, DVH([0], arange(0, 2)))