Skip to content

Commit

Permalink
format SetupLog
Browse files Browse the repository at this point in the history
  • Loading branch information
xumi1993 committed Dec 22, 2023
1 parent 3065e16 commit d1dffa3
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 33 deletions.
4 changes: 2 additions & 2 deletions seispy/ccp3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from seispy.geo import km2deg, extrema, skm2srad, rad2deg
from seispy import distaz
from seispy.core.depmodel import DepModel
from seispy.setuplog import setuplog
from seispy.setuplog import SetupLog
from scikits.bootstrap import ci
from seispy.ccppara import ccppara, CCPPara
from seispy.signal import smooth
Expand Down Expand Up @@ -118,7 +118,7 @@ class CCP3D():
"""
def __init__(self, cfg_file=None, log=None):
if log is None:
self.logger = setuplog()
self.logger = SetupLog()
else:
self.logger = log
if cfg_file is None:
Expand Down
4 changes: 2 additions & 2 deletions seispy/ccpprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from seispy.geo import km2deg, deg2km, latlon_from, \
geoproject, sind, rad2deg, skm2srad, \
geo2sph, sph2geo
from seispy.setuplog import setuplog
from seispy.setuplog import SetupLog
from seispy.distaz import distaz
from seispy.core.depmodel import DepModel
from seispy.rf2depth_makedata import Station
Expand Down Expand Up @@ -100,7 +100,7 @@ def init_profile(lat1, lon1, lat2, lon2, val):
class CCPProfile():
def __init__(self, cfg_file=None, log=None):
if log is None:
self.logger = setuplog()
self.logger = SetupLog()
else:
self.logger = log
if cfg_file is None:
Expand Down
4 changes: 2 additions & 2 deletions seispy/modcreator.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import numpy as np
from scipy.interpolate import griddata, interp1d
from seispy.core.depmodel import DepModel
from seispy.setuplog import setuplog
from seispy.setuplog import SetupLog
import argparse


class ModCreator():
def __init__(self, log=None):
if log is None:
self.logger = setuplog()
self.logger = SetupLog()
else:
self.logger = log
self.lats = np.array([])
Expand Down
6 changes: 4 additions & 2 deletions seispy/para.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def read_para(cls, cfg_file):
elif key == 'catalogpath':
pa.catalogpath = value
else:
exec('pa.{} = {}'.format(key, value))
exec('pa.{} = value'.format(key))
sections.remove('path')
if 'fetch' in sections:
for key, value in cf.items('fetch'):
Expand All @@ -254,8 +254,10 @@ def read_para(cls, cfg_file):
continue
else:
pa.data_server_password = value
elif key == 'data_server':
pa.data_server = value
else:
exec('pa.stainfo.{} = {}'.format(key, value))
exec('pa.stainfo.{} = value'.format(key))
sections.remove('fetch')
for sec in sections:
for key, value in cf.items(sec):
Expand Down
4 changes: 2 additions & 2 deletions seispy/pickdepth/pickdepthui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .get_depth import GoodDepth
from seispy.setuplog import setuplog
from seispy.setuplog import SetupLog
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QWidget, QHBoxLayout,\
QVBoxLayout, QSizePolicy, QGroupBox,\
Expand Down Expand Up @@ -56,7 +56,7 @@ class MapUI(QWidget):
def __init__(self, stack_data_path, depmin=30, depmax=65,
width=6, height=11, dpi=100, idx=0, smooth=10):
super(MapUI, self).__init__()
self.log = setuplog()
self.log = SetupLog()
# self._set_geom_center()
self.add_log_layout()
self.map_para = {'width': width, 'height':height, 'dpi':dpi}
Expand Down
4 changes: 2 additions & 2 deletions seispy/pickrf/pickfigure.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pandas as pd
from matplotlib.figure import Figure
from os.path import join, basename
from seispy.setuplog import setuplog
from seispy.setuplog import SetupLog
from seispy.rfcorrect import RFStation


Expand Down Expand Up @@ -45,7 +45,7 @@ def __init__(self, rfpath, width=21, height=11, dpi=100, xlim=[-2, 30]):
self.width = width
self.height = height
self.dpi = dpi
self.log = setuplog()
self.log = SetupLog()
self.rfpath = rfpath
self.enf = 3.5
self.ipage = 0
Expand Down
4 changes: 2 additions & 2 deletions seispy/pickseis/sviewerui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
QSizePolicy, QWidget, \
QPushButton, QHBoxLayout, QFileDialog
from os.path import exists, dirname, join
from seispy.setuplog import setuplog
from seispy.setuplog import SetupLog
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
Expand All @@ -21,7 +21,7 @@ def __init__(self, eqs, para, logger, width=21, height=11, dpi=100):
self.picker_time = pd.DataFrame({'trigger_shift': np.array([eqs.iloc[i]['data'].trigger_shift for i in range(self.row_num)])})
self.picker_time.set_index(eqs.index, inplace=True)
self.para = para
self.log = setuplog()
self.log = SetupLog()
self.idx = 0
self.init_figure(width=width, height=height, dpi=dpi)
self.plot()
Expand Down
6 changes: 3 additions & 3 deletions seispy/rf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from seispy.para import RFPara
from seispy import distaz
from seispy.eq import EQ
from seispy.setuplog import setuplog
from seispy.setuplog import SetupLog
from seispy.catalog import read_catalog_file
from seispy.utils import scalar_instance
import glob
Expand Down Expand Up @@ -169,7 +169,7 @@ def match_eq(eq_lst, pathname, stla, stlo, logger, ref_comp='Z', suffix='SAC', o
:param stlo: Station longitude
:type stlo: float
:param logger: Logger
:type logger: seispy.setuplog.Logger
:type logger: seispy.setuplog.SetupLog
:param ref_comp: Reference component, defaults to 'Z'
:type ref_comp: str, optional
:param suffix: Suffix of SAC files, defaults to 'SAC'
Expand Down Expand Up @@ -238,7 +238,7 @@ def CfgModify(cfg_file, session, key, value):
class RF(object):
def __init__(self, cfg_file=None, log=None):
if log is None:
self.logger = setuplog()
self.logger = SetupLog()
else:
self.logger = log
if cfg_file is None:
Expand Down
6 changes: 3 additions & 3 deletions seispy/rf2depth_makedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from seispy.core.pertmod import Mod3DPerturbation
import numpy as np
from seispy.ccppara import ccppara, CCPPara
from seispy.setuplog import setuplog
from seispy.setuplog import SetupLog
from seispy.geo import latlon_from, rad2deg
from os.path import join, exists
import argparse
Expand Down Expand Up @@ -51,13 +51,13 @@ def _load_mod(datapath, staname):
class RFDepth():
"""Convert receiver function to depth axis
"""
def __init__(self, cpara:CCPPara, log=setuplog(),
def __init__(self, cpara:CCPPara, log=SetupLog(),
raytracing3d=False, velmod3d=None, modfolder1d=None) -> None:
"""
:param cpara: CCPPara object
:type cpara: CCPPara
:param log: Log object
:type log: setuplog
:type log: SetupLog
:param raytracing3d: If True, use 3D ray tracing to calculate the travel time
:type raytracing3d: bool
:param velmod3d: Path to 3D velocity model in npz file
Expand Down
27 changes: 14 additions & 13 deletions seispy/setuplog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
from os.path import expanduser, join


