コード例 #1
0
ファイル: test_geometry.py プロジェクト: lukasHD/pyFAI
 def setUp(self):
     from pyFAI.detectors import Detector
     self.shape = (50, 49)
     size = (50, 60)
     det = Detector(*size)
     det.max_shape = self.shape
     self.geo = geometry.Geometry(detector=det, wavelength=1e-10)
コード例 #2
0
 def __init__(self):
     Detector.__init__(self)
     self.resolution = (1024, 1024)
     self.shape = self.resolution
     self.pixel1 = 102e-6
     self.pixel2 = 102e-6
     self.mask = np.zeros(self.shape)
     self.spline = None
コード例 #3
0
 def __init__(self):
     Detector.__init__(self)
     self.resolution = (2000, 2000)
     self.shape = self.resolution
     self.pixel1 = 2.0e-4
     self.pixel2 = 2.0e-4
     self.mask = np.zeros(self.shape)
     self.spline = None
コード例 #4
0
 def __init__(self):
     Detector.__init__(self)
     self.resolution = (1750, 1750)
     self.shape = self.resolution
     self.pixel1 = 11e-5
     self.pixel2 = 11e-5
     self.mask = np.zeros(self.shape)
     self.spline = None
コード例 #5
0
 def __init__(self):
     Detector.__init__(self)
     self.resolution = (2167, 2070)
     self.shape = self.resolution
     self.pixel1 = 7.5e-5
     self.pixel2 = 7.5e-5
     self.mask = np.zeros(self.shape)
     self.spline = None
コード例 #6
0
ファイル: Detectors.py プロジェクト: tschoonj/NanoPeakCell
 def __init__(self):
     Detector.__init__(self)
     self.resolution=(1024,1024)
     self.shape = self.resolution
     self.pixel1 = 102e-6
     self.pixel2 = 102e-6
     self.mask = np.zeros(self.shape)
     self.spline = None
コード例 #7
0
ファイル: Detectors.py プロジェクト: tschoonj/NanoPeakCell
 def __init__(self):
     Detector.__init__(self)
     self.resolution=(1750,1750)
     self.shape = self.resolution
     self.pixel1 = 11e-5
     self.pixel2 = 11e-5
     self.mask = np.zeros(self.shape)
     self.spline = None
コード例 #8
0
ファイル: Detectors.py プロジェクト: tschoonj/NanoPeakCell
 def __init__(self):
     Detector.__init__(self)
     self.resolution=(2167,2070)
     self.shape = self.resolution
     self.pixel1 = 7.5e-5
     self.pixel2 = 7.5e-5
     self.mask = np.zeros(self.shape)
     self.spline = None
コード例 #9
0
ファイル: Detectors.py プロジェクト: tschoonj/NanoPeakCell
 def __init__(self):
     Detector.__init__(self)
     self.resolution=(2399,2399)
     self.shape = self.resolution
     self.pixel1 = 5e-5
     self.pixel2 = 5e-5
     self.mask = np.zeros(self.shape)
     self.spline = None
コード例 #10
0
 def __init__(self):
     Detector.__init__(self)
     self.resolution = (2399, 2399)
     self.shape = self.resolution
     self.pixel1 = 5e-5
     self.pixel2 = 5e-5
     self.mask = np.zeros(self.shape)
     self.spline = None
コード例 #11
0
 def __init__(self):
     Detector.__init__(self)
     self.resolution=(4096,4096)
     self.shape = self.resolution
     self.pixel1 = 1.5e-5
     self.pixel2 = 1.5e-5
     self.mask = np.zeros(self.shape)
     self.spline = None
コード例 #12
0
 def reset_detector(self):
     self.detector_mode = DetectorModes.CUSTOM
     self.detector = Detector(pixel1=self.orig_pixel1,
                              pixel2=self.orig_pixel2)
     self.pattern_geometry.detector = self.detector
     if self.cake_geometry:
         self.cake_geometry.detector = self.detector
     self.set_supersampling()
コード例 #13
0
    def __init__(self, img_model=None):
        """
        :param img_model:
        :type img_model: ImgModel
        """
        super(CalibrationModel, self).__init__()
        self.img_model = img_model
        self.points = []
        self.points_index = []

        self.detector = Detector(pixel1=79e-6, pixel2=79e-6)
        self.detector_mode = DetectorModes.CUSTOM
        self._original_detector = None  # used for saving original state before rotating or flipping
        self.pattern_geometry = GeometryRefinement(
            detector=self.detector, wavelength=0.3344e-10, poni1=0,
            poni2=0)  # default params are necessary, otherwise fails...
        self.pattern_geometry_img_shape = None
        self.cake_geometry = None
        self.cake_geometry_img_shape = None
        self.calibrant = Calibrant()

        self.orig_pixel1 = self.detector.pixel1  # needs to be extra stored for applying supersampling
        self.orig_pixel2 = self.detector.pixel2

        self.start_values = {
            'dist': 200e-3,
            'wavelength': 0.3344e-10,
            'polarization_factor': 0.99
        }
        self.fit_wavelength = False
        self.fixed_values = {
        }  # dictionary for fixed parameters during calibration (keys can be e.g. rot1, poni1 etc.
        # and values are the values to what the respective parameter will be set
        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
コード例 #14
0
ファイル: pyfai_utils.py プロジェクト: tinabe/pyxem
def _get_setup(wavelength, pyxem_unit, pixel_scale, radial_range=None):
    """Returns a generic set up for a flat detector with accounting for Ewald sphere effects."""
    units_table = {
        "2th_deg": None,
        "2th_rad": None,
        "q_nm^-1": 1e-9,
        "q_A^-1": 1e-10,
        "k_nm^-1": 1e-9,
        "k_A^-1": 1e-10,
    }
    wavelength_scale = units_table[pyxem_unit]
    detector_distance = 1
    if wavelength_scale is None:
        if pyxem_unit == "2th_deg":
            pixel_1_size = np.tan((pixel_scale[0] / 180) * np.pi)
            pixel_2_size = np.tan((pixel_scale[1] / 180) * np.pi)
        if pyxem_unit == "2th_rad":
            pixel_1_size = np.tan(pixel_scale[0])
            pixel_2_size = np.tan(pixel_scale[1])
    else:
        theta0 = pixel_scale[0] * (wavelength / wavelength_scale)
        theta1 = pixel_scale[1] * (wavelength / wavelength_scale)
        pixel_1_size = np.tan(theta0) * detector_distance
        pixel_2_size = np.tan(theta1) * detector_distance
    detector = Detector(pixel1=pixel_1_size, pixel2=pixel_2_size)
    if radial_range is not None:
        radial_range = [radial_range[0], radial_range[1]]
    return (
        detector,
        detector_distance,
        radial_range,
    )
