def test_cressman_point(test_data): r"""Test Cressman interpolation for a point function.""" xp, yp, z = test_data r = 40 obs_tree = cKDTree(list(zip(xp, yp))) indices = obs_tree.query_ball_point([30, 30], r=r) dists = dist_2(30, 30, xp[indices], yp[indices]) values = z[indices] truth = 1.05499444404 value = cressman_point(dists, values, r) assert_almost_equal(truth, value)
# # The variable ``indices`` represents the index of each matched coordinate within the # cKDTree's ``data`` list. grid_points = np.array(list(zip(sim_gridx, sim_gridy))) radius = 40 obs_tree = cKDTree(list(zip(xp, yp))) indices = obs_tree.query_ball_point(grid_points, r=radius) ########################################### # For grid 0, we will use Cressman to interpolate its value. x1, y1 = obs_tree.data[indices[0]].T cress_dist = dist_2(sim_gridx[0], sim_gridy[0], x1, y1) cress_obs = zp[indices[0]] cress_val = cressman_point(cress_dist, cress_obs, radius) ########################################### # For grid 1, we will use barnes to interpolate its value. # # We need to calculate kappa--the average distance between observations over the domain. x2, y2 = obs_tree.data[indices[1]].T barnes_dist = dist_2(sim_gridx[1], sim_gridy[1], x2, y2) barnes_obs = zp[indices[1]] kappa = calc_kappa(average_spacing(list(zip(xp, yp)))) barnes_val = barnes_point(barnes_dist, barnes_obs, kappa) ########################################### # Plot all of the affiliated information and interpolation values.
# # The variable ``indices`` represents the index of each matched coordinate within the # cKDTree's ``data`` list. grid_points = np.array(list(zip(sim_gridx, sim_gridy))) radius = 40 obs_tree = cKDTree(list(zip(xp, yp))) indices = obs_tree.query_ball_point(grid_points, r=radius) ########################################### # For grid 0, we will use Cressman to interpolate its value. x1, y1 = obs_tree.data[indices[0]].T cress_dist = dist_2(sim_gridx[0], sim_gridy[0], x1, y1) cress_obs = zp[indices[0]] cress_val = cressman_point(cress_dist, cress_obs, radius) ########################################### # For grid 1, we will use barnes to interpolate its value. # # We need to calculate kappa--the average distance between observations over the domain. x2, y2 = obs_tree.data[indices[1]].T barnes_dist = dist_2(sim_gridx[1], sim_gridy[1], x2, y2) barnes_obs = zp[indices[1]] ave_spacing = np.mean((cdist(list(zip(xp, yp)), list(zip(xp, yp))))) kappa = calc_kappa(ave_spacing) barnes_val = barnes_point(barnes_dist, barnes_obs, kappa) ###########################################