Ejemplo n.º 1
0
def test_level_set():
    N = 64
    n, m = 1, 4
    test_data = tv.sin_cos_arr(N, n, m)

    dd = field_trace.Derivator(test_data)
    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()]
    saddle0s = [(s.x0, s.y0) for s in saddles]
    peak0s = [(p.x0, p.y0) for p in peaks]

    x0, y0 = saddle0s[0]

    psi_interp = Interp2DPeriodic(N, N, test_data)
    level_val = psi_interp.eval(x0, y0)

    level_sets = [null.levelset for null in nulls]

    mask = field_trace.marked_to_mask(test_data.shape, level_sets)

    masked_data = test_data.copy()
    masked_data[mask] = test_data.max()

    if 0:
        import pylab as pl
        pl.ion()
        pl.imshow(masked_data, cmap='hot', interpolation='nearest')
        # # 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')
        raw_input("enter to continue")
Ejemplo n.º 2
0
def test_level_set():
    # N = 128#{{{
    # n, m = 10, 15
    # test_data = tv.sin_cos_arr(N, n, m)
    arr_idx = -2
    test_data = psi_arrs[arr_idx].astype(np.double)
    N = test_data.shape[0]

    print("locating nulls")
    dd = field_trace.Derivator(test_data, N, N)
    nulls = field_trace.find_null_cells(dd)
    null0s = [(n.x0, n.y0) for n in nulls]

    psi_interp = Interp2DPeriodic(N, N, test_data)

    print("computing level sets")
    levels = [null.levelset for null in nulls]

    print("classifying nulls")

    peaks = []
    saddles = []
    for null in nulls:
        if null.is_saddle():
            saddles.append(null)
        else:
            peaks.append(null)

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

    print( "getting min regions")
    regions = []
    for null in nulls:
        regions.extend(null.regions)

    print( "number of regions: %d" % len(regions))

    min_regions = field_trace.filter_min_regions(regions)

    print( "number of min regions: %d" % len(min_regions))

    print( "plotting")

    if 1:
        import pylab as pl
        pl.ion()
        pl.figure()
        dta = np.zeros(test_data.shape, dtype=np.int32)
        for min_region in min_regions:
            dta[min_region.xs, min_region.ys] = 1
        pl.imshow(dta, interpolation='nearest')
        pl.figure()
        pl.imshow(cur_arrs[arr_idx])
        pl.figure()
        pl.imshow(psi_arrs[arr_idx])
        raw_input("enter to continue")

        
    if 0:
        import pylab as pl
        pl.ion()
        all_masks = field_trace.marked_to_mask(test_data.shape, levels)
        masked_data = test_data.copy()
        masked_data[all_masks] = test_data.max()
        pl.imshow(masked_data, cmap='hot', interpolation='nearest')
        X, Y = zip(*peak0s)
        pl.scatter(Y, X, c='k')
        X, Y = zip(*saddle0s)
        pl.scatter(Y, X, c='b')

        if 0:
            for level in levels:
                masked_data = test_data.copy()
                mask = field_trace.marked_to_mask(test_data.shape, [level])
                masked_data[mask] = test_data.max()
                pl.imshow(masked_data, cmap='hot', interpolation='nearest')
                X, Y = zip(*null0s)
                pl.scatter(Y, X, c='k')
                X, Y = zip(*null0s)
                pl.scatter(Y, X, c='b')

        raw_input("enter to continue")#}}}