コード例 #15
0
def _get_setup(wavelength, pyxem_unit, pixel_scale, radial_range=None):
    """Returns a generic set up for a flat detector with accounting for Ewald sphere effects."""
    units_table = {
        "2th_deg": [None, 1, "2th_deg"],
        "2th_rad": [None, 1, "2th_rad"],
        "q_nm^-1": [1e-9, 1, "q_nm^-1"],
        "q_A^-1": [1e-10, 1, "q_A^-1"],
        "k_nm^-1": [1e-9, 2 * np.pi, "q_nm^-1"],  # add to pyFAI
        "k_A^-1": [1e-10, 2 * np.pi, "q_A^-1"],  # add to pyFAI
    }
    wavelength_scale = units_table[pyxem_unit][0]
    scale_factor = units_table[pyxem_unit][1]
    unit = units_table[pyxem_unit][2]
    detector_distance = 1
    if wavelength_scale is None:
        if pyxem_unit == "2th_deg":
            pixel_1_size = np.tan((pixel_scale[0] / 180) * np.pi)
            pixel_2_size = np.tan((pixel_scale[1] / 180) * np.pi)
        if pyxem_unit == "2th_rad":
            pixel_1_size = np.tan(pixel_scale[0])
            pixel_2_size = np.tan(pixel_scale[1])
    else:
        pixel_1_size = (pixel_scale[0] * (wavelength / wavelength_scale) *
                        detector_distance)
        pixel_2_size = (pixel_scale[1] * (wavelength / wavelength_scale) *
                        detector_distance)
    detector = Detector(pixel1=pixel_1_size, pixel2=pixel_2_size)
    if radial_range is not None:
        radial_range = [
            radial_range[0] * scale_factor, radial_range[1] * scale_factor
        ]
    return detector, detector_distance, radial_range, unit, scale_factor
コード例 #16
0
 def __init__(self,
              dist=0,
              poni1=0,
              poni2=0,
              rot1=0,
              rot2=0,
              rot3=0,
              wavelength=1e-10,
              detector=Detector(100e-6, 100e-6)):
     """
     dist: float, distance to detector, meters
     poni1: float, location of point of nearest incidence 1, meters
     poni2: float, location of point of nearest incidence 2, meters
     rot1: float, angle of rotation 1, radians
     rot2: float, angle of rotation 2, radians
     rot3: float, angle of rotation 3, radians
     wavelength: float, wavelength of energy, used for
         collecting data, meters
     detector: pyFAI Detector, detector object
     """
     self.dist = dist
     self.poni1 = poni1
     self.poni2 = poni2
     self.rot1 = rot1
     self.rot2 = rot2
     self.rot3 = rot3
     self.wavelength = wavelength
     self.detector = detector
コード例 #17
0
ファイル: test_pyfai_utils.py プロジェクト: ptim0626/pyxem
    def test_get_azimuthal_integrator(self):
        dect = Detector(pixel1=1e-4, pixel2=1e-4, max_shape=(20, 20))
        ai = get_azimuthal_integrator(detector=dect,
                                      detector_distance=0.001,
                                      shape=(20, 20),
                                      center=(10.5, 10.5))
        assert isinstance(ai, AzimuthalIntegrator)
        ai_mask = get_azimuthal_integrator(
            detector=dect,
            detector_distance=1,
            shape=(20, 20),
            center=(10.5, 10.5),
            mask=np.zeros((20, 20)),
        )

        assert isinstance(ai_mask, AzimuthalIntegrator)
        aff = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
        ai_affine = get_azimuthal_integrator(
            detector=dect,
            detector_distance=1,
            shape=(20, 20),
            center=(10.5, 10.5),
            mask=np.zeros((20, 20)),
            affine=aff,
        )
        assert isinstance(ai_affine, AzimuthalIntegrator)
コード例 #18
0
 def setUp(self):
     from pyFAI.detectors import Detector
     self.shape = (50, 49)
     size = (50, 60)
     det = Detector(*size, max_shape=self.shape)
     self.geo = geometry.Geometry(detector=det, wavelength=1e-10)
     self.former_loglevel = geometry.logger.level
     geometry.logger.setLevel(logging.ERROR)
コード例 #19
0
ファイル: test_pyfai_utils.py プロジェクト: ptim0626/pyxem
 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,
     )
コード例 #20
0
    def test_2d_azimuthal_integral_pyfai(self, ones):
        from pyFAI.detectors import Detector

        d = Detector(pixel1=1e-4, pixel2=1e-4)
        ones.get_azimuthal_integral2d(
            npt_rad=10,
            detector=d,
            detector_dist=1,
            method="BBox",
            wavelength=1e-9,
            correctSolidAngle=False,
            unit="q_nm^-1",
        )
コード例 #21
0
 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
コード例 #22
0
    def test_1d_integrate_fast(self, radial_pattern):
        from pyxem.utils.pyfai_utils import get_azimuthal_integrator

        dect = Detector(pixel1=1e-4, pixel2=1e-4)
        ai = get_azimuthal_integrator(detector=dect,
                                      detector_distance=1,
                                      shape=np.shape(radial_pattern))
        integration = azimuthal_integrate1d_fast(
            radial_pattern,
            ai,
            npt_rad=100,
            method="numpy",
            unit="2th_rad",
            correctSolidAngle=True,
        )
