def create_transformed_mesh(width_data, length_data, factor_data): """Return factor data meshgrid.""" x = np.arange( np.floor(np.min(width_data)) - 1, np.ceil(np.max(width_data)) + 1, 0.1) y = np.arange( np.floor(np.min(length_data)) - 1, np.ceil(np.max(length_data)) + 1, 0.1) xx, yy = np.meshgrid(x, y) zz = spline_model_with_deformability( xx, convert2_ratio_perim_area(xx, yy), width_data, convert2_ratio_perim_area(width_data, length_data), factor_data, ) zz[xx > yy] = np.nan no_data_x = np.all(np.isnan(zz), axis=0) no_data_y = np.all(np.isnan(zz), axis=1) x = x[np.invert(no_data_x)] y = y[np.invert(no_data_y)] zz = zz[np.invert(no_data_y), :] zz = zz[:, np.invert(no_data_x)] return x, y, zz
def vector_is_close(vector1: Vector, vector2: Vector, delta: float = 0.1) -> bool: """Determine if two vectors are with delta of each other; this is a simple coordinate comparison check.""" for attr in ("x", "y", "z"): if np.isnan(getattr(vector1, attr)) and np.isnan(getattr( vector2, attr)): continue if (not getattr(vector2, attr) + delta >= getattr(vector1, attr) >= getattr(vector2, attr) - delta): return False return True
def create_bb_attenuation_func(diameter, penumbra, max_attenuation): dx = diameter / 100 radius = diameter / 2 image_half_width = penumbra * 2 + radius x = np.arange(-image_half_width, image_half_width + dx, dx) xx, yy = np.meshgrid(x, x) with warnings.catch_warnings(): warnings.simplefilter("ignore") z = np.sqrt(radius**2 - xx**2 - yy**2) / radius z[np.isnan(z)] = 0 sig = profiles.scaled_penumbra_sig() * penumbra sig_pixel = sig / dx filtered = scipy.ndimage.gaussian_filter(z, sig_pixel) interp = scipy.interpolate.RegularGridInterpolator((x, x), filtered, bounds_error=False, fill_value=None) def attenuation(x, y): return 1 - interp((x, y)) * max_attenuation return attenuation
def plot_gamma_hist(gamma, percent, dist): valid_gamma = gamma[~np.isnan(gamma)] plt.hist(valid_gamma, 50, density=True) pass_ratio = np.sum(valid_gamma <= 1) / len(valid_gamma) plt.title( "Local Gamma ({0}%/{1}mm) | Percent Pass: {2:.2f} % | Mean Gamma: {3:.2f} | Max Gamma: {4:.2f}" .format(percent, dist, pass_ratio * 100, np.mean(valid_gamma), np.max(valid_gamma)))
def apply_negative(column): result = np.ones_like(column).astype(np.float64) * np.nan negative_values = column.values > 2**15 result[negative_values] = column[negative_values] - 2**16 result[np.invert(negative_values)] = column[np.invert(negative_values)] if np.any(np.isnan(result)): raise Exception("Not all column values were converted") return result
def _calc_blocked_t(travel_diff, grid_resolution): blocked_t = np.ones_like(travel_diff) * np.nan fully_blocked = travel_diff <= -grid_resolution / 2 fully_open = travel_diff >= grid_resolution / 2 blocked_t[fully_blocked] = 1 blocked_t[fully_open] = 0 transient = ~fully_blocked & ~fully_open blocked_t[transient] = (-travel_diff[transient] + grid_resolution / 2) / grid_resolution assert np.all(~np.isnan(blocked_t)) return blocked_t
def absolute_scans_from_mephysto(mephysto_file, absolute_dose, depth_of_absolute_dose_mm): distance, relative_dose, scan_curvetype, scan_depth = api.load_mephysto( mephysto_file) depth_testing = scan_depth[~np.isnan(scan_depth)] depth_testing = np.unique(depth_testing) if depth_of_absolute_dose_mm == "dmax": choose_mephysto = scan_curvetype == "PDD" mephysto_pdd_depth = distance[choose_mephysto][0] mephysto_dose = relative_dose[choose_mephysto][0] depth_of_absolute_dose_mm = mephysto_pdd_depth[np.argmax( mephysto_dose)] mephysto_pdd_depth, mephysto_pdd_dose = mephysto_absolute_depth_dose( absolute_dose, depth_of_absolute_dose_mm, distance, relative_dose, scan_curvetype, ) scans = { "depth_dose": { "displacement": mephysto_pdd_depth, "dose": mephysto_pdd_dose }, "profiles": {}, } for depth_test in depth_testing: ( mephysto_distance_inplane, mephysto_normalised_dose_inplane, ) = mephysto_absolute_profiles( "INPLANE_PROFILE", depth_test, distance, relative_dose, scan_curvetype, scan_depth, mephysto_pdd_depth, mephysto_pdd_dose, ) ( mephysto_distance_crossplane, mephysto_normalised_dose_crossplane, ) = mephysto_absolute_profiles( "CROSSPLANE_PROFILE", depth_test, distance, relative_dose, scan_curvetype, scan_depth, mephysto_pdd_depth, mephysto_pdd_dose, ) scans["profiles"][depth_test] = { "inplane": { "displacement": mephysto_distance_inplane, "dose": mephysto_normalised_dose_inplane, }, "crossplane": { "displacement": mephysto_distance_crossplane, "dose": mephysto_normalised_dose_crossplane, }, } return scans
def calculate_pass_rate(gamma_array): valid_gamma = gamma_array[np.invert(np.isnan(gamma_array))] percent_pass = 100 * np.sum(valid_gamma < 1) / len(valid_gamma) return percent_pass