Exemple #1
0
    def diff_tth_X(self, dx=0.1):
        """
        Jerome peux-tu décrire de quoi il retourne ???

        @param dx: ???
        @type: float ???

        @return: ???
        @rtype: ???
        """
        f = self.ai.getFit2D()
        fp = f.copy()
        fm = f.copy()
        fm["centerX"] -= dx / 2.0
        fp["centerX"] += dx / 2.0
        ap = AzimuthalIntegrator()
        am = AzimuthalIntegrator()
        ap.setFit2D(**fp)
        am.setFit2D(**fm)
        dtthX = (ap.twoThetaArray(self.shape) - am.twoThetaArray(self.shape))\
            / dx
        tth, I = self.ai.xrpd(self.img, max(self.shape))
        dI = SGModule.getSavitzkyGolay(I, npoints=5, degree=2, order=1)\
            / (tth[1] - tth[0])
        dImg = self.reconstruct(tth, dI)
        return (dtthX * dImg).sum()
Exemple #2
0
    def setUp(self):
        # defining geometry
        image_shape = [2048, 2048]  # pixel
        detector_distance = 200  # mm
        wavelength = 0.31  # angstrom
        center_x = 1024  # pixel
        center_y = 1024  # pixel
        self.tilt = 0  # degree
        self.rotation = 0  # degree
        pixel_size = 79  # um
        dummy_tth = np.linspace(0, 35, 2000)
        dummy_int = np.ones(dummy_tth.shape)
        self.geometry = AzimuthalIntegrator()
        self.geometry.setFit2D(directDist=detector_distance,
                               centerX=center_x,
                               centerY=center_y,
                               tilt=self.tilt,
                               tiltPlanRotation=self.rotation,
                               pixelX=pixel_size,
                               pixelY=pixel_size)
        self.geometry.wavelength = wavelength / 1e10
        self.dummy_img = self.geometry.calcfrom1d(dummy_tth, dummy_int, shape=image_shape, correctSolidAngle=True)

        self.tth_array = self.geometry.twoThetaArray(image_shape)
        self.azi_array = self.geometry.chiArray(image_shape)
Exemple #3
0
    def setup_integrator(self):
        """Sets up integrator object"""
        # if self.poni_file is not None:
        if self.poni_dict is not None:
            # poni_dict = get_poni_dict(self.poni_file)
            integrator = create_ai_from_dict(self.poni_dict, self.gi)
            # if not self.gi:
            #     integrator = pyFAI.load(self.poni_file)
            #     integrator._rot3 -= np.deg2rad(90)
            # else:
            #     pFAI = pyFAI.load(self.poni_file)
            #     calib_pars = dict(
            #         dist=pFAI.dist, poni1=pFAI.poni1, poni2=pFAI.poni2,
            #         rot1=pFAI.rot1, rot2=pFAI.rot2, rot3=pFAI.rot3,
            #         wavelength=pFAI.wavelength, detector=pFAI.detector)
            #     integrator = pygix.Transform(**calib_pars)
            #     integrator.sample_orientation = 3  # 1 is horizontal, 2 is vertical

        else:
            integrator = AzimuthalIntegrator(dist=self.poni.dist,
                                             poni1=self.poni.poni1,
                                             poni2=self.poni.poni2,
                                             rot1=self.poni.rot1,
                                             rot2=self.poni.rot2,
                                             rot3=self.poni.rot3,
                                             wavelength=self.poni.wavelength,
                                             detector=self.poni.detector,
                                             **self.ai_args)
        return integrator
Exemple #4
0
    def scan_Fit2D(self, width=1.0, points=10, axis="tilt", dx=0.1):
        """
        ???

        @param width: ???
        @type width: float ???
        @param points: ???
        @type points: int ???
        @param axis: ???
        @type axis: str ???
        @param dx: ???
        @type dx: float ???

        @return: ???
        @rtype: ???
        """
        logger.info("Scanning along axis %s" % axis)
        f = self.ai.getFit2D()
        out = []
        meas_pts = numpy.linspace(f[axis] - width / 2.0,
                                  f[axis] + width / 2.0,
                                  points)
        for x in meas_pts:
            ax = AzimuthalIntegrator()
            fx = f.copy()
            fx[axis] = x
            ax.setFit2D(**fx)
            ref = Refinment2D(self.img, ax)
            res = ref.diff_Fit2D(axis=axis, dx=dx)
            print("x= %.3f mean= %e" % (x, res))
            out.append(res)
        return meas_pts, out
