本文整理匯總了Python中hyperspy.component.Parameter.connect方法的典型用法代碼示例。如果您正苦於以下問題:Python Parameter.connect方法的具體用法?Python Parameter.connect怎麽用?Python Parameter.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類hyperspy.component.Parameter
的用法示例。
在下文中一共展示了Parameter.connect方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setUp
# 需要導入模塊: from hyperspy.component import Parameter [as 別名]
# 或者: from hyperspy.component.Parameter import connect [as 別名]
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)