def dmsp_map_interpolate_NN_smooth(X_dmsp, Y_dmsp, X_map, Y_map, Obs_map, k=5, tol=3):
    '\n    generic function to spatially interpolate with the SSJ data using nearest neighbors using some arbirtary distance tolerance\n    '
    dmsp_points = np.hstack((X_dmsp.flatten().reshape((- 1), 1), Y_dmsp.flatten().reshape((- 1), 1)))
    map_points = np.hstack((X_map.flatten().reshape((- 1), 1), Y_map.flatten().reshape((- 1), 1)))
    N_points = dmsp_points.shape[0]
    obs_val = Obs_map.flatten()
    model = sklearn.neighbors.BallTree(map_points, leaf_size=40)
    (dists, inds) = model.query(dmsp_points, k=k)
    obs_interp = np.empty(N_points)
    for i in range(N_points):
        norm = LA.norm(dists[i])
        if (norm > tol):
            obs_interp[i] = np.nan
        else:
            weights = (dists[i] / np.nansum(dists[i]))
            obs_interp[i] = np.nansum((obs_val[inds[i]] * weights))
    return obs_interp
generic function to spatially interpolate with the SSJ data using nearest neighbors using some arbirtary distance tolerance
def dmsp_map_interpolate_NN_smooth(X_dmsp, Y_dmsp, X_map, Y_map, Obs_map, k=5, tol=3):
    '\n    \n    '
    dmsp_points = np.hstack((X_dmsp.flatten().reshape((- 1), 1), Y_dmsp.flatten().reshape((- 1), 1)))
    map_points = np.hstack((X_map.flatten().reshape((- 1), 1), Y_map.flatten().reshape((- 1), 1)))
    N_points = dmsp_points.shape[0]
    obs_val = Obs_map.flatten()
    model = sklearn.neighbors.BallTree(map_points, leaf_size=40)
    (dists, inds) = model.query(dmsp_points, k=k)
    obs_interp = np.empty(N_points)
    for i in range(N_points):
        norm = LA.norm(dists[i])
        if (norm > tol):
            obs_interp[i] = np.nan
        else:
            weights = (dists[i] / np.nansum(dists[i]))
            obs_interp[i] = np.nansum((obs_val[inds[i]] * weights))
    return obs_interp