Exemple #5
0
    def scan_tilt(self, width=1.0, points=10):
        """
        ???

        @param width: ???
        @type width: float ???
        @param points: ???
        @type points: int ???

        @return: ???
        @rtype: ???
        """
        f = self.ai.getFit2D()
        out = []
        for x in numpy.linspace(f["tilt"] - width / 2.0,
                                f["tilt"] + width / 2.0,
                                points):
            ax = AzimuthalIntegrator()
            fx = f.copy()
            fx["tilt"] = x
            ax.setFit2D(**fx)
#            print ax
            ref = Refinment2D(self.img, ax)
            res = ref.diff_tth_tilt()
            print("x= %.3f mean= %e" % (x, res))
            out.append(res)
        return numpy.linspace(f["tilt"] - width / 2.0,
                              f["tilt"] + width / 2.0,
                              points), out
Exemple #6
0
    def setUp(self):
        """Download files"""
        self.fit2dFile = UtilsTest.getimage(self.__class__.fit2dFile)
        self.halfFrelon = UtilsTest.getimage(self.__class__.halfFrelon)
        self.splineFile = UtilsTest.getimage(self.__class__.splineFile)
        poniFile = UtilsTest.getimage(self.__class__.poniFile)

        with open(poniFile) as f:
            data = []
            for line in f:
                if line.startswith("SplineFile:"):
                    data.append("SplineFile: " + self.splineFile)
                else:
                    data.append(line.strip())
        self.poniFile = os.path.join(self.tmp_dir, os.path.basename(poniFile))
        if not os.path.isdir(self.tmp_dir):
            os.makedirs(self.tmp_dir)

        with open(self.poniFile, "w") as f:
            f.write(os.linesep.join(data))
        self.fit2d = numpy.loadtxt(self.fit2dFile)
        self.ai = AzimuthalIntegrator()
        self.ai.load(self.poniFile)
        self.data = fabio.open(self.halfFrelon).data
        for tmpfile in self.tmpfiles.values():
            if os.path.isfile(tmpfile):
                os.unlink(tmpfile)
    def _update_integrator(self):
        constant = 1e-3 * constants.c * constants.h / constants.e
        self._wavelength = constant / self._ai_params["energy"]
        self._distance = self._ai_params["distance"]
        self._poni1 = \
            self._ai_params["centery"] * self._ai_params["pixel_size"]
        self._poni2 = \
            self._ai_params["centerx"] * self._ai_params["pixel_size"]

        if self._ai_integrator is None:
            self._ai_integrator = AzimuthalIntegrator(
                dist=self._ai_params["distance"],
                pixel1=self._ai_params["pixel_size"],
                pixel2=self._ai_params["pixel_size"],
                poni1=self._poni1,
                poni2=self._poni2,
                rot1=0,
                rot2=0,
                rot3=0,
                wavelength=self._wavelength)
        else:
            if self._ai_integrator.dist != self._distance \
                    or self._ai_integrator.wavelength != self._wavelength \
                    or self._ai_integrator.poni1 != self._poni1 \
                    or self._ai_integrator.poni2 != self._poni2:
                self._ai_integrator.set_param(
                    (self._distance, self._poni1, self._poni2, 0, 0, 0,
                     self._wavelength))
        return self._ai_integrator
