コード例 #1
0
 def setUp(self):
     gaussian = Gaussian()
     gaussian.A.value = 20
     gaussian.sigma.value = 10
     gaussian.centre.value = 50
     self.signal = Signal(gaussian.function(np.arange(0, 100, 0.01)))
     self.signal.axes_manager[0].scale = 0.01
コード例 #2
0
 def setUp(self):
     gaussian = Gaussian()
     gaussian.A.value = 20
     gaussian.sigma.value = 10
     gaussian.centre.value = 50
     self.spectrum = Signal(gaussian.function(np.arange(0, 100, 0.01)))
     self.spectrum.axes_manager[0].scale = 0.01
コード例 #3
0
ファイル: test_emd.py プロジェクト: dzhou36/hyperspy
 def test_save_and_read(self):
     signal_ref = Signal(data_save)
     signal_ref.metadata.General.title = test_title
     signal_ref.axes_manager[0].name = 'x'
     signal_ref.axes_manager[1].name = 'y'
     signal_ref.axes_manager[2].name = 'z'
     signal_ref.axes_manager[0].scale = 2
     signal_ref.axes_manager[1].scale = 3
     signal_ref.axes_manager[2].scale = 4
     signal_ref.axes_manager[0].offset = 10
     signal_ref.axes_manager[1].offset = 20
     signal_ref.axes_manager[2].offset = 30
     signal_ref.axes_manager[0].units = 'nmx'
     signal_ref.axes_manager[1].units = 'nmy'
     signal_ref.axes_manager[2].units = 'nmz'
     signal_ref.save(os.path.join(my_path, 'emd_files', 'example_temp.emd'), overwrite=True,
                     signal_metadata=sig_metadata, user=user, microscope=microscope,
                     sample=sample, comments=comments)
     signal = load(os.path.join(my_path, 'emd_files', 'example_temp.emd'))
     np.testing.assert_equal(signal.data, signal_ref.data)
     np.testing.assert_equal(signal.axes_manager[0].name, 'x')
     np.testing.assert_equal(signal.axes_manager[1].name, 'y')
     np.testing.assert_equal(signal.axes_manager[2].name, 'z')
     np.testing.assert_equal(signal.axes_manager[0].scale, 2)
     np.testing.assert_equal(signal.axes_manager[1].scale, 3)
     np.testing.assert_equal(signal.axes_manager[2].scale, 4)
     np.testing.assert_equal(signal.axes_manager[0].offset, 10)
     np.testing.assert_equal(signal.axes_manager[1].offset, 20)
     np.testing.assert_equal(signal.axes_manager[2].offset, 30)
     np.testing.assert_equal(signal.axes_manager[0].units, 'nmx')
     np.testing.assert_equal(signal.axes_manager[1].units, 'nmy')
     np.testing.assert_equal(signal.axes_manager[2].units, 'nmz')
     np.testing.assert_equal(signal.metadata.General.title, test_title)
     np.testing.assert_equal(
         signal.metadata.General.user.as_dictionary(), user)
     np.testing.assert_equal(
         signal.metadata.General.microscope.as_dictionary(),
         microscope)
     np.testing.assert_equal(
         signal.metadata.General.sample.as_dictionary(), sample)
     np.testing.assert_equal(
         signal.metadata.General.comments.as_dictionary(), comments)
     for key, ref_value in sig_metadata.items():
         np.testing.assert_equal(
             signal.metadata.Signal.as_dictionary().get(key), ref_value)
     nt.assert_is_instance(signal, Signal)
