def test_fetch_correct_backscatter_correction_from_database(): expected = 5 * [True] # Tabulated backscatter factor for param in data_norm tabulated_k_bs = [1.3, 1.458, 1.589, 1.617, 1.639] data_norm = pd.DataFrame({ 'kVp': 5 * [80], 'HVL': 5 * [7.88], 'FSL': [5, 10, 20, 25, 35] }) # create interpolation object bs_interp = calculate_k_bs(data_norm) # interpolate at tabulated filed sizes k_bs = bs_interp[0](data_norm.FSL) diff = [ 100 * (abs(k_bs[i] - tabulated_k_bs[i])) / tabulated_k_bs[i] for i in range(len(tabulated_k_bs)) ] test = [percent_difference <= 1 for percent_difference in diff] assert expected == test
def test_calculate_k_bs(): """Tests the backscatter correction. Tests if the interpolated backscatter factor lies within 1% of the tabulated value, for all tabulated field sizes at a specific kVp/HVL combination. """ expected = 5 * [True] # Tabulated backscatter factor for param in data_norm tabulated_k_bs = [1.3, 1.458, 1.589, 1.617, 1.639] data_norm = pd.DataFrame({ 'kVp': 5 * [80], 'HVL': 5 * [7.88], 'FSL': [5, 10, 20, 25, 35] }) # create interpolation object bs_interp = calculate_k_bs(data_norm) # interpolate at tabulated filed sizes k_bs = bs_interp[0](data_norm.FSL) diff = [ 100 * (abs(k_bs[i] - tabulated_k_bs[i])) / tabulated_k_bs[i] for i in range(len(tabulated_k_bs)) ] test = [percent_difference <= 1 for percent_difference in diff] assert expected == test
def calculate_dose( normalized_data: pd.DataFrame, settings: PyskindoseSettings, table: Phantom, pad: Phantom, ) -> Tuple[Phantom, Optional[Dict[str, Any]]]: """Calculate skin dose. This function initializes the skin dose calculations. Parameters ---------- normalized_data : pd.DataFrame RDSR data, normalized for compliance with PySkinDose. settings : PyskindoseSettings Settings class for PySkinDose table : Phantom Patient support table phantom pad : Phantom Patient support pad phantom Returns ------- Tuple[Phantom, Optional[Dict[str, Any]]] [description] """ if settings.mode != const.MODE_CALCULATE_DOSE: # logger.debug("Mode not set to calculate dose. Returning without doing anything") return None, None # logger.info("Start performing dose calculations") patient = Phantom( phantom_model=settings.phantom.model, phantom_dim=settings.phantom.dimension, human_mesh=settings.phantom.human_mesh, ) # position objects in starting position position_geometry( patient=patient, table=table, pad=pad, pad_thickness=settings.phantom.dimension.pad_thickness, patient_offset=[ settings.phantom.patient_offset.d_lat, settings.phantom.patient_offset.d_ver, settings.phantom.patient_offset.d_lon, ], ) normalized_data = fetch_and_append_hvl(data_norm=normalized_data) # Check which irradiation events that contains updated # geometry parameters since the previous irradiation event new_geometry = check_new_geometry(normalized_data) # fetch of k_bs interpolation object (k_bs=f(field_size))for all events back_scatter_interpolation = calculate_k_bs(data_norm=normalized_data) k_tab = calculate_k_tab( data_norm=normalized_data, estimate_k_tab=settings.estimate_k_tab, k_tab_val=settings.k_tab_val, ) total_number_of_events = len(normalized_data) output_template = { const.OUTPUT_KEY_HITS: [[]] * total_number_of_events, const.OUTPUT_KEY_KERMA: [np.array] * total_number_of_events, const.OUTPUT_KEY_CORRECTION_INVERSE_SQUARE_LAW: [[]] * total_number_of_events, const.OUTPUT_KEY_CORRECTION_BACK_SCATTER: [[]] * total_number_of_events, const.OUTPUT_KEY_CORRECTION_MEDIUM: [[]] * total_number_of_events, const.OUTPUT_KEY_CORRECTION_TABLE: [[]] * total_number_of_events, const.OUTPUT_KEY_DOSE_MAP: np.zeros(len(patient.r)), } output = calculate_irradiation_event_result( normalized_data=normalized_data, event=0, total_events=len(normalized_data), new_geometry=new_geometry, k_tab=k_tab, hits=[], patient=patient, table=table, pad=pad, back_scatter_interpolation=back_scatter_interpolation, output=output_template, ) return patient, output