Exemplo n.º 1
0
def CfgParser(cfg_file):
    cf = configparser.RawConfigParser()
    pa = para()
    try:
        cf.read(cfg_file)
    except Exception:
        raise FileNotFoundError('Cannot open configure file %s' % cfg_file)
    pa.datapath = cf.get('path', 'datapath')
    pa.rfpath = cf.get('path', 'rfpath')
    pa.imagepath = cf.get('path', 'imagepath')
    logpath = cf.get('path', 'catalogpath')
    if logpath != '':
        pa.catalogpath = cf.get('path', 'catalogpath')
    for key, value in cf.items('para'):
        if key == 'date_begin':
            pa.__dict__[key] = obspy.UTCDateTime(value)
        elif key == 'date_end':
            pa.__dict__[key] = obspy.UTCDateTime(value)
        elif key == 'offset':
            try:
                pa.__dict__[key] = float(value)
            except:
                pa.__dict__[key] = None
        elif key == 'only_r':
            pa.only_r = cf.getboolean('para', 'only_r')
        else:
            try:
                pa.__dict__[key] = float(value)
            except ValueError:
                pa.__dict__[key] = value
    return pa
Exemplo n.º 2
0
def CfgParser(cfg_file):
    cf = configparser.RawConfigParser(allow_no_value=True)
    pa = para()
    try:
        cf.read(cfg_file)
    except Exception:
        raise FileNotFoundError('Cannot open configure file %s' % cfg_file)
    for key, value in cf.items('path'):
        if value == '':
            continue
        elif key == 'datapath':
            pa.datapath = value
        elif key == 'rfpath':
            pa.rfpath = value
        elif key == 'catalogpath':
            pa.catalogpath = value
        else:
            pa.__dict__[key] = value
    sections = cf.sections()
    sections.remove('path')
    for sec in sections:
        for key, value in cf.items(sec):
            if key == 'date_begin':
                pa.__dict__[key] = UTCDateTime(value)
            elif key == 'date_end':
                pa.__dict__[key] = UTCDateTime(value)
            elif key == 'offset':
                try:
                    pa.__dict__[key] = float(value)
                except:
                    pa.__dict__[key] = None
            elif key == 'itmax':
                pa.__dict__[key] = int(value)
            elif key == 'only_r':
                pa.__dict__[key] = cf.getboolean(sec, 'only_r')
            elif key == 'criterion':
                pa.criterion = value
            elif key == 'decon_method':
                pa.decon_method = value
            elif key == 'rmsgate':
                try:
                    pa.rmsgate = cf.getfloat(sec, 'rmsgate')
                except:
                    pa.rmsgate = None
            else:
                try:
                    pa.__dict__[key] = float(value)
                except ValueError:
                    pa.__dict__[key] = value
    return pa
Exemplo n.º 3
0
Arquivo: rf.py Projeto: Ji-Cong/seispy
 def __init__(self, cfg_file=None, log=None):
     if cfg_file is None:
         self.para = para()
     elif isinstance(cfg_file, str):
         self.para = CfgParser(cfg_file)
     else:
         raise TypeError('cfg should be \'str\' not \'{0}\''.format(
             type(cfg_file)))
     if not isinstance(self.para, para):
         raise TypeError('Input value should be class seispy.rf.para')
     if log is None:
         self.logger = setuplog()
     else:
         self.logger = log
     self.eq_lst = pd.DataFrame()
     self.eqs = pd.DataFrame()
     self.model = TauPyModel('iasp91')
     self.stainfo = stainfo()
Exemplo n.º 4
0
 def __init__(self, cfg_file=None, log=None):
     if log is None:
         self.logger = setuplog()
     else:
         self.logger = log
     if cfg_file is None:
         self.para = para()
     elif isinstance(cfg_file, str):
         if not exists(cfg_file):
             self.logger.RFlog.error('No such file of {}.'.format(cfg_file))
             sys.exit(1)
         self.para = CfgParser(cfg_file)
     else:
         raise TypeError(
             'cfg should be in \'str\' format rather than \'{0}\''.format(
                 type(cfg_file)))
     if not isinstance(self.para, para):
         raise TypeError('Input value should be class seispy.rf.para')
     self.eq_lst = pd.DataFrame()
     self.eqs = pd.DataFrame()
     self.model = TauPyModel('iasp91')
     self.stainfo = stainfo()
     self.baz_shift = 0