-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgenquake
executable file
·51 lines (44 loc) · 2.44 KB
/
genquake
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Created on Tue Jan 9 15:58:51 2018
@author: marnold
Quakeml Generator uses the Obspy framework to create, fill and write a new event to
a quakeml file. Data to be written to a quakeml file is passed to the program as a
.txt file. Instructions and examples for formatting the .txt file for proper parsing
are in 'README.md'. For licensing and disclaimers see LICENSE.md and DISCLAIMER.md
"""
import utils as h
import text_as_input as p
import obspy
if __name__ == '__main__':
data, output_filename = p.txt2dictionary() # import file to python dictionary and get output filename
h.lowercaseInput(data) # make case-sensitive input lowercase
h.updateDictionary(data) # generate calculated fields
h.depthToMeters(data)
# Generate quakeml with obspy
magnitudes, origins = [], [] # lists for magnitudes and origins
creation_info = h.generateCreationInfo(data) # create creation_info object
origin = h.generateOrigin(data, creation_info) # create origin object
origins.append(origin)
magnitude = h.generateMagnitude(data, creation_info, origin) # create magnitude object
magnitudes.append(magnitude)
event = h.generateEvent(data, creation_info, origins, magnitudes) # create event object
# Add ANSS specific attributes
extra = { 'eventsource': {'value': data['eventsource'],
'type': 'attribute',
'namespace': 'http://anss.org/xmlns/catalog/0.1'},
'dataid': {'value': data['dataid'],
'type': 'attribute',
'namespace': 'http://anss.org/xmlns/catalog/0.1'},
'eventid': {'value': data['eventid'],
'type': 'attribute',
'namespace': 'http://anss.org/xmlns/catalog/0.1'},
'datasource': {'value': data['datasource'],
'type': 'attribute',
'namespace': 'http://anss.org/xmlns/catalog/0.1'}}
event.extra = extra # add attributes to event
catalog = obspy.core.event.Catalog(events=[event], resource_id = data['epPid']) # create catalog object
# Write event if new or updated using obspy write
catalog.write(output_filename, format='QUAKEML',
nsmap={'catalog': 'http://anss.org/xmlns/catalog/0.1'})
print("file was exported to: " + output_filename)