Exemple #8
0
    def load_from_h5(self, file):
        """Loads data from hdf5 file and sets attributes.

        args:
            file: h5py file or group object

        returns:
            None
        """
        with self.file_lock:
            with self.arch_lock:
                if str(self.idx) not in file:
                    print("No data can be found")
                grp = file[str(self.idx)]
                lst_attr = [
                    "map_raw", "mask", "map_norm", "map_q", "xyz", "tcr",
                    "qchi", "scan_info", "ai_args"
                ]
                pawstools.h5_to_attributes(self, grp, lst_attr)
                pawstools.h5_to_attributes(self.int_1d, grp['int_1d'])
                pawstools.h5_to_attributes(self.int_2d, grp['int_2d'])
                self.poni = PONI.from_yamdict(pawstools.h5_to_dict(
                    grp['poni']))
                self.integrator = AzimuthalIntegrator(
                    dist=self.poni.dist,
                    poni1=self.poni.poni1,
                    poni2=self.poni.poni2,
                    rot1=self.poni.rot1,
                    rot2=self.poni.rot2,
                    rot3=self.poni.rot3,
                    wavelength=self.poni.wavelength,
                    detector=self.poni.detector,
                    **self.ai_args)
    def _update_integrator(self):
        if self._integrator is None:
            self._integrator = AzimuthalIntegrator(dist=self._sample_dist,
                                                   pixel1=self._pixel1,
                                                   pixel2=self._pixel2,
                                                   poni1=self._poni1,
                                                   poni2=self._poni2,
                                                   rot1=0,
                                                   rot2=0,
                                                   rot3=0,
                                                   wavelength=self._wavelength)
        else:
            if self._integrator.dist != self._sample_dist \
                    or self._integrator.wavelength != self._wavelength \
                    or self._integrator.poni1 != self._poni1 \
                    or self._integrator.poni2 != self._poni2:
                # dist, poni1, poni2, rot1, rot2, rot3, wavelength
                self._integrator.set_param(
                    (self._sample_dist, self._poni1, self._poni2, 0, 0, 0,
                     self._wavelength))

        try:
            # 1/nm -> 1/A
            self._q_map = 0.1 * self._integrator._cached_array["q_center"]
        except KeyError:
            pass

        return self._integrator
Exemple #10
0
    def diff_Fit2D(self, axis="all", dx=0.1):
        """
        ???

        @param axis: ???
        @type axis: ???
        @param dx: ???
        @type dx: ???

        @return: ???
        @rtype: ???
        """
        tth, I = self.ai.xrpd(self.img, max(self.shape))
        dI = SGModule.getSavitzkyGolay(I, npoints=5, degree=2, order=1)\
            / (tth[1] - tth[0])
        dImg = self.reconstruct(tth, dI)
        f = self.ai.getFit2D()
        tth2d_ref = self.ai.twoThetaArray(self.shape)  # useless variable ???

        keys = ["centerX", "centerY", "tilt", "tiltPlanRotation"]
        if axis != "all":
            keys = [i for i in keys if i == axis]
        grad = {}
        for key in keys:
            fp = f.copy()
            fp[key] += dx
            ap = AzimuthalIntegrator()
            ap.setFit2D(**fp)
            dtth = (ap.twoThetaArray(self.shape)
                    - self.ai.twoThetaArray(self.shape)) / dx
            grad[key] = (dtth * dImg).sum()
        if axis == "all":
            return grad
        else:
            return grad[axis]
Exemple #11
0
def set_geometry(distance: float = 1,
                 center_x: float = 0,
                 center_y: float = 0,
                 tilt: float = 0.0,
                 tilt_plane_rotation: float = 0.0):
    ai = AzimuthalIntegrator()
    ai.setFit2D(distance, center_x, center_y, tilt, tilt_plane_rotation)
    return ai
Exemple #12
0
 def setup_calibration(self, calib):
     """set up calibration from calibration dict"""
     if self.image.rot90 in (1, 3):
         calib['rot3'] = np.pi / 2.0
     self.calib = calib
     if HAS_PYFAI:
         self.integrator = AzimuthalIntegrator(**calib)
         self.show1d_btn.Enable()
Exemple #13
0
    def update_ai(self, center=None, nbins=1000):

        if center is None:
            center = self.center

        ai = AzimuthalIntegrator(detector=self.detector, dist=self.distance)
        ai.setFit2D(self.distance * 1000, center[0], center[1])
        ai.wavelength = self.wavelength * 1e-10
        return ai
Exemple #14
0
 def setUp(self):
     self.edfPilatus = UtilsTest.getimage(self.__class__.saxsPilatus)
     self.maskFile = UtilsTest.getimage(self.__class__.maskFile)
     self.poniFile = UtilsTest.getimage(self.__class__.poniFile)
     self.maskRef = UtilsTest.getimage(self.__class__.maskRef)
     self.maskDummy = UtilsTest.getimage(self.__class__.maskDummy)
     self.ai = AzimuthalIntegrator()
     self.ai.load(self.poniFile)
     if not os.path.isdir(self.tmp_dir):
         os.mkdir(self.tmp_dir)
