How to use the sigpy.util.resize function in sigpy

To help you get started, we’ve selected a few sigpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mikgroup / sigpy / sigpy / nufft.py View on Github external
output = interp.gridding(input, os_shape, width, table, coord)

        for a in range(-ndim, 0):
            i = oshape[a]
            os_i = os_shape[a]
            idx = xp.arange(i, dtype=input.dtype)
            os_shape[a] = i

            # Swap axes
            output = output.swapaxes(a, -1)
            os_shape[a], os_shape[-1] = os_shape[-1], os_shape[a]

            # Oversampled IFFT
            output = fft.ifft(output, axes=[-1], norm=None)
            output *= os_i / i**0.5
            output = util.resize(output, os_shape)

            # Calculate apodization
            apod = (beta**2 - (np.pi * width * (idx - i // 2) / os_i)**2)**0.5
            apod /= xp.sinh(apod)

            # Apodize
            output *= apod

            # Swap back
            output = output.swapaxes(a, -1)
            os_shape[a], os_shape[-1] = os_shape[-1], os_shape[a]

        return output
github mikgroup / sigpy / tests / test_util.py View on Github external
npt.assert_allclose(y, [0, 1, 2, 3])

        x = np.array([1, 2])
        oshape = [5]
        y = util.resize(x, oshape)
        npt.assert_allclose(y, [0, 1, 2, 0, 0])

        x = np.array([1, 2])
        oshape = [4]
        y = util.resize(x, oshape)
        npt.assert_allclose(y, [0, 1, 2, 0])

        # Zero-pad non centered
        x = np.array([1, 2, 3])
        oshape = [5]
        y = util.resize(x, oshape, oshift=[0])
        npt.assert_allclose(y, [1, 2, 3, 0, 0])

        # Crop
        x = np.array([0, 1, 2, 3, 0])
        oshape = [3]
        y = util.resize(x, oshape)
        npt.assert_allclose(y, [1, 2, 3])

        x = np.array([0, 1, 2, 3])
        oshape = [3]
        y = util.resize(x, oshape)
        npt.assert_allclose(y, [1, 2, 3])

        x = np.array([0, 1, 2, 0, 0])
        oshape = [2]
        y = util.resize(x, oshape)
github mikgroup / sigpy / tests / test_util.py View on Github external
npt.assert_allclose(y, [1, 2, 3])

        x = np.array([0, 1, 2, 0, 0])
        oshape = [2]
        y = util.resize(x, oshape)
        npt.assert_allclose(y, [1, 2])

        x = np.array([0, 1, 2, 0])
        oshape = [2]
        y = util.resize(x, oshape)
        npt.assert_allclose(y, [1, 2])

        # Crop non centered
        x = np.array([1, 2, 3, 0, 0])
        oshape = [3]
        y = util.resize(x, oshape, ishift=[0])
        npt.assert_allclose(y, [1, 2, 3])
github mikgroup / sigpy / sigpy / fft.py View on Github external
if oshape is None:
        oshape = input.shape

    with device:
        tmp = input
        tshape = list(input.shape)
        for a in axes:

            i = oshape[a]
            tshape[a] = i

            tmp = tmp.swapaxes(a, -1)
            tshape[a], tshape[-1] = tshape[-1], tshape[a]

            tmp = util.resize(tmp, tshape)
            tmp = xp.fft.ifftshift(tmp, axes=-1)
            tmp = xp.fft.ifft(tmp, axis=-1, norm=norm)
            tmp = xp.fft.fftshift(tmp, axes=-1)

            tmp = tmp.swapaxes(a, -1)
            tshape[a], tshape[-1] = tshape[-1], tshape[a]

        output = tmp

    return output
github mikgroup / sigpy / sigpy / fourier.py View on Github external
def _fftc(input, oshape=None, axes=None, norm='ortho'):

    ndim = input.ndim
    axes = util._normalize_axes(axes, ndim)
    xp = backend.get_array_module(input)

    if oshape is None:
        oshape = input.shape

    tmp = util.resize(input, oshape)
    tmp = xp.fft.ifftshift(tmp, axes=axes)
    tmp = xp.fft.fftn(tmp, axes=axes, norm=norm)
    output = xp.fft.fftshift(tmp, axes=axes)
    return output
github mikgroup / sigpy / sigpy / dataset.py View on Github external
def _get_dataset(self, i):
        return util.resize(np.load(self.filepaths[i]), self.shape[1:])
github mikgroup / sigpy / sigpy / fourier.py View on Github external
def _ifftc(input, oshape=None, axes=None, norm='ortho'):
    ndim = input.ndim
    axes = util._normalize_axes(axes, ndim)
    xp = backend.get_array_module(input)

    if oshape is None:
        oshape = input.shape

    tmp = util.resize(input, oshape)
    tmp = xp.fft.ifftshift(tmp, axes=axes)
    tmp = xp.fft.ifftn(tmp, axes=axes, norm=norm)
    output = xp.fft.fftshift(tmp, axes=axes)
    return output