Example #1
0
    def _get_cbase(self):
        """Get detector calibration base object.

        Psana 1 only.
        """
        from PSCalib.CalibParsBasePnccdV1 import CalibParsBasePnccdV1
        return CalibParsBasePnccdV1()
Example #2
0
    def Create(self, calibdir, group, source, runnum, pbits=0, fnexpc=None, fnrepo=None, tsec=None) :
        """ Factory method

            Parameters

            - calibdir : string - calibration directory, ex: /reg/d/psdm/AMO/amoa1214/calib
            - group    : string - group, ex: PNCCD::CalibV1
            - source   : string - data source, ex: Camp.0:pnCCD.0
            - runnum   : int    - run number, ex: 10
            - pbits=0  : int    - print control bits, ex: 255

            Returns

            - GenericCalibPars object
        """        

        dettype = gu.det_type_from_source(source)
        grp = group if group is not None else gu.dic_det_type_to_calib_group[dettype]

        if pbits : print '%s: Detector type = %d: %s' % (self.name, dettype, gu.dic_det_type_to_name[dettype])

        cbase = None
        if   dettype ==  gu.CSPAD     : cbase = CalibParsBaseCSPadV1()
        elif dettype ==  gu.CSPAD2X2  : cbase = CalibParsBaseCSPad2x2V1() 
        elif dettype ==  gu.PNCCD     : cbase = CalibParsBasePnccdV1()    
        elif dettype ==  gu.PRINCETON : cbase = CalibParsBasePrincetonV1()
        elif dettype ==  gu.ANDOR3D   : cbase = CalibParsBaseAndor3dV1()    
        elif dettype ==  gu.ANDOR     : cbase = CalibParsBaseAndorV1()    
        elif dettype ==  gu.EPIX100A  : cbase = CalibParsBaseEpix100aV1() 
        elif dettype ==  gu.EPIX10KA  : cbase = CalibParsBaseEpix10kaV1() 
        elif dettype ==  gu.JUNGFRAU  : cbase = CalibParsBaseJungfrauV1()    
        elif dettype ==  gu.ACQIRIS   : cbase = CalibParsBaseAcqirisV1() 
        elif dettype ==  gu.IMP       : cbase = CalibParsBaseImpV1() 
        elif dettype in (gu.OPAL1000,\
                         gu.OPAL2000,\
                         gu.OPAL4000,\
                         gu.OPAL8000,\
                         gu.TM6740,\
                         gu.ORCAFL40,\
                         gu.FCCD960,\
                         gu.QUARTZ4A150,\
                         gu.RAYONIX,\
                         gu.FCCD,\
                         gu.TIMEPIX,\
                         gu.FLI,\
                         gu.ZYLA,\
                         gu.EPICSCAM,\
                         gu.PIMAX) : cbase = CalibParsBaseCameraV1()

        else :
            print '%s: calibration is not implemented data source "%s"' % (self.__class__.__name__, source)
            #raise IOError('Calibration parameters for source: %s are not implemented in class %s' % (source, self.__class__.__name__))
        return GenericCalibPars(cbase, calibdir, grp, source, runnum, pbits, fnexpc, fnrepo, tsec)
