當前位置: 首頁>>代碼示例>>Python>>正文


Python component.Parameter類代碼示例

本文整理匯總了Python中hyperspy.component.Parameter的典型用法代碼示例。如果您正苦於以下問題:Python Parameter類的具體用法?Python Parameter怎麽用?Python Parameter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Parameter類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_invalid_name

 def test_invalid_name(self):
     d = self.par.as_dictionary()
     d['_id_name'] = 'otherone'
     p = Parameter()
     p._id_name = 'newone'
     with pytest.raises(ValueError):
         _id = p._load_dictionary(d)
開發者ID:mwalls,項目名稱:hyperspy,代碼行數:7,代碼來源:test_model_as_dictionary.py

示例2: setUp

class TestParameterTwin:

    def setUp(self):
        self.p1 = Parameter()
        self.p2 = Parameter()

    def test_slave_fixed(self):
        assert_true(self.p2.free)
        self.p2.twin = self.p1
        assert_false(self.p2.free)

    def test_twin_value(self):
        self.p2.twin = self.p1
        self.p1.value = 3
        assert_equal(self.p1.value, self.p2.value)
        self.p2.twin = None
        assert_equal(self.p1.value, self.p2.value)
        self.p1.value = 2
        assert_equal(3, self.p2.value)

    def test_twin_value_bounded(self):
        self.p2.bmax = 2
        self.p2.ext_bounded = True
        self.p2.twin = self.p1
        self.p1.value = 3
        assert_equal(self.p1.value, self.p2.value)
        self.p2.twin = None
        assert_equal(self.p2.value, self.p2.bmax)

    def test_twin_function(self):
        self.p2.twin_function = lambda x: x + 2
        self.p2.twin_inverse_function = lambda x: x - 2
        self.p2.twin = self.p1
        assert_equal(self.p1.value, self.p2.value - 2)
        self.p2.value = 10
        assert_equal(self.p1.value, 8)

    def test_inherit_connections(self):
        dummy = Dummy()
        self.p2.connect(dummy.add_one)
        self.p2.twin = self.p1
        self.p1.value = 2
        assert_equal(dummy.value, 2)
        # The next line calls add_one -> value = 3
        self.p2.twin = None
        # Next one shouldn't call add_one -> value = 3
        self.p1.value = 4
        assert_equal(dummy.value, 3)
        self.p2.value = 10
        assert_equal(dummy.value, 4)
開發者ID:gdonval,項目名稱:hyperspy,代碼行數:50,代碼來源:test_parameter.py

示例3: test_load_dictionary

    def test_load_dictionary(self):
        d = self.par.as_dictionary()
        p = Parameter()
        p._id_name = 'newone'
        _id = p._load_dictionary(d)

        nt.assert_equal(_id, id(self.par))
        nt.assert_true(p.name == self.par.name)
        nt.assert_true(p._id_name == self.par._id_name)
        nt.assert_true(p.map['values'][0] == 1)
        nt.assert_true(p.map['std'][0] == 0.1)
        nt.assert_true(p.map['is_set'][0])
        nt.assert_true(p.value == self.par.value)
        nt.assert_true(p.std == self.par.std)
        nt.assert_true(p.free == self.par.free)
        nt.assert_true(p._bounds == self.par._bounds)

        rn = np.random.random()
        nt.assert_equal(p.twin_function(rn), self.par.twin_function(rn))
        nt.assert_equal(
            p.twin_inverse_function(rn),
            self.par.twin_inverse_function(rn))
開發者ID:temcode,項目名稱:hyperspy,代碼行數:22,代碼來源:test_model_as_dictionary.py

示例4: setup_method

 def setup_method(self, method):
     self.par = Parameter()
     self.par.name = 'asd'
     self.par._id_name = 'newone'
     self.par.twin_function_expr = "x * x"
     self.par.twin_inverse_function_expr = "x * x + 1"
     self.par._axes_manager = DummyAxesManager()
     self.par._create_array()
     self.par.value = 1
     self.par.std = 0.1
     self.par.store_current_value_in_array()
     self.par.ext_bounded = False
     self.par.ext_force_positive = False
開發者ID:mwalls,項目名稱:hyperspy,代碼行數:13,代碼來源:test_model_as_dictionary.py

示例5: test_load_dictionary

    def test_load_dictionary(self):
        d = self.par.as_dictionary()
        p = Parameter()
        p._id_name = 'newone'
        _id = p._load_dictionary(d)

        assert _id == id(self.par)
        assert p.name == self.par.name
        assert p._id_name == self.par._id_name
        np.testing.assert_equal(p.map['values'][0], 1)
        np.testing.assert_equal(p.map['std'][0], 0.1)
        assert p.map['is_set'][0]
        np.testing.assert_equal(p.value, self.par.value)
        np.testing.assert_equal(p.std, self.par.std)
        np.testing.assert_equal(p.free, self.par.free)
        np.testing.assert_equal(p._bounds, self.par._bounds)

        rn = np.random.random()
        np.testing.assert_equal(
            p.twin_function(rn),
            self.par.twin_function(rn))
        np.testing.assert_equal(
            p.twin_inverse_function(rn),
            self.par.twin_inverse_function(rn))
開發者ID:mwalls,項目名稱:hyperspy,代碼行數:24,代碼來源:test_model_as_dictionary.py

示例6: setUp

    def setUp(self):
        self.par = Parameter()
        self.par.name = 'asd'
        self.par._id_name = 'newone'

        def ft(x):
            return x * x

        def fit(x):
            return x * x + 1
        self.par.twin_function = ft
        self.par.twin_inverse_function = fit
        self.par._axes_manager = DummyAxesManager()
        self.par._create_array()
        self.par.value = 1
        self.par.std = 0.1
        self.par.store_current_value_in_array()
        self.par.ext_bounded = False
        self.par.ext_force_positive = False
開發者ID:AakashV,項目名稱:hyperspy,代碼行數:19,代碼來源:test_model_as_dictionary.py

示例7: setUp

 def setUp(self):
     self.par = Parameter()
開發者ID:jhemmelg,項目名稱:hyperspy,代碼行數:2,代碼來源:test_parameter.py

示例8: test_invalid_name

 def test_invalid_name(self):
     d = self.par.as_dictionary()
     d['_id_name'] = 'otherone'
     p = Parameter()
     p._id_name = 'newone'
     _id = p._load_dictionary(d)
開發者ID:AakashV,項目名稱:hyperspy,代碼行數:6,代碼來源:test_model_as_dictionary.py


注:本文中的hyperspy.component.Parameter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。