Exemple #1
0
def py_planning_item():
    plan_dict = PyDicomParser(filename=rp).GetPlan()
    rs_dvh = os.path.join(DATA_DIR, 'RS_dvh.dcm')
    structures_tmp1 = PyDicomParser(filename=rs_dvh).GetStructures()
    criteria1 = pd.read_excel(file_path, sheet_name='calc_dvh')
    rt_case_tmp = RTCase("H&N", 123, structures_tmp1, criteria1)
    dose_values = PyDicomParser(filename=rd).get_dose_matrix()
    grid = PyDicomParser(filename=rd).get_grid_3d()
    dose = Dose3D(dose_values, grid, pq.Gy)
    dvh_calc = DVHCalculator(rt_case_tmp, calculation_options)

    return PyPlanningItem(plan_dict, rt_case_tmp, dose, dvh_calc)
Exemple #2
0
def test_dvh_comparisson(setup_calculation_options):
    # Given plan DVH
    folder = os.path.join(DATA_DIR, 'lungSBRT')

    # parse DICOM folder
    # plan_folder = r'C:\Users\Victor\Dropbox\Plan_Competition_Project\tests\tests_data\pinnacle\plan1'
    plan_folder = r'C:\Users\Victor\Dropbox\Plan_Competition_Project\tests\tests_data\pinnacle\plan2'
    dcm_files, flag = get_participant_folder_data(plan_folder)

    rs_dvh = os.path.join(folder, 'RS.dcm')

    plan_dict = PyDicomParser(filename=dcm_files['rtplan']).GetPlan()
    # structures = PyDicomParser(filename=dcm_files['rtss']).GetStructures()
    structures = PyDicomParser(filename=rs_dvh).GetStructures()
    rd_dcm = PyDicomParser(filename=dcm_files['rtdose'])
    dose = rd_dcm.get_dose_3d()

    # criteria file
    file_path = os.path.join(folder, 'Scoring_criteria.xlsx')
    criteria = pd.read_excel(file_path, sheet_name='BiLateralLungSBRTCase')

    # setup RT case
    rt_case_tmp = RTCase("SBRT", 123, structures, criteria)
    dvh_calc = DVHCalculator(rt_case_tmp, setup_calculation_options)

    # when calculate DVH using pyplanScoring
    planning_obj = PyPlanningItem(plan_dict, rt_case_tmp, dose, dvh_calc)
    planning_obj.calculate_dvh()

    # for k, v in planning_obj.dvh_data.items():
    #     plot_dvh(v, v['name'])
    #     plt.show()

    # # Calculating the score
    plan_eval = PlanEvaluation()
    plan_eval.criteria = criteria
    df = plan_eval.eval_plan(planning_obj)

    raw_score = df['Raw score'].sum()
    pass
