Exemplo n.º 1
0
def test_local_gaussian_method_exciting(dp, diffraction_vectors):
    """
    This aims to test that our x/y convention is correct. The peak shape for
    these tests is unsuitable for this method.
    """
    spr = SubpixelrefinementGenerator(dp, diffraction_vectors)
    s = spr.local_gaussian_method(8)
Exemplo n.º 2
0
def test_assertioned_xc(create_spot):
    spr = SubpixelrefinementGenerator(create_spot,
                                      np.asarray([[90 - 64, 30 - 64]]))
    s = spr.conventional_xc(12, 4, 8)
    error = np.subtract(s[0, 0], np.asarray([[90 - 64, 30 - 64]]))
    rms_error = np.sqrt(error[0, 0]**2 + error[0, 1]**2)
    assert rms_error < 0.2  # 1/5th a pixel
Exemplo n.º 3
0
def test_assertioned_com(create_spot):
    spr = SubpixelrefinementGenerator(create_spot,
                                      np.asarray([[90 - 64, 30 - 64]]))
    s = spr.center_of_mass_method(8)
    error = np.subtract(s[0, 0], np.asarray([[90 - 64, 30 - 64]]))
    rms_error = np.sqrt(error[0, 0]**2 + error[0, 1]**2)
    assert rms_error < 1e-5  # perfect detection for this trivial case
Exemplo n.º 4
0
def test_local_gaussian_method_dull(dp, diffraction_vectors):
    """
    This aims to test that our x/y convention is correct. The peak shape for
    these tests is unsuitable for this method.
    """
    spr = SubpixelrefinementGenerator(dp, diffraction_vectors)
    s = spr.local_gaussian_method(8)
    error = s.data[0, 0] - np.asarray([[90 - 64, 30 - 64]])
    assert np.all(error < 5)
def test_xy_errors_in_conventional_xc_method_as_per_issue_490():
    """ This was the MWE example code for the issue """
    dp = get_simulated_disc(100, 20)
    # translate y by +4
    shifted = np.pad(dp, ((0, 4), (0, 0)),
                     'constant')[4:].reshape(1, 1, *dp.shape)
    signal = ElectronDiffraction2D(shifted)
    spg = SubpixelrefinementGenerator(signal, np.array([[0, 0]]))
    peaks = spg.conventional_xc(100, 20, 1).data[0, 0,
                                                 0]  # as quoted in the issue
    np.testing.assert_allclose([0, -4], peaks)
    """ we also test com method for clarity """
    peaks = spg.center_of_mass_method(60).data[0, 0, 0]
    np.testing.assert_allclose([0, -4], peaks, atol=1.5)
Exemplo n.º 6
0
def test_bad_vectors_numpy():
    """ tests that putting bad vectors in causes an error to be thrown when
    you initiate the geneartor
    """
    v = np.array([[1, -100]])
    dp = ElectronDiffraction(np.ones((20, 20)))
    sprg = SubpixelrefinementGenerator(dp, v)
Exemplo n.º 7
0
    def test_out_of_range_vectors_DiffractionVectors(self):
        """Test that putting vectors that lie outside of the
        diffraction patterns raises a ValueError"""
        vectors = DiffractionVectors(np.array([[1, -100]]))
        dp = ElectronDiffraction2D(np.ones((20, 20)))

        with pytest.raises(
            ValueError,
            match="Some of your vectors do not lie within your diffraction pattern",
        ):
            sprg = SubpixelrefinementGenerator(dp, vectors)
Exemplo n.º 8
0
    def test_wrong_navigation_dimensions(self):
        """Tests that navigation dimensions must be appropriate too."""
        dp = ElectronDiffraction2D(np.zeros((2, 2, 8, 8)))
        vectors = DiffractionVectors(np.zeros((1, 2)))
        dp.axes_manager.set_signal_dimension(2)
        vectors.axes_manager.set_signal_dimension(0)

        # Note - uses regex via re.search()
        with pytest.raises(
            ValueError,
            match=r"Vectors with shape .* must have the same navigation shape as .*",
        ):
            sprg = SubpixelrefinementGenerator(dp, vectors)
Exemplo n.º 9
0
def test_conventional_xc(diffraction_pattern):
    SPR_generator = SubpixelrefinementGenerator(diffraction_pattern,
                                                np.asarray([[1, -1]]))
    assert SPR_generator.calibration == 1
    assert np.allclose(SPR_generator.center, 4)
    diff_vect = SPR_generator.conventional_xc(4, 2, 10)
Exemplo n.º 10
0
 def get_spr(self, diffraction_vectors):
     dp = set_up_for_subpixelpeakfinders().create_spot()
     return SubpixelrefinementGenerator(dp, diffraction_vectors)
Exemplo n.º 11
0
 def test_wrong_navigation_dimensions(self):
     dp = ElectronDiffraction2D(np.zeros((2, 2, 8, 8)))
     vectors = DiffractionVectors(np.zeros((1, 2)))
     dp.axes_manager.set_signal_dimension(2)
     vectors.axes_manager.set_signal_dimension(0)
     SPR_generator = SubpixelrefinementGenerator(dp, vectors)
Exemplo n.º 12
0
 def test_out_of_range_vectors_DiffractionVectors(self):
     vectors = DiffractionVectors(np.array([[1, -100]]))
     dp = ElectronDiffraction2D(np.ones((20, 20)))
     sprg = SubpixelrefinementGenerator(dp, vectors)
Exemplo n.º 13
0
def test_assertioned_xc(dp, diffraction_vectors):
    spr = SubpixelrefinementGenerator(dp, diffraction_vectors)
    s = spr.conventional_xc(12, 4, 8)
    error = s.data[0, 0] - np.asarray([[90 - 64, 30 - 64]])
    rms_error = np.sqrt(error[0, 0]**2 + error[0, 1]**2)
    assert rms_error < 0.2  # 1/5th a pixel
Exemplo n.º 14
0
def test_bad_vectors_DiffractionVectors():
    v = np.array([[1, -100]])
    dv = DiffractionVectors(v)
    dp = ElectronDiffraction(np.ones((20, 20)))
    sprg = SubpixelrefinementGenerator(dp, dv)
Exemplo n.º 15
0
def test_assertioned_com(dp, diffraction_vectors):
    spr = SubpixelrefinementGenerator(dp, diffraction_vectors)
    s = spr.center_of_mass_method(8)
    error = s.data[0, 0] - np.asarray([[90 - 64, 30 - 64]])
    rms_error = np.sqrt(error[0, 0]**2 + error[0, 1]**2)
    assert rms_error < 1e-5  # perfect detection for this trivial case
Exemplo n.º 16
0
def test_bad_square_size_local_gaussian_method(dp, diffraction_vectors):
    spr = SubpixelrefinementGenerator(dp, diffraction_vectors)
    s = spr.local_gaussian_method(2)
def test_local_gaussian_method(dp, diffraction_vectors, refined_vectors):
    spr = SubpixelrefinementGenerator(dp, diffraction_vectors)
    s = spr.local_gaussian_method(10)
    np.testing.assert_allclose(s.data[0, 0], refined_vectors, atol=0.1)