当前位置: 首页>>代码示例>>Python>>正文


Python ndimage.map_coordinates方法代码示例

本文整理汇总了Python中scipy.ndimage.map_coordinates方法的典型用法代码示例。如果您正苦于以下问题:Python ndimage.map_coordinates方法的具体用法?Python ndimage.map_coordinates怎么用?Python ndimage.map_coordinates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.ndimage的用法示例。


在下文中一共展示了ndimage.map_coordinates方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: query

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import map_coordinates [as 别名]
def query(self, coords, order=1):
        """
        Returns the map value at the specified location(s) on the sky.

        Args:
            coords (`astropy.coordinates.SkyCoord`): The coordinates to query.
            order (Optional[int]): Interpolation order to use. Defaults to `1`,
                for linear interpolation.

        Returns:
            A float array containing the map value at every input coordinate.
            The shape of the output will be the same as the shape of the
            coordinates stored by `coords`.
        """
        out = np.full(len(coords.l.deg), np.nan, dtype='f4')

        for pole in self.poles:
            m = (coords.b.deg >= 0) if pole == 'ngp' else (coords.b.deg < 0)

            if np.any(m):
                data, w = self._data[pole]
                x, y = w.wcs_world2pix(coords.l.deg[m], coords.b.deg[m], 0)
                out[m] = map_coordinates(data, [y, x], order=order, mode='nearest')

        return out 
开发者ID:gregreen,项目名称:dustmaps,代码行数:27,代码来源:sfd.py

示例2: bicubic_interpolation

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import map_coordinates [as 别名]
def bicubic_interpolation(LR, HR_shape):

    LR_padded = np.zeros((LR.shape[0]+1,LR.shape[1]+1,LR.shape[2]+1))
    LR_padded[:-1,:-1,:-1] = LR[:,:,:]
    LR_padded[-1,:-1,:-1] = LR[0,:,:]
    LR_padded[:-1,-1,:-1] = LR[:,0,:]
    LR_padded[:-1,:-1,-1] = LR[:,:,0]
    LR_padded[:-1,-1,-1] = LR[:,0,0]
    LR_padded[-1,:-1,-1] = LR[0,:,0]
    LR_padded[-1,-1,:-1] = LR[0,0,:]
    LR_padded[-1,-1,-1] = LR[0,0,0]
    
    x_HR = np.linspace(0, LR.shape[0], num=HR_shape[0]+1)[:-1]
    y_HR = np.linspace(0, LR.shape[1], num=HR_shape[1]+1)[:-1]
    z_HR = np.linspace(0, LR.shape[2], num=HR_shape[2]+1)[:-1]
    
    xx, yy, zz = np.meshgrid(x_HR, y_HR, z_HR, indexing='ij')
    
    xx = xx.reshape((-1))
    yy = yy.reshape((-1))
    zz = zz.reshape((-1))
    out_BC = ndimage.map_coordinates(LR_padded, [xx, yy, zz], order=3, mode='wrap').reshape(HR_shape)
    
    return out_BC 
开发者ID:akshaysubr,项目名称:TEGAN,代码行数:26,代码来源:plot_generator_outputs.py

示例3: test_map_coordinates03

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import map_coordinates [as 别名]
def test_map_coordinates03(self):
        data = numpy.array([[4, 1, 3, 2],
                               [7, 6, 8, 5],
                               [3, 5, 3, 6]], order='F')
        idx = numpy.indices(data.shape) - 1
        out = ndimage.map_coordinates(data, idx)
        assert_array_almost_equal(out, [[0, 0, 0, 0],
                                   [0, 4, 1, 3],
                                   [0, 7, 6, 8]])
        assert_array_almost_equal(out, ndimage.shift(data, (1, 1)))
        idx = numpy.indices(data[::2].shape) - 1
        out = ndimage.map_coordinates(data[::2], idx)
        assert_array_almost_equal(out, [[0, 0, 0, 0],
                                   [0, 4, 1, 3]])
        assert_array_almost_equal(out, ndimage.shift(data[::2], (1, 1)))
        idx = numpy.indices(data[:,::2].shape) - 1
        out = ndimage.map_coordinates(data[:,::2], idx)
        assert_array_almost_equal(out, [[0, 0], [0, 4], [0, 7]])
        assert_array_almost_equal(out, ndimage.shift(data[:,::2], (1, 1))) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:21,代码来源:test_ndimage.py

