def get_dvh(structure, dose, roi, limit=None, callback=None): """Calculate a cumulative DVH in Gy from a DICOM RT Structure Set & Dose. Parameters ---------- structure : pydicom Dataset DICOM RT Structure Set used to determine the structure data. dose : pydicom Dataset DICOM RT Dose used to determine the dose grid. roi : int The ROI number used to uniquely identify the structure in the structure set. limit : int, optional Dose limit in cGy as a maximum bin for the histogram. callback : function, optional A function that will be called at every iteration of the calculation. """ from dicompylercore import dicomparser rtss = dicomparser.DicomParser(structure) rtdose = dicomparser.DicomParser(dose) structures = rtss.GetStructures() s = structures[roi] s['planes'] = rtss.GetStructureCoordinates(roi) s['thickness'] = rtss.CalculatePlaneThickness(s['planes']) hist = calculate_dvh(s, rtdose, limit, callback) return dvh.DVH( counts=hist, bins=(np.arange(0, 2) if (hist.size == 1) else np.arange(0, hist.size + 1) / 100), dvh_type='differential', dose_units='gy', name=s['name']).cumulative
def test_raw_data_dvh(self): """Test if a DVH can be created from raw data.""" self.assertEqual(dvh.DVH.from_data(1, 1), dvh.DVH([1], [1])) self.assertEqual( repr(dvh.DVH.from_data(1, 1)), "DVH(cumulative, 1 bins: [0:1] Gy, volume: 1 cm3, " "name: None, rx_dose: 0 Gy)") assert_array_equal(dvh.DVH.from_data(0, 1).bins, array([0, 0])) assert_array_equal(dvh.DVH.from_data(5, 2).bins, array([0, 2, 4, 5]))
def get_dvh(structure, dose, roi, limit=None, calculate_full_volume=True, use_structure_extents=False, interpolation_resolution=None, interpolation_segments_between_planes=0, thickness=None, callback=None): """Calculate a cumulative DVH in Gy from a DICOM RT Structure Set & Dose. Parameters ---------- structure : pydicom Dataset DICOM RT Structure Set used to determine the structure data. dose : pydicom Dataset DICOM RT Dose used to determine the dose grid. roi : int The ROI number used to uniquely identify the structure in the structure set. limit : int, optional Dose limit in cGy as a maximum bin for the histogram. calculate_full_volume : bool, optional Calculate the full structure volume including contours outside of the dose grid. use_structure_extents : bool, optional Limit the DVH calculation to the in-plane structure boundaries. interpolation_resolution : tuple or float, optional Resolution in mm (row, col) to interpolate structure and dose data to. If float is provided, original dose grid pixel spacing must be square. interpolation_segments_between_planes : integer, optional Number of segments to interpolate between structure slices. thickness : float, optional Structure thickness used to calculate volume of a voxel. callback : function, optional A function that will be called at every iteration of the calculation. """ from dicompylercore import dicomparser rtss = dicomparser.DicomParser(structure) rtdose = dicomparser.DicomParser(dose) structures = rtss.GetStructures() s = structures[roi] s['planes'] = rtss.GetStructureCoordinates(roi) s['thickness'] = thickness if thickness else rtss.CalculatePlaneThickness( s['planes']) calcdvh = calculate_dvh(s, rtdose, limit, calculate_full_volume, use_structure_extents, interpolation_resolution, interpolation_segments_between_planes, callback) return dvh.DVH(counts=calcdvh.histogram, bins=(np.arange(0, 2) if (calcdvh.histogram.size == 1) else np.arange(0, calcdvh.histogram.size + 1) / 100), dvh_type='differential', dose_units='Gy', notes=calcdvh.notes, name=s['name']).cumulative
def test_dose_constraint_with_zero_volume(self): subject = dvh.DVH(array([0, 0]), array([0, 1])) subject.dose_constraint(1)
def test_dvh_statistics_with_zero_volume(self): subject = dvh.DVH(array([0, 0]), array([0, 1])) self.assertEqual(subject.max, 0) self.assertEqual(subject.min, 0) self.assertEqual(subject.mean, 0)
def test_dose_constraint_with_no_counts(self): subject = dvh.DVH(array([]), array([0])) subject.dose_constraint(1)
def test_dvh_statistics_with_no_counts(self): subject = dvh.DVH(array([]), array([0])) self.assertEqual(subject.max, 0) self.assertEqual(subject.min, 0) self.assertEqual(subject.mean, 0)