Exemple #15
0
    def load_from_h5(self, file, load_2d=True):
        """Loads data from hdf5 file and sets attributes.

        args:
            file: h5py file or group object
        """
        with self.file_lock:
            with self.arch_lock:
                if str(self.idx) not in file:
                    print("No data can be found")
                else:
                    grp = file[str(self.idx)]
                    if 'type' in grp.attrs:
                        if grp.attrs['type'] == 'EwaldArch':
                            lst_attr = [
                                "map_raw", "mask", "map_norm", "scan_info",
                                "ai_args", "gi", "static", "poni_dict"
                                # "poni_file", "gi", "static", "poni_dict"
                            ]
                            utils.h5_to_attributes(self, grp, lst_attr)
                            self.int_1d.from_hdf5(grp['int_1d'])
                            if load_2d:
                                self.int_2d.from_hdf5(grp['int_2d'])
                            self.poni = PONI.from_yamdict(
                                utils.h5_to_dict(grp['poni']))

                            # if self.poni_file is not None:
                            if self.poni_dict is not None:
                                self.integrator = create_ai_from_dict(
                                    self.poni_dict)
                                # if not self.gi:
                                #     self.integrator = pyFAI.load(self.poni_file)
                                #     self.integrator._rot3 -= np.deg2rad(90)
                                # else:
                                #     pFAI = pyFAI.load(self.poni_file)
                                #     calib_pars = dict(
                                #         dist=pFAI.dist, poni1=pFAI.poni1, poni2=pFAI.poni2,
                                #         rot1=pFAI.rot1, rot2=pFAI.rot2, rot3=pFAI.rot3,
                                #         wavelength=pFAI.wavelength, detector=pFAI.detector)
                                #     self.integrator = pygix.Transform(**calib_pars)
                                #     self.integrator.sample_orientation = 3  # 1 is horizontal, 2 is vertical
                                #     self.integrator.incident_angle = 1  # incident angle in deg
                                #     self.integrator.tilt_angle = 0  # tilt angle of sample in deg (misalignment in "chi")

                            else:
                                self.integrator = AzimuthalIntegrator(
                                    dist=self.poni.dist,
                                    poni1=self.poni.poni1,
                                    poni2=self.poni.poni2,
                                    rot1=self.poni.rot1,
                                    rot2=self.poni.rot2,
                                    rot3=self.poni.rot3,
                                    wavelength=self.poni.wavelength,
                                    detector=self.poni.detector,
                                    **self.ai_args)
Exemple #16
0
    def read_config(self):
        calfile = self.scandb.get_info('xrd_calibration')
        self.label = self.scandb.get_info('xrd_1dint_label')
        self.folder = self.scandb.get_info('map_folder')
        if self.folder.endswith('/'):
            self.folder = self.folder[:-1]

        calib = json.loads(self.scandb.get_detectorconfig(calfile).text)
        print("Read Integration configuration: ", calfile)
        if HAS_PYFAI:
            self.integrator = AzimuthalIntegrator(**calib)
Exemple #17
0
 def test_get_extent(self):
     dect = Detector(pixel1=1e-4, pixel2=1e-4)
     ai = AzimuthalIntegrator(detector=dect, dist=0.1)
     ai.setFit2D(directDist=1000, centerX=50.5, centerY=50.5)
     extent = _get_radial_extent(ai=ai, shape=(100, 100), unit="2th_rad")
     max_rad = 50 * np.sqrt(2)
     calc_extent = np.arctan(max_rad * 1e-4 / 1)
     np.testing.assert_almost_equal(
         extent[1],
         calc_extent,
     )
