Exemplo n.º 1
0
    def _make_quaternion(self, data):

        if data.ndim % 2 != 0:
            raise ValueError(
                "An array of data to be transformed to quaternion must be 2D.")

        if data.dtype not in TYPE_COMPLEX:
            if data.shape[1] % 2 != 0:
                raise ValueError(
                    "An array of real data to be transformed to quaternion must have even number of columns!."
                )
            # convert to double precision complex
            data = self._make_complex(data)

        if data.shape[0] % 2 != 0:
            raise ValueError(
                "An array data to be transformed to quaternion must have even number of rows!."
            )

        r = data[::2]
        i = data[1::2]
        #  _data = as_quat_array(list(zip(r.real.flatten(), r.imag.flatten(), i.real.flatten(), i.imag.flatten())))
        #  _data = _data.reshape(r.shape)

        self._dtype = None  # reset dtyep
        return as_quaternion(r, i)
Exemplo n.º 2
0
def _ifft(data):
    if data.dtype == typequaternion:

        fr = get_component(data, "R")
        dr = np.fft.ifft(np.fft.ifftshift(fr, -1))
        fi = get_component(data, "I")
        di = np.fft.ifft(np.fft.ifftshift(fi, -1))

        # rebuild the quaternion
        data = as_quaternion(dr, di)

    else:
        data = np.fft.ifft(np.fft.ifftshift(data, -1))

    return data
Exemplo n.º 3
0
def _ifft_positive(data):
    if data.dtype == typequaternion:

        fr = get_component(data, "R")
        dr = np.fft.fft(np.fft.ifftshift(fr, -1)) * data.shape[-1]
        fi = get_component(data, "I")
        di = np.fft.fft(np.fft.ifftshift(fi, -1)) * data.shape[-1]

        # rebuild the quaternion
        data = as_quaternion(dr, di)

    else:
        data = np.fft.fft(np.fft.ifftshift(data, -1)) * data.shape[-1]

    return data
Exemplo n.º 4
0
def _fft(data):
    if data.dtype == typequaternion:

        dr = get_component(data, "R")
        fr = np.fft.fftshift(np.fft.fft(dr), -1)
        di = get_component(data, "I")
        fi = np.fft.fftshift(np.fft.fft(di), -1)

        # rebuild the quaternion
        data = as_quaternion(fr, fi)

    else:
        data = np.fft.fftshift(np.fft.fft(data), -1)

    return data
Exemplo n.º 5
0
def _echoanti_fft(data):
    # FFT transform according to ECHO-ANTIECHO encoding

    # warning: at this point, data must have been swapped so the last dimension is the one used for FFT
    wt, yt, xt, zt = as_float_array(
        data).T  # x and y are exchanged due to swapping of dims
    w, y, x, z = wt.T, xt.T, yt.T, zt.T

    c = (w + y) + 1j * (w - y)
    s = (x + z) - 1j * (x - z)
    fc = np.fft.fftshift(np.fft.fft(c / 2.0), -1)
    fs = np.fft.fftshift(np.fft.fft(s / 2.0), -1)
    data = as_quaternion(fc, fs)

    return data
Exemplo n.º 6
0
def _fft_positive(data):
    if data.dtype == typequaternion:

        dr = get_component(data, "R")
        fr = np.fft.fftshift(np.fft.ifft(dr).astype(
            data.dtype)) * data.shape[-1]
        di = get_component(data, "I")
        fi = np.fft.fftshift(np.fft.ifft(di).astype(
            data.dtype)) * data.shape[-1]

        # rebuild the quaternion
        data = as_quaternion(fr, fi)

    else:
        data = np.fft.fftshift(np.fft.ifft(data).astype(
            data.dtype)) * data.shape[-1]

    return data
Exemplo n.º 7
0
def _tppi_fft(data):
    # FFT transform according to TPPI encoding

    # warning: at this point, data must have been swapped so the last dimension is the one used for FFT
    wt, yt, xt, zt = as_float_array(
        data).T  # x and y are exchanged due to swapping of dims
    w, y, x, z = wt.T, xt.T, yt.T, zt.T

    sx = w + 1j * y
    sy = x + 1j * z

    sx[..., 1::2] = -sx[..., 1::2]
    sy[..., 1::2] = -sy[..., 1::2]

    fx = np.fft.fftshift(np.fft.fft(sx), -1)  # reverse
    fy = np.fft.fftshift(np.fft.fft(sy), -1)

    # rebuild the quaternion
    data = as_quaternion(fx, fy)

    return data
Exemplo n.º 8
0
def _states_fft(data, tppi=False):
    # FFT transform according to STATES encoding

    # warning: at this point, data must have been swapped so the last dimension is the one used for FFT
    wt, yt, xt, zt = as_float_array(
        data).T  # x and y are exchanged due to swapping of dims
    w, y, x, z = wt.T, yt.T, xt.T, zt.T

    sr = (w - 1j * y) / 2.0
    si = (x - 1j * z) / 2.0

    if tppi:
        sr[..., 1::2] = -sr[..., 1::2]
        si[..., 1::2] = -si[..., 1::2]

    fr = np.fft.fftshift(np.fft.fft(sr), -1)
    fi = np.fft.fftshift(np.fft.fft(si), -1)

    # rebuild the quaternion
    data = as_quaternion(fr, fi)

    return data