当前位置: 首页>>代码示例>>Python>>正文


Python Signal.deepcopy方法代码示例

本文整理汇总了Python中hyperspy.signal.Signal.deepcopy方法的典型用法代码示例。如果您正苦于以下问题:Python Signal.deepcopy方法的具体用法?Python Signal.deepcopy怎么用?Python Signal.deepcopy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hyperspy.signal.Signal的用法示例。


在下文中一共展示了Signal.deepcopy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from hyperspy.signal import Signal [as 别名]
# 或者: from hyperspy.signal.Signal import deepcopy [as 别名]
class Test2D:
    def setUp(self):
        self.signal = Signal(np.arange(5*10).reshape(5,10))
        self.signal.axes_manager[0].name = "x"
        self.signal.axes_manager[1].name = "E"
        self.signal.axes_manager[0].scale = 0.5
        self.signal.mapped_parameters.set_item('splitting.axis', 0)
        self.signal.mapped_parameters.set_item(
                                        'splitting.step_sizes',[2,2])
        self.data = self.signal.data.copy()

        
    def test_axis_by_str(self):
        s1 = self.signal.deepcopy()
        s2 = self.signal.deepcopy()
        s1.crop(0, 2,4)
        s2.crop("x", 2, 4)
        assert_true((s1.data==s2.data).all())
        
    def test_crop_int(self):
        s = self.signal
        d = self.data
        s.crop(0, 2,4)
        assert_true((s.data==d[2:4,:]).all())
        
    def test_crop_float(self):
        s = self.signal
        d = self.data
        s.crop(0, 2, 2.)
        assert_true((s.data==d[2:4,:]).all())
        
    def test_split_axis0(self):
        result = self.signal.split(0,2)
        assert_true(len(result) == 2)
        assert_true((result[0].data == self.data[:2,:]).all())
        assert_true((result[1].data == self.data[2:4,:]).all())
    
    def test_split_axis1(self):
        result = self.signal.split(1,2)
        assert_true(len(result) == 2)
        assert_true((result[0].data == self.data[:,:5]).all())
        assert_true((result[1].data == self.data[:,5:]).all())
        
    def test_split_axisE(self):
        result = self.signal.split("E",2)
        assert_true(len(result) == 2)
        assert_true((result[0].data == self.data[:,:5]).all())
        assert_true((result[1].data == self.data[:,5:]).all())
        
    def test_split_default(self):
        result = self.signal.split()
        assert_true(len(result) == 2)
        assert_true((result[0].data == self.data[:2,:]).all())
        assert_true((result[1].data == self.data[2:4,:]).all())
    
    def test_histogram(self):
        result = self.signal.get_histogram(3)
        assert_true(isinstance(result,signals.Spectrum))
        assert_true((result.data==np.array([17, 16, 17])).all())
开发者ID:Emilieringe,项目名称:hyperspy,代码行数:61,代码来源:test_tools.py

示例2: setUp

# 需要导入模块: from hyperspy.signal import Signal [as 别名]
# 或者: from hyperspy.signal.Signal import deepcopy [as 别名]
class TestSignalVarianceFolding:
    def setUp(self):
        self.s = Signal(np.empty((2, 3, 4, 5)))
        self.s.axes_manager.set_signal_dimension(2)
        self.s.estimate_poissonian_noise_variance()

    def test_unfold_navigation(self):
        s = self.s.deepcopy()
        s.unfold_navigation_space()
        meta_am = s.metadata.Signal.Noise_properties.variance.axes_manager
        nose.tools.assert_equal(meta_am.navigation_shape, (self.s.axes_manager.navigation_size,))

    def test_unfold_signal(self):
        s = self.s.deepcopy()
        s.unfold_signal_space()
        meta_am = s.metadata.Signal.Noise_properties.variance.axes_manager
        nose.tools.assert_equal(meta_am.signal_shape, (self.s.axes_manager.signal_size,))
开发者ID:lu-chi,项目名称:hyperspy,代码行数:19,代码来源:test_folding.py

示例3: setUp

