Changeset 12987 for fact/tools


Ignore:
Timestamp:
03/01/12 15:47:58 (13 years ago)
Author:
lusterma
Message:
next() fixed, filters removed
File:
1 edited

Legend:

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

    r12975 r12987  
    119119    def next(self):
    120120        """ used by __iter__ """
    121         if self.event_id.value == self.nevents:
     121
     122        if self.data_file.GetNextRow() == False:
    122123            raise StopIteration
    123124        else:
    124             self.data_file.GetNextRow()
    125125            self.calibrate_drs_amplitude()
     126
     127        #print 'nevents = ', self.nevents, 'event_id = ', self.event_id.value
    126128        return self.acal_data, self.start_cells, self.trigger_type.value
    127129
     
    158160        self.acal_data = acal_data * 1907.35
    159161
    160        
    161     def filter_sliding_average(self, window_size=4):
    162         """ sliding average filter
    163 
    164         using:
    165             self.acal_data
    166         filling array:
    167             self.data_saverage_out
    168 
    169         """
    170 
    171         #scipy.signal.lfilter(b, a, x, axis=-1, zi=None)
    172         data_saverage_out = self.acal_data.copy()
    173         b = np.ones( window_size )
    174         a = np.zeros( window_size )
    175         a[0] = len(b)
    176         data_saverage_out[:,:] = signal.lfilter(b, a, data_saverage_out[:,:])
    177 
    178         #: data output of sliding average filter
    179         self.data_saverage_out = data_saverage_out
    180 
    181        
    182     def filter_CFD(self, length=10, ratio=0.75):
    183         """ constant fraction discriminator (implemented as FIR)
    184        
    185         using:
    186             self.data_saverage_out
    187         filling array:
    188             self.data_CFD_out
    189 
    190         """
    191        
    192         if self.data_saverage_out == None:
    193             print """error pyfact.filter_CFD was called without
    194             prior call to filter_sliding_average
    195             variable self.data_saverage_out is needed
    196             """
    197            
    198         data_CFD_out = self.data_saverage_out.copy()
    199         b = np.zeros(length)
    200         a = np.zeros(length)
    201         b[0] = -1. * ratio
    202         b[length-1] = 1.
    203         a[0] = 1.
    204         data_CFD_out[:,:] = signal.lfilter(b, a, data_CFD_out[:,:])
    205        
    206         #: data output of the constant fraction discriminator
    207         self.data_CFD_out = data_CFD_out
    208  
    209     def find_peak(self, min=30, max=250):
    210         """ find maximum in search window
    211        
    212         using:
    213             self.data_saverage_out
    214         filling arrays:
    215             self.pulse_time_of_maximum
    216             self.pulse_amplitude
    217 
    218         """
    219 
    220         if self.data_saverage_out == None:
    221             print """error pyfact.find_peakMax was called without \
    222             prior call to filter_sliding_average
    223             variable self.data_saverage_out is needed"""
    224             pass
    225 
    226         pulse_time_of_maximum = np.argmax( self.data_saverage_out[:,min:max],
    227                                           1)
    228         pulse_amplitude = np.max( self.data_saverage_out[:,min:max], 1)
    229         self.pulse_time_of_maximum = pulse_time_of_maximum
    230         self.pulse_amplitude = pulse_amplitude
    231 
    232     def sum_around_peak(self, left=13, right=23):
    233         """ integrate signal in gate around Peak
    234 
    235         using:
    236             self.pulse_time_of_maximum
    237             self.acal_data
    238         filling array:
    239             self.pulse_integral_simple
    240            
    241         """
    242        
    243         if self.pulse_time_of_maximum == None:
    244             print """error pyfact.sum_around_peak was called \
    245             without prior call of find_peak
    246             variable self.pulse_time_of_maximum is needed"""
    247             pass
    248 
    249         # find left and right limit and sum the amplitudes in the range
    250         pulse_integral_simple = np.empty(self.npix)
    251         for pixel in range(self.npix):
    252             min = self.pulse_time_of_maximum[pixel]-left
    253             max = self.pulse_time_of_maximum[pixel]+right
    254             pulse_integral_simple[pixel] = self.acal_data[pixel,min:max].sum()
    255        
    256         self.pulse_integral_simple = pulse_integral_simple
    257162       
    258163    def baseline_read_values(self, file, bsl_hist='bsl_sum/hplt_mean'):
Note: See TracChangeset for help on using the changeset viewer.