コード例 #23
0
    def test_load_detector_with_spline_file(self):
        # create detector and save it
        spline_detector = Detector()
        spline_detector.set_splineFile(os.path.join(data_path, 'distortion', 'f4mnew.spline'))
        spline_detector.save(os.path.join(data_path, 'detector_with_spline.h5'))

        # load and check if it is working
        self.calibration_model.load_detector_from_file(os.path.join(data_path, 'detector_with_spline.h5'))
        detector = self.calibration_model.detector
        self.assertAlmostEqual(detector.pixel1, 50e-6)
        self.assertFalse(detector.uniform_pixel)
コード例 #24
0
 def __init__(self,
              dist=0,
              poni1=0,
              poni2=0,
              rot1=0,
              rot2=0,
              rot3=0,
              wavelength=1e-10,
              detector=Detector(100e-6, 100e-6)):
     self.dist = dist
     self.poni1 = poni1
     self.poni2 = poni2
     self.rot1 = rot1
     self.rot2 = rot2
     self.rot3 = rot3
     self.wavelength = wavelength
     self.detector = detector
コード例 #25
0
 def test_2d_integrate_slow(self, radial_pattern):
     dect = Detector(pixel1=1e-4, pixel2=1e-4)
     integration = azimuthal_integrate2d_slow(radial_pattern,
                                              detector=dect,
                                              detector_distance=1,
                                              npt_rad=100)
コード例 #26
0
 def __init__(self, size_x, size_y):
     MAX_SHAPE = size_x, size_y
     Detector.__init__(self, pixel1=1, pixel2=1, max_shape=MAX_SHAPE)