# 需要导入模块: from hyperspy.signal import Signal [as 别名]
# 或者: from hyperspy.signal.Signal import deepcopy [as 别名]
class Test2D:

    def setUp(self):
        self.signal = Signal(np.arange(5 * 10).reshape(5, 10))
        self.signal.axes_manager[0].name = "x"
        self.signal.axes_manager[1].name = "E"
        self.signal.axes_manager[0].scale = 0.5
        self.data = self.signal.data.copy()

    def test_axis_by_str(self):
        s1 = self.signal.deepcopy()
        s2 = self.signal.deepcopy()
        s1.crop(0, 2, 4)
        s2.crop("x", 2, 4)
        assert_true((s1.data == s2.data).all())

    def test_crop_int(self):
        s = self.signal
        d = self.data
        s.crop(0, 2, 4)
        assert_true((s.data == d[2:4, :]).all())

    def test_crop_float(self):
        s = self.signal
        d = self.data
        s.crop(0, 2, 2.)
        assert_true((s.data == d[2:4, :]).all())

    def test_split_axis0(self):
        result = self.signal.split(0, 2)
        assert_true(len(result) == 2)
        assert_true((result[0].data == self.data[:2, :]).all())
        assert_true((result[1].data == self.data[2:4, :]).all())

    def test_split_axis1(self):
        result = self.signal.split(1, 2)
        assert_true(len(result) == 2)
        assert_true((result[0].data == self.data[:, :5]).all())
        assert_true((result[1].data == self.data[:, 5:]).all())

    def test_split_axisE(self):
        result = self.signal.split("E", 2)
        assert_true(len(result) == 2)
        assert_true((result[0].data == self.data[:, :5]).all())
        assert_true((result[1].data == self.data[:, 5:]).all())

    def test_split_default(self):
        result = self.signal.split()
        assert_true(len(result) == 5)
        assert_true((result[0].data == self.data[0]).all())

    def test_histogram(self):
        result = self.signal.get_histogram(3)
        assert_true(isinstance(result, signals.Spectrum))
        assert_true((result.data == np.array([17, 16, 17])).all())

    def test_estimate_poissonian_noise_copy_data(self):
        self.signal.estimate_poissonian_noise_variance()
        assert_true(self.signal.metadata.Signal.Noise_properties.variance.data
                    is not self.signal.data)

    def test_estimate_poissonian_noise_noarg(self):
        self.signal.estimate_poissonian_noise_variance()
        assert_true(
            (self.signal.metadata.Signal.Noise_properties.variance.data ==
             self.signal.data).all())

    def test_estimate_poissonian_noise_with_args(self):
        self.signal.estimate_poissonian_noise_variance(
            expected_value=self.signal,
            gain_factor=2,
            gain_offset=1,
            correlation_factor=0.5)
        assert_true(
            (self.signal.metadata.Signal.Noise_properties.variance.data ==
             (self.signal.data * 2 + 1) * 0.5).all())
开发者ID:LewysJones,项目名称:hyperspy,代码行数:78,代码来源:test_tools.py

示例4: setUp

