Changeset 14118 for fact/tools


Ignore:
Timestamp:
06/08/12 15:31:05 (12 years ago)
Author:
neise
Message:
added a lot of docu
File:
1 edited

Legend:

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

    r13815 r14118  
    2929            the second should be an amplitude calibration file(\*.drs.fits.gz)
    3030        """
     31       
     32        self.__module__ = 'pyfact'
     33       
    3134        # sanity check for input
    3235        if type(filelist) != type(list()):
     
    7275    """ raw data access and calibration
    7376   
     77    class is **iterable**
     78   
    7479    - open raw data file and drs calibration file
    7580    - performs amplitude calibration
     
    8388
    8489    def __init__(self, data_file_name, calib_file_name,
    85                 user_action_calib=lambda acal_data, data, blm, tom, gm, scells, nroi: None,
    8690                baseline_file_name='',
    8791                return_dict = True,
     92                use_CalFactFits = True,
    8893                do_calibration = True,
    89                 use_CalFactFits = True):
    90         """ initialize object
    91        
    92         open data file and calibration data file
    93         get basic information about the data in data_file_name
    94         allocate buffers for data access
    95 
    96         data_file_name   : fits or fits.gz file of the data including the path
    97         calib_file_name : fits or fits.gz file containing DRS calibration data
    98         baseline_file_name : npy file containing the baseline values
     94                user_action_calib=lambda acal_data, data, blm, tom, gm, scells, nroi: None):
     95        """ -constructor-
     96       
     97        - open data file and calibration data file
     98        - get basic information about the data in data_file_name
     99        - allocate buffers for data access
     100
     101        *data_file_name*   : fits or fits.gz file of the data including the path
     102       
     103        *calib_file_name* : fits or fits.gz file containing DRS calibration data
     104       
     105        *baseline_file_name* : npy file containing the baseline values
     106       
     107        *return_dict* : this option will be removed in future releases.
     108            formerly the next() method returned only a subset of (important) event information,
     109            and it was not transparent how to retrieve the other (less important) information.
     110            Nowadays next() returns self.__dict__ which contains everything we were able to find in the fits file.
     111           
     112        *use_CalFactFits* : formerly the DRS amplitude calibration was
     113        implemented in python. But for performance reasons this was now moved into
     114        a C++ class called CalFactFits. For test purposes, this option can be set to
     115        False, but this is not really maintained anymore. If DRS the DRS calibration algorithm is
     116        beeing updated in C++ it may not be updated in the python implementation.
     117       
     118        *do_calibration* : In case *use_CalFactFits* is False, one may choose
     119        not to calibrate the data at all, thus safe quite some time.
     120        This is imho only needed in case one is interesting in learning something about the
     121        calibration algorithm itself.
     122       
     123        *user_action_calib* : callback function, intended for tests of the DRS calibration algorithm.
     124        but since this is not done in the Python regime anymore, this function is never called.
     125        (depending on *use_CalFactFits* of course)
    99126        """
    100127        self.__module__='pyfact'
     
    122149            self.correct_baseline = True
    123150       
     151       
    124152        # access data file
    125153        if use_CalFactFits:
     
    129157                print 'problem accessing data file: ', data_file_name
    130158                raise  # stop ! no data
    131                
     159           
     160            #: either CalFactFits object or FactFits object, depending on *use_CalFactFits*
    132161            self.data_file = data_file
     162            #: 1440x300 nparray containing the event data. pixel sorted according to CHID
    133163            self.data      = np.empty( data_file.npix * data_file.nroi, np.float64)
    134164            data_file.SetNpcaldataPtr(self.data)
    135             self.data      = self.data.reshape( data_file.npix, data_file.nroi )
     165            self.data      = self.data.reshape( data_file.npix, data_file.nroi )
     166            #: copy of data. here for historical reasons
    136167            self.acal_data = self.data
    137 
     168            #: region of interest. (number of DRS slices read).
     169            # for FACT data mostly 300. for special runs sometimes 1024.
    138170            self.nroi    = data_file.nroi
     171            #: number of Pixel in FACT. should be 1440
    139172            self.npix    = data_file.npix
     173            #: the total number of events in the data_file
    140174            self.nevents = data_file.nevents
    141175           
    142176            # Data per event
     177            #:  starting at 1
    143178            self.event_id     = None
     179            #: data=4 ; the rest I don't know by heart .. should be documented here :-)
    144180            self.trigger_type = None
    145181            #self.start_cells  = None
    146182            #self.board_times  = None
     183            #: slice where drs readout started for all DRS chips (160) .. but enlarged to the size of 1440 pixel. thus there are always 9 equal numbers inside.
    147184            self.start_cells = np.zeros( self.npix, np.int16 )
     185            #: each FAD has an onboard clock running from startup time. Currently I don't know the time unit. However this is an array of 40 times, since we have 40 boards.
    148186            self.board_times = np.zeros( 40, np.int32 )
    149187
     
    164202           
    165203            # get basic information about the data file
    166             #: region of interest (number of DRS slices read)
    167204            self.nroi    = data_file.GetUInt('NROI')
    168             #: number of pixels (should be 1440)
    169205            self.npix    = data_file.GetUInt('NPIX')
    170             #: number of events in the data run
    171206            self.nevents = data_file.GetNumRows()
    172207           
     
    174209            self.event_id = c_ulong()
    175210            self.trigger_type = c_ushort()
    176             #: 1D array with raw data
    177211            self.data  = np.zeros( self.npix * self.nroi, np.int16 ).reshape(self.npix ,self.nroi)
    178             #: slice where drs readout started
    179212            self.start_cells = np.zeros( self.npix, np.int16 )
    180             #: time when the FAD was triggered, in some strange units...
    181213            self.board_times = np.zeros( 40, np.int32 )
    182214
     
    226258
    227259    def next(self):
    228         """ used by __iter__ """
     260        """ used by __iter__
     261       
     262            returns self.__dict__
     263        """
    229264        if self.use_CalFactFits:
    230265            if self.data_file.GetCalEvent() == False:
     
    250285
    251286    def next_event(self):
    252         """ load the next event from disk and calibrate it
     287        """ ---- DEPRICATED ----
     288       
     289            load the next event from disk and calibrate it
    253290        """
    254291        if self.use_CalFactFits:
     
    259296
    260297    def calibrate_drs_amplitude(self):
    261         """ perform the drs amplitude calibration of the event data
    262        
     298        """ --- DEPRICATED ---
     299           
     300            since the DRS calibration is done by the C++  class CalFactFits
     301           
     302            perform the drs amplitude calibration of the event data
    263303        """
    264304        # shortcuts
     
    295335    def baseline_read_values(self, file, bsl_hist='bsl_sum/hplt_mean'):
    296336        """
    297        
    298337        open ROOT file with baseline histogram and read baseline values
    299         file       name of the root file
    300         bsl_hist   path to the histogram containing the basline values
    301 
     338       
     339        *file* : name of the root file
     340       
     341        *bsl_hist* : path to the histogram containing the basline values
    302342        """
    303343
     
    317357    def baseline_correct(self):
    318358        """ subtract baseline from the data
    319 
     359       
     360            DN 08.06.2011: I didn't use this function at all so far... don't know how well it works.
    320361        """
    321362       
     
    325366    def info(self):
    326367        """ print run information
    327        
     368           
     369            not very well implemented ... we need more info here.
    328370        """
    329371        print 'data file:  ', self.data_file_name
     
    334376class RawDataFake( object ):
    335377    """ raw data FAKE access similar to real RawData access
     378   
     379        DO NOT USE ... its not working
    336380    """
    337381
     
    419463class SlowData( FactFits ):
    420464    """ -Fact SlowData File-
    421         A Python wrapper for the fits-class implemented in pyfits.h
     465
     466        A Python wrapper for the fits-class implemented in factfits.h
    422467        provides easy access to the fits file meta data.
     468
    423469        * dictionary of file metadata - self.meta
    424470        * dict of table metadata - self.columns
     
    429475        """
    430476        self.path = path
     477        self.__module__ = 'pyfact'
    431478        try:
    432479            FactFits.__init__(self,path)
     
    438485        self.columns = self._make_columns_dict()
    439486       
    440         self.treat_meta_dict()
     487        self._treat_meta_dict()
    441488       
    442489       
     
    533580#                raise TypeError("I don't know how to stack "+col+". It is of type: "+str(type(self.dict[col])))
    534581   
    535     def register(self, input_str):
     582    def register(self, col_name):
     583        """ register for a column in the fits file
     584       
     585            after the call, this SlowData object will have a new member variable
     586            self.col_name, if col_name is a key in self.colums
     587           
     588            the value will be updated after each call of next(), or while iterating over self.
     589            NB: the initial value is zero(s)
     590       
     591            *col_name* : name of a key in self.columns, or 'all' to choose all.
     592        """
    536593        columns = self.columns
    537         if input_str.lower() == 'all':
     594        if col_name.lower() == 'all':
    538595            for col in columns:
    539596                self._register(col)
    540597        else:
    541598            #check if colname is in columns:
    542             if input_str not in columns:
     599            if col_name not in columns:
    543600                error_msg = 'colname:'+ input_str +' is not a column in the binary table.\n'
    544601                error_msg+= 'possible colnames are\n'
     
    630687       
    631688   
    632     def treat_meta_dict(self):
     689    def _treat_meta_dict(self):
    633690        """make 'interesting' meta information available like normal members.
    634691            non interesting are:
     
    699756
    700757    def next(self):
    701         """ used by __iter__ """
     758        """ use to iterate over the file
     759       
     760            do not forget to call register() before iterating over the file
     761            call show() in order to find out, what parameters register() accepts.
     762            or just call register('all') in case you are unsure.
     763           
     764            returns self
     765        """
    702766        # Here one might check, if looping makes any sense, and if not
    703767        # one could stop looping or so...
     
    725789
    726790    def show(self):
     791        """
     792        """
    727793        pprint.pprint(self.dict)
    728794
Note: See TracChangeset for help on using the changeset viewer.