Exemple #1
0
    def run(self):
        ai = AzimuthalIntegrator(dist=self.__distance,
                                 poni1=self.__poni1,
                                 poni2=self.__poni2,
                                 rot1=self.__rotation1,
                                 rot2=self.__rotation2,
                                 rot3=self.__rotation3,
                                 detector=self.__detector,
                                 wavelength=self.__wavelength)

        # FIXME Add error model
        method = method_registry.Method(0, self.__method.split,
                                        self.__method.algo, self.__method.impl,
                                        None)
        method1d = method.fixed(dim=1)
        methods = method_registry.IntegrationMethod.select_method(
            method=method1d)
        if len(methods) == 0:
            method1d = method_registry.Method(1, method1d.split, "*", "*",
                                              None)
            _logger.warning("Downgrade 1D integration method to %s", method1d)
        else:
            method1d = methods[0].method

        method2d = method.fixed(dim=2)
        methods = method_registry.IntegrationMethod.select_method(
            method=method2d)
        if len(methods) == 0:
            method2d = method_registry.Method(2, method2d.split, "*", "*",
                                              None)
            _logger.warning("Downgrade 2D integration method to %s", method2d)
        else:
            method2d = methods[0].method

        try:
            self.__result1d = ai.integrate1d_ng(
                method=method1d,
                data=self.__image,
                npt=self.__nPointsRadial,
                unit=self.__radialUnit,
                mask=self.__mask,
                polarization_factor=self.__polarizationFactor)

            self.__result2d = ai.integrate2d(
                method=method2d,
                data=self.__image,
                npt_rad=self.__nPointsRadial,
                npt_azim=self.__nPointsAzimuthal,
                unit=self.__radialUnit,
                mask=self.__mask,
                polarization_factor=self.__polarizationFactor)

            # Create an image masked where data exists
            self.__resultMask2d = None
            if self.__mask is not None:
                if self.__mask.shape == self.__image.shape:
                    maskData = numpy.ones(shape=self.__image.shape,
                                          dtype=numpy.float32)
                    maskData[self.__mask == 0] = float("NaN")

                    if self.__displayMask:
                        self.__resultMask2d = ai.integrate2d(
                            method=method2d,
                            data=maskData,
                            npt_rad=self.__nPointsRadial,
                            npt_azim=self.__nPointsAzimuthal,
                            unit=self.__radialUnit,
                            polarization_factor=self.__polarizationFactor)
                else:
                    _logger.warning(
                        "Inconsistency between image and mask sizes. %s != %s",
                        self.__image.shape, self.__mask.shape)
        except Exception as e:
            _logger.debug("Error while integrating", exc_info=True)
            self.__errorMessage = e
            # TODO: Could be nice to  compute anyway other content (directDist...)
            return

        try:
            self.__directDist = ai.getFit2D()["directDist"]
        except Exception:
            # The geometry could not fit this param
            _logger.debug("Backtrace", exc_info=True)
            self.__directDist = None

        if self.__calibrant:

            rings = self.__calibrant.get_2th()
            try:
                rings = unitutils.from2ThRad(rings, self.__radialUnit,
                                             self.__wavelength,
                                             self.__directDist)
            except ValueError:
                message = "Convertion to unit %s not supported. Ring locations ignored."
                _logger.warning(message, self.__radialUnit)
                self.__errorMessage = message % self.__radialUnit
                rings = []

            # Filter the rings which are not part of the result
            minAngle, maxAngle = self.__result1d.radial[
                0], self.__result1d.radial[-1]
            rings = [(i, angle) for i, angle in enumerate(rings)
                     if minAngle <= angle <= maxAngle]
        else:
            rings = []

        self.__rings = rings
        self.__ai = ai