Exemple #1
0
    def test_setting_info_dict(self):

        h = np.array((0, 1, 2, 3, 4))
        t = UniformLineScan(h, 4)

        assert t.info == {}

        t = UniformLineScan(h, 4, info=dict(unit='A'))
        assert t.info['unit'] == 'A'

        #
        # This info should be inherited in the pipeline
        #
        st = t.scale(2)
        assert st.info['unit'] == 'A'

        #
        # It should be also possible to set the info
        #
        st = t.scale(2, info=dict(unit='B'))
        assert st.info['unit'] == 'B'

        #
        # Again the info should be passed
        #
        dt = st.detrend(detrend_mode='center')
        assert dt.info['unit'] == 'B'

        #
        # Alternatively, it can be changed
        #
        dt = st.detrend(detrend_mode='center', info=dict(unit='C'))
        assert dt.info['unit'] == 'C'
    def test_init_with_lists_calling_scale_and_detrend(self):

        t = UniformLineScan([2, 4, 6, 8],
                            4)  # initialize with list instead of arrays

        # the following commands should be possible without errors
        st = t.scale(1)
        st.detrend(detrend_mode='center')
    def test_setting_info_dict(self):

        h = np.array((0, 1, 2, 3, 4))
        t = UniformLineScan(h, 4)

        assert t.info == {}

        with pytest.deprecated_call():
            t = UniformLineScan(h, 4, info=dict(unit='A'))
        t = UniformLineScan(h, 4, unit='A')
        with pytest.deprecated_call():
            assert t.info['unit'] == 'A'

        #
        # This info should be inherited in the pipeline
        #
        st = t.scale(2)
        with pytest.deprecated_call():
            assert st.info['unit'] == 'A'

        #
        # It should be also possible to set the info
        #
        with pytest.deprecated_call():
            st = t.scale(2, info=dict(unit='B'))
        st = t.scale(2, 2, unit='B')
        with pytest.deprecated_call():
            assert st.info['unit'] == 'B'

        #
        # Again the info should be passed
        #
        dt = st.detrend(detrend_mode='center')
        with pytest.deprecated_call():
            assert dt.info['unit'] == 'B'

        #
        # It can no longer be changed in detrend (you need to use scale)
        #
        with pytest.deprecated_call():
            dt = st.detrend(detrend_mode='center', info=dict(unit='C'))
    def test_attribute_error(self):

        h = np.array((0, 1, 2, 3, 4))
        t = UniformLineScan(h, 4)

        with self.assertRaises(AttributeError):
            t.height_scale_factor
        # a scaled line scan has a scale_factor
        self.assertEqual(t.scale(1).height_scale_factor, 1)

        #
        # This should also work after the topography has been pickled
        #
        pt = pickle.dumps(t)
        t2 = pickle.loads(pt)

        with self.assertRaises(AttributeError):
            t2.height_scale_factor
        # a scaled line scan has a scale_factor
        self.assertEqual(t2.scale(1).height_scale_factor, 1)