# 需要导入模块: from hyperspy.signal import Signal [as 别名]
# 或者: from hyperspy.signal.Signal import deepcopy [as 别名]
class Test2D:

    def setUp(self):
        self.signal = Signal(np.arange(5 * 10).reshape(5, 10))
        self.signal.axes_manager[0].name = "x"
        self.signal.axes_manager[1].name = "E"
        self.signal.axes_manager[0].scale = 0.5
        self.data = self.signal.data.copy()

    def test_sum_x(self):
        s = self.signal.sum("x")
        np.testing.assert_array_equal(self.signal.data.sum(0), s.data)
        nt.assert_equal(s.data.ndim, 1)
        nt.assert_equal(s.axes_manager.navigation_dimension, 0)

    def test_sum_x_E(self):
        s = self.signal.sum(("x", "E"))
        _verify_test_sum_x_E(self, s)
        s = self.signal.sum((0, "E"))
        _verify_test_sum_x_E(self, s)
        s = self.signal.sum((self.signal.axes_manager[0], "E"))
        _verify_test_sum_x_E(self, s)
        s = self.signal.sum("x").sum("E")
        _verify_test_sum_x_E(self, s)

    def test_axis_by_str(self):
        m = mock.Mock()
        s1 = self.signal.deepcopy()
        s1.events.data_changed.connect(m.data_changed)
        s2 = self.signal.deepcopy()
        s1.crop(0, 2, 4)
        nt.assert_true(m.data_changed.called)
        s2.crop("x", 2, 4)
        nt.assert_true((s1.data == s2.data).all())

    def test_crop_int(self):
        s = self.signal
        d = self.data
        s.crop(0, 2, 4)
        nt.assert_true((s.data == d[2:4, :]).all())

    def test_crop_float(self):
        s = self.signal
        d = self.data
        s.crop(0, 2, 2.)
        nt.assert_true((s.data == d[2:4, :]).all())

    def test_split_axis0(self):
        result = self.signal.split(0, 2)
        nt.assert_true(len(result) == 2)
        nt.assert_true((result[0].data == self.data[:2, :]).all())
        nt.assert_true((result[1].data == self.data[2:4, :]).all())

    def test_split_axis1(self):
        result = self.signal.split(1, 2)
        nt.assert_true(len(result) == 2)
        nt.assert_true((result[0].data == self.data[:, :5]).all())
        nt.assert_true((result[1].data == self.data[:, 5:]).all())

    def test_split_axisE(self):
        result = self.signal.split("E", 2)
        nt.assert_true(len(result) == 2)
        nt.assert_true((result[0].data == self.data[:, :5]).all())
        nt.assert_true((result[1].data == self.data[:, 5:]).all())

    def test_split_default(self):
        result = self.signal.split()
        nt.assert_true(len(result) == 5)
        nt.assert_true((result[0].data == self.data[0]).all())

    def test_histogram(self):
        result = self.signal.get_histogram(3)
        nt.assert_true(isinstance(result, signals.Spectrum))
        nt.assert_true((result.data == np.array([17, 16, 17])).all())
        nt.assert_true(result.metadata.Signal.binned)

    def test_estimate_poissonian_noise_copy_data(self):
        self.signal.estimate_poissonian_noise_variance()
        variance = self.signal.metadata.Signal.Noise_properties.variance
        nt.assert_true(
            variance.data is not self.signal.data)

    def test_estimate_poissonian_noise_noarg(self):
        self.signal.estimate_poissonian_noise_variance()
        variance = self.signal.metadata.Signal.Noise_properties.variance
        nt.assert_true((variance.data == self.signal.data).all())

    def test_estimate_poissonian_noise_with_args(self):
        self.signal.estimate_poissonian_noise_variance(
            expected_value=self.signal,
            gain_factor=2,
            gain_offset=1,
            correlation_factor=0.5)
        variance = self.signal.metadata.Signal.Noise_properties.variance
        nt.assert_true(
            (variance.data == (self.signal.data * 2 + 1) * 0.5).all())

    def test_unfold_image(self):
        s = self.signal
        s.axes_manager.set_signal_dimension(2)
#.........这里部分代码省略.........
开发者ID:temcode,项目名称:hyperspy,代码行数:103,代码来源:test_tools.py

示例5: setUp

