Exemplo n.º 1
0
    def _initGui(self):
        qt.loadUi(pyFAI.utils.get_ui_file("calibration-result.ui"), self)
        icon = silx.gui.icons.getQIcon("pyfai:gui/icons/task-cake")
        self.setWindowIcon(icon)

        self.initNextStep()

        self._methodLabel.setLabelTemplate("{split}")
        self._warning.setVisible(False)

        self.__integrationUpToDate = True
        self.__integrationResetZoomPolicy = None
        method = method_registry.Method(666, "bbox", "csr", "cython", None)
        self.__setMethod(method)

        positiveValidator = validators.IntegerAndEmptyValidator(self)
        positiveValidator.setBottom(1)

        self._radialPoints.setValidator(positiveValidator)
        self._azimuthalPoints.setValidator(positiveValidator)
        self._radialUnit.setUnits(pyFAI.units.RADIAL_UNITS.values())
        self.__polarizationModel = None
        self._polarizationFactorCheck.clicked[bool].connect(
            self.__polarizationFactorChecked)
        self.widgetShow.connect(self.__widgetShow)
        self._displayMask.clicked[bool].connect(self.__displayMaskChecked)

        self._integrateButton.beforeExecuting.connect(self.__integrate)
        self._integrateButton.setDisabledWhenWaiting(True)
        self._integrateButton.finished.connect(self.__integratingFinished)

        self._customMethodButton.clicked.connect(
            self.__customIntegrationMethod)

        self._savePoniButton.clicked.connect(self.__saveAsPoni)
Exemplo n.º 2
0
 def __customIntegrationMethod(self):
     dialog = IntegrationMethodDialog(self)
     dialog.selectMethod(self.__method)
     result = dialog.exec_()
     if result:
         method = dialog.selectedMethod()
         # TODO selectedMethod should return a `Method` tuple
         split, algo, impl = method
         method = method_registry.Method(dim=666,
                                         split=split,
                                         algo=algo,
                                         impl=impl,
                                         target=None)
         self.__setMethod(method)
Exemplo n.º 3
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