def test_gk_dvh(): # Given slicer_dvh_file = r'C:\Users\Victor\Dropbox\Plan_Competition_Project\tests\tests_data\gk_plan\SLICER_RT_DVH.csv' plan_folder = r'C:\Users\Victor\Dropbox\Plan_Competition_Project\tests\tests_data\gk_plan' slicer_dvh = read_slicer_dvh(slicer_dvh_file) # strip columns names slicer_dvh.columns = [ 'Skull Value', 'CerebelarDir', 'FrontalEsq ', 'Tumor', 'Tumor 2', 'Tumor 3', 'Tumor 4', 'Tumor 5' ] dcm_files, flag = get_participant_folder_data(plan_folder) plan_dict = PyDicomParser(filename=dcm_files['rtplan']).GetPlan() structures = PyDicomParser(filename=dcm_files['rtss']).GetStructures() rd_dcm = PyDicomParser(filename=dcm_files['rtdose']) dose = rd_dcm.get_dose_3d() structures_py = [ PyStructure(s, end_cap=s['thickness'] / 2) for k, s in structures.items() ] grid = (0.1, 0.1, 0.1) dvh_pyplan = {} for s in structures_py[:-1]: dvh_calci = DVHCalculation(s, dose, calc_grid=grid) dvh_l = dvh_calci.calculate(verbose=True) dvh_pyplan[dvh_l['name']] = dvh_l # plot_dvh(dvh_l, dvh_l['name']) for target_name, dvh_calc in dvh_pyplan.items(): dose_t5 = slicer_dvh.index t5 = slicer_dvh.loc[:, target_name].values x_calc = np.arange(len(dvh_calc['data'])) * float(dvh_calc['scaling']) py_t5 = dvh_calc['data'] plt.plot(dose_t5, t5, label='Slicer-RT') plt.plot(x_calc, py_t5, label='PyPlanScoring') plt.title(target_name) plt.legend() plt.show()
# filter rtdose rd_files = [d[1] for d in dicom_data if d[0] == 'rtdose'] dcm_objs = [PyDicomParser(filename=rd_file) for rd_file in rd_files] doses_3d = [obj.get_dose_3d() for obj in dcm_objs] # Sum DVHs acc = DoseAccumulation(doses_3d) plan_sum = acc.get_plan_sum() # TODO compare with slicerRT plan sum DVH rs_file = '/home/victor/Dropbox/Plan_Competition_Project/tests/tests_data/left_chest_wall/photon_electron/RS.1.2.246.352.71.4.584747638204.283643.20180405155645.dcm' structures = PyDicomParser(filename=rs_file).GetStructures() structures_py = [ PyStructure(s, end_cap=s['thickness']) for k, s in structures.items() ] dvh_pyplan = {} for s in structures_py: if s.name in eclipse_dvh.keys(): if s.volume < 100: dvh_calci = DVHCalculation(s, plan_sum, calc_grid=(0.5, 0.5, 0.5)) else: dvh_calci = DVHCalculation(s, plan_sum, calc_grid=None) dvh_l = dvh_calci.calculate(verbose=True) dvh_pyplan[dvh_l['name']] = dvh_l plot_dvh(dvh_l, dvh_l['name']) plt.plot(eclipse_dvh[s.name][:, 0],
rs = os.path.join(DATA_DIR, 'RS.dcm') rd = os.path.join(DATA_DIR, 'RD.dcm') rp = os.path.join(DATA_DIR, 'RP.dcm') str_names = [ 'LENS LT', 'PAROTID LT', 'BRACHIAL PLEXUS', 'OPTIC N. RT PRV', 'OPTIC CHIASM PRV', 'OPTIC N. RT', 'ORAL CAVITY', 'BRAINSTEM', 'SPINAL CORD', 'OPTIC CHIASM', 'LENS RT', 'LARYNX', 'SPINAL CORD PRV', 'EYE LT', 'PTV56', 'BRAINSTEM PRV', 'PTV70', 'OPTIC N. LT PRV', 'EYE RT', 'PTV63', 'OPTIC N. LT', 'LIPS', 'ESOPHAGUS', 'PTV70' ] rs_dvh = os.path.join(DATA_DIR, 'RS_dvh.dcm') structures_tmp = PyDicomParser(filename=rs_dvh).GetStructures() to_index = {v['name']: k for k, v in structures_tmp.items()} # fixtures @pytest.fixture(scope="session") def rp_dcm(): """ Fixture to return DICOM-RTPLAN obj :return: """ return PyDicomParser(filename=rp) @pytest.fixture(scope="session") def rs_dcm(): """