# 需要导入模块: from hyperspy.signal import Signal [as 别名]
# 或者: from hyperspy.signal.Signal import deepcopy [as 别名]
class TestSignalFolding:

    def setUp(self):
        self.s = Signal(np.empty((2, 3, 4, 5)))
        self.s.axes_manager.set_signal_dimension(2)

    def test_unfold_navigation(self):
        s = self.s.deepcopy()
        s.unfold_navigation_space()
        nt.assert_equal(s.axes_manager.navigation_shape,
                        (self.s.axes_manager.navigation_size,))

    def test_unfold_signal(self):
        s = self.s.deepcopy()
        s.unfold_signal_space()
        nt.assert_equal(s.axes_manager.signal_shape,
                        (self.s.axes_manager.signal_size,))

    def test_unfolded_repr(self):
        self.s.unfold()
        nt.assert_true("unfolded" in repr(self.s))

    def test_unfold_navigation_by_keyword(self):
        s = self.s.deepcopy()
        s.unfold(unfold_navigation=True, unfold_signal=False)
        nt.assert_equal(s.axes_manager.navigation_shape,
                        (self.s.axes_manager.navigation_size,))

    def test_unfold_signal_by_keyword(self):
        s = self.s.deepcopy()
        s.unfold(unfold_navigation=False, unfold_signal=True)
        nt.assert_equal(s.axes_manager.signal_shape,
                        (self.s.axes_manager.signal_size,))

    def test_unfold_nothing_by_keyword(self):
        s = self.s.deepcopy()
        s.unfold(unfold_navigation=False, unfold_signal=False)
        nt.assert_equal(s.data.shape, self.s.data.shape)

    def test_unfold_full_by_keyword(self):
        s = self.s.deepcopy()
        s.unfold(unfold_navigation=True, unfold_signal=True)
        nt.assert_equal(s.axes_manager.signal_shape,
                        (self.s.axes_manager.signal_size,))
        nt.assert_equal(s.axes_manager.navigation_shape,
                        (self.s.axes_manager.navigation_size,))

    def test_unfolded_context_manager(self):
        s = self.s.deepcopy()
        with s.unfolded():
            # Check that both spaces unfold as expected
            nt.assert_equal(s.axes_manager.navigation_shape,
                            (self.s.axes_manager.navigation_size,))
            nt.assert_equal(s.axes_manager.signal_shape,
                            (self.s.axes_manager.signal_size,))
        # Check that it folds back as expected
        nt.assert_equal(s.axes_manager.navigation_shape,
                        self.s.axes_manager.navigation_shape)
        nt.assert_equal(s.axes_manager.signal_shape,
                        self.s.axes_manager.signal_shape)

    def test_unfolded_full_by_keywords(self):
        s = self.s.deepcopy()
        with s.unfolded(unfold_navigation=True, unfold_signal=True) as folded:
            nt.assert_true(folded)
            # Check that both spaces unfold as expected
            nt.assert_equal(s.axes_manager.navigation_shape,
                            (self.s.axes_manager.navigation_size,))
            nt.assert_equal(s.axes_manager.signal_shape,
                            (self.s.axes_manager.signal_size,))
        # Check that it folds back as expected
        nt.assert_equal(s.axes_manager.navigation_shape,
                        self.s.axes_manager.navigation_shape)
        nt.assert_equal(s.axes_manager.signal_shape,
                        self.s.axes_manager.signal_shape)

    def test_unfolded_navigation_by_keyword(self):
        s = self.s.deepcopy()
        with s.unfolded(unfold_navigation=True, unfold_signal=False) as folded:
            nt.assert_true(folded)
            # Check that only navigation space unfolded
            nt.assert_equal(s.axes_manager.navigation_shape,
                            (self.s.axes_manager.navigation_size,))
            nt.assert_equal(s.axes_manager.signal_shape,
                            self.s.axes_manager.signal_shape)
        # Check that it folds back as expected
        nt.assert_equal(s.axes_manager.navigation_shape,
                        self.s.axes_manager.navigation_shape)
        nt.assert_equal(s.axes_manager.signal_shape,
                        self.s.axes_manager.signal_shape)

    def test_unfolded_signal_by_keyword(self):
        s = self.s.deepcopy()
        with s.unfolded(unfold_navigation=False, unfold_signal=True) as folded:
            nt.assert_true(folded)
            # Check that only signal space unfolded
            nt.assert_equal(s.axes_manager.navigation_shape,
                            self.s.axes_manager.navigation_shape)
            nt.assert_equal(s.axes_manager.signal_shape,
                            (self.s.axes_manager.signal_size,))
#.........这里部分代码省略.........
开发者ID:jerevon,项目名称:hyperspy,代码行数:103,代码来源:test_folding.py


注:本文中的hyperspy.signal.Signal.deepcopy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。