def test_barnes_point(test_data): r"""Test Barnes 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([60, 60], r=r) dists = dist_2(60, 60, xp[indices], yp[indices]) values = z[indices] assert_almost_equal(barnes_point(dists, values, 5762.7), 4.0871824)
def test_barnes_point(test_data): r"""Test Barnes 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([60, 60], r=r) dists = dist_2(60, 60, xp[indices], yp[indices]) values = z[indices] truth = 4.08718241061 ave_spacing = np.mean((cdist(list(zip(xp, yp)), list(zip(xp, yp))))) kappa = calc_kappa(ave_spacing) value = barnes_point(dists, values, kappa) assert_almost_equal(truth, value)
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. fig, ax = plt.subplots(1, 1, figsize=(15, 10)) for i, zval in enumerate(zp): ax.plot(pts[i, 0], pts[i, 1], '.') ax.annotate(str(zval) + ' F', xy=(pts[i, 0] + 2, pts[i, 1])) ax.plot(sim_gridx, sim_gridy, '+', markersize=10) ax.plot(x1, y1, 'ko', fillstyle='none', markersize=10, label='grid 0 matches') ax.plot(x2, y2, 'ks', fillstyle='none', markersize=10, label='grid 1 matches') draw_circle(ax, sim_gridx[0],
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) ########################################### # Plot all of the affiliated information and interpolation values. fig, ax = plt.subplots(1, 1, figsize=(15, 10)) for i, zval in enumerate(zp): ax.plot(pts[i, 0], pts[i, 1], '.') ax.annotate(str(zval) + ' F', xy=(pts[i, 0] + 2, pts[i, 1])) ax.plot(sim_gridx, sim_gridy, '+', markersize=10) ax.plot(x1, y1, 'ko', fillstyle='none', markersize=10, label='grid 0 matches') ax.plot(x2, y2, 'ks', fillstyle='none', markersize=10, label='grid 1 matches') draw_circle(ax, sim_gridx[0], sim_gridy[0], m='k-', r=radius, label='grid 0 radius') draw_circle(ax, sim_gridx[1], sim_gridy[1], m='b-', r=radius, label='grid 1 radius')