コード例 #27
0
class CalibrationModel(QtCore.QObject):
    detector_reset = QtCore.Signal()

    def __init__(self, img_model=None):
        """
        :param img_model:
        :type img_model: ImgModel
        """
        super(CalibrationModel, self).__init__()
        self.img_model = img_model
        self.points = []
        self.points_index = []

        self.detector = Detector(pixel1=79e-6, pixel2=79e-6)
        self.detector_mode = DetectorModes.CUSTOM
        self._original_detector = None  # used for saving original state before rotating or flipping
        self.pattern_geometry = GeometryRefinement(
            detector=self.detector, wavelength=0.3344e-10, poni1=0,
            poni2=0)  # default params are necessary, otherwise fails...
        self.pattern_geometry_img_shape = None
        self.cake_geometry = None
        self.cake_geometry_img_shape = None
        self.calibrant = Calibrant()

        self.orig_pixel1 = self.detector.pixel1  # needs to be extra stored for applying supersampling
        self.orig_pixel2 = self.detector.pixel2

        self.start_values = {
            'dist': 200e-3,
            'wavelength': 0.3344e-10,
            'polarization_factor': 0.99
        }
        self.fit_wavelength = False
        self.fixed_values = {
        }  # dictionary for fixed parameters during calibration (keys can be e.g. rot1, poni1 etc.
        # and values are the values to what the respective parameter will be set
        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

    def find_peaks_automatic(self, x, y, peak_ind):
        """
        Searches peaks by using the Massif algorithm
        :param float x:
            x-coordinate in pixel - should be from original image (not supersampled x-coordinate)
        :param float y:
            y-coordinate in pixel - should be from original image (not supersampled y-coordinate)
        :param peak_ind:
            peak/ring index to which the found points will be added
        :return:
            array of points found
        """
        massif = Massif(self.img_model.img_data)
        cur_peak_points = massif.find_peaks(
            (int(np.round(x)), int(np.round(y))), stdout=DummyStdOut())
        if len(cur_peak_points):
            self.points.append(np.array(cur_peak_points))
            self.points_index.append(peak_ind)
        return np.array(cur_peak_points)

    def find_peak(self, x, y, search_size, peak_ind):
        """
        Searches a peak around the x,y position. It just searches for the maximum value in a specific search size.
        :param int x:
            x-coordinate in pixel - should be from original image (not supersampled x-coordinate)
        :param int y:
            y-coordinate in pixel - should be form original image (not supersampled y-coordinate)
        :param search_size:
            the length of the search rectangle in pixels in all direction in which the algorithm searches for
            the maximum peak
        :param peak_ind:
            peak/ring index to which the found points will be added
        :return:
            point found (as array)
        """
        left_ind = int(np.round(x - search_size * 0.5))
        if left_ind < 0:
            left_ind = 0
        top_ind = int(np.round(y - search_size * 0.5))
        if top_ind < 0:
            top_ind = 0
        search_array = self.img_model.img_data[left_ind:(left_ind +
                                                         search_size),
                                               top_ind:(top_ind + search_size)]
        x_ind, y_ind = np.where(search_array == search_array.max())
        x_ind = x_ind[0] + left_ind
        y_ind = y_ind[0] + top_ind
        self.points.append(np.array([x_ind, y_ind]))
        self.points_index.append(peak_ind)
        return np.array([np.array((x_ind, y_ind))])

    def clear_peaks(self):
        self.points = []
        self.points_index = []

    def remove_last_peak(self):
        if self.points:
            num_points = int(
                self.points[-1].size /
                2)  # each peak is x, y so length is twice as number of peaks
            self.points.pop(-1)
            self.points_index.pop(-1)
            return num_points

    def create_cake_geometry(self):
        self.cake_geometry = AzimuthalIntegrator(
            splineFile=self.distortion_spline_filename, detector=self.detector)

        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'],
                                    detector=self.detector)

        self.cake_geometry.wavelength = pyFAI_parameter['wavelength']

    def setup_peak_search_algorithm(self, algorithm, mask=None):
        """
        Initializes the peak search algorithm on the current image
        :param algorithm:
            peak search algorithm used. Possible algorithms are 'Massif' and 'Blob'
        :param mask:
            if a mask is used during the process this is provided here as a 2d array for the image.
        """

        if algorithm == 'Massif':
            self.peak_search_algorithm = Massif(self.img_model.img_data)
        elif algorithm == 'Blob':
            if mask is not None:
                self.peak_search_algorithm = BlobDetection(
                    self.img_model.img_data * mask)
            else:
                self.peak_search_algorithm = BlobDetection(
                    self.img_model.img_data)
            self.peak_search_algorithm.process()
        else:
            return

    def search_peaks_on_ring(self,
                             ring_index,
                             delta_tth=0.1,
                             min_mean_factor=1,
                             upper_limit=55000,
                             mask=None):
        """
        This function is searching for peaks on an expected ring. It needs an initial calibration
        before. Then it will search for the ring within some delta_tth and other parameters to get
        peaks from the calibrant.

        :param ring_index: the index of the ring for the search
        :param delta_tth: search space around the expected position in two theta
        :param min_mean_factor: a factor determining the minimum peak intensity to be picked up. it is based
                                on the mean value of the search area defined by delta_tth. Pick a large value
                                for larger minimum value and lower for lower minimum value. Therefore, a smaller
                                number is more prone to picking up noise. typical values like between 1 and 3.
        :param upper_limit: maximum intensity for the peaks to be picked
        :param mask: in case the image has to be masked from certain areas, it need to be given here. Default is None.
                     The mask should be given as an 2d array with the same dimensions as the image, where 1 denotes a
                     masked pixel and all others should be 0.
        """
        self.reset_supersampling()
        if not self.is_calibrated:
            return

        # transform delta from degree into radians
        delta_tth = delta_tth / 180.0 * np.pi

        # get appropriate two theta value for the ring number
        tth_calibrant_list = self.calibrant.get_2th()
        if ring_index >= len(tth_calibrant_list):
            raise NotEnoughSpacingsInCalibrant()
        tth_calibrant = np.float(tth_calibrant_list[ring_index])

        # get the calculated two theta values for the whole image
        tth_array = self.pattern_geometry.twoThetaArray(
            self.img_model.img_data.shape)

        # create mask based on two_theta position
        ring_mask = abs(tth_array - tth_calibrant) <= delta_tth

        if mask is not None:
            mask = np.logical_and(ring_mask, np.logical_not(mask))
        else:
            mask = ring_mask

        # calculate the mean and standard deviation of this area
        sub_data = np.array(self.img_model.img_data.ravel()[np.where(
            mask.ravel())],
                            dtype=np.float64)
        sub_data[np.where(sub_data > upper_limit)] = np.NaN
        mean = np.nanmean(sub_data)
        std = np.nanstd(sub_data)

        # set the threshold into the mask (don't detect very low intensity peaks)
        threshold = min_mean_factor * mean + std
        mask2 = np.logical_and(self.img_model.img_data > threshold, mask)
        mask2[np.where(self.img_model.img_data > upper_limit)] = False
        size2 = mask2.sum(dtype=int)

        keep = int(np.ceil(np.sqrt(size2)))
        try:
            sys.stdout = DummyStdOut
            res = self.peak_search_algorithm.peaks_from_area(mask2,
                                                             Imin=mean - std,
                                                             keep=keep)
            sys.stdout = sys.__stdout__
        except IndexError:
            res = []

        # Store the result
        if len(res):
            self.points.append(np.array(res))
            self.points_index.append(ring_index)

        self.set_supersampling()
        self.pattern_geometry.reset()

    def set_calibrant(self, filename):
        self.calibrant = Calibrant()
        self.calibrant.load_file(filename)
        self.pattern_geometry.calibrant = self.calibrant

    def set_start_values(self, start_values):
        self.start_values = start_values
        self.polarization_factor = start_values['polarization_factor']

    def set_pixel_size(self, pixel_size):
        """
        :param pixel_size: tuple with pixel_width and pixel height as element
        """
        self.orig_pixel1 = pixel_size[0]
        self.orig_pixel2 = pixel_size[1]

        self.detector.pixel1 = self.orig_pixel1
        self.detector.pixel2 = self.orig_pixel2
        self.set_supersampling()

    def set_fixed_values(self, fixed_values):
        """
        Sets the fixed and not fitted values for the geometry refinement
        :param fixed_values: a dictionary with the fixed parameters as key and their corresponding fixed value, possible
                             keys: 'dist', 'rot1', 'rot2', 'rot3', 'poni1', 'poni2'

        """
        self.fixed_values = fixed_values

    def calibrate(self):
        self.reset_supersampling()
        self.pattern_geometry = GeometryRefinement(
            self.create_point_array(self.points, self.points_index),
            dist=self.start_values['dist'],
            wavelength=self.start_values['wavelength'],
            detector=self.detector,
            calibrant=self.calibrant,
            splineFile=self.distortion_spline_filename)

        self.refine()
        self.create_cake_geometry()
        self.is_calibrated = True

        self.calibration_name = 'current'
        self.set_supersampling()
        # reset the integrator (not the geometric parameters)
        self.pattern_geometry.reset()

    def refine(self):
        self.reset_supersampling()
        self.pattern_geometry.data = self.create_point_array(
            self.points, self.points_index)

        fix = ['wavelength']
        if self.fit_wavelength:
            fix = []

        for key, value in self.fixed_values.items():
            fix.append(key)
            setattr(self.pattern_geometry, key, value)

        if self.fit_wavelength:
            self.pattern_geometry.refine2(fix=fix)
        self.pattern_geometry.refine2_wavelength(fix=fix)

        self.create_cake_geometry()
        self.set_supersampling()
        # reset the integrator (not the geometric parameters)
        self.pattern_geometry.reset()

    def _check_detector_and_image_shape(self):
        if self.detector.shape is not None:
            if self.detector.shape != self.img_model.img_data.shape:
                self.reset_detector()
                self.detector_reset.emit()

    def _prepare_integration_mask(self, mask):
        if mask is None:
            return self.detector.mask
        else:
            if self.detector.mask is None:
                return mask
            else:
                if mask.shape == self.detector.mask.shape:
                    return np.logical_or(self.detector.mask, mask)

    def _prepare_integration_super_sampling(self, mask):
        if self.supersampling_factor > 1:
            img_data = supersample_image(self.img_model.img_data,
                                         self.supersampling_factor)
            if mask is not None:
                mask = supersample_image(mask, self.supersampling_factor)
        else:
            img_data = self.img_model.img_data
        return img_data, mask

    def integrate_1d(self,
                     num_points=None,
                     mask=None,
                     polarization_factor=None,
                     filename=None,
                     unit='2th_deg',
                     method='csr'):
        if np.sum(mask) == self.img_model.img_data.shape[
                0] * self.img_model.img_data.shape[1]:
            # do not perform integration if the image is completely masked...
            return self.tth, self.int

        if self.pattern_geometry_img_shape != self.img_model.img_data.shape:
            # if cake geometry was used on differently shaped image before the azimuthal integrator needs to be reset
            self.pattern_geometry.reset()
            self.pattern_geometry_img_shape = self.img_model.img_data.shape

        if polarization_factor is None:
            polarization_factor = self.polarization_factor

        self._check_detector_and_image_shape()
        mask = self._prepare_integration_mask(mask)
        img_data, mask = self._prepare_integration_super_sampling(mask)

        if num_points is None:
            num_points = self.calculate_number_of_pattern_points(
                img_data.shape, 2)

        self.num_points = num_points

        t1 = time.time()

        if unit is 'd_A':
            try:
                self.tth, self.int = self.pattern_geometry.integrate1d(
                    img_data,
                    num_points,
                    method=method,
                    unit='2th_deg',
                    mask=mask,
                    polarization_factor=polarization_factor,
                    correctSolidAngle=self.correct_solid_angle,
                    filename=filename)
            except NameError:
                self.tth, self.int = self.pattern_geometry.integrate1d(
                    img_data,
                    num_points,
                    method='csr',
                    unit='2th_deg',
                    mask=mask,
                    polarization_factor=polarization_factor,
                    correctSolidAngle=self.correct_solid_angle,
                    filename=filename)
            self.tth = self.pattern_geometry.wavelength / (
                2 * np.sin(self.tth / 360 * np.pi)) * 1e10
            self.int = self.int
        else:
            try:
                self.tth, self.int = self.pattern_geometry.integrate1d(
                    img_data,
                    num_points,
                    method=method,
                    unit=unit,
                    mask=mask,
                    polarization_factor=polarization_factor,
                    correctSolidAngle=self.correct_solid_angle,
                    filename=filename)
            except NameError:
                self.tth, self.int = self.pattern_geometry.integrate1d(
                    img_data,
                    num_points,
                    method='csr',
                    unit=unit,
                    mask=mask,
                    polarization_factor=polarization_factor,
                    correctSolidAngle=self.correct_solid_angle,
                    filename=filename)
        logger.info('1d integration of {0}: {1}s.'.format(
            os.path.basename(self.img_model.filename),
            time.time() - t1))

        ind = np.where((self.int > 0) & (~np.isnan(self.int)))
        self.tth = self.tth[ind]
        self.int = self.int[ind]
        return self.tth, self.int

    def integrate_2d(self,
                     mask=None,
                     polarization_factor=None,
                     unit='2th_deg',
                     method='csr',
                     rad_points=None,
                     azimuth_points=360,
                     azimuth_range=None):
        if polarization_factor is None:
            polarization_factor = self.polarization_factor

        if self.cake_geometry_img_shape != self.img_model.img_data.shape:
            # if cake geometry was used on differently shaped image before the azimuthal integrator needs to be reset
            self.cake_geometry.reset()
            self.cake_geometry_img_shape = self.img_model.img_data.shape

        self._check_detector_and_image_shape()
        mask = self._prepare_integration_mask(mask)
        img_data, mask = self._prepare_integration_super_sampling(mask)

        if rad_points is None:
            rad_points = self.calculate_number_of_pattern_points(
                img_data.shape, 2)
        self.num_points = rad_points

        t1 = time.time()

        res = self.cake_geometry.integrate2d(
            img_data,
            rad_points,
            azimuth_points,
            azimuth_range=azimuth_range,
            method=method,
            mask=mask,
            unit=unit,
            polarization_factor=polarization_factor,
            correctSolidAngle=self.correct_solid_angle)
        logger.info('2d integration of {0}: {1}s.'.format(
            os.path.basename(self.img_model.filename),
            time.time() - t1))
        self.cake_img = res[0]
        self.cake_tth = res[1]
        self.cake_azi = res[2]
        return self.cake_img

    def create_point_array(self, points, points_ind):
        res = []
        for i, point_list in enumerate(points):
            if point_list.shape == (2, ):
                res.append([point_list[0], point_list[1], points_ind[i]])
            else:
                for point in point_list:
                    res.append([point[0], point[1], points_ind[i]])
        return np.array(res)

    def get_point_array(self):
        return self.create_point_array(self.points, self.points_index)

    def get_calibration_parameter(self):
        pyFAI_parameter = self.pattern_geometry.getPyFAI()
        pyFAI_parameter['polarization_factor'] = self.polarization_factor
        try:
            fit2d_parameter = self.pattern_geometry.getFit2D()
            fit2d_parameter['polarization_factor'] = self.polarization_factor
        except TypeError:
            fit2d_parameter = None

        pyFAI_parameter['wavelength'] = self.pattern_geometry.wavelength
        if fit2d_parameter:
            fit2d_parameter['wavelength'] = self.pattern_geometry.wavelength

        return pyFAI_parameter, fit2d_parameter

    def calculate_number_of_pattern_points(self,
                                           img_shape,
                                           max_dist_factor=1.5):
        # calculates the number of points for an integrated pattern, based on the distance of the beam center to the the
        # image corners. Maximum value is determined by the shape of the image.
        fit2d_parameter = self.pattern_geometry.getFit2D()
        center_x = fit2d_parameter['centerX']
        center_y = fit2d_parameter['centerY']
        width, height = img_shape

        if width > center_x > 0:
            side1 = np.max([abs(width - center_x), center_x])
        else:
            side1 = width

        if center_y < height and center_y > 0:
            side2 = np.max([abs(height - center_y), center_y])
        else:
            side2 = height
        max_dist = np.sqrt(side1**2 + side2**2)
        return int(max_dist * max_dist_factor)

    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 = GeometryRefinement(
            wavelength=0.3344e-10, detector=self.detector, poni1=0,
            poni2=0)  # default params are necessary, otherwise fails...
        self.pattern_geometry.load(filename)
        self.orig_pixel1 = self.pattern_geometry.pixel1
        self.orig_pixel2 = self.pattern_geometry.pixel2

        if self.pattern_geometry.pixel1 == self.detector.pixel1 and \
                self.pattern_geometry.pixel2 == self.detector.pixel2:
            self.pattern_geometry.detector = self.detector  # necessary since loading a poni file will reset the detector
        else:
            self.reset_detector()

        self.calibration_name = get_base_name(filename)
        self.filename = filename
        self.is_calibrated = True
        self.create_cake_geometry()
        self.set_supersampling()

    def save(self, filename):
        """
        Saves the current calibration parameters into a a text file. Default extension is
        *.poni
        """
        self.cake_geometry.save(filename)
        self.calibration_name = get_base_name(filename)
        self.filename = filename

    def load_detector(self, name):
        self.detector_mode = DetectorModes.PREDEFINED
        names, classes = get_available_detectors()
        detector_ind = names.index(name)

        self._load_detector(classes[detector_ind]())

    def load_detector_from_file(self, filename):
        self.detector_mode = DetectorModes.NEXUS
        self._load_detector(NexusDetector(filename))

    def _load_detector(self, detector):
        """ Loads a pyFAI detector
        :param detector: an instance of pyFAI Detector
        """
        self.detector = detector
        self.detector.calc_mask()
        self.orig_pixel1 = self.detector.pixel1
        self.orig_pixel2 = self.detector.pixel2

        self.pattern_geometry.detector = self.detector

        if self.cake_geometry:
            self.cake_geometry.detector = self.detector

        self.set_supersampling()
        self._original_detector = None

    def reset_detector(self):
        self.detector_mode = DetectorModes.CUSTOM
        self.detector = Detector(pixel1=self.orig_pixel1,
                                 pixel2=self.orig_pixel2)
        self.pattern_geometry.detector = self.detector
        if self.cake_geometry:
            self.cake_geometry.detector = self.detector
        self.set_supersampling()

    def create_file_header(self):
        try:
            # pyFAI version 0.12.0
            return self.pattern_geometry.makeHeaders(
                polarization_factor=self.polarization_factor)
        except AttributeError:
            # pyFAI after version 0.12.0
            from pyFAI.io import DefaultAiWriter
            return DefaultAiWriter(None, self.pattern_geometry).make_headers()

    def set_fit2d(self, fit2d_parameter):
        """
        Reads in a dictionary with fit2d parameters where the fields of the dictionary are:
        'directDist', 'centerX', 'centerY', 'tilt', 'tiltPlanRotation', 'pixelX', pixelY',
        'polarization_factor', 'wavelength'
        """
        self.pattern_geometry.setFit2D(
            directDist=fit2d_parameter['directDist'],
            centerX=fit2d_parameter['centerX'],
            centerY=fit2d_parameter['centerY'],
            tilt=fit2d_parameter['tilt'],
            tiltPlanRotation=fit2d_parameter['tiltPlanRotation'],
            pixelX=fit2d_parameter['pixelX'],
            pixelY=fit2d_parameter['pixelY'])
        # the detector pixel1 and pixel2 values are updated by setPyFAI
        self.orig_pixel1 = self.detector.pixel1
        self.orig_pixel2 = self.detector.pixel2

        self.pattern_geometry.wavelength = fit2d_parameter['wavelength']
        self.create_cake_geometry()
        self.polarization_factor = fit2d_parameter['polarization_factor']
        self.orig_pixel1 = fit2d_parameter['pixelX'] * 1e-6
        self.orig_pixel2 = fit2d_parameter['pixelY'] * 1e-6
        self.is_calibrated = True
        self.set_supersampling()

    def set_pyFAI(self, pyFAI_parameter):
        """
        Reads in a dictionary with pyFAI parameters where the fields of dictionary are:
        'dist', 'poni1', 'poni2', 'rot1', 'rot2', 'rot3', 'pixel1', 'pixel2', 'wavelength',
        'polarization_factor'
        """
        self.pattern_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.detector.pixel1 = pyFAI_parameter['pixel1']
        self.detector.pixel2 = pyFAI_parameter['pixel2']
        self.orig_pixel1 = self.detector.pixel1
        self.orig_pixel2 = self.detector.pixel2
        self.pattern_geometry.wavelength = pyFAI_parameter['wavelength']
        self.create_cake_geometry()
        self.polarization_factor = pyFAI_parameter['polarization_factor']
        self.is_calibrated = True
        self.set_supersampling()

    def load_distortion(self, spline_filename):
        self.distortion_spline_filename = spline_filename
        self.pattern_geometry.set_splineFile(spline_filename)
        if self.cake_geometry:
            self.cake_geometry.set_splineFile(spline_filename)

    def reset_distortion_correction(self):
        self.distortion_spline_filename = None
        self.detector.set_splineFile(None)
        self.pattern_geometry.set_splineFile(None)
        if self.cake_geometry:
            self.cake_geometry.set_splineFile(None)

    def set_supersampling(self, factor=None):
        """
        Sets the supersampling to a specific factor. Whereby the factor determines in how many artificial pixel the
        original pixel is split. (factor^2)

        factor  n_pixel
        1       1
        2       4
        3       9
        4       16
        """
        if factor is None:
            factor = self.supersampling_factor

        self.detector.pixel1 = self.orig_pixel1 / float(factor)
        self.detector.pixel2 = self.orig_pixel2 / float(factor)
        self.pattern_geometry.pixel1 = self.orig_pixel1 / float(factor)
        self.pattern_geometry.pixel2 = self.orig_pixel2 / float(factor)

        if factor != self.supersampling_factor:
            self.pattern_geometry.reset()
            self.supersampling_factor = factor

    def reset_supersampling(self):
        self.pattern_geometry.pixel1 = self.orig_pixel1
        self.pattern_geometry.pixel2 = self.orig_pixel2
        self.detector.pixel1 = self.orig_pixel1
        self.detector.pixel2 = self.orig_pixel2

    def get_two_theta_img(self, x, y):
        """
        Gives the two_theta value for the x,y coordinates on the image. Be aware that this function will be incorrect
        for pixel indices, since it does not correct for center of the pixel.
        :param  x: x-coordinate in pixel on the image
        :type   x: ndarray
        :param  y: y-coordinate in pixel on the image
        :type   y: ndarray

        :return  : two theta in radians
        """
        x *= self.supersampling_factor
        y *= self.supersampling_factor

        return self.pattern_geometry.tth(
            x - 0.5,
            y - 0.5)[0]  # deletes 0.5 because tth function uses pixel indices

    def get_azi_img(self, x, y):
        """
        Gives chi for position on image.
        :param  x: x-coordinate in pixel on the image
        :type   x: ndarray
        :param  y: y-coordinate in pixel on the image
        :type   y: ndarray

        :return  : azimuth in radians
        """
        x *= self.supersampling_factor
        y *= self.supersampling_factor
        return self.pattern_geometry.chi(x - 0.5, y - 0.5)[0]

    def get_two_theta_array(self):
        return self.pattern_geometry.twoThetaArray(
            self.img_model.img_data.shape)[::self.supersampling_factor, ::self.
                                           supersampling_factor]

    def get_pixel_ind(self, tth, azi):
        """
        Calculates pixel index for a specfic two theta and azimutal value.
        :param tth:
            two theta in radians
        :param azi:
            azimuth in radians
        :return:
            tuple of index 1 and 2
        """

        tth_ind = find_contours(self.pattern_geometry.ttha, tth)
        if len(tth_ind) == 0:
            return []
        tth_ind = np.vstack(tth_ind)
        azi_values = self.pattern_geometry.chi(tth_ind[:, 0], tth_ind[:, 1])
        min_index = np.argmin(np.abs(azi_values - azi))
        return tth_ind[min_index, 0], tth_ind[min_index, 1]

    @property
    def wavelength(self):
        return self.pattern_geometry.wavelength

    ##########################
    ## Detector rotation stuff
    def swap_detector_shape(self):
        self._swap_detector_shape()
        self._swap_pixel_size()
        self._swap_detector_module_size()

    def rotate_detector_m90(self):
        """
        Rotates the detector stuff by m90 degree. This includes swapping of shape, pixel size and module sizes, as well
        as dx and dy
        """
        self._save_original_detector_definition()

        self.swap_detector_shape()
        self._reset_detector_mask()
        self._transform_pixel_corners(rotate_matrix_m90)

    def rotate_detector_p90(self):
        """
        """
        self._save_original_detector_definition()

        self.swap_detector_shape()
        self._reset_detector_mask()
        self._transform_pixel_corners(rotate_matrix_p90)

    def flip_detector_horizontally(self):
        self._save_original_detector_definition()
        self._transform_pixel_corners(np.fliplr)

    def flip_detector_vertically(self):
        self._save_original_detector_definition()
        self._transform_pixel_corners(np.flipud)

    def reset_transformations(self):
        """Restores the detector to it's original state"""
        if self._original_detector is None:  # no transformations done so far
            return

        self.detector = deepcopy(self._original_detector)
        self.orig_pixel1, self.orig_pixel2 = self.detector.pixel1, self.detector.pixel2
        self.pattern_geometry.detector = self.detector
        if self.cake_geometry is not None:
            self.cake_geometry.detector = self.detector
        self.set_supersampling()
        self._original_detector = None

    def load_transformations_string_list(self, transformations):
        """ Transforms the detector parameters (shape, pixel size and distortion correction) based on a
        list of transformation actions.
        :param transformations: list of transformations specified as strings, values are "flipud", "fliplr",
                                "rotate_matrix_m90", "rotate_matrix_p90
        """
        for transformation in transformations:
            if transformation == "flipud":
                self.flip_detector_vertically()
            elif transformation == "fliplr":
                self.flip_detector_horizontally()
            elif transformation == "rotate_matrix_m90":
                self.rotate_detector_m90()
            elif transformation == "rotate_matrix_p90":
                self.rotate_detector_p90()

    def _save_original_detector_definition(self):
        """
        Saves the state of the detector to _original_detector if not done yet. Used for restoration upon resetting
        the transfromations.
        """
        if self._original_detector is None:
            self._original_detector = deepcopy(self.detector)
            self._original_detector.pixel1 = self.orig_pixel1
            self._original_detector.pixel2 = self.orig_pixel2
            self._mask = False

    def _transform_pixel_corners(self, transform_function):
        """
        :param transform_function: function pointer which will affect the dx, dy and pixel corners of the detector
        """
        if self.detector._dx is not None:
            old_dx, old_dy = self.detector._dx, self.detector._dy
            self.detector.set_dx(transform_function(old_dx))
            self.detector.set_dy(transform_function(old_dy))

        if self.detector._pixel_corners is not None:
            self.detector._pixel_corners = transform_function(
                self.detector._pixel_corners)

    def _swap_pixel_size(self):
        """swaps the pixel sizes"""
        self.orig_pixel1, self.orig_pixel2 = self.orig_pixel2, self.orig_pixel1
        self.set_supersampling()

    def _swap_detector_shape(self):
        """Swaps the detector shape and max_shape values"""
        if self.detector.shape is not None:
            self.detector.shape = (self.detector.shape[1],
                                   self.detector.shape[0])
        if self.detector.max_shape is not None:
            self.detector.max_shape = (self.detector.max_shape[1],
                                       self.detector.max_shape[0])

    def _swap_detector_module_size(self):
        """swaps the module size and gap sizes for e.g. Pilatus Detectors"""
        if hasattr(self.detector, 'module_size'):
            self.detector.module_size = (self.detector.module_size[1],
                                         self.detector.module_size[0])
        if hasattr(self.detector, 'MODULE_GAP'):
            self.detector.MODULE_GAP = (self.detector.MODULE_GAP[1],
                                        self.detector.MODULE_GAP[0])

    def _reset_detector_mask(self):
        """resets and recalculates the mask. Transforamtions to shape and module size have to be performed before."""
        self.detector._mask = False
