本文整理汇总了Python中hyperspy.signal.Signal.as_image方法的典型用法代码示例。如果您正苦于以下问题:Python Signal.as_image方法的具体用法?Python Signal.as_image怎么用?Python Signal.as_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hyperspy.signal.Signal
的用法示例。
在下文中一共展示了Signal.as_image方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from hyperspy.signal import Signal [as 别名]
# 或者: from hyperspy.signal.Signal import as_image [as 别名]
class Test2d:
def setUp(self):
self.s = Signal(np.random.random((2, 3)))
def test_as_image_T(self):
assert_true(
self.s.data.T.shape == self.s.as_image((0, 1)).data.shape)
def test_as_image(self):
assert_true(
self.s.data.shape == self.s.as_image((1, 0)).data.shape)
def test_as_spectrum_T(self):
assert_true(
self.s.data.T.shape == self.s.as_spectrum(0).data.shape)
def test_as_spectrum(self):
assert_true(
self.s.data.shape == self.s.as_spectrum(1).data.shape)
def test_s2EELS2im2s(self):
s = self.s.as_spectrum(0)
s.set_signal_type("EELS")
im = s.as_image((1, 0))
assert_equal(im.metadata.Signal.signal_type, "EELS")
s = im.as_spectrum(0)
assert_equal(s.metadata.Signal.signal_type, "EELS")
assert_true(isinstance(s, signals.EELSSpectrum))
示例2: setUp
# 需要导入模块: from hyperspy.signal import Signal [as 别名]
# 或者: from hyperspy.signal.Signal import as_image [as 别名]
class Test3D_Navigate_1:
def setUp(self):
self.signal = Signal(np.arange(24).reshape((2, 3, 4)))
self.data = self.signal.data.copy()
self.signal.axes_manager._axes[0].navigate = False
self.signal.axes_manager._axes[1].navigate = True
self.signal.axes_manager._axes[2].navigate = False
def test_1px_navigation_indexer_slice(self):
s = self.signal.inav[1:2]
d = self.data[:, 1:2]
np.testing.assert_array_equal(s.data, d)
assert_equal(s.axes_manager._axes[1].offset, 1)
assert_equal(s.axes_manager._axes[1].size, 1)
assert_equal(s.axes_manager._axes[1].scale,
self.signal.axes_manager._axes[1].scale)
def test_1px_signal_indexer_slice(self):
s = self.signal.isig[1:2]
d = self.data[:, :, 1:2]
np.testing.assert_array_equal(s.data, d)
assert_equal(s.axes_manager.signal_axes[0].offset, 1)
assert_equal(s.axes_manager.signal_axes[0].size, 1)
assert_equal(s.axes_manager.signal_axes[0].scale,
self.signal.axes_manager.signal_axes[0].scale)
def test_subclass_assignment(self):
im = self.signal.as_image((-2, -1))
assert_true(isinstance(im.isig[0], signals.Spectrum))
示例3: setUp
# 需要导入模块: from hyperspy.signal import Signal [as 别名]
# 或者: from hyperspy.signal.Signal import as_image [as 别名]
class Test1d:
def setUp(self):
self.s = Signal(np.arange(2))
@nt.raises(DataDimensionError)
def test_as_image(self):
self.s.as_image((0, 1))
def test_as_spectrum(self):
np.testing.assert_array_equal(self.s.data, self.s.as_spectrum(0).data)
def test_set_EELS(self):
s = self.s.as_spectrum(0)
s.set_signal_type("EELS")
nt.assert_equal(s.metadata.Signal.signal_type, "EELS")
nt.assert_is_instance(s, signals.EELSSpectrum)
示例4: Test1d
# 需要导入模块: from hyperspy.signal import Signal [as 别名]
# 或者: from hyperspy.signal.Signal import as_image [as 别名]
class Test1d():
def setUp(self):
self.s = Signal(np.arange(2))
@raises(DataDimensionError)
def test_as_image(self):
assert_true((self.s.data == self.s.as_image((0,1)).data).all())
def test_as_spectrum(self):
assert_true((self.s.data == self.s.as_spectrum(0).data).all())
def test_set_EELS(self):
s = self.s.as_spectrum(0)
s.set_signal_type("EELS")
assert_equal(s.mapped_parameters.signal_type, "EELS")
assert_true(isinstance(s, signals.EELSSpectrum))
示例5: setUp
# 需要导入模块: from hyperspy.signal import Signal [as 别名]
# 或者: from hyperspy.signal.Signal import as_image [as 别名]
class TestBinaryOperators:
def setUp(self):
self.s1 = Signal(np.ones((2, 3)))
self.s2 = Signal(np.ones((2, 3)))
self.s2.data *= 2
def test_sum_same_shape_signals(self):
s = self.s1 + self.s2
assert_array_equal(s.data, self.s1.data * 3)
def test_sum_in_place_same_shape_signals(self):
s1 = self.s1
self.s1 += self.s2
assert_array_equal(self.s1.data, np.ones((2, 3)) * 3)
nt.assert_is(s1, self.s1)
def test_sum_same_shape_signals_not_aligned(self):
s1 = self.s1
s2 = Signal(2 * np.ones((3, 2)))
s1.axes_manager._axes[0].navigate = False
s1.axes_manager._axes[1].navigate = True
s2.axes_manager._axes[1].navigate = False
s2.axes_manager._axes[0].navigate = True
s12 = s1 + s2
s21 = s2 + s1
assert_array_equal(s12.data, np.ones((3, 2)) * 3)
assert_array_equal(s21.data, s12.data)
def test_sum_in_place_same_shape_signals_not_aligned(self):
s1 = self.s1
s2 = Signal(2 * np.ones((3, 2)))
s1c = s1
s2c = s2
s1.axes_manager._axes[0].navigate = False
s1.axes_manager._axes[1].navigate = True
s2.axes_manager._axes[1].navigate = False
s2.axes_manager._axes[0].navigate = True
s1 += s2
assert_array_equal(s1.data, np.ones((3, 2)) * 3)
s2 += s2
assert_array_equal(s2.data, np.ones((3, 2)) * 4)
nt.assert_is(s1, s1c)
nt.assert_is(s2, s2c)
@nt.raises(ValueError)
def test_sum_wrong_shape(self):
s1 = self.s1
s2 = Signal(np.ones((3, 3)))
s1 + s2
def test_broadcast_missing_sig_and_nav(self):
s1 = self.s1
s2 = self.s2.as_image((1, 0)) # (|3, 2)
s1.axes_manager.set_signal_dimension(0) # (3, 2|)
s = s1 + s2
assert_array_equal(s.data, 3 * np.ones((2, 3, 2, 3)))
nt.assert_equal(s.metadata.Signal.record_by, "image")
def test_broadcast_missing_sig(self):
s1 = self.s1
s2 = self.s2
s1.axes_manager.set_signal_dimension(0) # (3, 2|)
s2.axes_manager._axes[1].navigate = True
s2.axes_manager._axes[0].navigate = False # (3| 2)
s12 = s1 + s2 # (3, 2| 2)
s21 = s2 + s1
assert_array_equal(s12.data, 3 * np.ones((2, 3, 2)))
assert_array_equal(s21.data, 3 * np.ones((2, 3, 2)))
@nt.raises(ValueError)
def test_broadcast_in_place_missing_sig_wrong(self):
s1 = self.s1
s2 = self.s2
s1.axes_manager.set_signal_dimension(0) # (3, 2|)
s2.axes_manager._axes[1].navigate = True
s2.axes_manager._axes[0].navigate = False # (3| 2)
s1 += s2
def test_broadcast_in_place(self):
s1 = self.s1
s1.axes_manager.set_signal_dimension(1) # (3|2)
s2 = Signal(np.ones((4, 2, 4, 3)))
s2c = s2
s2.axes_manager.set_signal_dimension(2) # (3, 4| 2, 4)
print(s2)
print(s1)
s2 += s1
assert_array_equal(s2.data, 2 * np.ones((4, 2, 4, 3)))
nt.assert_is(s2, s2c)
def test_equal_naxes_diff_shape(self):
s32 = self.s1 # (3| 2)
s31 = Signal(np.ones((1, 3)))
s12 = Signal(np.ones((2, 1)))
assert_array_equal((s32 + s31).data, s32.data + 1)
assert_array_equal((s32 + s12).data, s32.data + 1)