def filter_frames(self, data):
        print '############ ONE FILTER FRAME ########################'
        bc = [0, 0]
        distance, bc[0], bc[1], yaw, roll, px, px = self.ai_params
        t1 = time.time()
        data = data[0].astype(np.float)
        data -= np.min(data)
        mData = self.params[1]
        #         print self.params[2]
        #         foo = self.params[2]

        ai = AzimuthalIntegrator()
        ai.setFit2D(distance, bc[0], bc[1], yaw, roll, px, px, None)
        ai.set_wavelength(self.wl)
        foo = units.to_unit(units.TTH)
        twotheta = ai.__getattribute__(foo.center)(
            self.sh)  # get the detector array of Q # preallocate
        twotheta *= 180.0 / np.pi  # preallocate
        twotheta_flat = twotheta.ravel()  #pre allocate
        logging.debug(ai)
        #         twotheta_flat = self.params[3]
        logging.debug("Running azimuthal integration")
        mask = np.zeros_like(data, np.int)
        fit = ai.integrate1d(data=data,
                             npt=self.npts,
                             unit='q_A^-1',
                             correctSolidAngle=False)
        print "here"
        mData.set_meta_data('Q', fit[0])
        newplot = self.calcfrom1d(fit[0], fit[1], twotheta_flat)
        rat = data / newplot
        thing = data.copy()
        thing[np.abs(rat - 1.0) > self.parameters['thresh'] * 1e-2] = 0.0

        mask[thing == 0] = 1
        #         mask[data < minval] = 0
        #mask[data > maxval] = 0
        #         final = ai.integrate1d(data=data, npt=self.npts,unit='q_A^-1', correctSolidAngle=False)# works...
        del ai

        ai = AzimuthalIntegrator()
        ai.setFit2D(distance, bc[0], bc[1], yaw, roll, px, px, None)
        ai.set_wavelength(self.wl)
        print "DATA.shape is %s " % str(data.shape)

        final = ai.integrate1d(data,
                               self.npts,
                               mask=mask,
                               unit='q_A^-1',
                               correctSolidAngle=False,
                               method='numpy')  # doesn't work
        #         final = ai.integrate1d(data=data, npt=self.npts,mask=mask,unit='q_A^-1', correctSolidAngle=False)# doesn't work
        t2 = time.time()
        del ai
        #         print final[1].shape
        print "PyFAI iteration with correction took:" + str(
            (t2 - t1) * 1e3) + "ms"
        print '##################END##################'
        return final[1]
    def pre_process(self):
        in_dataset, out_datasets = self.get_datasets()
        mData = self.get_in_meta_data()[0]
        in_d1 = in_dataset[0]
        ai = AzimuthalIntegrator()  # get me an integrator object
        # prep the goemtry
        px_m = mData.get_meta_data('x_pixel_size')
        bc_m = [
            mData.get_meta_data("beam_center_x"),
            mData.get_meta_data("beam_center_y")
        ]  # in metres
        bc = bc_m / px_m  # convert to pixels
        px = px_m * 1e6  # convert to microns
        distance = mData.get_meta_data('distance') * 1e3  # convert to mm
        wl = mData.get_meta_data('incident_wavelength')[...]  # in m
        self.wl = wl

        yaw = -mData.get_meta_data("yaw")
        roll = mData.get_meta_data("roll")
        self.ai_params = distance, bc[0], bc[1], yaw, roll, px, px
        ai.setFit2D(distance, bc[0], bc[1], yaw, roll, px, px, None)
        ai.set_wavelength(wl)
        logging.debug(ai)

        self.sh = in_d1.get_shape()[-2:]
        self.npts = self.get_parameters('num_bins')
        foo = units.to_unit(units.TTH)  #  preallocate
        pretenddata = np.zeros(self.sh)
        pretendfit = ai.integrate1d(data=pretenddata,
                                    npt=self.npts,
                                    unit='q_A^-1',
                                    correctSolidAngle=False)
        self.add_axes_to_meta_data(pretendfit[0], mData)
        twotheta = ai.__getattribute__(foo.center)(
            self.sh)  # get the detector array of Q # preallocate
        twotheta *= 180.0 / np.pi  # preallocate
        twotheta_flat = twotheta.ravel()  #pre allocate
        self.params = [self.npts, mData, twotheta_flat]
    def pre_process(self):
        """
        This method is called after the plugin has been created by the
        pipeline framework as a pre-processing step

        :param parameters: A dictionary of the parameters for this plugin, or
            None if no customisation is required
        :type parameters: dict
        """
        in_dataset, out_datasets = self.get_datasets()
        mData = self.get_in_meta_data()[0]
        in_d1 = in_dataset[0]
        ai = AzimuthalIntegrator()  # get me an integrator object
        ### prep the goemtry
        bc = [mData.get_meta_data("beam_center_x")[...],
              mData.get_meta_data("beam_center_y")[...]]
        distance = mData.get_meta_data('distance')[...]
        wl = mData.get_meta_data('incident_wavelength')[...]
        px = mData.get_meta_data('x_pixel_size')[...]
        orien = mData.get_meta_data(
            'detector_orientation')[...].reshape((3, 3))
        #Transform
        yaw = math.degrees(-math.atan2(orien[2, 0], orien[2, 2]))
        roll = math.degrees(-math.atan2(orien[0, 1], orien[1, 1]))
        ai.setFit2D(distance, bc[0], bc[1], -yaw, roll, px, px, None)
        ai.set_wavelength(wl)
        
        self.sh = in_d1.get_shape()[-2:]
        self.npts = self.get_parameters('num_bins')
        foo = units.to_unit(units.TTH) #  preallocate
        pretenddata = np.zeros(self.sh)
        pretendfit = ai.xrpd(data=pretenddata, npt=self.npts)
        twotheta=ai.__getattribute__(foo.center)(ai.detector.max_shape) # get the detector array of Q # preallocate
        twotheta *= 180.0/np.pi # preallocate
        twotheta_flat = twotheta.ravel() #pre allocate
        self.params = [self.npts, mData, ai, twotheta_flat]
