from pymedphys.dicom import get_gantry_angles_from_dicom input_directory = 'input' output_directory = 'output' grid_resolution = 5 / 3 gantry_angle_tolerance = 3 image_dpi = 254 trf_filepaths = glob(os.path.join(input_directory, '*.trf')) dicom_filepaths = glob(os.path.join(input_directory, '*.dcm')) filepath_mu_density_map: Dict[str, np.ndarray] = {} filepath_mu_density_diff_map: Dict[str, np.ndarray] = {} for trf_filepath in trf_filepaths: trf_delivery: Delivery = Delivery.from_logfile(trf_filepath).filter_cps() trf_filename = os.path.basename(trf_filepath) for dicom_filepath in dicom_filepaths: dicom_dataset = pydicom.dcmread(dicom_filepath, force=True, stop_before_pixels=True) try: dicom_deliveries = Delivery.load_all_fractions(dicom_dataset) except AttributeError: print("{} does not appear to be an RT DICOM plan, " "skipping...".format(dicom_filepath)) continue for fraction_number, dicom_delivery_raw in dicom_deliveries.items(): dicom_delivery = dicom_delivery_raw.filter_cps()
from pymedphys import Delivery input_directory = "input" output_directory = "output" trf_filepaths = glob(os.path.join(input_directory, "*.trf")) dicom_filepaths = glob(os.path.join(input_directory, "*.dcm")) for filepath in trf_filepaths: print("Preparing to convert {}".format(filepath)) filename = os.path.basename(filepath) output_filepath = os.path.join(output_directory, "{}.dcm".format(filename)) print("Loading log file") delivery_data = Delivery.from_logfile(filepath) print("Converting log file to RT Plan DICOM") for dicom_filepath in dicom_filepaths: dicom_template = pydicom.dcmread(dicom_filepath, force=True) try: created_dicom = delivery_data.to_dicom(dicom_template) print("{} appears to be an RT DICOM plan with appropriate " "angle meterset combination, using this one.".format( dicom_filepath)) continue except AttributeError: print("{} does not appear to be an RT DICOM plan, " "skipping...".format(dicom_filepath)) print("Saving newly created RT Plan DICOM")
def logfile_delivery_data(): path = get_file_in_dir(DIR_TO_TEST, "imrt.trf") return Delivery.from_logfile(path)
def logfile_delivery_data(): return Delivery.from_logfile(LOGFILE_FILEPATH)
import pymedphys from pymedphys import Delivery # trf file read trf_file = 'C:/GitFolder/VMAT-QA-metrics/MU intensity/MonacoHDMLC.trf' delivery = Delivery.from_logfile(trf_file) trf_mu_density = delivery.mudensity() # This is the "fluence" grid = pymedphys.mudensity.grid() pymedphys.mudensity.display(grid, trf_mu_density) # plot the MU density # dicom file read # dicom_rtplan_filepath = 'C:/GitFolder/VMAT-QA-metrics/example/test_case/VMAT1Arc/0028_VMAT202003181arc.dcm' # fraction_number = 28 # delivery = Delivery.from_dicom_file(dicom_rtplan_filepath, fraction_number) # dcm_mudensity = delivery.mudensity() # This is the "fluence" # plot the comparison # subplot(1,2,1) # plt.imshow(trf_mu_density) # plt.title('TRF file (Elekta Log file)') # subplot(1,2,2) # plt.imshow(dcm_mudensity) # plt.title('DCM file (Monaco Plan file)') # plt.colorbar() # plt.show()