コード例 #1
0
def test_correlation_methods(lt_ctx, cls, dtype, kwargs):
    shape = np.array([128, 128])
    zero = shape / 2 + np.random.uniform(-1, 1, size=2)
    a = np.array([27.17, 0.]) + np.random.uniform(-1, 1, size=2)
    b = np.array([0., 29.19]) + np.random.uniform(-1, 1, size=2)
    indices = np.mgrid[-2:3, -2:3]
    indices = np.concatenate(indices.T)

    radius = 8

    data, indices, peaks = cbed_frame(*shape, zero, a, b, indices, radius)

    dataset = MemoryDataSet(data=data,
                            tileshape=(1, *shape),
                            num_partitions=1,
                            sig_dims=2)

    template = m.radial_gradient(centerX=radius + 1,
                                 centerY=radius + 1,
                                 imageSizeX=2 * radius + 2,
                                 imageSizeY=2 * radius + 2,
                                 radius=radius)

    match_patterns = [
        blobfinder.RadialGradient(radius=radius),
        blobfinder.Circular(radius=radius),
        blobfinder.BackgroundSubtraction(radius=radius),
        blobfinder.RadialGradientBackgroundSubtraction(radius=radius),
        blobfinder.UserTemplate(template=template)
    ]

    print("zero: ", zero)
    print("a: ", a)
    print("b: ", b)

    for match_pattern in match_patterns:
        print("refining using template %s" % type(match_pattern))
        udf = cls(match_pattern=match_pattern,
                  peaks=peaks.astype(dtype),
                  **kwargs)
        res = lt_ctx.run_udf(dataset=dataset, udf=udf)
        print(peaks)
        print(res['refineds'].data[0])
        print(peaks - res['refineds'].data[0])
        print(res['peak_values'].data[0])
        print(res['peak_elevations'].data[0])

        # import matplotlib.pyplot as plt
        # fig, ax = plt.subplots()
        # plt.imshow(data[0])
        # for p in np.flip(res['refineds'].data[0], axis=-1):
        #     ax.add_artist(plt.Circle(p, radius, fill=False, color='y'))
        # plt.show()

        assert np.allclose(res['refineds'].data[0], peaks, atol=0.5)
コード例 #2
0
def test_run_refine_fastmatch(lt_ctx):
    shape = np.array([128, 128])
    zero = shape / 2 + np.random.uniform(-1, 1, size=2)
    a = np.array([27.17, 0.]) + np.random.uniform(-1, 1, size=2)
    b = np.array([0., 29.19]) + np.random.uniform(-1, 1, size=2)
    indices = np.mgrid[-2:3, -2:3]
    indices = np.concatenate(indices.T)

    drop = np.random.choice([True, False], size=len(indices), p=[0.9, 0.1])
    indices = indices[drop]

    radius = 10

    data, indices, peaks = cbed_frame(*shape, zero, a, b, indices, radius)

    dataset = MemoryDataSet(data=data,
                            tileshape=(1, *shape),
                            num_partitions=1,
                            sig_dims=2)
    matcher = grm.Matcher()

    template = m.radial_gradient(centerX=radius + 1,
                                 centerY=radius + 1,
                                 imageSizeX=2 * radius + 2,
                                 imageSizeY=2 * radius + 2,
                                 radius=radius)

    match_patterns = [
        blobfinder.RadialGradient(radius=radius),
        blobfinder.Circular(radius=radius),
        blobfinder.BackgroundSubtraction(radius=radius),
        blobfinder.RadialGradientBackgroundSubtraction(radius=radius),
        blobfinder.UserTemplate(template=template)
    ]

    print("zero: ", zero)
    print("a: ", a)
    print("b: ", b)

    for match_pattern in match_patterns:
        print("refining using template %s" % type(match_pattern))
        (res, real_indices) = blobfinder.run_refine(
            ctx=lt_ctx,
            dataset=dataset,
            zero=zero + np.random.uniform(-1, 1, size=2),
            a=a + np.random.uniform(-1, 1, size=2),
            b=b + np.random.uniform(-1, 1, size=2),
            matcher=matcher,
            match_pattern=match_pattern)
        print(peaks - grm.calc_coords(res['zero'].data[0], res['a'].data[0],
                                      res['b'].data[0], indices))

        assert np.allclose(res['zero'].data[0], zero, atol=0.5)
        assert np.allclose(res['a'].data[0], a, atol=0.2)
        assert np.allclose(res['b'].data[0], b, atol=0.2)