Ejemplo n.º 4
0
import h5py
import numpy as np
from bluesky.utils import new_uid
from pyFAI import AzimuthalIntegrator


def format_keys(*args):
    return '/'.join(args)


key_data_map = {'RayMX': 'image', 'photodiode': 'I0', 'eh1_qbpm1': 'eh1_qbpm1',
                'oh_qbpm2': 'oh_qbpm2'}
ai = AzimuthalIntegrator(wavelength=(12.398 / 9.70803 * 1.0e-10))
# TODO: need to load this info from somewhere!
ai.setFit2D(60.550, 1440.364, (2880 - -26.378), tilt=(-0.024),
            tiltPlanRotation=54.442, pixelX=78, pixelY=78)
calib_config_dict = dict(ai.getPyFAI())


def parse_hdf5(fn):
    """Parse hdf5 file from the PAL-XFEL beamline into an event stream

    Parameters
    ----------
    fn: str
        The path to the hdf5 file

    Yields
    -------
    name: str
        The name of the document
Ejemplo n.º 5
0
def format_keys(*args):
    return '/'.join(args)


key_data_map = {
    'RayMX': 'image',
    'photodiode': 'I0',
    'eh1_qbpm1': 'eh1_qbpm1',
    'oh_qbpm2': 'oh_qbpm2'
}
ai = AzimuthalIntegrator(wavelength=(12.398 / 9.70803 * 1.0e-10))
# TODO: need to load this info from somewhere!
ai.setFit2D(60.550,
            1440.364, (2880 - -26.378),
            tilt=(-0.024),
            tiltPlanRotation=54.442,
            pixelX=78,
            pixelY=78)
calib_config_dict = dict(ai.getPyFAI())


def parse_hdf5(fn):
    """Parse hdf5 file from the PAL-XFEL beamline into an event stream

    Parameters
    ----------
    fn: str
        The path to the hdf5 file

    Yields
    -------