Exemple #3
0
def test_lung_case_dvh(setup_calculation_options):
    # Given plan DVH
    folder = os.path.join(DATA_DIR, 'lungSBRT')

    # DVH reference
    dvh_ref_path = os.path.join(folder,
                                'PlanIQ DVH - Ahmad Plan - March 12.txt')
    plan_dvh = read_planiq_dvh(dvh_ref_path)

    # parse DICOM folder

    rp = os.path.join(folder, 'RP.dcm')
    rs_dvh = os.path.join(folder, 'RS.dcm')
    rd = os.path.join(folder, 'RD.dcm')

    plan_dict = PyDicomParser(filename=rp).GetPlan()
    structures = PyDicomParser(filename=rs_dvh).GetStructures()
    dose_values = PyDicomParser(filename=rd).get_dose_matrix()
    grid = PyDicomParser(filename=rd).get_grid_3d()
    dose = Dose3D(dose_values, grid, pq.Gy)

    # criteria file
    file_path = os.path.join(folder, 'Scoring_criteria.xlsx')
    criteria = pd.read_excel(file_path, sheet_name='BiLateralLungSBRTCase')

    # setup RT case
    rt_case_tmp = RTCase("SBRT", 123, structures, criteria)
    dvh_calc = DVHCalculator(rt_case_tmp, setup_calculation_options)

    # when calculate DVH using pyplanScoring
    planning_obj = PyPlanningItem(plan_dict, rt_case_tmp, dose, dvh_calc)
    planning_obj.calculate_dvh()

    # compare against PLANIQ
    for roi_number, dvh in planning_obj.dvh_data.items():
        name = dvh['name']
        plot_dvh_comp(dvh, plan_dvh, name, folder)

    # plt.show()

    # compare clinical DVH data
    #
    dvhs = PyDicomParser(filename=rd).GetDVHs()
    # compare against Eclipse DVH
    dvh_calculated = planning_obj.dvh_data
    res = {}
    res_eclipse = {}
    for roi_number in dvhs.keys():
        if roi_number in dvh_calculated:
            dvh_calc = dvh_calculated[roi_number]
            planiq_dvh = plan_dvh[structures[roi_number]['name']]

            x_calc = np.arange(len(dvh_calc['data'])) * float(
                dvh_calc['scaling'])
            x_planiq = plan_dvh.index
            cmp = CurveCompare(x_planiq, planiq_dvh, x_calc, dvh_calc['data'])
            # cmp.plot_results("PlanIQ", "PyPlanScoring", structures[roi_number]['name'])
            # plt.show()
            res[structures[roi_number]['name']] = cmp.stats_paper

            # Eclipse
            eclipse_dvh = dvhs[roi_number]
            x_eclipse = np.arange(len(eclipse_dvh['data'])) * float(
                eclipse_dvh['scaling'])

            cmp1 = CurveCompare(x_eclipse, eclipse_dvh['data'], x_calc,
                                dvh_calc['data'])
            # cmp.plot_results("PlanIQ", "PyPlanScoring", structures[roi_number]['name'])
            res_eclipse[structures[roi_number]['name']] = cmp1.stats_paper

    res_plan_iq = pd.DataFrame.from_dict(res)
    res_plan_iq.to_csv(os.path.join(folder, "PyPlanScoringXPlanIQ.csv"))

    res_eclipsedf = pd.DataFrame.from_dict(res_eclipse)
    res_eclipsedf.to_csv(os.path.join(folder, "PyPlanScoringXEclipse.csv"))

    piq = [
        res_plan_iq.min().min(),
        res_plan_iq.max().max(),
        res_plan_iq.mean().mean()
    ]
    ecl = [
        res_eclipsedf.min().min(),
        res_eclipsedf.max().max(),
        res_eclipsedf.mean().mean()
    ]

    # # # then Get dvh data and compare with plan_data
    # for roi_number, dvh in planning_obj.dvh_data.items():
    #     name = dvh['name']
    #     plot_dvh_comp(dvh, plan_dvh, name, folder)
    #
    # plt.show()
    #
    # # compare it abainst eclipse data
    # # compare with TPS DVH
    dvhs = PyDicomParser(filename=rd).GetDVHs()
    # compare against Eclipse DVH
    dvh_calculated = planning_obj.dvh_data
    for roi_number in dvhs.keys():
        if roi_number in dvh_calculated:
            plot_dvh_comp1(dvh_calculated[roi_number], dvhs[roi_number],
                           structures[roi_number]['name'], folder)

    # plt.show()
    # # lung SBRT case
    #
    # # Calculating the score
    plan_eval = PlanEvaluation()
    plan_eval.criteria = criteria
    df = plan_eval.eval_plan(planning_obj)

    assert df['Raw score'].sum() == 88.612
Exemple #4
0
 def setup_case(self, rs_file_path, file_path, sheet_name):
     structures = PyDicomParser(filename=rs_file_path).GetStructures()
     self._plan_eval.read(file_path, sheet_name=sheet_name)
     # todo implement setup case by id
     self._case = RTCase(sheet_name, 1, structures,
                         self._plan_eval.criteria)
Exemple #5
0
    rtss = r'/home/victor/Dropbox/Plan_Competition_Project/tests/tests_data/ptv_based_SRS/RS.1.2.246.352.205.5644208623194161296.369175407993399980.dcm'
    rt_dose = '/home/victor/Dropbox/Plan_Competition_Project/tests/tests_data/ptv_based_SRS/RD.1.2.246.352.71.7.584747638204.1898898.20180324182516.dcm'
    ini_file = '/home/victor/Dropbox/Plan_Competition_Project/gui/cases/BrainMetSRSCase/PyPlanScoring.ini'
    setup_calculation_options = get_calculation_options(ini_file)

    structures = PyDicomParser(filename=rtss).GetStructures()
    rd_dcm = PyDicomParser(filename=rt_dose)
    dose = rd_dcm.get_dose_3d()
    plan_dict = {}

    # criteria file
    file_path = '/home/victor/Dropbox/Plan_Competition_Project/tests/tests_data/ptv_based_SRS/Scoring_criteria.xlsx'
    criteria = pd.read_excel(file_path, sheet_name='BrainSRS')

    # setup RT case
    rt_case_tmp = RTCase("SRS", 123, structures, criteria)
    dvh_calc = DVHCalculator(rt_case_tmp, setup_calculation_options)

    # when calculate DVH using pyplanScoring
    planning_obj = PyPlanningItem(plan_dict, rt_case_tmp, dose, dvh_calc)
    planning_obj.calculate_dvh()

    # # Calculating the score
    plan_eval = PlanEvaluation()
    plan_eval.criteria = criteria
    df = plan_eval.eval_plan(planning_obj)
    score = df['Raw score'].sum()

    # compare DVHs
    # TPS
    # dvhs = rd_dcm.GetDVHs()
Exemple #6
0
def dvh_calculator():
    rs_dvh = os.path.join(DATA_DIR, 'RS_dvh.dcm')
    structures_tmp1 = PyDicomParser(filename=rs_dvh).GetStructures()
    rt_case_tmp = RTCase("H&N", 123, structures_tmp1, criteria)
    return DVHCalculator(rt_case_tmp, calculation_options)
Exemple #7
0
def rt_case():
    """
        Return RT case object
    :return:
    """
    return RTCase("H&N", 123, structures_tmp, criteria)