Exemple #18
0
def azimuthal_integrate(
    z,
    origin,
    detector_distance,
    detector,
    wavelength,
    size_1d,
    unit,
    kwargs_for_integrator,
    kwargs_for_integrate1d,
):
    """Calculate the azimuthal integral of z around a determined origin.

    This method is used for signals where the origin is iterated, compared to
    azimuthal_integrate_fast which is used when the origin in the data is
    constant.

    Parameters
    ----------
    z : np.array()
        Two-dimensional data array containing the signal.
    origin : np.array()
        A size 2 numpy array containing the position of the origin.
    detector_distance : float
        Detector distance in meters passed to pyFAI AzimuthalIntegrator.
    detector : pyFAI.detectors.Detector object
        A pyFAI detector used for the AzimuthalIntegrator.
    wavelength : float
        The electron wavelength in meters. Used by pyFAI AzimuthalIntegrator.
    size_1d : int
        The size of the returned 1D signal. (i.e. number of pixels in the 1D
        azimuthal integral.)
    unit : str
        The unit for for PyFAI integrate1d.
    *args :
        Arguments to be passed to AzimuthalIntegrator.
    **kwargs :
        Keyword arguments to be passed to AzimuthalIntegrator.
    Returns
    -------
    tth : np.array()
        One-dimensional scattering vector axis of z.
    I : np.array()
        One-dimensional azimuthal integral of z.
    """
    p1, p2 = origin[0] * detector.pixel1, origin[1] * detector.pixel2
    ai = AzimuthalIntegrator(dist=detector_distance,
                             poni1=p1,
                             poni2=p2,
                             detector=detector,
                             wavelength=wavelength,
                             **kwargs_for_integrator)
    tth, I = ai.integrate1d(z, size_1d, unit=unit, **kwargs_for_integrate1d)
    return tth, I
Exemple #19
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 error model, method

        self.__result1d = ai.integrate1d(
            data=self.__image,
            npt=self.__nPointsRadial,
            unit=self.__radialUnit,
            mask=self.__mask,
            polarization_factor=self.__polarizationFactor)

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

        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 = utils.from2ThRad(rings, self.__radialUnit,
                                         self.__wavelength, self.__directDist)
            except ValueError:
                message = "Convertion to unit %s not supported. Ring marks ignored"
                _logger.warning(message, self.__radialUnit)
                rings = []
            # Filter the rings which are not part of the result
            rings = filter(
                lambda x: self.__result1d.radial[0] <= x <= self.__result1d.
                radial[-1], rings)
            rings = list(rings)
        else:
            rings = []
        self.__ringAngles = rings

        self.__ai = ai
Exemple #20
0
def get_azimuthal_integrator(detector,
                             detector_distance,
                             shape,
                             center=None,
                             affine=None,
                             mask=None,
                             wavelength=None,
                             **kwargs):
    """Basic method for creating a azimuthal integrator.

    This helps to deal with taking some of the pyXEM standards and apply them to pyFAI

    Parameters
    ----------
    detector: pyFAI.detectors.Detector
        The detector to be integrated
    detector_distance:
        distance sample - detector plan (orthogonal distance, not along the beam), in meter.
    shape: (int, int)
        The shape of the signal we are operating on. For the
    center: (float, float)
        The center of the diffraction pattern
    affine: (3x3)
        The affine transformation to apply to the data
    mask: np.array
        A boolean array to be added to the integrator.
    wavelength: float
        The wavelength of the beam in meter. Needed to accounting for the
        Ewald sphere.
    kwargs: dict
        Any additional arguments to the Azimuthal Integrator class
    """
    if center is None:
        center = np.divide(shape, 2)  # Center is middle of the image
    if affine is not None:
        # create spline representation with (dx,dy) displacements
        dx, dy = _get_displacements(center=center, shape=shape, affine=affine)
        detector.max_shape = shape
        detector.shape = shape
        detector.set_dx(dx)
        detector.set_dy(dy)
    ai = AzimuthalIntegrator(detector=detector,
                             dist=detector_distance,
                             wavelength=wavelength,
                             **kwargs)
    if mask is not None:
        ai.set_mask(mask)
    if wavelength is not None:
        ai.wavelength = wavelength
    ai.setFit2D(directDist=detector_distance * 1000,
                centerX=center[1],
                centerY=center[0])
    return ai
Exemple #21
0
 def __init__(self, img, ai=None):
     """
     @param img: raw image we are working on
     @type img: ndarray
     @param ai: azimuhal integrator we are working on
     @type ai: pyFAI.azimuthalIntegrator.AzimutalIntegrator
     """
     self.img = img
     if ai is None:
         self.ai = AzimuthalIntegrator()
     else:
         self.ai = ai
Exemple #22
0
 def addDevice(self, device):
     if device:
         try:
             self.setSilence(True)
             devicechild = DeviceParameter(device)
             self.addChild(devicechild)
             ai = AzimuthalIntegrator(wavelength=self['Wavelength'])
             ai.detector = detectors.Pilatus2M()
             self.AIs[device] = ai
             self.multiAI.ais = list(self.AIs.values())
         finally:
             self.setSilence(False)
