def uniform_cart_to_polar(x, y, data):
''' Interpolates data uniformly sampled in cartesian coordinates to polar
coordinates.
Args:
x (`numpy.ndarray`): sorted 1D array of x sample pts.
y (`numpy.ndarray`): sorted 1D array of y sample pts.
data (`numpy.ndarray`): data sampled over the (x,y) coordinates.
Returns:
`tuple` containing:
`numpy.ndarray`: rho samples for interpolated values.
`numpy.ndarray`: phi samples for interpolated values.
`numpy.ndarray`: data uniformly sampled in (rho,phi).
Notes:
Assumes data is sampled along x = [-1,1] and y = [-1,1] over a square grid.
'''
# create a set of polar coordinates to interpolate onto
xmax = x[-1]
num_pts = len(x)
rho = np.linspace(0, xmax, num_pts / 2)
phi = np.linspace(0, 2 * pi, num_pts)
rv, pv = np.meshgrid(rho, phi)
# map points to x, y and make a grid for the original samples
xv, yv = polar_to_cart(rv, pv)
# interpolate the function onto the new points
f = interpolate.RegularGridInterpolator((x, y), data)
return rho, phi, f((xv, yv), method='linear')
评论列表
文章目录