Changeset 17979


Ignore:
Timestamp:
10/02/14 20:18:07 (10 years ago)
Author:
dneise
Message:
removed all pylint warnings and errors
File:
1 edited

Legend:

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

    r17978 r17979  
    1010ROOT.gROOT.SetBatch(True)
    1111
    12 ########## BUILDING OF THE SHARED OBJECT FILES ###############################
     12#--------- BUILDING OF THE SHARED OBJECT FILES -------------------------------
    1313if __name__ == '__main__' and len(sys.argv) > 1 and 'build' in sys.argv[1]:
    1414    ROOT.gSystem.AddLinkedLibs("-lz")
    1515    root_make_string = ROOT.gSystem.GetMakeSharedLib()
    16     if not "-std=c++0x" in root_make_string:
     16    if "-std=c++0x" not in root_make_string:
    1717        make_string = root_make_string.replace('$Opt', '$Opt -std=c++0x -D HAVE_ZLIB')
    1818    ROOT.gSystem.SetMakeSharedLib(make_string)
     
    2121    ROOT.gROOT.ProcessLine(".L extern_Mars_mcore/zfits.h+O")
    2222    ROOT.gROOT.ProcessLine(".L extern_Mars_mcore/factfits.h+O")
    23     if not "-std=c++0x" in root_make_string:
    24         make_string = root_make_string.replace('$Opt', "$Opt -std=c++0x -D HAVE_ZLIB -D'PACKAGE_NAME=\"PACKAGE_NAME\"' "
    25                                                         "-D'PACKAGE_VERSION=\"PACKAGE_VERSION\"' -D'REVISION=\"REVISION\"' ")
     23    if "-std=c++0x" not in root_make_string:
     24        make_string = root_make_string.replace(
     25            '$Opt',
     26            "$Opt -std=c++0x "
     27            "-D HAVE_ZLIB "
     28            "-D'PACKAGE_NAME=\"PACKAGE_NAME\"' "
     29            "-D'PACKAGE_VERSION=\"PACKAGE_VERSION\"' "
     30            "-D'REVISION=\"REVISION\"' "
     31            )
    2632    ROOT.gSystem.SetMakeSharedLib(make_string)
    2733    ROOT.gROOT.ProcessLine(".L extern_Mars_mcore/DrsCalib.h+O")
    2834
    29     ROOT.gInterpreter.GenerateDictionary("map<string,fits::Entry>","map;string;extern_Mars_mcore/fits.h")
    30     ROOT.gInterpreter.GenerateDictionary("pair<string,fits::Entry>","map;string;extern_Mars_mcore/fits.h")
    31     ROOT.gInterpreter.GenerateDictionary("map<string,fits::Table::Column>","map;string;extern_Mars_mcore/fits.h")
    32     ROOT.gInterpreter.GenerateDictionary("pair<string,fits::Table::Column>","map;string;extern_Mars_mcore/fits.h")
    33     ROOT.gInterpreter.GenerateDictionary("vector<DrsCalibrate::Step>","vector;extern_Mars_mcore/DrsCalib.h")
    34 
    35 ########## USAGE #############################################################
     35    ROOT.gInterpreter.GenerateDictionary(
     36        "map<string,fits::Entry>",
     37        "map;string;extern_Mars_mcore/fits.h")
     38    ROOT.gInterpreter.GenerateDictionary(
     39        "pair<string,fits::Entry>",
     40        "map;string;extern_Mars_mcore/fits.h")
     41    ROOT.gInterpreter.GenerateDictionary(
     42        "map<string,fits::Table::Column>",
     43        "map;string;extern_Mars_mcore/fits.h")
     44    ROOT.gInterpreter.GenerateDictionary(
     45        "pair<string,fits::Table::Column>",
     46        "map;string;extern_Mars_mcore/fits.h")
     47    ROOT.gInterpreter.GenerateDictionary(
     48        "vector<DrsCalibrate::Step>",
     49        "vector;extern_Mars_mcore/DrsCalib.h")
     50
     51#-------- USAGE -------------------------------------------------------------
    3652if __name__ == '__main__' and len(sys.argv) < 3:
    3753    print """ Usage:
     
    5268    sys.exit(1)
    5369
    54 #########  START OF PYFACT MODULE ############################################
     70#--------  START OF PYFACT MODULE --------------------------------------------
    5571path = os.path.dirname(os.path.realpath(__file__))
    5672ROOT.gSystem.Load(path+'/AutoDict_map_string_fits__Entry__cxx.so')
     
    6682del path
    6783
    68 raw_base = '/fact/raw'
    69 aux_base = '/fact/aux'
     84env_name = 'FACT_DATA_BASE_DIR'
     85if env_name in os.environ:
     86    base_path = os.environ[env_name]
     87    raw_base = os.path.join(base_path, 'raw')
     88    aux_base = os.path.join(base_path, 'aux')
     89else:
     90    raw_base = os.path.join('fact', 'raw')
     91    aux_base = os.path.join('fact', 'aux')
    7092
    7193
    7294def stub_to_auxfile(s, s2=None, basep=aux_base, basen="*"):
    73     """ FIXME :-) 
     95    """ FIXME :-)
    7496        It's not yet clear how to generate aux file names from stubs, or iterables
    7597    """
    7698    if s2 is not None:
    77         s = "{0}_{1:03d}".format(s,s2)
     99        s = "{0}_{1:03d}".format(s, s2)
    78100    y = s[0:4]
    79101    m = s[4:6]
    80102    d = s[6:8]
    81103    date = s[0:8]
    82     r = s[9:12]
    83     return os.path.join(basep,y,m,d,date+'.'+basen+'.fits')
     104    #r = s[9:12]
     105    return os.path.join(basep, y, m, d, date + '.' + basen + '.fits')
    84106
    85107
    86108def make_path(s):
    87109    """ make path to fits file
    88        
     110
    89111        s : string or iterable
    90        
     112
    91113        Fits files in pyfact do not need to be specified by full paths
    92114        A so called stub path is sufficient. A valid stub path looks like:
     
    96118
    97119        In addition a file can be specified by a 2-element integer iterable,
    98         e.g. a list or a tuple, whose first element is the integer denoting the 
     120        e.g. a list or a tuple, whose first element is the integer denoting the
    99121        'night' : yyyymmdd
    100122        the 2nd integer is the 'run' : rrr
     
    103125
    104126        the pyfact.Fits class can handle .fits, .fits.gz, and .fits.fz files.
    105         stubs dont's specify which one should be used, so we need to check 
    106         which one exists, if more than one file exists fitting to the stub, 
     127        stubs dont's specify which one should be used, so we need to check
     128        which one exists, if more than one file exists fitting to the stub,
    107129        the order of precendence is:
    108130            * .fits    -- since access should be pretty fast
     
    116138        night = int(s[0])
    117139        run = int(s[1])
    118         _s = "{0:08d}_{1:03d}".format(night,run)
     140        _s = "{0:08d}_{1:03d}".format(night, run)
    119141    else:
    120142        _s = s
     
    122144    # so now s is some kind of string
    123145    # maybe it is already a path:
    124     if os.path.isabs( _s ):
    125         # s is already an absolute path. 
     146    if os.path.isabs(_s):
     147        # s is already an absolute path.
    126148        # maybe the file is not there, but we don't care about that
    127149        return _s
    128150
    129     # it was not an absolute path, maybe it's a relative path, let's check if 
     151    # it was not an absolute path, maybe it's a relative path, let's check if
    130152    # it points to a file.
    131     elif os.path.exists( _s ):
     153    elif os.path.exists(_s):
    132154        # s is certainly a path, it even points to a file :-)
    133155        return os.path.abspath(_s)
    134156
    135     # okay ... s was not a path, so let's generate a nice absolute path 
     157    # okay ... s was not a path, so let's generate a nice absolute path
    136158    # from the stub, in case it is a stub ..
    137159    elif re.match('\d{8}_\d{3}', _s):
     
    140162        m = _s[4:6]
    141163        d = _s[6:8]
    142         r = _s[9:12]
    143         start = os.path.join(raw_base,y,m,d,_s[:12]+'.fits')
     164        #r = _s[9:12]
     165        start = os.path.join(raw_base, y, m, d, _s[:12] + '.fits')
    144166        candidates = [start, start+'.fz', start+'.gz']
    145167        for c in candidates:
    146168            if os.path.exists(c):
    147169                return c
    148         # if we reached this point, s was a stub, but we were not 
    149         # able to find a file on the file system... 
    150         # let's return our best guess, the '.fz' file path 
     170        # if we reached this point, s was a stub, but we were not
     171        # able to find a file on the file system...
     172        # let's return our best guess, the '.fz' file path
    151173        # the Fits.__init__() will complain, if it can't find the file.
    152174        return candidates[1]
     
    154176        raise IOError("{0} can't be used for path generation".format(s))
    155177
    156 class Fits( object ):
     178
     179class Fits(object):
    157180    """ General FITS file access
    158181
     
    162185    """
    163186    __module__ = 'pyfact'
     187
    164188    def __init__(self, path):
    165189        """ Open fits file, parse header and setup table colums
     
    178202    def __repr__(self):
    179203        return '{s.__class__.__name__}(path="{s._path}")'.format(s=self)
    180    
     204
    181205    def __str__(self):
    182         s = """Fits object: 
     206        s = """Fits object:
    183207        path = {s._path}
    184208        row = {s._current_row}
     
    187211        return s
    188212
    189 
    190213    def __len__(self):
    191214        """ return the number of events, in case it's a FACT physics data file
     
    197220        """
    198221        """
    199         str_to_bool = { 'T':True, 'F':False}
    200         type_conversion = { 'I' : int, 'F' : float, 'T' : str, 'B' : str_to_bool.__getitem__}
     222        str_to_bool = {'T': True, 'F': False}
     223        type_conversion = {'I': int, 'F': float, 'T': str, 'B': str_to_bool.__getitem__}
    201224
    202225        self.header = {}
    203226        self.header_comments = {}
    204         for key,entry in self.f.GetKeys():
     227        for key, entry in self.f.GetKeys():
    205228            try:
    206229                self.header[key] = type_conversion[entry.type](entry.value)
    207230            except KeyError:
    208                 raise IOError("Error: entry type unknown.\n Is %s, but should be one of: [I,F,T,B]" % (entry.type) )
     231                raise IOError(
     232                    "Error: entry type unknown.\n "
     233                    "Is %s, but should be one of: [I,F,T,B]" % (entry.type))
    209234            self.header_comments[key] = entry.comment
    210235
     
    212237        """
    213238        """
    214         col_type_to_np_type_map = { 'L' : 'b1',  'A' : 'a1', 'B' : 'i1',
    215             'I' : 'i2', 'J' : 'i4', 'K' : 'i8', 'E' : 'f4', 'D' : 'f8'}
     239        col_type_to_np_type_map = {
     240            'L': 'b1',
     241            'A': 'a1',
     242            'B': 'i1',
     243            'I': 'i2',
     244            'J': 'i4',
     245            'K': 'i8',
     246            'E': 'f4',
     247            'D': 'f8'}
    216248        self.cols = {}
    217         for key,col in self.f.GetColumns():
     249        for key, col in self.f.GetColumns():
    218250            self.cols[key] = np.zeros(col.num, col_type_to_np_type_map[col.type])
    219251            if col.num != 0:
     
    231263            else:
    232264                self._current_row += 1
    233             if self.f.GetNextRow() == False:
     265            if self.f.GetNextRow() is False:
    234266                self._current_row = None
    235267                raise StopIteration
     
    237269            row = int(row)
    238270            self._current_row = row
    239             if self.f.GetRow(row) == False:
     271            if self.f.GetRow(row) is False:
    240272                self._current_row = None
    241273                raise StopIteration
    242274        return self
    243275
    244 class AuxFile( Fits ):
     276
     277class AuxFile(Fits):
    245278    """ easy(?) access to FACT aux files
    246279    """
    247280    __module__ = 'pyfact'
     281
    248282    def __init__(self, path, verbose=False):
    249283        self._verbose = verbose
     
    251285
    252286    def _setup_columns(self):
    253         col_type_to_np_type_map = { 'L' : 'b1',  'A' : 'a1', 'B' : 'i1',
    254             'I' : 'i2', 'J' : 'i4', 'K' : 'i8', 'E' : 'f4', 'D' : 'f8'}
     287        col_type_to_np_type_map = {
     288            'L': 'b1',
     289            'A': 'a1',
     290            'B': 'i1',
     291            'I': 'i2',
     292            'J': 'i4',
     293            'K': 'i8',
     294            'E': 'f4',
     295            'D': 'f8'}
    255296        self._cols = {}
    256297        self.cols = {}
    257        
     298
    258299        N = len(self)
    259         for key,col in self.f.GetColumns():
     300        for key, col in self.f.GetColumns():
    260301            self._cols[key] = np.zeros(col.num, col_type_to_np_type_map[col.type])
    261302            self.cols[key] = np.zeros((N, col.num), col_type_to_np_type_map[col.type])
     
    263304                self.f.SetPtrAddress(key, self._cols[key])
    264305
    265 
    266         for i,row in enumerate(self):
     306        for i, row in enumerate(self):
    267307            if self._verbose:
    268308                try:
     
    274314
    275315            for key in self._cols:
    276                 self.cols[key][i,:] = self._cols[key]
    277 
    278 
    279 class RawData( Fits ):
     316                self.cols[key][i, :] = self._cols[key]
     317
     318
     319class RawData(Fits):
    280320    """ Special raw data FITS file access (with DRS4 calibration)
    281321
    282322        During iteration the C++ method DrsCalibration::Apply is being called.
    283323    """
    284     __module__='pyfact'
     324    __module__ = 'pyfact'
     325
    285326    def __init__(self, data_path, calib_path):
    286327        """ -constructor-
     
    289330        """
    290331        super(RawData, self).__init__(data_path)
    291         self.cols['CalibData'] = np.zeros( self.cols['Data'].shape, np.float32)
    292         self.cols['CalibData2D'] = self.cols['CalibData'].reshape( self.header['NPIX'], -1)
     332        self.cols['CalibData'] = np.zeros(self.cols['Data'].shape, np.float32)
     333        self.cols['CalibData2D'] = self.cols['CalibData'].reshape(self.header['NPIX'], -1)
    293334        if not self.cols['CalibData2D'].base is self.cols['CalibData']:
    294335            print "Error seomthing went wrong!"
    295336        self.drs_calibration = ROOT.DrsCalibration()
    296         self.drs_calibration.ReadFitsImp( calib_path )
     337        self.drs_calibration.ReadFitsImp(calib_path)
    297338
    298339        self.drs_calibrate = ROOT.DrsCalibrate()
     
    308349        super(RawData, self).next(row)
    309350
    310         self.drs_calibration.Apply( self.cols['CalibData'],
    311                                     self.cols['Data'],
    312                                     self.cols['StartCellData'],
    313                                     self.header['NROI'])
     351        self.drs_calibration.Apply(
     352            self.cols['CalibData'],
     353            self.cols['Data'],
     354            self.cols['StartCellData'],
     355            self.header['NROI']
     356            )
    314357
    315358        for previous_start_cells in self.list_of_previous_start_cells:
    316359            self.drs_calibrate.CorrectStep(
    317                                 self.cols['CalibData'],
    318                                 self.header['NPIX'],
    319                                 self.header['NROI'],
    320                                 previous_start_cells,
    321                                 self.cols['StartCellData'],
    322                                 self.header['NROI']+10)
     360                self.cols['CalibData'],
     361                self.header['NPIX'],
     362                self.header['NROI'],
     363                previous_start_cells,
     364                self.cols['StartCellData'],
     365                self.header['NROI']+10)
    323366            self.drs_calibrate.CorrectStep(
    324                                 self.cols['CalibData'],
    325                                 self.header['NPIX'],
    326                                 self.header['NROI'],
    327                                 previous_start_cells,
    328                                 self.cols['StartCellData'],
    329                                 3)
     367                self.cols['CalibData'],
     368                self.header['NPIX'],
     369                self.header['NROI'],
     370                previous_start_cells,
     371                self.cols['StartCellData'],
     372                3)
    330373        self.list_of_previous_start_cells.append(self.cols['StartCellData'])
    331374        if len(self.list_of_previous_start_cells) > 5:
     
    336379
    337380        return self
    338 
    339381
    340382
     
    348390    print "The files has these cols:", f.cols.keys()
    349391
    350     for counter,row in enumerate(f):
     392    for counter, row in enumerate(f):
    351393        print "Event Id:", row.cols['EventNum']
    352394        print "shape of column 'StartCellData'", row.cols['StartCellData'].shape
Note: See TracChangeset for help on using the changeset viewer.