本文整理汇总了Python中hyperspy.component.Parameter.store_current_value_in_array方法的典型用法代码示例。如果您正苦于以下问题:Python Parameter.store_current_value_in_array方法的具体用法?Python Parameter.store_current_value_in_array怎么用?Python Parameter.store_current_value_in_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hyperspy.component.Parameter
的用法示例。
在下文中一共展示了Parameter.store_current_value_in_array方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from hyperspy.component import Parameter [as 别名]
# 或者: from hyperspy.component.Parameter import store_current_value_in_array [as 别名]
class TestParameterLen1:
def setUp(self):
self.par = Parameter()
def test_set_value(self):
self.par.value = 2
assert_equal(self.par.value, 2)
@raises(ValueError)
def test_set_value_wrong_length(self):
self.par.value = (2, 2)
def test_set_value_bounded(self):
self.par.bmin = 1
self.par.bmax = 3
self.par.ext_bounded = True
assert_equal(self.par.value, 1)
self.par.value = 1.5
assert_equal(self.par.value, 1.5)
self.par.value = 0.5
assert_equal(self.par.value, 1)
self.par.value = 4
assert_equal(self.par.value, 3)
self.par.bmax = 2
assert_equal(self.par.value, 2)
self.par.value = 1.5
self.par.bmin = 1.6
assert_equal(self.par.value, 1.6)
def test_ext_force_positive(self):
self.par.ext_bounded = True
self.par.ext_force_positive = True
self.par.value = -1.5
assert_equal(self.par.value, 1.5)
self.par.bmax = 2
self.par.value = -3
assert_equal(self.par.value, 2)
def test_number_of_elements(self):
assert_equal(len(self.par), 1)
def test_default_value(self):
assert_equal(self.par.value, 0)
def test_connect_disconnect(self):
dummy = Dummy()
self.par.events.value_changed.connect(dummy.add_one, [])
self.par.value = 1
assert_equal(dummy.value, 2)
# Setting the same value should not call the connected functions
self.par.value = 1
assert_equal(dummy.value, 2)
# After disconnecting dummy.value should not change
self.par.events.value_changed.disconnect(dummy.add_one)
self.par.value = 2
assert_equal(dummy.value, 2)
def test_map_size0(self):
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()
assert_equal(self.par.map['values'][0], 1)
assert_true(self.par.map['is_set'][0])
assert_equal(self.par.map['std'][0], 0.1)
def test_map_size1(self):
self.par._axes_manager = DummyAxesManager()
self.par._axes_manager.navigation_shape = [1, ]
self.par._create_array()
self.par.value = 1
self.par.std = 0.1
self.par.store_current_value_in_array()
assert_equal(self.par.map['values'][0], 1)
assert_true(self.par.map['is_set'][0])
assert_equal(self.par.map['std'][0], 0.1)
def test_map_size2(self):
self.par._axes_manager = DummyAxesManager()
self.par._axes_manager.navigation_shape = [2, ]
self.par._axes_manager.indices = (1,)
self.par._create_array()
self.par.value = 1
self.par.std = 0.1
self.par.store_current_value_in_array()
assert_equal(self.par.map['values'][1], 1)
assert_true(self.par.map['is_set'][1])
assert_equal(self.par.map['std'][1], 0.1)
示例2: setUp
# 需要导入模块: from hyperspy.component import Parameter [as 别名]
# 或者: from hyperspy.component.Parameter import store_current_value_in_array [as 别名]
class TestParameterDictionary:
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
def test_to_dictionary(self):
d = self.par.as_dictionary()
nt.assert_equal(d['name'], self.par.name)
nt.assert_equal(d['_id_name'], self.par._id_name)
np.testing.assert_equal(d['map']['values'][0], 1)
np.testing.assert_equal(d['map']['std'][0], 0.1)
nt.assert_true(d['map']['is_set'][0])
np.testing.assert_equal(d['value'], self.par.value)
np.testing.assert_equal(d['std'], self.par.std)
nt.assert_is(d['free'], self.par.free)
nt.assert_equal(d['self'], id(self.par))
np.testing.assert_equal(d['_bounds'], self.par._bounds)
nt.assert_is(d['ext_bounded'], self.par.ext_bounded)
nt.assert_is(
d['ext_force_positive'], self.par.ext_force_positive)
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_equal(p.name, self.par.name)
nt.assert_equal(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)
nt.assert_true(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))
@nt.raises(ValueError)
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)
示例3: setup_method
# 需要导入模块: from hyperspy.component import Parameter [as 别名]
# 或者: from hyperspy.component.Parameter import store_current_value_in_array [as 别名]
class TestParameterDictionary:
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
def test_to_dictionary(self):
d = self.par.as_dictionary()
assert d['name'] == self.par.name
assert d['_id_name'] == self.par._id_name
np.testing.assert_equal(d['map']['values'][0], 1)
np.testing.assert_equal(d['map']['std'][0], 0.1)
assert d['map']['is_set'][0]
np.testing.assert_equal(d['value'], self.par.value)
np.testing.assert_equal(d['std'], self.par.std)
assert d['free'] is self.par.free
assert d['self'] == id(self.par)
np.testing.assert_equal(d['_bounds'], self.par._bounds)
assert d['ext_bounded'] is self.par.ext_bounded
assert (
d['ext_force_positive'] is self.par.ext_force_positive)
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))
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)