コード例 #28
0
ファイル: xpcs.py プロジェクト: kif/dahu
    def make_qmask(self):
        "create the q_mask from the geometry"

        experiment_setup = self.input.get("experiment_setup", {})
        detector_section = self.input.get("detector", {})
        pixel_size = detector_section.get("pixel")
        if pixel_size is None:
            self.log_error(
                "Pixel size is mandatory in detector description section")
        detector = Detector(pixel1=pixel_size,
                            pixel2=pixel_size,
                            max_shape=self.shape)
        wavelength = experiment_setup.get("wavelength")
        if wavelength is None:
            self.log_error(
                "wavelength is mandatory in experiment_setup section")
        else:
            wavelength *= 1e-10  # Convert Å in m
        distance = experiment_setup.get("detector_distance")
        if distance is None:
            self.log_error(
                "detector_distance is mandatory in experiment_setup section")
        directbeam_x = experiment_setup.get("directbeam_x")
        directbeam_y = experiment_setup.get("directbeam_y")
        if (directbeam_x is None) or (directbeam_y is None):
            self.log_error(
                "directbeam_[xy] is mandatory in experiment_setup section")

        self.unit = experiment_setup.get("unit", self.unit)

        geometry = Geometry(distance,
                            directbeam_y * pixel_size,
                            directbeam_x * pixel_size,
                            detector=detector,
                            wavelength=wavelength)
        self.ai = geometry

        firstq = experiment_setup.get("firstq", 0)
        widthq = experiment_setup.get("widthq", 0)
        stepq = experiment_setup.get("stepq", 0)
        numberq = experiment_setup.get(
            "numberq", (1 << 16) - 2)  # we plan to store the qmask as uint16

        if experiment_setup.get("q_mask"):
            qmask = fabio.open(experiment_setup["q_mask"]).data
        else:
            q_array = geometry.center_array(self.shape, unit=self.unit)

            detector_maskfile = detector_section.get("mask", '')
            if os.path.exists(detector_maskfile):
                detector_mask = fabio.open(detector_maskfile).data
            else:
                detector_mask = detector.mask
                if detector_mask is None:
                    detector_mask = numpy.zeros(self.shape, dtype=numpy.int8)
            beamstop_maskfile = experiment_setup.get("beamstop_mask", "")
            if os.path.exists(beamstop_maskfile, ""):
                beamstop_mask = fabio.open(beamstop_maskfile).data
            else:
                beamstop_mask = numpy.zeros(self.shape, dtype=numpy.int8)
            mask = numpy.logical_or(detector_mask, beamstop_mask)

            if widthq is None:
                self.log_error(
                    "widthq is mandatory in experiment_setup section")
            if numexpr is None:
                qmaskf = (q_array - firstq) / (widthq + stepq)
                qmaskf[qmaskf < 0] = 0
                qmaskf[qmaskf > (numberq + 1)] = 0
                qmaskf[(qmaskf % 1) > widthq / (widthq + stepq)] = 0
                qmaskf[mask] = 0
                qmask = qmaskf.astype(dtype=numpy.uint16)
                self.log_warning("numexpr is missing, calculation is slower")
            else:
                qmaskf = numexpr.evaluate(
                    "(q_array - firstq) / (widthq + stepq)")
                qmask = numexpr.evaluate(
                    "where(qmaskf<0, 0, where(qmaskf>(numberq+1),0, where((qmaskf%1)>(widthq/(widthq + stepq)), 0, where(mask, 0, qmaskf))))",
                    out=numpy.empty(q_array.shape, dtype=numpy.uint16),
                    casting="unsafe")

        self.qrange = firstq + widthq / 2.0 + numpy.arange(
            qmask.max()) * (widthq + stepq)

        return qmask
