-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathplot.py
More file actions
189 lines (136 loc) · 5.62 KB
/
plot.py
File metadata and controls
189 lines (136 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import os
import fnmatch
import sys
from optparse import OptionParser
import logging
import imp
import obspy.core
# add local directories to import path #hs+
sys.path.append ('Waveform/')
sys.path.append ('Process/')
sys.path.append ('Cluster/')
sys.path.append ('Common/')
import WaveformProgs
import ProcessProgs
import ClusterProgs
import CommonProgs
#hs-
config = imp.load_source ('Config',os.path.join (os.getcwd(),'tools','config.py'))
logger = logging.getLogger(sys.argv[0])
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
logger.addHandler(ch)
usage = ''' %prog [options] <command> [args]
%prog list [list all events from event folder]
%prog search [search for events in online catalog parameter from global.conf]
%prog create eventID [eventID from online catalog]
%prog getstations eventname
%prog getdata eventname
%prog getmeta eventname
%prog plotstations eventname
%prog cluster eventname [automatic array clustering and print arrayconfig]
%prog process eventname
%prog plotresult eventname
'''
parser = OptionParser(usage=usage)
(options, args) = parser.parse_args()
def folderContent(p):
'''
method to lookup necessary config files for event processing in the event folders
return list of eventname if config and origin file are existing
'''
L = []
for root,dirs,files in os.walk(p):
flags=0
for i in files:
if fnmatch.fnmatch (i,'*.config'): flags += 1
if fnmatch.fnmatch (i,'*.origin'): flags += 1
if flags == 2:
name = root.split('/')
L.append(name[-1:])
return L
def listEvents():
'''
method to list events in the event folder
only list event if config and origin files are exisiting in event folder
return list of events and print them
'''
for item in os.listdir(os.path.join(os.getcwd(),'events')):
print item
# -------------------------------------------------------------------------------------------------
def parseArguments (args):
'''
parse arguments of main and entry script for arraytool
do what you gave as commandline argument to main script
'''
dir = 'tools'
#hs+
if WaveformProgs.start (config) : return # sys.argv[1] : 'getstations' 'getdata' 'getmeta'
if ProcessProgs.start (config) : return # 'process'
if ClusterProgs.start (config) : return # 'cluster'
if CommonProgs.start () : return # 'new_version (for internal use)
#hs-
if sys.argv[1] == 'list':
listEvents()
elif sys.argv[1] == 'process': # nicht mehr benutzt
path = os.path.join (os.getcwd(),'events',sys.argv[2])
at = os.path.join (os.getcwd(), dir, 'main.py')
cmd = sys.executable+' '+at+' -f '+ path
os.chdir (os.path.join(os.getcwd(),"tools"))
os.system (cmd)
elif sys.argv[1] == 'energy':
path = os.path.join (os.getcwd(),'events',sys.argv[2])
at = os.path.join (os.getcwd(), dir, 'energy.py')
cmd = sys.executable+' '+at+' -f '+ path
os.chdir (os.path.join (os.getcwd(),"tools"))
os.system (cmd)
elif sys.argv[1] == 'create':
at = os.path.join (os.getcwd(),dir,'create.py')
t = ''
for i in sys.argv[2:] : t +=i+'_'
cmd = sys.executable+' '+at+' '+t
os.chdir (os.path.join (os.getcwd(),"tools"))
os.system(cmd)
'''
elif sys.argv[1] == 'rotate':
at = os.path.join(os.getcwd(),dir,'rotatecomp.py')
path = os.path.join(os.getcwd(),'events',sys.argv[2])
print path
cmd = sys.executable+' '+at+' -p '+ path
os.chdir (os.path.join(os.getcwd(),"tools"))
os.system(cmd)
'''
elif sys.argv[1] == 'cluster':
at = os.path.join(os.getcwd(), dir, 'callcluster.py')
path = os.path.join(os.getcwd(),'events',sys.argv[2])
cmd = sys.executable+' '+at+' -f '+ path
os.chdir (os.path.join (os.getcwd(),"tools"))
os.system(cmd)
elif sys.argv[1] == 'plotstations':
at = os.path.join(os.getcwd(),dir,'makeplot.py')
path = os.path.join(os.getcwd(),'events',sys.argv[2])
cmd = sys.executable+' '+at+' -f '+ path
os.chdir (os.path.join(os.getcwd(),"tools"))
os.system(cmd)
elif sys.argv[1] == 'search':
at = os.path.join(os.getcwd(),dir,'eventsearch.py')
cmd = sys.executable+' '+ at
os.system (cmd)
elif sys.argv[1] == 'plotresult':
at = os.path.join(os.getcwd(),dir,'plotresult.py')
path = os.path.join(os.getcwd(),'events',sys.argv[2])
cmd = sys.executable+' '+at+' -f '+ path
os.chdir(os.path.join(os.getcwd(),"tools"))
os.system(cmd)
else:
logger.info('\033[31m Option not available \033[0m')
# -------------------------------------------------------------------------------------------------
if __name__ == "__main__":
if len(sys.argv) > 1:
parseArguments(sys.argv)
else:
cmd = 'python '+sys.argv[0]+' --help'
os.system(cmd)