Exemple #23
0
    def openPoniFile(self, file=None):
        """
        Select and imports the calibration file
        """
        if file is None:
            self.poniFile = QFileDialog.getOpenFileName(
                self,
                'Select calibration file',
                directory=self.curDir,
                filter='Calibration file (*.poni)')[0]
            self.poniFileLineEdit.setText(self.poniFile)
        else:
            self.poniFile = file
        if os.path.exists(self.poniFile):
            self.setup_dict['poniFile'] = self.poniFile
            json.dump(self.setup_dict,
                      open('./SetupData/reducer_setup.txt', 'w'))
            fh = open(self.poniFile, 'r')
            lines = fh.readlines()
            self.calib_data = {}
            for line in lines:
                if line[0] != '#':
                    key, val = line.split(': ')
                    self.calib_data[key] = float(val)
            self.dist = self.calib_data['Distance']
            self.pixel1 = self.calib_data['PixelSize1']
            self.pixel2 = self.calib_data['PixelSize2']
            self.poni1 = self.calib_data['Poni1']
            self.poni2 = self.calib_data['Poni2']
            self.rot1 = self.calib_data['Rot1']
            self.rot2 = self.calib_data['Rot2']
            self.rot3 = self.calib_data['Rot3']
            self.wavelength = self.calib_data['Wavelength']
            self.ai = AzimuthalIntegrator(dist=self.dist,
                                          poni1=self.poni1,
                                          poni2=self.poni2,
                                          pixel1=self.pixel1,
                                          pixel2=self.pixel2,
                                          rot1=self.rot1,
                                          rot2=self.rot2,
                                          rot3=self.rot3,
                                          wavelength=self.wavelength)
            #pos=[self.poni2/self.pixel2,self.poni1/self.pixel1]
            #self.roi=cake(pos,movable=False)
            #self.roi.sigRegionChangeStarted.connect(self.endAngleChanged)

            #self.imageView.addItem(self.roi)
        else:
            QMessageBox.warning(
                self, 'File error',
                'The calibration file ' + self.poniFile + ' doesnot exists.',
                QMessageBox.Ok)
 def create_cake_geometry(self):
     self.cake_geometry = AzimuthalIntegrator()
     pyFAI_parameter = self.pattern_geometry.getPyFAI()
     pyFAI_parameter['wavelength'] = self.pattern_geometry.wavelength
     self.cake_geometry.setPyFAI(dist=pyFAI_parameter['dist'],
                                 poni1=pyFAI_parameter['poni1'],
                                 poni2=pyFAI_parameter['poni2'],
                                 rot1=pyFAI_parameter['rot1'],
                                 rot2=pyFAI_parameter['rot2'],
                                 rot3=pyFAI_parameter['rot3'],
                                 pixel1=pyFAI_parameter['pixel1'],
                                 pixel2=pyFAI_parameter['pixel2'])
     self.cake_geometry.wavelength = pyFAI_parameter['wavelength']
