Skip to content

Commit

Permalink
Merge pull request #4 from nqdu/devel
Browse files Browse the repository at this point in the history
remove obspy dependency
  • Loading branch information
nqdu authored Jun 2, 2024
2 parents 10427d2 + bc22354 commit 517033b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
13 changes: 8 additions & 5 deletions bak/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,14 @@ def read_cmt(self,cmtfile):
read cmt file, and return 6 moment tensor components
"""
from obspy import read_events
cat = read_events(cmtfile)[0]
tensor = cat.focal_mechanisms[0].moment_tensor.tensor
mzz = tensor.m_rr; mxx = tensor.m_tt; myy = tensor.m_pp
mxz = tensor.m_rt; myz = tensor.m_rp; mxy = tensor.m_tp
# from obspy import read_events
# cat = read_events(cmtfile)[0]
# tensor = cat.focal_mechanisms[0].moment_tensor.tensor
# mzz = tensor.m_rr; mxx = tensor.m_tt; myy = tensor.m_pp
# mxz = tensor.m_rt; myz = tensor.m_rp; mxy = tensor.m_tp
# mzz,mxx,myy,mxz,myz,mxy = map(lambda x: x / self.mag,[mzz,mxx,myy,mxz,myz,mxy])
from utils import read_cmtsolution
mzz,mxx,myy,mxz,myz,mxy = read_cmtsolution(cmtfile)
mzz,mxx,myy,mxz,myz,mxy = map(lambda x: x / self.mag,[mzz,mxx,myy,mxz,myz,mxy])

return mzz,mxx,myy,mxz,myz,mxy
Expand Down
7 changes: 2 additions & 5 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,8 @@ def set_source(self,evla:float,evlo:float):
pass

def read_cmt(self,cmtfile:str):
from obspy import read_events
cat = read_events(cmtfile)[0]
tensor = cat.focal_mechanisms[0].moment_tensor.tensor
mzz = tensor.m_rr; mxx = tensor.m_tt; myy = tensor.m_pp
mxz = tensor.m_rt; myz = tensor.m_rp; mxy = tensor.m_tp
from utils import read_cmtsolution
mzz,mxx,myy,mxz,myz,mxy = read_cmtsolution(cmtfile)
mzz,mxx,myy,mxz,myz,mxy = map(lambda x: x / self.mag,[mzz,mxx,myy,mxz,myz,mxy])

return mzz,mxx,myy,mxz,myz,mxy
Expand Down
20 changes: 19 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,22 @@ def allocate_task(ntasks,nprocs,myrank):

endid = startid + sub_n - 1

return startid,endid
return startid,endid

def read_cmtsolution(cmtfile):
M = {}
with open(cmtfile) as f:
for line in f:
info = line.strip().split(":")
if len(info) == 2:
key,value = info

if 'M' in key:
M[key] = float(value) * 1.0e-7

# get moment tensor
mzz = M['Mrr']; mxx = M['Mtt']
myy = M['Mpp']; mxz = M['Mrt']
myz = M['Mrp']; mxy = M['Mtp']

return mzz,mxx,myy,mxz,myz,mxy

0 comments on commit 517033b

Please sign in to comment.