Esempio n. 1
0
    def updatePhysicalMarkerPixels(self, geometry):
        self.__geometry = geometry
        if geometry is None:
            self.__wavelength = None
            self.__directDist = None
        else:
            self.__wavelength = geometry.wavelength
            try:
                self.__directDist = geometry.getFit2D()["directDist"]
            except Exception:
                # The geometry could not fit this param
                _logger.debug("Backtrace", exc_info=True)
                self.__directDist = None

        invertGeometry = InvertGeometry(
            self.__geometry.array_from_unit(typ="center",
                                            unit=pyFAI.units.TTH_RAD,
                                            scale=False),
            self.__geometry.chiArray())

        self.__markerModel.lockSignals()
        for marker in self.__markerModel:
            if not isinstance(marker, MarkerModel.PhysicalMarker):
                continue

            chiRad, tthRad = marker.physicalPosition()
            pixel = None
            if self.__geometry is not None:
                pixel = invertGeometry(tthRad, chiRad, True)

                ax, ay = numpy.array([pixel[1]]), numpy.array([pixel[0]])
                tth = self.__geometry.tth(ay, ax)[0]
                chi = self.__geometry.chi(ay, ax)[0]

                error = numpy.sqrt((tthRad - tth)**2 + (chiRad - chi)**2)
                if error > 0.05:
                    # The identified pixel is far from the requested chi/tth. Marker ignored.
                    pixel = None
            if pixel is not None:
                marker.setPixelPosition(pixel[1], pixel[0])
            else:
                marker.removePixelPosition()
        # TODO: should be managed by the model
        self.__markerModel.wasChanged()
        self.__markerModel.unlockSignals()
Esempio n. 2
0
 def updateProjection(self,
                      geometry,
                      radialUnit,
                      wavelength,
                      directDist,
                      redraw=True):
     if self.__pixelBasedPlot:
         raise RuntimeError("Invalide operation for this kind of plot")
     self.__geometry = geometry
     self.__radialUnit = radialUnit
     self.__invertGeometry = InvertGeometry(
         self.__geometry.array_from_unit(typ="center",
                                         unit=self.__radialUnit,
                                         scale=True),
         numpy.rad2deg(self.__geometry.chiArray()))
     self.__wavelength = wavelength
     self.__directDist = directDist
     if redraw:
         self.__updateMarkers()
Esempio n. 3
0
    def setIntegrationProcess(self, integrationProcess):
        """
        :param :class:`~pyFAI.gui.tasks.IntegrationTask.IntegrationProcess` integrationProcess:
            Result of the integration process
        """
        self.__clearRings()

        self.__availableRings = integrationProcess.rings()
        self.__updateRings()

        result1d = integrationProcess.result1d()
        self.__plot1d.addHistogram(legend="result1d",
                                   align="center",
                                   edges=result1d.radial,
                                   color="blue",
                                   histogram=result1d.intensity,
                                   resetzoom=False)
        self.__plot1d.setGraphXLabel(result1d.unit.label)
        self.__setResult(result1d)

        def compute_location(result):
            # Assume that axes are linear
            if result.intensity.shape[1] > 1:
                scaleX = (result.radial[-1] -
                          result.radial[0]) / (result.intensity.shape[1] - 1)
            else:
                scaleX = 1.0
            if result.intensity.shape[0] > 1:
                scaleY = (result.azimuthal[-1] - result.azimuthal[0]) / (
                    result.intensity.shape[0] - 1)
            else:
                scaleY = 1.0
            halfPixel = 0.5 * scaleX, 0.5 * scaleY
            origin = (result.radial[0] - halfPixel[0],
                      result.azimuthal[0] - halfPixel[1])
            return origin, scaleX, scaleY

        resultMask2d = integrationProcess.resultMask2d()
        isMaskDisplayed = resultMask2d is not None

        result2d = integrationProcess.result2d()
        result2d_intensity = result2d.intensity

        # Mask pixels with no data
        result2d_intensity[result2d.count == 0] = float("NaN")

        if isMaskDisplayed:
            maskedColor = CalibrationContext.instance().getMaskedColor()
            transparent = (0.0, 0.0, 0.0, 0.0)
            resultMask2d_rgba = imageutils.maskArrayToRgba(
                resultMask2d.count != 0,
                falseColor=transparent,
                trueColor=maskedColor)
            origin, scaleX, scaleY = compute_location(resultMask2d)
            self.__plot2d.addImage(legend="integrated_mask",
                                   data=resultMask2d_rgba,
                                   origin=origin,
                                   scale=(scaleX, scaleY),
                                   resetzoom=False)
        else:
            try:
                self.__plot2d.removeImage("integrated_mask")
            except Exception:
                pass

        colormap = self.getDefaultColormap()
        origin, scaleX, scaleY = compute_location(result2d)
        self.__plot2d.addImage(legend="integrated_data",
                               data=result2d_intensity,
                               origin=origin,
                               scale=(scaleX, scaleY),
                               colormap=colormap,
                               resetzoom=False)
        self.__plot2d.setGraphXLabel(result2d.unit.label)

        self.__radialUnit = integrationProcess.radialUnit()
        self.__wavelength = integrationProcess.wavelength()
        self.__directDist = integrationProcess.directDist()
        self.__geometry = integrationProcess.geometry()
        self.__inverseGeometry = InvertGeometry(
            self.__geometry.array_from_unit(typ="center",
                                            unit=self.__radialUnit,
                                            scale=True),
            numpy.rad2deg(self.__geometry.chiArray()))

        self.__markerManager.updateProjection(self.__geometry,
                                              self.__radialUnit,
                                              self.__wavelength,
                                              self.__directDist)

        resetZoomPolicy = integrationProcess.resetZoomPolicy()
        if resetZoomPolicy is None:
            # Default behaviour
            self.resetZoom()
        elif resetZoomPolicy is False:
            pass
        else:
            raise ValueError("Reset zoom policy not implemented")
