Esempio n. 1
0
def test_find_ramp():
    p_ramp = .025
    L = 128
    sig_rms = 5.0

    def iid_nz(scale):
        return np.random.normal(loc=0, scale=scale, size=L)

    fov_win = np.zeros((L, ), 'i')
    fov_win[L / 2 - 40:L / 2 + 40] = 1

    sig_phs = np.arange(L) * p_ramp + np.random.randn(1)
    sig_mag = iid_nz(sig_rms)

    sig = np.abs(sig_mag) * np.exp(1j * sig_phs)

    # attenutate the signal according to a simulated object pattern
    atten = np.zeros(L)
    segs = np.unique(np.random.randint(0, high=10, size=5))
    segs = map(lambda s: int(round(s * (L - 1) / 10.)), segs)
    segs.sort()
    segs = np.insert(segs, len(segs), L)
    segs = np.insert(segs, 0, 0)
    s_val = [.1, 1]
    vi = 1
    for i in xrange(len(segs) - 1):
        atten[segs[i]:segs[i + 1]] = s_val[vi]
        vi = vi ^ 1
    sig *= atten
    # now add a small amount of noise to real/imag channels
    sig.real += iid_nz(sig_rms / 50.)
    sig.imag += iid_nz(sig_rms / 50.)

    m = util.find_ramp(np.angle(sig))
    print m
Esempio n. 2
0
def test_find_ramp():
    p_ramp = .025
    L = 128
    sig_rms = 5.0
    def iid_nz(scale):
        return np.random.normal(loc=0, scale=scale, size=L)

    fov_win = np.zeros((L,), 'i')
    fov_win[L/2-40:L/2+40] = 1

    sig_phs = np.arange(L) * p_ramp + np.random.randn(1)
    sig_mag = iid_nz(sig_rms)

    sig = np.abs(sig_mag) * np.exp(1j*sig_phs)

    # attenutate the signal according to a simulated object pattern
    atten = np.zeros(L)
    segs = np.unique(np.random.randint(0, high=10, size=5))
    segs = map(lambda s: int(round(s*(L-1)/10.)), segs)
    segs.sort()
    segs = np.insert(segs, len(segs), L)
    segs = np.insert(segs, 0, 0)
    s_val = [.1, 1]
    vi = 1
    for i in xrange(len(segs)-1):
        atten[segs[i]:segs[i+1]] = s_val[vi]
        vi = vi ^ 1
    sig *= atten
    # now add a small amount of noise to real/imag channels
    sig.real += iid_nz(sig_rms/50.)
    sig.imag += iid_nz(sig_rms/50.)
    
    m = util.find_ramp(np.angle(sig))
    print m
Esempio n. 3
0
def simple_unbal_phase_ramp(rdata,
                            nramp,
                            nflat,
                            pref_polarity,
                            fov_lim=None,
                            mask_noise=True,
                            debug=False):
    N1 = rdata.shape[-1]
    rdata[:, :nramp + 1] = 0.
    rdata[:, nflat + 1:] = 0.
    irdata = util.ifft1(rdata, shift=True)

    if pref_polarity == 1:
        # [(pos - neg), (neg - pos)]
        ref_funcs = irdata[:2] * irdata[1:3].conj()
    else:
        # [(pos - neg), (neg - pos)]
        ref_funcs = irdata[:2].conj() * irdata[1:3]
    ref = ref_funcs[0] * ref_funcs[1].conjugate()
    ref_funcs_phs = np.angle(ref_funcs)
    pos_neg_diff = ref_funcs_phs[0]
    neg_pos_diff = ref_funcs_phs[1]

    ref_peak = np.abs(ref).max()

    # if an FOV limit is requested, then make sure the rest of the algorithm
    # only considers data within the limit
    if fov_lim:
        fov_max, fov = fov_lim
        dx = fov / N1
        x_grid = np.arange(-N1 / 2, N1 / 2) * dx
        fov_q1_mask = np.where(np.abs(x_grid) > fov_max, 0, 1)
    else:
        fov_q1_mask = np.ones((N1, ), 'i')

    ref_peak = np.abs(ref * fov_q1_mask).max()
    if mask_noise:
        thresh = 0.1
        nz_q1_mask = np.where(np.abs(ref) > thresh * ref_peak, 1, 0)
        while nz_q1_mask.sum() < 10:
            thresh *= 0.5
            print 'relaxing threshold to include more points in the fit:', thresh
            nz_q1_mask = np.where(np.abs(ref) > thresh * ref_peak, 1, 0)
    else:
        nz_q1_mask = np.ones((N1, ), 'i')

    ref_phs = (pos_neg_diff - neg_pos_diff)

    q1_mask = nz_q1_mask & fov_q1_mask
    # only do the unwrapping in the method if noisy patches have been rejected
    m = util.find_ramp(ref_phs / 4.,
                       mask=q1_mask,
                       do_unwrap=mask_noise,
                       debug=debug)

    ##     m,b,r = util.lin_regression(ref_phs/4, mask=nz_q1_mask & fov_q1_mask)
    ##     m = m[0]; b = b[0]
    return m
Esempio n. 4
0
def simple_unbal_phase_ramp(rdata, nramp, nflat, pref_polarity, 
                            fov_lim=None, mask_noise=True,
                            debug=False):
    N1 = rdata.shape[-1]
    rdata[:,:nramp+1] = 0.
    rdata[:,nflat+1:] = 0.
    irdata = util.ifft1(rdata, shift=True)

    if pref_polarity==1:
        # [(pos - neg), (neg - pos)]
        ref_funcs = irdata[:2] * irdata[1:3].conj()
    else:
        # [(pos - neg), (neg - pos)]        
        ref_funcs = irdata[:2].conj()*irdata[1:3]
    ref = ref_funcs[0]*ref_funcs[1].conjugate()
    ref_funcs_phs = np.angle(ref_funcs)
    pos_neg_diff = ref_funcs_phs[0]
    neg_pos_diff = ref_funcs_phs[1]
    
    ref_peak = np.abs(ref).max()

    # if an FOV limit is requested, then make sure the rest of the algorithm
    # only considers data within the limit
    if fov_lim:
        fov_max, fov = fov_lim
        dx = fov/N1
        x_grid = np.arange(-N1/2, N1/2) * dx
        fov_q1_mask = np.where(np.abs(x_grid)>fov_max,0,1)
    else:
        fov_q1_mask = np.ones((N1,), 'i')

    ref_peak = np.abs(ref*fov_q1_mask).max()
    if mask_noise:
        thresh = 0.1
        nz_q1_mask = np.where(np.abs(ref) > thresh*ref_peak, 1, 0)
        while nz_q1_mask.sum() < 10:
            thresh *= 0.5
            print 'relaxing threshold to include more points in the fit:', thresh
            nz_q1_mask = np.where(np.abs(ref) > thresh*ref_peak, 1, 0)
    else:
        nz_q1_mask = np.ones((N1,), 'i')

    ref_phs = (pos_neg_diff-neg_pos_diff)

    q1_mask = nz_q1_mask & fov_q1_mask
    # only do the unwrapping in the method if noisy patches have been rejected
    m = util.find_ramp(ref_phs/4., mask=q1_mask, do_unwrap=mask_noise,
                       debug=debug)
    
##     m,b,r = util.lin_regression(ref_phs/4, mask=nz_q1_mask & fov_q1_mask)
##     m = m[0]; b = b[0]
    return m