コード例 #4
0
ファイル: inline_holo.py プロジェクト: MLPhasing/inline_holo
    def integrate_binary(self, bin_mask, normalize=True, *args, **kwargs):
        '''
        Image integration with binarized mask. The binarization is achieved by
        first finding the unique elements of the provided array and adding the
        values of the image(s) in the corresponding coordinates.

        Parameters
        ----------
        bin_mask : Signal2D
         A 2D signal with the same shape as the image(s), the coordinates of
         unique elements in the data array are found by calling ``np.unique``.
        normalize : bool
         Controls wether we obtain an absolute sum or a normalized integral,
         the last one being the default setting.

        *args, **kwargs are passed to the `self.map`` function.

        Returns
        -------
        integral : signal
         With signal dimension axis equal to the radial mesh bins used for the
         integration and a single navigation dimension with size corresponding
         to the navigation dimension of the original signal but flattened, if
         the original signal had one.
        '''
        # Complex data support
        if np.iscomplexobj(self.data):
            integrator = integrate_binary_comp
        else:
            integrator = integrate_binary_real

        integral_signal = self.map(integrator,
                                   bin_mask=bin_mask,
                                   normalize=normalize,
                                   inplace=False,
                                   *args,
                                   **kwargs)

        integral_signal = Signal(integral_signal.data)

        if bin_mask.axes_manager.navigation_dimension == 0:
            # We can set the axis, in other cases the signal could be ragged
            dst = np.unique(bin_mask.data)
            integral_signal.axes_manager.signal_axes[0].axis = dst

            # Set the scales only if the mask bins were regular
            nbins = np.unique(np.round(np.diff(dst), 5)).size
            if nbins == 1:
                # regular mask
                integral_signal.axes_manager.signal_axes[0].offset = dst[0]
                integral_signal.axes_manager.signal_axes[0].scale  = \
                                                                 dst[1] - dst[0]

        return integral_signal
コード例 #5
0
class Test1D():
    def setUp(self):
        gaussian = Gaussian() 
        gaussian.A.value = 20
        gaussian.sigma.value = 10
        gaussian.centre.value = 50
        self.signal = Signal(gaussian.function(np.arange(0,100,0.01)))
        self.signal.axes_manager[0].scale = 0.01
    
    def test_integrate_in_range(self):
        integrated_signal = self.signal.integrate_in_range(signal_range=(None,None))
        assert_true(np.allclose(integrated_signal.data, 20,))
コード例 #6
0
ファイル: roi.py プロジェクト: temcode/hyperspy
    def __call__(self, signal, axes=None, order=0):
        """Slice the signal according to the ROI, and return it.

        Arguments
        ---------
        signal : Signal
            The signal to slice with the ROI.
        axes : specification of axes to use, default = None
            The axes argument specifies which axes the ROI will be applied on.
            The items in the collection can be either of the following:
                * a tuple of:
                    - DataAxis. These will not be checked with
                      signal.axes_manager.
                    - anything that will index signal.axes_manager
                * For any other value, it will check whether the navigation
                  space can fit the right number of axis, and use that if it
                  fits. If not, it will try the signal space.
        """
        if axes is None and signal in self.signal_map:
            axes = self.signal_map[signal][1]
        else:
            axes = self._parse_axes(axes, signal.axes_manager)
        linewidth = self.linewidth / np.min([ax.scale for ax in axes])
        profile = Line2DROI.profile_line(signal.data, (self.x1, self.y1),
                                         (self.x2, self.y2),
                                         axes=axes,
                                         linewidth=linewidth,
                                         order=order)
        length = np.linalg.norm(np.diff(np.array(
            ((self.x1, self.y1), (self.x2, self.y2))),
                                        axis=0),
                                axis=1)[0]
        axm = signal.axes_manager.deepcopy()
        idx = []
        for ax in axes:
            idx.append(ax.index_in_axes_manager)
        for i in reversed(sorted(idx)):  # Remove in reversed order
            axm.remove(i)
        axis = DataAxis(len(profile),
                        scale=length / len(profile),
                        units=axes[0].units,
                        navigate=axes[0].navigate)
        axis.axes_manager = axm
        i0 = min(axes[0].index_in_array, axes[1].index_in_array)
        axm._axes.insert(i0, axis)
        from hyperspy.signals import Signal
        roi = Signal(profile,
                     axes=axm._get_axes_dicts(),
                     metadata=signal.metadata.deepcopy().as_dictionary(),
                     original_metadata=signal.original_metadata.deepcopy().
                     as_dictionary())
        return roi
コード例 #7
0
class Test1D:

    def setUp(self):
        gaussian = Gaussian()
        gaussian.A.value = 20
        gaussian.sigma.value = 10
        gaussian.centre.value = 50
        self.signal = Signal(gaussian.function(np.arange(0, 100, 0.01)))
        self.signal.axes_manager[0].scale = 0.01

    def test_integrate_in_range(self):
        integrated_signal = self.signal.integrate_in_range(signal_range=(None,
                                                                         None))
        nose.tools.assert_true(np.allclose(integrated_signal.data, 20,))