コード例 #29
0
ファイル: debug_peakfinder_p9.py プロジェクト: silx-kit/pyFAI
from pyFAI.detectors import Detector
from pyFAI.azimuthalIntegrator import AzimuthalIntegrator
import pyFAI.opencl.peak_finder
shape = 2048, 2048
npeaks = 100
nbins = 512
numpy.random.seed(0)

img = numpy.ones(shape, dtype="float32")
variance = img.copy()
peaks = numpy.random.randint(0, shape[0] * shape[1], size=npeaks)
img.ravel()[peaks] = 4e9
print(img.shape, img.mean(), img.std())
# or a in zip(peaks//shape[1], peaks%shape[1]): print(a)

JF4 = Detector(pixel1=75e-6, pixel2=75e-6, max_shape=shape)
ai = AzimuthalIntegrator(detector=JF4)
ai.setFit2D(100, shape[1] // 2, shape[0] // 2)
csr = ai.setup_CSR(None, nbins, unit="r_m", split="no").lut

r2 = ai.array_from_unit(unit="r_m")
res = ai.integrate1d(img, nbins, unit="r_m")
pf = pyFAI.opencl.peak_finder.OCL_PeakFinder(csr,
                                             img.size,
                                             bin_centers=res[0],
                                             radius=r2,
                                             profile=True)
print(pf.count(img, error_model="azimuthal", cutoff_clip=6), npeaks)
# res = pf(img, variance=variance)
# for a in zip(res[0] // shape[1], res[0] % shape[1], res[1]): print(a)
pf.log_profile(stats=True)
コード例 #30
0
 def setUp(self):
     from pyFAI.detectors import Detector
     self.shape = (50, 49)
     size = (50, 60)
     det = Detector(*size, max_shape=self.shape)
     self.geo = geometry.Geometry(detector=det, wavelength=1e-10)
コード例 #31
0
 def __init__(self):
     pixel1 = 55e-6  # 55 micron pixel size in x
     pixel2 = 55e-6  # 55 micron pixel size in y
     Detector.__init__(self, pixel1=pixel1, pixel2=pixel2)