当前位置: 首页>>代码示例>>Python>>正文


Python signal.Signal类代码示例

本文整理汇总了Python中hyperspy.signal.Signal的典型用法代码示例。如果您正苦于以下问题:Python Signal类的具体用法?Python Signal怎么用?Python Signal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Signal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_signal_iterator

def test_signal_iterator():
    s = Signal(np.arange(3).reshape((3, 1)))
    assert_equal(s.next().data[0], 0)
    # If the following fails it can be because the iteration index was not
    # restarted
    for i, signal in enumerate(s):
        assert_equal(i, signal.data[0])
开发者ID:LewysJones,项目名称:hyperspy,代码行数:7,代码来源:test_tools.py

示例2: setUp

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))
开发者ID:SungJinKang2,项目名称:hyperspy,代码行数:29,代码来源:test_signal_subclass_conversion.py

示例3: reconstruct_object

def reconstruct_object(flags, value):
    """ Reconstructs the value (if necessary) after having saved it in a
    dictionary
    """
    if not isinstance(flags, list):
        flags = parse_flag_string(flags)
    if 'sig' in flags:
        if isinstance(value, dict):
            from hyperspy.signal import Signal
            value = Signal(**value)
            value._assign_subclass()
        return value
    if 'fn' in flags:
        ifdill, thing = value
        if ifdill is None:
            return thing
        if ifdill in [False, 'False']:
            return types.FunctionType(marshal.loads(thing), globals())
        if ifdill in [True, 'True']:
            if not dill_avail:
                raise ValueError("the dictionary was constructed using "
                                 "\"dill\" package, which is not available on the system")
            else:
                return dill.loads(thing)
        # should not be reached
        raise ValueError("The object format is not recognized")
    return value
开发者ID:jerevon,项目名称:hyperspy,代码行数:27,代码来源:export_dictionary.py

示例4: setUp

 def setUp(self):
     s = Signal(np.empty((5, 5, 5)))
     s.save("tmp.hdf5")
     self.shape = (10000, 10000, 100)
     del s
     f = h5py.File("tmp.hdf5", model="r+")
     s = f["Experiments/__unnamed__"]
     del s["data"]
     s.create_dataset("data", shape=self.shape, dtype="float64", chunks=True)
     f.close()
开发者ID:jerevon,项目名称:hyperspy,代码行数:10,代码来源:test_hdf5.py

示例5: test_add_signal_in_dictionary

 def test_add_signal_in_dictionary(self):
     tree = self.tree
     s = Signal([1.0, 2, 3])
     s.axes_manager[0].name = "x"
     s.axes_manager[0].units = "ly"
     tree.add_dictionary({"_sig_signal name": s._to_dictionary()})
     nose.tools.assert_is_instance(tree.signal_name, Signal)
     np.testing.assert_array_equal(tree.signal_name.data, s.data)
     nose.tools.assert_dict_equal(tree.signal_name.metadata.as_dictionary(), s.metadata.as_dictionary())
     nose.tools.assert_equal(tree.signal_name.axes_manager._get_axes_dicts(), s.axes_manager._get_axes_dicts())
开发者ID:siriagus,项目名称:hyperspy,代码行数:10,代码来源:test_dictionary_tree_browser.py

示例6: setUp

class Test2D:
    def setUp(self):
        self.signal = Signal(np.arange(5*10).reshape(5,10))
        self.signal.axes_manager[0].name = "x"
        self.signal.axes_manager[1].name = "E"
        self.signal.axes_manager[0].scale = 0.5
        self.signal.mapped_parameters.set_item('splitting.axis', 0)
        self.signal.mapped_parameters.set_item(
                                        'splitting.step_sizes',[2,2])
        self.data = self.signal.data.copy()

        
    def test_axis_by_str(self):
        s1 = self.signal.deepcopy()
        s2 = self.signal.deepcopy()
        s1.crop(0, 2,4)
        s2.crop("x", 2, 4)
        assert_true((s1.data==s2.data).all())
        
    def test_crop_int(self):
        s = self.signal
        d = self.data
        s.crop(0, 2,4)
        assert_true((s.data==d[2:4,:]).all())
        
    def test_crop_float(self):
        s = self.signal
        d = self.data
        s.crop(0, 2, 2.)
        assert_true((s.data==d[2:4,:]).all())
        
    def test_split_axis0(self):
        result = self.signal.split(0,2)
        assert_true(len(result) == 2)
        assert_true((result[0].data == self.data[:2,:]).all())
        assert_true((result[1].data == self.data[2:4,:]).all())
    
    def test_split_axis1(self):
        result = self.signal.split(1,2)
        assert_true(len(result) == 2)
        assert_true((result[0].data == self.data[:,:5]).all())
        assert_true((result[1].data == self.data[:,5:]).all())
        
    def test_split_axisE(self):
        result = self.signal.split("E",2)
        assert_true(len(result) == 2)
        assert_true((result[0].data == self.data[:,:5]).all())
        assert_true((result[1].data == self.data[:,5:]).all())
        
    def test_split_default(self):
        result = self.signal.split()
        assert_true(len(result) == 2)
        assert_true((result[0].data == self.data[:2,:]).all())
        assert_true((result[1].data == self.data[2:4,:]).all())
开发者ID:mfm24,项目名称:hyperspy,代码行数:54,代码来源:test_tools.py

