How to use the pyxem.signals.diffraction_vectors.DiffractionVectors function in pyxem

To help you get started, we’ve selected a few pyxem examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyxem / pyxem / tests / test_signals / test_diffraction_vectors.py View on Github external
def diffraction_vectors_map(request):
    dvm = DiffractionVectors(request.param)
    dvm.axes_manager.set_signal_dimension(0)
    return dvm
github pyxem / pyxem / tests / test_peak_finders.py View on Github external
def test_findpeaks_runs_without_error(sample,method):
    assert type(sample.find_peaks(method)) == DiffractionVectors
github pyxem / pyxem / tests / test_generators / test_vdf_generator.py View on Github external
def test_vdf_generator_init_with_vectors(self, diffraction_pattern):
        dvm = DiffractionVectors(np.array([[np.array([[1, 1],
                                                      [2, 2]]),
                                            np.array([[1, 1],
                                                      [2, 2],
                                                      [1, 2]])],
                                           [np.array([[1, 1],
                                                      [2, 2]]),
                                            np.array([[1, 1],
                                                      [2, 2]])]], dtype=object))
        dvm.axes_manager.set_signal_dimension(0)

        vdfgen = VDFGenerator(diffraction_pattern, dvm)
        assert isinstance(vdfgen.signal, ElectronDiffraction)
        assert isinstance(vdfgen.vectors, DiffractionVectors)
github pyxem / pyxem / pyxem / signals / diffraction2d.py View on Github external
'laplacian_of_gaussians': find_peaks_log,
            'difference_of_gaussians': find_peaks_dog,
            'xc': find_peaks_xc
        }
        if method in method_dict:
            method = method_dict[method]
        else:
            raise NotImplementedError("The method `{}` is not implemented. "
                                      "See documentation for available "
                                      "implementations.".format(method))

        peaks = self.map(method, *args, **kwargs, inplace=False, ragged=True)
        peaks.map(peaks_as_gvectors,
                  center=np.array(self.axes_manager.signal_shape) / 2 - 0.5,
                  calibration=self.axes_manager.signal_axes[0].scale)
        peaks = DiffractionVectors(peaks)
        peaks.axes_manager.set_signal_dimension(0)

        # Set calibration to same as signal
        x = peaks.axes_manager.navigation_axes[0]
        y = peaks.axes_manager.navigation_axes[1]

        x.name = 'x'
        x.scale = self.axes_manager.navigation_axes[0].scale
        x.units = 'nm'

        y.name = 'y'
        y.scale = self.axes_manager.navigation_axes[1].scale
        y.units = 'nm'

        return peaks
github pyxem / pyxem / pyxem / signals / diffraction_vectors.py View on Github external
clusters.labels_, return_counts=True)
            unique_peaks = np.zeros((unique_labels.max() + 1, 2))

            # For each cluster, a center of mass is calculated based
            # on all the peaks within the cluster, and the center of
            # mass is taken as the final unique vector position.
            for n in np.arange(unique_labels.max() + 1):
                peaks_n_temp = unique_vectors[clusters.labels_ == n]
                peaks_n_counts_temp = unique_vectors_counts[
                    clusters.labels_ == n]
                unique_peaks[n] = np.average(
                    peaks_n_temp, weights=peaks_n_counts_temp, axis=0)

        # Manipulate into DiffractionVectors class
        if unique_peaks.size > 0:
            unique_peaks = DiffractionVectors(unique_peaks)
            unique_peaks.axes_manager.set_signal_dimension(1)
        if return_clusters and method == 'DBSCAN':
            return unique_peaks, clusters
        else:
            return unique_peaks
github pyxem / pyxem / pyxem / utils / io_utils.py View on Github external
from pyxem.signals.crystallographic_map import CrystallographicMap
from pyxem.signals.diffraction_vectors import DiffractionVectors
from pyxem.signals.indexation_results import TemplateMatchingResults

from pyxem.signals.diffraction1d import LazyDiffraction1D
from pyxem.signals.diffraction2d import LazyDiffraction2D
from pyxem.signals.electron_diffraction1d import LazyElectronDiffraction1D
from pyxem.signals.electron_diffraction2d import LazyElectronDiffraction2D

signal_dictionary = {'diffraction1d': Diffraction1D,
                     'diffraction2d': Diffraction2D,
                     'electron_diffraction1d': ElectronDiffraction1D,
                     'electron_diffraction2d': ElectronDiffraction2D,
                     'vdf_image': VDFImage,
                     'template_matching': TemplateMatchingResults,
                     'diffraction_vectors': DiffractionVectors,
                     'crystallographic_map': CrystallographicMap}

lazy_signal_dictionary = {'diffraction1d': LazyDiffraction1D,
                          'diffraction2d': LazyDiffraction2D,
                          'electron_diffraction1d': LazyElectronDiffraction1D,
                          'electron_diffraction2d': LazyElectronDiffraction2D}


def load(filename, lazy=False):
    """Load data into pyxem objects.

    Parameters
    ----------
    filename : str
        A single filename of a previously saved pyxem object. Other arguments may
        succeed, but will have fallen back on hyperspy load and warn accordingly
github pyxem / pyxem / pyxem / generators / integration_generator.py View on Github external
"""
        result = self.dp.map(_get_intensities_summation_method,
                             vectors=self.vector_pixels,
                             box_inner=box_inner,
                             box_outer=box_outer,
                             n_min=n_min,
                             n_max=n_max,
                             snr_thresh=snr_thresh,
                             inplace=False,
                             ragged=True)

        peaks = result.map(_take_ragged, indices=[0, 1], _axis=1, inplace=False, ragged=True)
        intensities = result.map(_take_ragged, indices=2, _axis=1, inplace=False, ragged=True)
        sigma = result.map(_take_ragged, indices=3, _axis=1, inplace=False, ragged=True)

        vectors = DiffractionVectors.from_peaks(peaks, calibration=self.calibration, center=self.center)
        vectors.intensities = intensities
        vectors.sigma = sigma
        vectors.snr = intensities / sigma

        return vectors
github pyxem / pyxem / pyxem / generators / subpixelrefinement_generator.py View on Github external
Returns
        -------
        vector_out: DiffractionVectors
            DiffractionVectors containing the refined vectors in calibrated
            units with the same navigation shape as the diffraction patterns.

        """
        def _conventional_xc_map(dp, vectors, sim_disc, upsample_factor, center, calibration):
            shifts = np.zeros_like(vectors, dtype=np.float64)
            for i, vector in enumerate(vectors):
                expt_disc = get_experimental_square(dp, vector, square_size)
                shifts[i] = _conventional_xc(expt_disc, sim_disc, upsample_factor)
            return (((vectors + shifts) - center) * calibration)

        sim_disc = get_simulated_disc(square_size, disc_radius)
        self.vectors_out = DiffractionVectors(
            self.dp.map(_conventional_xc_map,
                        vectors=self.vector_pixels,
                        sim_disc=sim_disc,
                        upsample_factor=upsample_factor,
                        center=self.center,
                        calibration=self.calibration,
                        inplace=False))
        self.vectors_out.axes_manager.set_signal_dimension(0)
        self.last_method = "conventional_xc"
        return self.vectors_out