class setuplog(object):
class SetupLog(object):
default_level = logging.INFO
default_logs={
"RF2depthlog":("RF2depth","INFO","stream_handler"),
"RFlog":("RF","INFO","stream_handler"),
"Batlog":("Bat","INFO","stream_handler","file_handler"),
"CCPlog":("CCP","INFO","stream_handler"),
"ModCreatorlog":("ModCreator","INFO","stream_handler"),
"PickDepthlog": ("PickDepth", "INFO","stream_handler")
"RF2depthlog":("RF2depth",default_level,"stream_handler"),
"RFlog":("RF",default_level,"stream_handler"),
"Batlog":("Bat",default_level,"stream_handler","file_handler"),
"CCPlog":("CCP",default_level,"stream_handler"),
"ModCreatorlog":("ModCreator",default_level,"stream_handler"),
"PickDepthlog": ("PickDepth", default_level,"stream_handler")
}
def __init__(self, filename=join(expanduser('~'), '.RF.log')):
"""
Expand All @@ -29,18 +30,18 @@ def __init__(self, filename=join(expanduser('~'), '.RF.log')):
# init, setlevel
log = logging.getLogger(config[0])
log.setLevel(config[1])
next if log.hasHandlers else None

# add handler
if "file_handler" in config:
log.addHandler(fh)
if "stream_handler" in config:
log.addHandler(ch)
if not log.hasHandlers():
if "file_handler" in config:
log.addHandler(fh)
if "stream_handler" in config:
log.addHandler(ch)

# attach to class
setattr(self,loger_branch,log)


if __name__ == '__main__':
logger = setuplog()
logger = SetupLog()
logger.RFlog.info('print')

0 comments on commit d1dffa3

Please sign in to comment.