def test_1d_azimuthal_integration(self):
     var = DiffractionVariance2D(data=np.ones((
         3,
         3,
         3,
         3,
     )))
     var.unit = "2th_rad"
     integration = var.get_azimuthal_integral1d(npt_rad=10)
     assert isinstance(integration, DiffractionVariance1D)
Esempio n. 2
0
    def test_get_dif_var_radial_profile(self, diffraction_pattern, inplace):
        difvar = DiffractionVariance2D(diffraction_pattern)
        difvar.metadata.General.title = "A Title"
        difvar.axes_manager.navigation_axes[0].name = "x"
        difvar_copy = difvar.deepcopy()
        rp = difvar.get_radial_profile(inplace=inplace)
        if inplace:
            rp = difvar

        assert isinstance(rp, DiffractionVariance1D)
        assert difvar_copy.metadata.General.title == rp.metadata.General.title
        assert (difvar_copy.axes_manager.navigation_axes[0].name ==
                rp.axes_manager.navigation_axes[0].name)
Esempio n. 3
0
    def get_diffraction_variance(self, dqe, set_data_type=None):
        """Calculates the variance in scattered intensity as a function of
        scattering vector.

        Parameters
        ----------

        dqe : float
            Detective quantum efficiency of the detector for Poisson noise
            correction.
        data_type : numpy data type.
            For numpy data types, see
            https://docs.scipy.org/doc/numpy-1.13.0/user/basics.types.html.
            This is incorporated as squaring the numbers in meansq_dp results
            in considerably larger than the ones in the original array. This can
            result in an overflow error that is difficult to distinguish. Hence
            the data can be converted to a different data type to accommodate.



        Returns
        -------

        vardps : DiffractionVariance2D
            A DiffractionVariance2D object containing the mean DP, mean
            squared DP, and variance DP.
        """

        dp = self.signal
        mean_dp = dp.mean((0, 1))
        if set_data_type is None:
            meansq_dp = Signal2D(np.square(dp.data)).mean((0, 1))
        else:
            meansq_dp = Signal2D(np.square(
                dp.data.astype(set_data_type))).mean((0, 1))

        normvar = (meansq_dp.data / np.square(mean_dp.data)) - 1.
        var_dp = Signal2D(normvar)
        corr_var_array = var_dp.data - (np.divide(dqe, mean_dp.data))
        corr_var_array[np.isinf(corr_var_array)] = 0
        corr_var_array[np.isnan(corr_var_array)] = 0
        corr_var = Signal2D(corr_var_array)
        vardps = stack((mean_dp, meansq_dp, var_dp, corr_var))
        sig_x = vardps.data.shape[1]
        sig_y = vardps.data.shape[2]

        dv = DiffractionVariance2D(vardps.data.reshape((2, 2, sig_x, sig_y)))

        dv = transfer_signal_axes(dv, self.signal)

        return dv
Esempio n. 4
0
 def test_get_dif_var_radial_profile(self, diffraction_pattern):
     difvar = DiffractionVariance2D(diffraction_pattern)
     rp = difvar.get_radial_profile()
     assert isinstance(rp, DiffractionVariance1D)
Esempio n. 5
0
 def test_get_diffraction_variance_signal(self, diffraction_pattern):
     difvar = DiffractionVariance2D(diffraction_pattern)
     assert isinstance(difvar, DiffractionVariance2D)