Changeset 13382 for fact/tools/pyscripts


Ignore:
Timestamp:
04/18/12 20:00:26 (13 years ago)
Author:
neise
Message:
optimizing amplitude_calibration: no np.roll() and moved reshaping to __init__
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/pyscripts/pyfact/pyfact.py

    r13380 r13382  
    145145        self.trigger_type = c_ushort()
    146146        #: 1D array with raw data
    147         self.data  = np.zeros( self.npix * self.nroi, np.int16 )
     147        self.data  = np.zeros( self.npix * self.nroi, np.int16 ).reshape(self.npix ,self.nroi)
    148148        #: slice where drs readout started
    149149        self.start_cells = np.zeros( self.npix, np.int16 )
     
    171171        trigger_offset_mean = calib_file.GetN('TriggerOffsetMean')
    172172
    173         self.blm = np.zeros(baseline_mean, np.float32)
    174         self.gm  = np.zeros(gain_mean, np.float32)
    175         self.tom = np.zeros(trigger_offset_mean, np.float32)
     173        self.blm = np.zeros(baseline_mean, np.float32).reshape(self.npix , baseline_mean/self.npix)
     174        self.gm  = np.zeros(gain_mean, np.float32).reshape(self.npix , gain_mean/self.npix)
     175        self.tom = np.zeros(trigger_offset_mean, np.float32).reshape(self.npix , trigger_offset_mean/self.npix)
    176176
    177177        self.Nblm = baseline_mean / self.npix
     
    183183        calib_file.SetPtrAddress('TriggerOffsetMean', self.tom)
    184184        calib_file.GetRow(0)
     185       
     186        # make calibration constants double, so we never need to roll
     187        self.blm = np.hstack((self.blm, self.blm))
     188        self.gm = np.hstack((self.gm, self.gm))
     189        self.tom = np.hstack((self.tom, self.tom))
    185190
    186191        self.v_bsl = np.zeros(self.npix)  # array of baseline values (all ZERO)
     
    221226       
    222227        """
    223 
     228        blm = self.blm
     229        gm = self.gm
     230        tom = self.tom
     231       
    224232        to_mV = 2000./4096.
    225233        #: 2D array with amplitude calibrated dat in mV
     
    227235
    228236        # make 2D arrays: row = pixel, col = drs_slice
    229         acal_data = np.reshape(acal_data, (self.npix, self.nroi) )
    230         blm = np.reshape(self.blm, (self.npix, self.Nblm) )
    231         tom = np.reshape(self.tom, (self.npix, self.Ntom) )
    232         gm  = np.reshape(self.gm,  (self.npix, self.Ngm) )
     237        #acal_data = np.reshape(acal_data, (self.npix, self.nroi) )
     238        #blm = np.reshape(self.blm, (self.npix, self.Nblm) )
     239        #tom = np.reshape(self.tom, (self.npix, self.Ntom) )
     240        #gm  = np.reshape(self.gm,  (self.npix, self.Ngm) )
    233241       
    234242        # double the calibration constants
     
    237245       
    238246        for pixel in range( self.npix ):
     247            #shortcuts
     248            sc = self.start_cells[pixel]
     249            roi = self.nroi
    239250            # rotate the pixel baseline mean to the Data startCell
    240             #blm_pixel = np.roll( blm[pixel,:], -self.start_cells[pixel] )
    241             blm_pixel = blm[pixel, self.start_cells[pixel]:self.start_cells[pixel]+self.nroi]
     251            blm_pixel = blm[pixel,sc:sc+roi]
    242252            # rotate the pixel gain mean to the Data startCell
    243             #gm_pixel = np.roll( gm[pixel,:], -self.start_cells[pixel] )
    244             gm_pixel = gm[pixel, self.start_cells[pixel]:self.start_cells[pixel]+self.nroi]
     253            gm_pixel = gm[pixel,sc:sc+roi]
    245254            # the 'trigger offset mean' does not need to be rolled
    246255            # on the contrary, it seems there is an offset in the DRS data,
    247256            # which is related to its distance to the startCell, not to its
    248257            # distance to the beginning of the physical pipeline in the DRS chip
    249             tom_pixel = tom[pixel,0:self.nroi ]
     258            tom_pixel = tom[pixel,0:roi]
    250259           
    251260            acal_data[pixel,:] -= blm_pixel
Note: See TracChangeset for help on using the changeset viewer.