Skip to content

Commit 1268a32

Browse files
committed
4: add option to write out standard CMTSOLUTION files
1 parent 09b6abf commit 1268a32

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

4-writeCMTSOLUTION.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# %% markdown
2+
# # writeCMTSOLUTION
3+
#
4+
# Write out standard CMTSOLUTION files for each event
5+
#
6+
# ##### JBR - 10/11/2021
7+
# %% codecell
8+
# %load_ext autoreload
9+
# %autoreload
10+
from setup_parameters import *
11+
import matplotlib.pyplot as plt
12+
import obspy
13+
from obspy.clients.fdsn import Client
14+
from obspy import UTCDateTime
15+
from obspy.core import AttribDict
16+
from obspy.io.sac import SACTrace
17+
from obspy import read
18+
import numpy as np
19+
import matplotlib.pylab as plt
20+
# %matplotlib inline
21+
from datetime import datetime
22+
import os
23+
import calendar
24+
import urllib
25+
26+
# %% codecell
27+
# Load Client
28+
client = Client(webservice)
29+
print(client)
30+
31+
if not os.path.exists(CMTSOLUTION_path):
32+
os.makedirs(CMTSOLUTION_path)
33+
# %% codecell
34+
t1 = UTCDateTime(tstart)
35+
t2 = UTCDateTime(tend)
36+
37+
# Load events from GCMT catalogue using IRIS SPUD
38+
url_query = 'http://ds.iris.edu/spudservice/momenttensor/ids?' \
39+
+'evtstartdate='+t1.strftime('%Y-%m-%dT%H:%M:%S') \
40+
+'&evtenddate='+t2.strftime('%Y-%m-%dT%H:%M:%S') \
41+
+'&evtminmag='+str(minmagnitude)
42+
evids = urllib.request.urlopen(url_query)
43+
events_str = '&'.join([line.decode("utf-8").replace("\n", "") for line in evids])+'&'
44+
url_ndk = 'http://ds.iris.edu/spudservice/momenttensor/bundleids/ndk?'+events_str
45+
cat_evts = obspy.read_events(url_ndk)
46+
47+
48+
# %% codecell
49+
for iev, ev in enumerate(cat_evts) :
50+
51+
evname = ev.origins[0].time.strftime('%Y%m%d%H%M');
52+
outpath = CMTSOLUTION_path+'/'+evname+'_CMTSOLUTION'
53+
print('Working on '+outpath)
54+
55+
ev.write(outpath,format='CMTSOLUTION')
56+
57+

setup_parameters.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,7 @@
4141

4242

4343
########## 3-CMT2idagrn ##########
44-
CMT2idagrn_path = search_dir+'CMT2idagrn/' # OUTPUT PATH
44+
CMT2idagrn_path = search_dir+'CMT2idagrn/' # OUTPUT PATH
45+
46+
########## 4-writeCMTSOLUTION ##########
47+
CMTSOLUTION_path = search_dir+'CMTSOLUTIONS/' # OUTPUT PATH

0 commit comments

Comments
 (0)