coordinates.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:prysm 作者: brandondube 项目源码 文件源码
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')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号