def tester(n, m):
        N = global_N
        test_data = tv.sin_cos_prod(N, n, m)
        from upsample import upsample
        test_data = upsample(test_data, factor=4)
        dd = field_trace.Derivator(test_data)
        nulls = field_trace.find_null_cells_minimize(dd)
        null_locs = [(null.x0, null.y0) for null in nulls]
        saddles = [_ for _ in nulls if _.is_saddle()]
        maxs = [_ for _ in nulls if _.is_maximum()]
        mins = [_ for _ in nulls if _.is_minimum()]
        eq_(len(saddles + maxs + mins), len(nulls))

        print ("4*n*m: %d num_saddles: %d num_max+num_min: %d" %
                (4*n*m, len(saddles), len(maxs+mins)))

        if 1:
            import pylab as pl
            pl.ion()
            pl.imshow(test_data)
            X = [_.x0 for _ in saddles]
            Y = [_.y0 for _ in saddles]
            pl.scatter(Y, X, marker='x', c='k')
            X = [_.x0 for _ in maxs]
            Y = [_.y0 for _ in maxs]
            pl.scatter(Y, X, c='r', marker='d')
            X = [_.x0 for _ in mins]
            Y = [_.y0 for _ in mins]
            pl.scatter(Y, X, c='b', marker='o')
            raw_input("enter to continue")
            pl.close('all')
Beispiel #2
0
def test_tracer():
    from kaw_analysis import test_vcalc as tv#{{{
    N = 64
    dta = tv.sin_cos_prod(N, 5, 5)
    # dta = psi_arrs[-1]

    dd = field_trace.Derivator(dta, dta.shape[0], dta.shape[1])

    nulls = field_trace.find_null_cells(dd)
    saddles = [null for null in nulls if null.is_saddle()]
    peaks = [null for null in nulls if not null.is_saddle()]

    error = 0.0
    for null in nulls:
        error += abs(dd.perp_deriv1_interp.eval(null.x0, null.y0))
        error += abs(dd.perp_deriv2_interp.eval(null.x0, null.y0))
    error /= len(nulls)

    saddle0s = [(s.x0, s.y0) for s in saddles]

    peak0s = [(p.x0, p.y0) for p in peaks]

    # finished, traces = field_trace.make_skeleton(
            # arr=dta, deriv=dd, saddles=saddles, ncomb=1, start_offset=1.e-3, hit_radius=1.e-3)

    traces = []
    for saddle in saddles:
        for outgoing in (True, False):
            for sgn in (1,-1):
                trace = field_trace.trace_from_saddle(
                        arr=dta, deriv=dd, start_saddle=saddle,
                        start_offset=sgn*1.e-2, outgoing=outgoing, timeout=0.001)
                traces.append(trace)

    if 1:
        import pylab as pl
        pl.ion()
        pl.imshow(dta, cmap='hot')
        for tr in traces:
            tr = np.array(tr)
            for i in range(0, len(tr[0]), 2):
                X,Y = tr[:,i], tr[:,i+1]
                pl.scatter(Y, X, c='r')

        # Plot the grid points
        if 0:
            X = np.linspace(0, dta.shape[0]-1, dta.shape[0])
            for i in range(dta.shape[0]):
                Y = np.zeros(dta.shape[1])
                Y.fill(i)
                pl.scatter(Y, X, c='m')
            
        X, Y = zip(*saddle0s)
        pl.scatter(Y, X, c='k')
        X, Y = zip(*peak0s)
        pl.scatter(Y, X, c='b')
        import pdb; pdb.set_trace()#}}}
Beispiel #3
0
def test_upsample():
    upsample_factor = 4
    N = global_N
    test_data = tv.sin_cos_prod(N, N/4, N/8)
    test_data_4 = tv.sin_cos_prod(N*4, N/4, N/8)

    upsampled = upsample.upsample(test_data, factor=4)

    ok_(np.allclose(upsample_factor**2 * upsampled, test_data_4))

    if 0:
        pl.ion()
        pl.imshow(test_data, interpolation='nearest', cmap='hot')
        pl.title('original data')
        pl.figure()
        pl.imshow(upsampled, interpolation='nearest', cmap='hot')
        pl.title('upsampled by %d' % upsample_factor)
        pl.figure()
        pl.imshow(test_data_4, interpolation='nearest', cmap='hot')
        pl.title('comparison')
        raw_input('enter to continue')
    def tester(n, m):
        N = global_N
        test_data = tv.sin_cos_prod(N, n, m)
        # from upsample import upsample
        # test_data = upsample(test_data, factor=4)
        dd = field_trace.Derivator(test_data)
        arr1 = np.zeros((N, N), dtype=np.double)
        arr2 = np.zeros((N, N), dtype=np.double)
        for i in range(N):
            for j in range(N):
                evals, evecs = field_trace.hessian_esys(dd, i, j)
                arr1[i,j] = min(evals)
                arr2[i,j] = max(evals)
        nulls = field_trace.find_null_cells_minimize(dd)
        null_locs = [(null.x0, null.y0) for null in nulls]
        saddles = [_ for _ in nulls if _.is_saddle()]
        maxs = [_ for _ in nulls if _.is_maximum()]
        mins = [_ for _ in nulls if _.is_minimum()]
        saddleXs, saddleYs = [_.x0 for _ in saddles], [_.y0 for _ in saddles]
        minXs, minYs = [_.x0 for _ in mins], [_.y0 for _ in mins]
        maxXs, maxYs = [_.x0 for _ in maxs], [_.y0 for _ in maxs]

        if 0:
            def ims(x):
                pl.imshow(x, interpolation='nearest', cmap='hot')
                pl.scatter(saddleYs, saddleXs, marker='x', c='k')
                pl.scatter(minYs, minXs, marker='o', c='b')
                pl.scatter(maxYs, maxXs, marker='d', c='r')
            import pylab as pl
            pl.ion()
            # ims(dd.deriv11)
            # pl.figure()
            # ims(dd.deriv22)
            # pl.figure()
            # ims(dd.deriv12)
            # pl.figure()
            ims(test_data)
            pl.figure()
            ims(arr1)
            pl.figure()
            ims(arr2)
            pl.figure()
            ims(arr1*arr2)
            raw_input("enter to continue")
            pl.close('all')