Ejemplo n.º 1
0
def phaseshift_regular_grid(A, speed):
    """
    Phase shift data for wave-frame moving averages

    Parameters
    ----------
    A: DataArray
        The input data array can have any number of dimensions, but it must
        satisfy some simple properties:

        - periodicity in the 'x' direction
        - 'time' is the first dimension of the dataset
        - 'x', and 'time' are defined on a regular grid
        - the units of speed are [x]/[time]

    speed: float
        The speed of waves to follow.

    Returns
    -------
    C : The phase shifted data array

    """
    from scipy.ndimage.interpolation import shift as ndshift
    C = A.copy()

    # Grid spacing
    dx = A.x[1] - A.x[0]
    dt = (A.time[1] - A.time[0])

    # shift = (-c * t, 0) = (- c * dt * i / dx)
    def indshift(i):
        shift = [0]*(C.ndim-1)
        shift[C.get_axis_num('x')-1] = float((-speed *dt * i/dx).values)
        return shift



    # shift data
    for it, t in enumerate(A.time):
        ndshift(A.values[it,...], indshift(it), output=C.values[it,...], mode='wrap')

    return C
Ejemplo n.º 2
0
def test_normfunc2():
    norm_func = norm.set_normfunc(bg, dk)
    res1 = norm_func(im)
    res2 = norm_func(im, bp=bp)
    res3 = norm_func(im, bp=bp, bc=bc)
    real1 = np.zeros(im.shape, dtype=im.dtype)+r1
    real2 = np.zeros(im.shape, dtype=im.dtype)+r2
    real3 = ndshift(np.zeros(im.shape, dtype=im.dtype)+r2, bc, mode='constant', cval=r3)
    assert_allclose(real1, res1)
    assert_allclose(real2, res2)
    assert_allclose(real3, res3)
Ejemplo n.º 3
0
def shift2d(data, t=0.0):
    '''
    t: float or sequence
    '''
    ret = None
    if isvector(t):
        map_obj = map(ndshift, data, t)
        ret = fromiter(map_obj)
    else:
        ret = ndshift(data, (0.0, t))

    return ret
Ejemplo n.º 4
0
def test_corr1d():
    A = np.array([1, 3, 5, 3, 1], dtype=np.double)
    A = np.pad(A, 10, mode='constant', constant_values=1)

    ran = np.zeros(ntry, dtype=np.double)
    cor = np.zeros(ntry, dtype=np.double)

    for i in range(ntry):
        ran[i] = np.ceil(np.random.random()*50.-100.)/10.
        B = ndshift(A, (ran[i]), mode='constant', cval=1.0)
        cor[i] = corr.corr1d(A, B)

    assert_allclose(ran, cor, rtol=0, atol=0.1)
Ejemplo n.º 5
0
    def normfunc(im, bp=None, bc=None):
        '''
        im: 2d image
        bp: beam power value
        bc: beam center
        '''
        _im = im
        _bg = bg
        _dk = dk

        if dk is not None:
            _im = _im - _dk
            _bg = _bg - _dk
        if bp is not None:
            _im = _im - bp
        if bc is not None:
            _bg = ndshift(_bg, bc, mode='constant', cval=1.0)
        res = (_im / _bg)
        return res
Ejemplo n.º 6
0
def test_corr2d():
    A = np.array([[1, 1, 1, 1, 1],
                  [1, 3, 3, 3, 1],
                  [1, 3, 5, 3, 1],
                  [1, 3, 3, 3, 1],
                  [1, 1, 1, 1, 1]], dtype=np.double)

    A = np.pad(A, 10, mode='constant', constant_values=1)

    ran_dx = np.zeros(ntry, dtype=np.double)
    ran_dy = np.zeros(ntry, dtype=np.double)
    cor_dx = np.zeros(ntry, dtype=np.double)
    cor_dy = np.zeros(ntry, dtype=np.double)

    for i in range(ntry):
        ran_dy[i] = np.ceil(np.random.random()*50.-100.)/10.
        ran_dx[i] = np.ceil(np.random.random()*50.-100.)/10.
        B = ndshift(A, (ran_dy[i], ran_dx[i]), mode='constant', cval=1.0)
        cor_dy[i], cor_dx[i] = corr.corr2d(A, B)

    assert_allclose(ran_dx, cor_dx, rtol=0, atol=0.1)
    assert_allclose(ran_dy, cor_dy, rtol=0, atol=0.1)
Ejemplo n.º 7
0
def test_norm_all3():
    norm_func = norm.set_normfunc(bg, dk)
    res = norm.norm_all(np.array([im, im]), bg, dk=dk, beam_power=np.array([bp,bp]), beam_center=np.array([bc, bc]), crop=True)
    real = ndshift(np.zeros(im.shape, dtype=im.dtype)+r2, bc, mode='constant', cval=r3)
    real = np.array([real, real])
    assert_allclose(real[:,2:,1:], res)