示例7: _spikes_diagnosis

    def _spikes_diagnosis(self, signal_mask=None,
                          navigation_mask=None):
        """Plots a histogram to help in choosing the threshold for
        spikes removal.

        Parameters
        ----------
        signal_mask: boolean array
            Restricts the operation to the signal locations not marked
            as True (masked)
        navigation_mask: boolean array
            Restricts the operation to the navigation locations not
            marked as True (masked).

        See also
        --------
        spikes_removal_tool

        """
        self._check_signal_dimension_equals_one()
        dc = self.data
        if signal_mask is not None:
            dc = dc[..., ~signal_mask]
        if navigation_mask is not None:
            dc = dc[~navigation_mask, :]
        der = np.abs(np.diff(dc, 1, -1))
        n = ((~navigation_mask).sum() if navigation_mask else
             self.axes_manager.navigation_size)

        # arbitrary cutoff for number of spectra necessary before histogram
        # data is compressed by finding maxima of each spectrum
        tmp = Signal(der) if n < 2000 else Signal(np.ravel(der.max(-1)))

        # get histogram signal using smart binning and plot
        tmph = tmp.get_histogram()
        tmph.plot()

        # Customize plot appearance
        plt.gca().set_title('')
        plt.gca().fill_between(tmph.axes_manager[0].axis,
                               tmph.data,
                               facecolor='#fddbc7',
                               interpolate=True,
                               color='none')
        ax = tmph._plot.signal_plot.ax
        axl = tmph._plot.signal_plot.ax_lines[0]
        axl.set_line_properties(color='#b2182b')
        plt.xlabel('Derivative magnitude')
        plt.ylabel('Log(Counts)')
        ax.set_yscale('log')
        ax.set_ylim(10 ** -1, plt.ylim()[1])
        ax.set_xlim(plt.xlim()[0], 1.1 * plt.xlim()[1])
        plt.draw()
开发者ID:jerevon,项目名称:hyperspy,代码行数:53,代码来源:spectrum.py

示例8: setUp

 def setUp(self):
     s = Signal(np.empty((5, 5, 5)))
     s.save('tmp.hdf5', overwrite=True)
     self.shape = (10000, 10000, 100)
     del s
     f = h5py.File('tmp.hdf5', model='r+')
     s = f['Experiments/__unnamed__']
     del s['data']
     s.create_dataset(
         'data',
         shape=self.shape,
         dtype='float64',
         chunks=True)
     f.close()
开发者ID:SungJinKang2,项目名称:hyperspy,代码行数:14,代码来源:test_hdf5.py

示例9: setUp

 def setUp(self):
     self.signal = Signal(np.arange(2 * 4 * 6).reshape(2, 4, 6))
     self.signal.axes_manager[0].name = "x"
     self.signal.axes_manager[1].name = "y"
     self.signal.axes_manager[2].name = "E"
     self.signal.axes_manager[0].scale = 0.5
     self.data = self.signal.data.copy()
开发者ID:LewysJones,项目名称:hyperspy,代码行数:7,代码来源:test_tools.py

示例10: Test1d

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))
开发者ID:Emilieringe,项目名称:hyperspy,代码行数:16,代码来源:test_signal_subclass_conversion.py

示例11: setUp

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))
开发者ID:AakashV,项目名称:hyperspy,代码行数:30,代码来源:test_fancy_indexing.py

示例12: setUp

class TestSignalVarianceFolding:
    def setUp(self):
        self.s = Signal(np.empty((2, 3, 4, 5)))
        self.s.axes_manager.set_signal_dimension(2)
        self.s.estimate_poissonian_noise_variance()

    def test_unfold_navigation(self):
        s = self.s.deepcopy()
        s.unfold_navigation_space()
        meta_am = s.metadata.Signal.Noise_properties.variance.axes_manager
        nose.tools.assert_equal(meta_am.navigation_shape, (self.s.axes_manager.navigation_size,))

    def test_unfold_signal(self):
        s = self.s.deepcopy()
        s.unfold_signal_space()
        meta_am = s.metadata.Signal.Noise_properties.variance.axes_manager
        nose.tools.assert_equal(meta_am.signal_shape, (self.s.axes_manager.signal_size,))
开发者ID:lu-chi,项目名称:hyperspy,代码行数:17,代码来源:test_folding.py

示例13: setUp

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)
开发者ID:AakashV,项目名称:hyperspy,代码行数:17,代码来源:test_signal_subclass_conversion.py

示例14: setUp

 def setUp(self):
     self.signal = Signal(np.arange(5*10).reshape(5,10))
     self.signal.axes_manager[0].name = "x"
     self.signal.axes_manager[1].name = "E"
     self.signal.axes_manager[0].scale = 0.5
     self.signal.mapped_parameters.set_item('splitting.axis', 0)
     self.signal.mapped_parameters.set_item(
                                     'splitting.step_sizes',[2,2])
     self.data = self.signal.data.copy()
开发者ID:Emilieringe,项目名称:hyperspy,代码行数:9,代码来源:test_tools.py

示例15: reconstruct_object

def reconstruct_object(flags, value):
    """ Reconstructs the value (if necessary) after having saved it in a
    dictionary
    """
    if not isinstance(flags, list):
        flags = parse_flag_string(flags)
    if "sig" in flags:
        if isinstance(value, dict):
            from hyperspy.signal import Signal

            value = Signal(**value)
            value._assign_subclass()
        return value
    if "fn" in flags:
        ifdill, thing = value
        if ifdill is None:
            return thing
        if ifdill in [True, "True", b"True"]:
            return dill.loads(thing)
        # should not be reached
        raise ValueError("The object format is not recognized")
    return value
开发者ID:siriagus,项目名称:hyperspy,代码行数:22,代码来源:export_dictionary.py


注:本文中的hyperspy.signal.Signal类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。