Ejemplo n.º 1
0
def test_autocenter_no_side_effects():
    """ Test that autocenter() does not modify the inputs """
    im = np.random.random(size=(256, 256))
    mask = np.ones_like(im, dtype=bool)

    # Modifying the arrays will result in "ValueError: output array is read-only"
    im.setflags(write=False)
    mask.setflags(write=False)

    autocenter(im, mask=mask)
Ejemplo n.º 2
0
def test_autocenter_gaussian_shifted(rc, cc):
    """ Test that autocenter() finds the center of a shifted gaussian """
    im = np.zeros(shape=(128, 128), dtype=float)
    rows, cols = np.indices(im.shape)
    center = np.array([64 + rc, 64 + cc])
    im += gaussian([rows, cols], center=center, fwhm=20)

    assert np.allclose(autocenter(im), center, atol=1)
Ejemplo n.º 3
0
def test_autocenter_trivial():
    """ Test that autocenter() finds the center of perfect gaussian at (0,0) """
    im = np.zeros(shape=(256, 256), dtype=float)
    center = np.asarray(im.shape) / 2
    rows, cols = np.indices(im.shape)
    im += gaussian([rows, cols], center=center, fwhm=center.max() / 2)

    assert np.allclose(autocenter(im), center, atol=1)
Ejemplo n.º 4
0
def test_autocenter_single_crystal(rc, cc):
    """Test that autocenter() finds the center of a simulated
    shifted single-crystal diffraction pattern."""
    I = 10 * diff_pattern_sc(center=(rc, cc))
    mask = np.ones_like(I, dtype=bool)
    mask[0:rc + 10, cc - 10:cc + 10] = False
    I += 0.01 * I.max() * np.random.random(size=I.shape)

    assert np.allclose(autocenter(I, mask=mask), (rc, cc), atol=1)
Ejemplo n.º 5
0
def test_autocenter_shifted_with_mask(rc, cc):
    """Test that autocenter() finds the center of a shifted gaussian, where
    the center has been masked away."""
    im = np.zeros(shape=(256, 256), dtype=float)
    mask = np.ones_like(im, dtype=bool)
    mask[0:130, 118:138] = False

    rows, cols = np.indices(im.shape)
    center = np.array([128 + rc, 128 + cc])
    im += gaussian([rows, cols], center=center, fwhm=50)

    im[np.logical_not(mask)] *= 0.8

    assert np.allclose(autocenter(im, mask=mask), center, atol=1)
Ejemplo n.º 6
0
def test_autocenter_single_crystal_ewald_walkoff(rc, cc):
    """Test that autocenter() finds the center of a simulated
    shifted single-crystal diffraction pattern."""
    I = 10 * diff_pattern_sc(center=(rc, cc))

    # Walkoff is the effect when diffraction patterns slide reflections
    # at strange angles, such that certain bragg peaks that should have the same
    # intensity do not (e.g. brigher (n00) vs (-n00))
    # We simulate this with a linear intensity gradient
    rows, cols = np.indices(I.shape)
    walkoff = rows.astype(float) / rows.max()
    walkoff *= 0.2
    I += walkoff

    mask = np.ones_like(I, dtype=bool)
    mask[0:rc + 10, cc - 10:cc + 10] = False
    I += 0.01 * I.max() * np.random.random(size=I.shape)

    assert np.allclose(autocenter(I, mask=mask), (rc, cc), atol=1)