def get_heatmap_from_polar_all_predictors(predictions, curve_secant, intersection_angle): # Set up the grid to sample the RBF at r_min = 2.0 r_max = 25.0 r_resolution = 100 phi_min = 0.0 phi_max = np.pi phi_resolution = 100 R = np.rot90(np.tile(np.linspace(r_min, r_max, r_resolution), (phi_resolution, 1))) Phi = np.tile(np.linspace(phi_min, phi_max, phi_resolution), (r_resolution, 1)) D = np.zeros((np.shape(Phi)[0]-1, np.shape(Phi)[1]-1)) # Set up the RBF Interpolator angle_steps = np.linspace(0., np.pi, SAMPLE_RESOLUTION) rbfPhi = [] rbfR = [] for pred in predictions: rbfPhi.extend(list(angle_steps)) rbfR.extend(list(pred)) # Scale factor to balance the coordinate influence in determination of r for rbf scale_phi = 0.5*(r_min + r_max) #1/(phi_max - phi_min) scale_r = 1#/(r_max - r_min) rbfi = RBFValley(np.array(rbfPhi)*scale_phi, np.array(rbfR)*scale_r, 0.7) # Sample the RBF for j in range(np.shape(Phi)[0]-1): for k in range(np.shape(Phi)[1]-1): D[j,k] = rbfi(scale_phi*Phi[j,k], scale_r*R[j,k]) # Transform RBF grid into XY-Space for heatmap X, Y = get_cartesian_from_polar(R, Phi, curve_secant, intersection_angle) return X, Y, D
def plot_polar_probability_heatmap(predicted_proba, curve_secant, intersection_angle): """Plot a heatmap in polar coordinates""" prediction = np.flipud(np.rot90(predicted_proba['predictions_proba'])) bin_num = np.shape(prediction)[0] max_radius = predicted_proba['max_radius'] min_radius = predicted_proba['min_radius'] bin_width = np.pi/(np.shape(prediction)[1]) R = np.rot90(np.tile(np.linspace(max_radius, min_radius, bin_num + 1), (np.shape(prediction)[1] + 1, 1))) Phi = np.tile((np.linspace(0.-bin_width/2, np.pi+bin_width/2, np.shape(prediction)[1] + 1) - bin_width/2), (bin_num + 1, 1)) X, Y = get_cartesian_from_polar(R, Phi, curve_secant, intersection_angle) # if rotation: # rot_phi, rot_c = rotation # target_shape = np.shape(X) # coords = np.transpose(np.vstack((X.ravel(), Y.ravel()))) # rot_coords = np.transpose(rotate_xy(coords, rot_phi, rot_c)) # X = np.reshape(rot_coords[0], target_shape) # Y = np.reshape(rot_coords[1], target_shape) ax = plt.gca() p = ax.pcolormesh(X, Y, prediction, cmap="Oranges") plt.gcf().colorbar(p)