Esempio n. 4
0
    def setIntegrationProcess(self, integrationProcess):
        """
        :param IntegrationProcess integrationProcess: Result of the integration
            process
        """
        self.__clearRings()

        self.__availableRingAngles = integrationProcess.ringAngles()
        self.__updateRings()

        # FIXME set axes units
        result1d = integrationProcess.result1d()
        self.__plot1d.addHistogram(legend="result1d",
                                   align="center",
                                   edges=result1d.radial,
                                   color="blue",
                                   histogram=result1d.intensity,
                                   resetzoom=False)

        if silx.version_info[0:2] == (0, 8):
            # Invalidate manually the plot datarange on silx 0.8
            # https://github.com/silx-kit/silx/issues/2079
            self.__plot1d._invalidateDataRange()

        self.__setResult(result1d)

        # Assume that axes are linear
        result2d = integrationProcess.result2d()
        if result2d.intensity.shape[1] > 1:
            scaleX = (result2d.radial[-1] -
                      result2d.radial[0]) / (result2d.intensity.shape[1] - 1)
        else:
            scaleX = 1.0
        if result2d.intensity.shape[0] > 1:
            scaleY = (result2d.azimuthal[-1] - result2d.azimuthal[0]) / (
                result2d.intensity.shape[0] - 1)
        else:
            scaleY = 1.0
        halfPixel = 0.5 * scaleX, 0.5 * scaleY
        origin = (result2d.radial[0] - halfPixel[0],
                  result2d.azimuthal[0] - halfPixel[1])
        colormap = self.getDefaultColormap()
        self.__plot2d.addImage(legend="result2d",
                               data=result2d.intensity,
                               origin=origin,
                               scale=(scaleX, scaleY),
                               colormap=colormap,
                               resetzoom=False)

        self.__radialUnit = integrationProcess.radialUnit()
        self.__wavelength = integrationProcess.wavelength()
        self.__directDist = integrationProcess.directDist()
        self.__geometry = integrationProcess.geometry()
        self.__inverseGeometry = InvertGeometry(
            self.__geometry.array_from_unit(typ="center",
                                            unit=self.__radialUnit,
                                            scale=True),
            numpy.rad2deg(self.__geometry.chiArray()))

        self.__markerManager.updateProjection(self.__geometry,
                                              self.__radialUnit,
                                              self.__wavelength,
                                              self.__directDist)

        resetZoomPolicy = integrationProcess.resetZoomPolicy()
        if resetZoomPolicy is None:
            # Default behaviour
            self.resetZoom()
        elif resetZoomPolicy is False:
            pass
        else:
            raise ValueError("Reset zoom policy not implemented")