Example #3
0
    def initialize(self, geom, run_num=0):
        """
        Initialize the detector as pnccd
        :param geom: The pnccd .data file which characterize the geometry profile.
        :param run_num: The run_num containing the background, rms and gain and the other
                        pixel pixel properties.
        :return:  None
        """

        # Redirect the output stream
        old_stdout = sys.stdout
        f = six.StringIO()
        # f = open('Detector_initialization.log', 'w')
        sys.stdout = f

        ###########################################################################################
        # Initialize the geometry configuration
        ############################################################################################
        self.geometry = GeometryAccess(geom, 0o377)
        self.run_num = run_num

        # Set coordinate in real space
        temp = self.geometry.get_pixel_coords()
        temp_index = self.geometry.get_pixel_coord_indexes()

        self.panel_num = temp[0].shape[1] * temp[0].shape[2]
        self.distance = temp[2][0, 0, 0, 0, 0] * 1e-6  # Convert to m

        self.pixel_position = np.zeros(
            (self.panel_num, temp[0].shape[3], temp[0].shape[4], 3))
        self.pixel_index_map = np.zeros(
            (self.panel_num, temp[0].shape[3], temp[0].shape[4], 2))

        for l in range(temp[0].shape[1]):
            for m in range(temp[0].shape[2]):
                for n in range(3):
                    self.pixel_position[m + l * temp[0].shape[2], :, :,
                                        n] = temp[n][0, l, m]
                for n in range(2):
                    self.pixel_index_map[m + l * temp[0].shape[2], :, :,
                                         n] = temp_index[n][0, l, m]

        self.pixel_index_map = self.pixel_index_map.astype(np.int64)

        # Get the range of the pixel index
        self.detector_pixel_num_x = np.max(self.pixel_index_map[:, :, :,
                                                                0]) + 1
        self.detector_pixel_num_y = np.max(self.pixel_index_map[:, :, :,
                                                                1]) + 1

        self.panel_pixel_num_x = np.array([
            self.pixel_index_map.shape[1],
        ] * self.panel_num)
        self.panel_pixel_num_y = np.array([
            self.pixel_index_map.shape[2],
        ] * self.panel_num)
        self.pixel_num_total = np.sum(
            np.multiply(self.panel_pixel_num_x, self.panel_pixel_num_y))

        tmp = float(self.geometry.get_pixel_scale_size() *
                    1e-6)  # Convert to m
        self.pixel_width = np.ones((self.panel_num, self.panel_pixel_num_x[0],
                                    self.panel_pixel_num_y[0])) * tmp
        self.pixel_height = np.ones((self.panel_num, self.panel_pixel_num_x[0],
                                     self.panel_pixel_num_y[0])) * tmp

        # Calculate the pixel area
        self.pixel_area = np.multiply(self.pixel_height, self.pixel_width)

        ###########################################################################################
        # Initialize the pixel effects
        ###########################################################################################
        # first we should parse the path
        parsed_path = geom.split('/')
        source = parsed_path[-3]

        if six.PY2:
            cbase = CalibParsBasePnccdV1()
            calibdir = '/'.join(parsed_path[:-4])
            group = parsed_path[-4]
            pbits = 255
            gcp = GenericCalibPars(cbase, calibdir, group, source, run_num,
                                   pbits)

            self._pedestals = gcp.pedestals()
            self._pixel_rms = gcp.pixel_rms()
            self._pixel_mask = gcp.pixel_mask()
            self._pixel_bkgd = gcp.pixel_bkgd()
            self._pixel_status = gcp.pixel_status()
            self._pixel_gain = gcp.pixel_gain()
        else:
            self.det = "pnccd_000" + source[-1]
            self.exp = parsed_path[-5]

            self._pedestals = None
            self._pixel_rms = None
            self._pixel_mask = None
            self._pixel_bkgd = None
            self._pixel_status = None
            self._pixel_gain = None

        # Redirect the output stream
        sys.stdout = old_stdout
Example #4
0
    def _initialize(self, path):

        #################################################################
        ## The following several lines initialize the geometry information
        #################################################################
        ## Set coordinate in real space
        temp = self.geometry.get_pixel_coords()
        temp_index = self.geometry.get_pixel_coord_indexes()

        self.panel_num = temp[0].shape[1] * temp[0].shape[2]
        self.distance = temp[2][0, 0, 0, 0, 0]

        self.pixel_position = np.zeros(
            (self.panel_num, temp[0].shape[3], temp[0].shape[4], 3))
        self.pixel_index_map = np.zeros(
            (self.panel_num, temp[0].shape[3], temp[0].shape[4], 2))

        for l in range(temp[0].shape[1]):
            for m in range(temp[0].shape[2]):
                for n in range(3):
                    self.pixel_position[m + l * temp[0].shape[2], :, :,
                                        n] = temp[n][0, l, m, :, :]
                for n in range(2):
                    self.pixel_index_map[m + l * temp[0].shape[2], :, :,
                                         n] = temp_index[n][0, l, m, :, :]

        self.pixel_index_map = self.pixel_index_map.astype('int32')

        del temp
        del temp_index

        self.panel_orientation = np.array([
            [0, 0, 1],
        ] * self.panel_num)
        self.pix_num_x = np.array([
            self.pixel_index_map.shape[1],
        ] * self.panel_num)
        self.pix_num_y = np.array([
            self.pixel_index_map.shape[2],
        ] * self.panel_num)
        self.pix_num_total = np.sum(np.multiply(self.pix_num_x,
                                                self.pix_num_y))

        tmp = float(self.geometry.get_pixel_scale_size())
        self.pix_width = np.ones(
            (self.panel_num, self.pix_num_x[0], self.pix_num_y[0])) * tmp
        self.pix_height = np.ones(
            (self.panel_num, self.pix_num_x[0], self.pix_num_y[0])) * tmp

        ####################################################################
        ## The following several lines initialize the detector effects besides cross talk.
        ####################################################################
        ## first we should parse the path
        parsed_path = parsed_path = path.split('/')

        cbase = CalibParsBasePnccdV1()
        calibdir = '/'.join(parsed_path[:-3])
        group = parsed_path[-3]
        source = parsed_path[-2]
        runnum = 0
        pbits = 255
        ctype = gu.PEDESTALS
        gcp = GenericCalibPars(cbase, calibdir, group, source, runnum, pbits)

        self.pedestal = gcp.pedestals()
        self.pixel_rms = gcp.pixel_rms()
        self.pixel_mask = gcp.pixel_mask()
        self.pixel_bkgd = gcp.pixel_bkgd()
        self.pixel_status = gcp.pixel_status()
        self.pixel_gain = gcp.pixel_gain()

        self._calculate_pixel_range()