示例4: test_uint64_max

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import map_coordinates [as 别名]
def test_uint64_max():
    # Test interpolation respects uint64 max.  Reported to fail at least on
    # win32 (due to the 32 bit visual C compiler using signed int64 when
    # converting between uint64 to double) and Debian on s390x.
    # Interpolation is always done in double precision floating point, so we
    # use the largest uint64 value for which int(float(big)) still fits in
    # a uint64.
    big = 2**64-1025
    arr = np.array([big, big, big], dtype=np.uint64)
    # Tests geometric transform (map_coordinates, affine_transform)
    inds = np.indices(arr.shape) - 0.1
    x = ndimage.map_coordinates(arr, inds)
    assert_equal(x[1], int(float(big)))
    assert_equal(x[2], int(float(big)))
    # Tests zoom / shift
    x = ndimage.shift(arr, 0.1)
    assert_equal(x[1], int(float(big)))
    assert_equal(x[2], int(float(big))) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:20,代码来源:test_datatypes.py

示例5: test_map_coordinates03

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import map_coordinates [as 别名]
def test_map_coordinates03(self):
        data = numpy.array([[4, 1, 3, 2],
                            [7, 6, 8, 5],
                            [3, 5, 3, 6]], order='F')
        idx = numpy.indices(data.shape) - 1
        out = ndimage.map_coordinates(data, idx)
        assert_array_almost_equal(out, [[0, 0, 0, 0],
                                        [0, 4, 1, 3],
                                        [0, 7, 6, 8]])
        assert_array_almost_equal(out, ndimage.shift(data, (1, 1)))
        idx = numpy.indices(data[::2].shape) - 1
        out = ndimage.map_coordinates(data[::2], idx)
        assert_array_almost_equal(out, [[0, 0, 0, 0],
                                        [0, 4, 1, 3]])
        assert_array_almost_equal(out, ndimage.shift(data[::2], (1, 1)))
        idx = numpy.indices(data[:, ::2].shape) - 1
        out = ndimage.map_coordinates(data[:, ::2], idx)
        assert_array_almost_equal(out, [[0, 0], [0, 4], [0, 7]])
        assert_array_almost_equal(out, ndimage.shift(data[:, ::2], (1, 1))) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:21,代码来源:test_ndimage.py

示例6: __call__

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import map_coordinates [as 别名]
def __call__(self, img, steps=2):
        n, m = np.shape(img)
        def_imgs = []


        xn, yn = np.meshgrid(np.arange(m), np.arange(n))
        xn_mapped, yn_mapped = xn, yn

        for i in range(steps):
            if i == 0:
                Ic = img
            else:
                if self.multiplicative:
                    xn_mapped, yn_mapped = self.coodinate_mapper(xn_mapped, yn_mapped)
                else:
                    xn_mapped, yn_mapped = self.coodinate_mapper(xn, yn,frame=i)

                Ic = nd.map_coordinates(img, np.array([yn_mapped, xn_mapped]), order=self.order, cval=0)

            def_imgs.append(Ic)

        return def_imgs 
开发者ID:PolymerGuy,项目名称:muDIC,代码行数:24,代码来源:image_deformer.py

示例7: resample_inplace

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import map_coordinates [as 别名]
def resample_inplace(self, nbins):
        """
        Change the shape of the histogram using an n-dimensional
        interpolation function (via `ndimage.map_coordinates`).

        Parameters
        ----------
        nbins: tuple of int
            a tuple of the new number of bins to resample_inplace
            this histogram over (e.g. if the original histogram was
            (100,100), setting bins to (200,200) would provide double
            the resolution, with the interviening bins interpolated.
        """

        oldbins = self._nbins
        # iold = np.indices(oldbins)
        inew = np.indices(nbins)

        coords = np.array(
            [inew[X] * (oldbins[X]) / float(nbins[X]) for X in range(len(nbins))]
        )

        self._nbins = nbins
        self.data = ndimage.map_coordinates(self.data, coords)
        self._bin_lower_edges = None  # need to be recalculated 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:27,代码来源:fitshistogram.py