Exemple #25
0
def test_AzimuthalIntegrator_pickle():
    import dill
    import numpy as np
    from pyFAI.azimuthalIntegrator import AzimuthalIntegrator

    det = pyFAI.detectors.detector_factory('pilatus2m')
    ai = AzimuthalIntegrator(detector=det)
    ai.set_wavelength(.1)
    spectra = ai.integrate1d(np.ones(det.shape), 1000)  # force lut generation
    dump = dumps(ai)
    newai = loads(dump)
    assert np.array_equal(newai.integrate1d(np.ones(det.shape), 1000), spectra)
    assert newai.detector.shape == (1679, 1475)
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.data = fabio.open(UtilsTest.getimage("1788/moke.tif")).data
     self.lst_data = [
         self.data[:250, :300], self.data[250:, :300],
         self.data[:250, 300:], self.data[250:, 300:]
     ]
     self.det = Detector(1e-4, 1e-4)
     self.det.max_shape = (500, 600)
     self.sub_det = Detector(1e-4, 1e-4)
     self.sub_det.max_shape = (250, 300)
     self.ai = AzimuthalIntegrator(0.1, 0.03, 0.03, detector=self.det)
     self.range = (0, 23)
     self.ais = [
         AzimuthalIntegrator(0.1, 0.030, 0.03, detector=self.sub_det),
         AzimuthalIntegrator(0.1, 0.005, 0.03, detector=self.sub_det),
         AzimuthalIntegrator(0.1, 0.030, 0.00, detector=self.sub_det),
         AzimuthalIntegrator(0.1, 0.005, 0.00, detector=self.sub_det),
     ]
     self.mg = MultiGeometry(self.ais,
                             radial_range=self.range,
                             unit="2th_deg")
     self.N = 390
 def setUp(self):
     self.ai = AzimuthalIntegrator()
     shape = (10, 15)
     self.rnd1 = numpy.random.random(shape).astype(numpy.float32)
     self.rnd2 = numpy.random.random(shape).astype(numpy.float32)
     testdir = os.path.join(os.path.dirname(__file__), "tmp")
     if not os.path.isdir(testdir):
         os.makedirs(testdir)
     fd, self.edf1 = tempfile.mkstemp(".edf", "testAI1", testdir)
     os.close(fd)
     fd, self.edf2 = tempfile.mkstemp(".edf", "testAI2", testdir)
     os.close(fd)
     fabio.edfimage.edfimage(data=self.rnd1).write(self.edf1)
     fabio.edfimage.edfimage(data=self.rnd2).write(self.edf2)
Exemple #28
0
 def load(self, filename):
     """
     Loads a calibration file and and sets all the calibration parameter.
     :param filename: filename for a *.poni calibration file
     """
     self.pattern_geometry = AzimuthalIntegrator()
     self.pattern_geometry.load(filename)
     self.orig_pixel1 = self.pattern_geometry.pixel1
     self.orig_pixel2 = self.pattern_geometry.pixel2
     self.calibration_name = get_base_name(filename)
     self.filename = filename
     self.is_calibrated = True
     self.create_cake_geometry()
     self.set_supersampling()
Exemple #29
0
    def setUp(self):
        self.ai = AzimuthalIntegrator()
        shape = (10, 15)
        self.rnd1 = numpy.random.random(shape).astype(numpy.float32)
        self.rnd2 = numpy.random.random(shape).astype(numpy.float32)
        if not os.path.isdir(self.tmp_dir):
            os.mkdir(self.tmp_dir)

        fd, self.edf1 = tempfile.mkstemp(".edf", "testAI1", self.tmp_dir)
        os.close(fd)
        fd, self.edf2 = tempfile.mkstemp(".edf", "testAI2", self.tmp_dir)
        os.close(fd)
        fabio.edfimage.edfimage(data=self.rnd1).write(self.edf1)
        fabio.edfimage.edfimage(data=self.rnd2).write(self.edf2)
Exemple #30
0
    def __init__(self, img_model=None):
        super(CalibrationModel, self).__init__()
        """
        :param img_model:
        :type img_model: ImgModel
        """
        self.img_model = img_model
        self.points = []
        self.points_index = []
        self.pattern_geometry = AzimuthalIntegrator()
        self.pattern_geometry_img_shape = None
        self.cake_geometry = None
        self.cake_geometry_img_shape = None
        self.calibrant = Calibrant()
        self.pattern_geometry.wavelength = 0.3344e-10
        self.start_values = {'dist': 200e-3,
                             'wavelength': 0.3344e-10,
                             'pixel_width': 79e-6,
                             'pixel_height': 79e-6,
                             'polarization_factor': 0.99}
        self.orig_pixel1 = 79e-6
        self.orig_pixel2 = 79e-6
        self.fit_wavelength = False
        self.fit_distance = True
        self.fit_poni1 = True
        self.fit_poni2 = True
        self.fit_rot1 = True
        self.fit_rot2 = True
        self.fit_rot3 = True
        self.is_calibrated = False
        self.use_mask = False
        self.filename = ''
        self.calibration_name = 'None'
        self.polarization_factor = 0.99
        self.supersampling_factor = 1
        self.correct_solid_angle = True
        self._calibrants_working_dir = calibrants_path

        self.distortion_spline_filename = None

        self.tth = np.linspace(0, 25)
        self.int = np.sin(self.tth)
        self.num_points = len(self.int)

        self.cake_img = np.zeros((2048, 2048))
        self.cake_tth = None
        self.cake_azi = None

        self.peak_search_algorithm = None