def get_machine_centre_map(): config = st_config.get_config() machine_centre_map = {} for site in config["site"]: for linac in site["linac"]: machine_centre_map[linac["name"]] = site["name"] return machine_centre_map
def get_mosaiq_details(): config = st_config.get_config() mosaiq_details = { site["name"]: { "timezone": site["mosaiq"]["timezone"], "server": f'{site["mosaiq"]["hostname"]}:{site["mosaiq"]["port"]}', } for site in config["site"] } return mosaiq_details
def get_icom_live_stream_directories(): config = st_config.get_config() icom_live_stream_directories = {} for site in config["site"]: icom_live_base_directory = pathlib.Path( site["export-directories"]["icom_live"]) for linac in site["linac"]: icom_live_stream_directories[linac["name"]] = str( icom_live_base_directory.joinpath(linac["ip"])) return icom_live_stream_directories
def get_logfile_root_dir(): config = st_config.get_config() logfile_root_dir = pathlib.Path(config["trf_logfiles"]["root_directory"]) return logfile_root_dir
def get_default_gamma_options(): config = st_config.get_config() default_gamma_options = config["gamma"] return default_gamma_options
def get_default_icom_directories(): config = st_config.get_config() default_icom_directory = config["icom"]["patient_directories"] return default_icom_directory
def main(): st.write(""" # MU Density comparison tool Tool to compare the MU Density between planned and delivery. """) config = st_config.get_config() st.sidebar.markdown(""" # MU Density Overview """) st.sidebar.markdown(""" ## Reference """) set_reference_overview = sidebar_overview() st.sidebar.markdown(""" ## Evaluation """) set_evaluation_overview = sidebar_overview() overview_updater_map = { "reference": set_reference_overview, "evaluation": set_evaluation_overview, } st.sidebar.markdown(""" # Status indicators """) show_status_indicators() st.sidebar.markdown(""" # Advanced options Enable advanced functionality by ticking the below. """) advanced_mode = st.sidebar.checkbox("Run in Advanced Mode") gamma_options = _config.get_gamma_options(advanced_mode) data_option_functions = { "monaco": _monaco.monaco_input_method, "dicom": _dicom.dicom_input_method, "icom": _icom.icom_input_method, "trf": _trf.trf_input_method, "mosaiq": _mosaiq.mosaiq_input_method, } default_reference_id = config["data_methods"]["default_reference"] default_evaluation_id = config["data_methods"]["default_evaluation"] available_data_methods = config["data_methods"]["available"] default_reference = DATA_OPTION_LABELS[default_reference_id] default_evaluation = DATA_OPTION_LABELS[default_evaluation_id] data_method_map = {} for method in available_data_methods: data_method_map[ DATA_OPTION_LABELS[method]] = data_option_functions[method] st.write(""" ## Selection of data to compare """) st.write(""" ### Reference """) reference_results = get_input_data_ui( overview_updater_map, data_method_map, default_reference, "reference", advanced_mode, ) st.write(""" ### Evaluation """) evaluation_results = get_input_data_ui( overview_updater_map, data_method_map, default_evaluation, "evaluation", advanced_mode, **reference_results, ) st.write(""" ## Output Locations """) st.write(""" ### eSCAN Directory The location to save the produced pdf report. """) default_site = evaluation_results.get("site", None) if default_site is None: default_site = reference_results.get("site", None) _, escan_directory = st_misc.get_site_and_directory( "eScan Site", "escan", default=default_site, key="escan_export_site_picker") escan_directory = pathlib.Path( os.path.expanduser(escan_directory)).resolve() if advanced_mode: st.write(escan_directory) default_png_output_directory = config["output"]["png_directory"] if advanced_mode: st.write(""" ### Image record Path to save the image of the results for posterity """) png_output_directory = pathlib.Path( st.text_input("png output directory", default_png_output_directory)) st.write(png_output_directory.resolve()) else: png_output_directory = pathlib.Path(default_png_output_directory) png_output_directory = pathlib.Path( os.path.expanduser(png_output_directory)).resolve() st.write(""" ## Calculation """) if st.button("Run Calculation"): st.write(""" ### MU Density usage warning """) st.warning(pymedphys.mudensity.WARNING_MESSAGE) st.write(""" ### Calculation status """) run_calculation( reference_results, evaluation_results, gamma_options, escan_directory, png_output_directory, ) if advanced_mode: advanced_debugging()
def advanced_debugging(): config = st_config.get_config() st.sidebar.markdown("# Advanced Debugging") if st.sidebar.button("Compare Baseline to Output Directory"): st.write(""" ## Comparing Results to Baseline """) baseline_directory = pathlib.Path( config["debug"]["baseline_directory"]).resolve() png_baseline_directory = baseline_directory.joinpath("png") baseline_png_paths = [ path for path in (png_baseline_directory.rglob("*")) if path.is_file() ] relative_png_paths = [ path.relative_to(png_baseline_directory) for path in baseline_png_paths ] output_dir = pathlib.Path(config["output"]["png_directory"]).resolve() evaluation_png_paths = [ output_dir.joinpath(path) for path in relative_png_paths ] for baseline, evaluation in zip(baseline_png_paths, evaluation_png_paths): st.write(f"### {baseline.parent.name}/{baseline.name}") st.write(f"`{baseline}`\n\n**vs**\n\n`{evaluation}`") baseline_image = imageio.imread(baseline) try: evaluation_image = imageio.imread(evaluation) except FileNotFoundError as e: st.write(""" #### File was not found """) st.write(e) st.write(f""" For debugging purposes, here are all the files that were found within {str(output_dir)} """) st.write([ str(path) for path in output_dir.rglob("*") if path.is_file() ]) return agree = np.allclose(baseline_image, evaluation_image) st.write(f"Images Agree: `{agree}`")