def test_zero_plane(self, correction):
        result = correct_background(np.array(zero_plane),
                                    correction,
                                    keep_offset=False)
        assert np.all(np.isclose(result, zero_plane))

        correct_background(np.array(zero_plane), correction, keep_offset=True)
        assert np.all(np.isclose(result, zero_plane))
    def test_y_tilted_plane(self, correction):
        result = correct_background(np.array(y_tilted_plane),
                                    correction,
                                    keep_offset=True)
        if correction is BGCorrectionType.legendre_0:
            assert np.all(np.isclose(result, y_tilted_plane))
        else:
            assert np.all(np.isclose(result, offset_plane))

        result = correct_background(np.array(y_tilted_plane),
                                    correction,
                                    keep_offset=False)
        if correction is BGCorrectionType.legendre_0:
            assert np.all(
                np.isclose(result, (y_tilted_plane - np.mean(y_tilted_plane))))
        else:
            assert np.all(np.isclose(result, zero_plane))
    def test_curved_plane(self, correction):
        result = correct_background(np.array(curved_plane),
                                    correction,
                                    keep_offset=True)
        if correction in [
                BGCorrectionType.legendre_0, BGCorrectionType.legendre_1,
                BGCorrectionType.gradient
        ]:
            assert np.all(np.isclose(result, curved_plane))
        else:
            assert np.all(
                np.isclose(result, (zero_plane + np.mean(curved_plane))))

        result = correct_background(np.array(curved_plane),
                                    correction,
                                    keep_offset=False)
        if correction in [
                BGCorrectionType.legendre_0, BGCorrectionType.legendre_1,
                BGCorrectionType.gradient
        ]:
            assert np.all(
                np.isclose(result, (curved_plane - np.mean(curved_plane))))
        else:
            assert np.all(np.isclose(result, zero_plane))
예제 #4
0
    def correct_background(
            self,
            correction_type: BGCorrectionType = BGCorrectionType.legendre_1,
            keep_offset: bool = False):
        """
        Corrects background using the given correction_type on values_original and save the result in values.
        If keep_z_offset is True, the mean value of dataset is preserved. Otherwise the average value is set to zero.
        Right now only changes topographical data. Also, the original data can be obtained again via
        GDEFMeasurement.values_original.

        :param correction_type: select type of background correction
        :param keep_offset: If True (default) keeps average offset, otherwise average offset is reduced to 0.
        :return: None
        """
        if not self.settings.source_channel == 11:  # only correct topography data
            return
        self.values = correct_background(self.values_original,
                                         correction_type=correction_type,
                                         keep_offset=keep_offset)
        self.background_correction_type = correction_type
 def test_none(self, correction):
     result = correct_background(None, correction, keep_offset=False)
     assert result is None