本文整理汇总了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)