Beispiel #1
0
 def test_large_values_in_middle(self):
     data = np.zeros((100, 100))
     data[5:95, :] = 10
     data[:, 5:95] = 10
     s = hs.signals.Signal2D(data)
     ramp05 = pst._fit_ramp_to_image(s, corner_size=0.05)
     assert_allclose(ramp05, np.zeros((100, 100)), atol=1e-15)
     ramp10 = pst._fit_ramp_to_image(s, corner_size=0.1)
     assert (ramp05 != ramp10).all()
Beispiel #2
0
 def test_different_corner_values(self):
     data = np.zeros((100, 100))
     data[:5, :5], data[:5, -5:] = -10, 10
     data[-5:, :5] = 10
     data[-5:, -5:] = 30
     s = hs.signals.Signal2D(data)
     ramp = pst._fit_ramp_to_image(s, corner_size=0.05)
     s.data = s.data - ramp
     assert approx(s.data[:5, :5].mean()) == 0.0
     assert approx(s.data[:5, -5:].mean()) == 0.0
     assert approx(s.data[-5:, :5].mean()) == 0.0
     assert approx(s.data[-5:, -5:].mean()) == 0.0
     assert s.data[5:95, 5:95].mean() != 0
    def correct_ramp(self, corner_size=0.05, only_offset=False, out=None):
        """
        Subtracts a plane from the signal, useful for removing
        the effects of d-scan in a STEM beam shift dataset.

        The plane is calculated by fitting a plane to the corner values
        of the signal. This will only work well when the property one
        wants to measure is zero in these corners.

        Parameters
        ----------
        corner_size : number, optional
            The size of the corners, as a percentage of the image's axis.
            If corner_size is 0.05 (5%), and the image is 500 x 1000,
            the size of the corners will be (500*0.05) x (1000*0.05) = 25 x 50.
            Default 0.05
        only_offset : bool, optional
            If True, will subtract a "flat" plane, i.e. it will subtract the
            mean value of the corners. Default False
        out : optional, DPCSignal2D signal

        Returns
        -------
        corrected_signal : Signal2D

        Examples
        --------
        >>> s = pxm.dummy_data.get_square_dpc_signal(add_ramp=True)
        >>> s_corr = s.correct_ramp()
        >>> s_corr.plot()

        Only correct offset

        >>> s_corr = s.correct_ramp(only_offset=True)
        >>> s_corr.plot()

        """
        if out is None:
            output = self.deepcopy()
        else:
            output = out

        for i, s in enumerate(self):
            if only_offset:
                corners = pst._get_corner_values(s, corner_size=corner_size)[2]
                ramp = corners.mean()
            else:
                ramp = pst._fit_ramp_to_image(s, corner_size=0.05)
            output.data[i, :, :] -= ramp
        if out is None:
            return output
Beispiel #4
0
 def test_wrong_input_dimensions(self):
     s = hs.signals.Signal2D(np.ones((2, 10, 10)))
     with pytest.raises(ValueError):
         pst._fit_ramp_to_image(s)
     s = hs.signals.Signal2D(np.ones((2, 2, 10, 10)))
     with pytest.raises(ValueError):
         pst._fit_ramp_to_image(s)
     s = hs.signals.Signal1D(np.ones(10))
     with pytest.raises(ValueError):
         pst._fit_ramp_to_image(s)
Beispiel #5
0
 def test_negative_values(self):
     data = np.ones((100, 100)) * -10
     s = hs.signals.Signal2D(data)
     ramp = pst._fit_ramp_to_image(s, corner_size=0.05)
     assert_allclose(ramp, data, atol=1e-30)
Beispiel #6
0
 def test_zero_values(self):
     data = np.zeros((100, 100))
     s = hs.signals.Signal2D(data)
     ramp = pst._fit_ramp_to_image(s, corner_size=0.05)
     assert_allclose(ramp, data, atol=1e-15)