示例8: interpolate_slice

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import map_coordinates [as 别名]
def interpolate_slice(f3d, rot, pfac=2, size=None):
    nhalf = f3d.shape[0] / 2
    if size is None:
        phalf = nhalf
    else:
        phalf = size / 2
    qot = rot * pfac  # Scaling!
    px, py, pz = np.meshgrid(np.arange(-phalf, phalf), np.arange(-phalf, phalf), 0)
    pr = np.sqrt(px ** 2 + py ** 2 + pz ** 2)
    pcoords = np.vstack([px.reshape(-1), py.reshape(-1), pz.reshape(-1)])
    mcoords = qot.T.dot(pcoords)
    mcoords = mcoords[:, pr.reshape(-1) < nhalf]
    pvals = map_coordinates(np.real(f3d), mcoords, order=1, mode="wrap") + \
             1j * map_coordinates(np.imag(f3d), mcoords, order=1, mode="wrap")
    pslice = np.zeros(pr.shape, dtype=np.complex)
    pslice[pr < nhalf] = pvals
    return pslice 
开发者ID:asarnow,项目名称:pyem,代码行数:19,代码来源:vop.py

示例9: sample_equirec

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import map_coordinates [as 别名]
def sample_equirec(e_img, coor_xy, order):
    w = e_img.shape[1]
    coor_x, coor_y = np.split(coor_xy, 2, axis=-1)
    pad_u = np.roll(e_img[[0]], w // 2, 1)
    pad_d = np.roll(e_img[[-1]], w // 2, 1)
    e_img = np.concatenate([e_img, pad_d, pad_u], 0)
    return map_coordinates(e_img, [coor_y, coor_x],
                           order=order, mode='wrap')[..., 0] 
开发者ID:sunset1995,项目名称:py360convert,代码行数:10,代码来源:utils.py

示例10: sample_cubefaces

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import map_coordinates [as 别名]
def sample_cubefaces(cube_faces, tp, coor_y, coor_x, order):
    cube_faces = cube_faces.copy()
    cube_faces[1] = np.flip(cube_faces[1], 1)
    cube_faces[2] = np.flip(cube_faces[2], 1)
    cube_faces[4] = np.flip(cube_faces[4], 0)

    # Pad up down
    pad_ud = np.zeros((6, 2, cube_faces.shape[2]))
    pad_ud[0, 0] = cube_faces[5, 0, :]
    pad_ud[0, 1] = cube_faces[4, -1, :]
    pad_ud[1, 0] = cube_faces[5, :, -1]
    pad_ud[1, 1] = cube_faces[4, ::-1, -1]
    pad_ud[2, 0] = cube_faces[5, -1, ::-1]
    pad_ud[2, 1] = cube_faces[4, 0, ::-1]
    pad_ud[3, 0] = cube_faces[5, ::-1, 0]
    pad_ud[3, 1] = cube_faces[4, :, 0]
    pad_ud[4, 0] = cube_faces[0, 0, :]
    pad_ud[4, 1] = cube_faces[2, 0, ::-1]
    pad_ud[5, 0] = cube_faces[2, -1, ::-1]
    pad_ud[5, 1] = cube_faces[0, -1, :]
    cube_faces = np.concatenate([cube_faces, pad_ud], 1)

    # Pad left right
    pad_lr = np.zeros((6, cube_faces.shape[1], 2))
    pad_lr[0, :, 0] = cube_faces[1, :, 0]
    pad_lr[0, :, 1] = cube_faces[3, :, -1]
    pad_lr[1, :, 0] = cube_faces[2, :, 0]
    pad_lr[1, :, 1] = cube_faces[0, :, -1]
    pad_lr[2, :, 0] = cube_faces[3, :, 0]
    pad_lr[2, :, 1] = cube_faces[1, :, -1]
    pad_lr[3, :, 0] = cube_faces[0, :, 0]
    pad_lr[3, :, 1] = cube_faces[2, :, -1]
    pad_lr[4, 1:-1, 0] = cube_faces[1, 0, ::-1]
    pad_lr[4, 1:-1, 1] = cube_faces[3, 0, :]
    pad_lr[5, 1:-1, 0] = cube_faces[1, -2, :]
    pad_lr[5, 1:-1, 1] = cube_faces[3, -2, ::-1]
    cube_faces = np.concatenate([cube_faces, pad_lr], 2)

    return map_coordinates(cube_faces, [tp, coor_y, coor_x], order=order, mode='wrap') 
开发者ID:sunset1995,项目名称:py360convert,代码行数:41,代码来源:utils.py

示例11: fuv2img

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import map_coordinates [as 别名]
def fuv2img(fuv, coorW=1024, floorW=1024, floorH=512):
    '''
    Project 1d signal in uv space to 2d floor plane image
    '''
    floor_plane_x, floor_plane_y = np.meshgrid(range(floorW), range(floorH))
    floor_plane_x, floor_plane_y = -(floor_plane_y - floorH / 2), floor_plane_x - floorW / 2
    floor_plane_coridx = (np.arctan2(floor_plane_y, floor_plane_x) / (2 * PI) + 0.5) * coorW - 0.5
    floor_plane = map_coordinates(fuv, floor_plane_coridx.reshape(1, -1), order=1, mode='wrap')
    floor_plane = floor_plane.reshape(floorH, floorW)
    return floor_plane 
开发者ID:sunset1995,项目名称:HorizonNet,代码行数:12,代码来源:post_proc.py

示例12: make_comparison_plots

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import map_coordinates [as 别名]
def make_comparison_plots(LR, HR, out, output_label='Generated output'):

    vmin = HR.min()
    vmax = HR.max()

    LR_padded = np.zeros((LR.shape[0]+1,LR.shape[1]+1))
    LR_padded[:-1,:-1] = LR[:,:]
    LR_padded[-1,:-1] = LR[0,:]
    LR_padded[:-1,-1] = LR[:,0]
    LR_padded[-1,-1] = LR[0,0]

    x_HR = np.linspace(0, LR.shape[0], num=HR.shape[0]+1)[:-1]
    y_HR = np.linspace(0, LR.shape[1], num=HR.shape[1]+1)[:-1]
    print(x_HR)

    yy, xx = np.meshgrid(y_HR, x_HR)
    xx = xx.reshape((-1))
    yy = yy.reshape((-1))
    out_BC = ndimage.map_coordinates(LR_padded, [xx, yy], order=3, mode='wrap').reshape(HR.shape)

    fig, (ax1, ax2, ax3, ax4) = plt.subplots(1, 4, sharey=True, figsize=(17,5))

    im1 = plot(LR,  ax1, vmin=vmin, vmax=vmax)
    ax1.set_title('Low resolution')

    im2 = plot(out_BC,  ax2, vmin=vmin, vmax=vmax)
    ax2.set_title('Bicubic')

    im3 = plot(out,  ax3, vmin=vmin, vmax=vmax)
    ax3.set_title(output_label)

    im4 = plot(HR, ax4, vmin=vmin, vmax=vmax)
    ax4.set_title('High resolution')

    fig.tight_layout()
    
    return fig, (ax1, ax2, ax3, ax4) 
开发者ID:akshaysubr,项目名称:TEGAN,代码行数:39,代码来源:plot_generator_outputs.py

示例13: __init__

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import map_coordinates [as 别名]
def __init__(self, skeleton_image, *, spacing=1, source_image=None,
                 _buffer_size_offset=None, keep_images=True, 
                 unique_junctions=True):
        graph, coords, degrees = skeleton_to_csgraph(skeleton_image,
                                                     spacing=spacing,
                                                     unique_junctions=unique_junctions)
        if np.issubdtype(skeleton_image.dtype, np.float_):
            pixel_values = ndi.map_coordinates(skeleton_image, coords.T,
                                               order=3)
        else:
            pixel_values = None
        self.graph = graph
        self.nbgraph = csr_to_nbgraph(graph, pixel_values)
        self.coordinates = coords
        self.paths = _build_skeleton_path_graph(self.nbgraph,
                                    _buffer_size_offset=_buffer_size_offset)
        self.n_paths = self.paths.shape[0]
        self.distances = np.empty(self.n_paths, dtype=float)
        self._distances_initialized = False
        self.skeleton_image = None
        self.source_image = None
        self.degrees_image = degrees
        self.degrees = np.diff(self.graph.indptr)
        self.spacing = (np.asarray(spacing) if not np.isscalar(spacing)
                        else np.full(skeleton_image.ndim, spacing))
        if keep_images:
            self.skeleton_image = skeleton_image
            self.source_image = source_image 
开发者ID:jni,项目名称:skan,代码行数:30,代码来源:csr.py

示例14: distort_with_noise

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import map_coordinates [as 别名]
def distort_with_noise(image, deltas, order=1):
    assert deltas.shape[0] == 2
    assert image.shape == deltas.shape[1:], (image.shape, deltas.shape)
    n, m = image.shape
    xy = np.transpose(np.array(np.meshgrid(
        range(n), range(m))), axes=[0, 2, 1])
    deltas += xy
    return ndi.map_coordinates(image, deltas, order=order, mode="reflect") 
开发者ID:Calamari-OCR,项目名称:calamari,代码行数:10,代码来源:degrade.py

示例15: el_field

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import map_coordinates [as 别名]
def el_field(self, X, Q, gamma, nxyz):
        N = X.shape[0]
        X[:, 2] = X[:, 2] * gamma
        XX = np.max(X, axis=0) - np.min(X, axis=0)
        if self.random_mesh:
            XX = XX * np.random.uniform(low=1, high=1.1)
        logger.debug('mesh steps:' + str(XX))
        # here we use a fast 3D "near-point" interpolation
        # we need a stand-alone module with 1D,2D,3D parricles-to-grid functions
        steps = XX / (nxyz - 3)
        X = X / steps
        X_min = np.min(X, axis=0)
        X_mid = np.dot(Q, X) / np.sum(Q)
        X_off = np.floor(X_min - X_mid) + X_mid
        if self.random_mesh:
            X_off = X_off + np.random.uniform(low=-0.5, high=0.5)
        X = X - X_off
        nx = nxyz[0]
        ny = nxyz[1]
        nz = nxyz[2]
        nzny = nz * ny
        Xi = np.int_(np.floor(X) + 1)
        inds = np.int_(Xi[:, 0] * nzny + Xi[:, 1] * nz + Xi[:, 2])  # 3d -> 1d
        q = np.bincount(inds, Q, nzny * nx).reshape(nxyz)
        p = self.potential(q, steps)
        Ex = np.zeros(p.shape)
        Ey = np.zeros(p.shape)
        Ez = np.zeros(p.shape)
        Ex[:nx - 1, :, :] = (p[:nx - 1, :, :] - p[1:nx, :, :]) / steps[0]
        Ey[:, :ny - 1, :] = (p[:, :ny - 1, :] - p[:, 1:ny, :]) / steps[1]
        Ez[:, :, :nz - 1] = (p[:, :, :nz - 1] - p[:, :, 1:nz]) / steps[2]
        Exyz = np.zeros((N, 3))
        Exyz[:, 0] = ndimage.map_coordinates(Ex, np.c_[X[:, 0], X[:, 1] + 0.5, X[:, 2] + 0.5].T, order=1) * gamma
        Exyz[:, 1] = ndimage.map_coordinates(Ey, np.c_[X[:, 0] + 0.5, X[:, 1], X[:, 2] + 0.5].T, order=1) * gamma
        Exyz[:, 2] = ndimage.map_coordinates(Ez, np.c_[X[:, 0] + 0.5, X[:, 1] + 0.5, X[:, 2]].T, order=1)
        return Exyz 
开发者ID:ocelot-collab,项目名称:ocelot,代码行数:38,代码来源:sc.py


注:本文中的scipy.ndimage.map_coordinates方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。