Пример #1
0
def test_select_fake_method_from_method_dict(method_dict):
    with pytest.raises(NotImplementedError):
        _ = select_method_from_method_dict("fake_choice",
                                           method_dict,
                                           print_help=True)
Пример #2
0
def test_select_method_from_method_dict_print_help(method_dict):
    method_dict = {"dummy_choice": select_method_from_method_dict}
    _ = select_method_from_method_dict("dummy_choice",
                                       method_dict,
                                       print_help=True)
Пример #3
0
    def correlate(
        self,
        n_largest=5,
        method="fast_correlation",
        mask=None,
        print_help=False,
        **kwargs,
    ):
        """Correlates the library of simulated diffraction patterns with the
        electron diffraction signal.

        Parameters
        ----------
        n_largest : int
            The n orientations with the highest correlation values for each phase are returned.
        method : str
            Name of method used to compute correlation between templates and diffraction patterns. Can be
            'fast_correlation' or 'zero_mean_normalized_correlation'.
        mask : hs.BaseSignal or None
            Only apply the method a unmasked (value=1) pixel, default is None (index all pixels)
        print_help : bool
            Display information about the method used.
        **kwargs : arguments
            Keyword arguments passed map().

        Returns
        -------
        matching_results : TemplateMatchingResults
        """
        signal = self.signal
        library = self.library

        method_dict = {
            "fast_correlation": fast_correlation,
            "zero_mean_normalized_correlation":
            zero_mean_normalized_correlation,
        }

        if mask is None:
            # Index at all real space pixels
            mask = 1

        # tests if selected method is valid and can print help for selected method.
        _ = select_method_from_method_dict(method, method_dict, print_help)

        # adds a normalisation to library #TODO: Port to diffsims
        for phase in library.keys():
            # initialise a container for the norms
            norm_array = np.ones(library[phase]["intensities"].shape[0])

            for i, intensity_array in enumerate(library[phase]["intensities"]):
                norm_array[i] = np.linalg.norm(intensity_array)
                library[phase]["pattern_norms"] = norm_array

        matches = signal.map(
            _correlate_templates,
            library=library,
            n_largest=n_largest,
            method=method,
            mask=mask,
            inplace=False,
            **kwargs,
        )

        matching_results = TemplateMatchingResults(matches)

        return matching_results