[add] read event info from obsDMT pickle file
This commit is contained in:
parent
36a4f0df8a
commit
e6648a3cec
@ -15,7 +15,7 @@ from pylot.core.util.event import Event
|
||||
from pylot.core.util.utils import fnConstructor, full_range, remove_underscores, check4gaps, check4doubled, \
|
||||
check4rotated, trim_station_components
|
||||
import pylot.core.loc.velest as velest
|
||||
|
||||
from pylot.core.util.obspyDMT_interface import qml_from_obspyDMT
|
||||
|
||||
class Data(object):
|
||||
"""
|
||||
@ -60,6 +60,8 @@ class Data(object):
|
||||
raise NotImplementedError('PILOT location information '
|
||||
'read support not yet '
|
||||
'implemeted.')
|
||||
elif 'event.pkl' in evtdata:
|
||||
evtdata = qml_from_obspyDMT(evtdata)
|
||||
else:
|
||||
raise e
|
||||
else:
|
||||
|
@ -7,6 +7,7 @@ from obspy import UTCDateTime
|
||||
from obspy.core.event import Event as ObsPyEvent
|
||||
from obspy.core.event import Origin, ResourceIdentifier
|
||||
from pylot.core.io.phases import picks_from_picksdict
|
||||
from pylot.core.util.obspyDMT_interface import qml_from_obspyDMT
|
||||
|
||||
|
||||
class Event(ObsPyEvent):
|
||||
@ -33,6 +34,7 @@ class Event(ObsPyEvent):
|
||||
self._testEvent = False
|
||||
self._refEvent = False
|
||||
self.get_notes()
|
||||
self.get_obspy_event_info()
|
||||
|
||||
def get_notes_path(self):
|
||||
"""
|
||||
@ -43,6 +45,18 @@ class Event(ObsPyEvent):
|
||||
notesfile = os.path.join(self.path, 'notes.txt')
|
||||
return notesfile
|
||||
|
||||
def get_obspy_event_info(self):
|
||||
infile_pickle = os.path.join(self.path, 'info/event.pkl')
|
||||
if not os.path.isfile(infile_pickle):
|
||||
return
|
||||
try:
|
||||
event_dmt = qml_from_obspyDMT(infile_pickle)
|
||||
except Exception as e:
|
||||
print('Could not get obspy event info: {}'.format(e))
|
||||
return
|
||||
self.magnitudes = event_dmt.magnitudes
|
||||
self.origins = event_dmt.origins
|
||||
|
||||
def get_notes(self):
|
||||
"""
|
||||
set self.note attribute to content of notes file
|
||||
|
@ -25,4 +25,20 @@ def check_obspydmt_eventfolder(folder):
|
||||
except Exception as e:
|
||||
return False, e
|
||||
|
||||
check_obspydmt_eventfolder('20110311_054623.a')
|
||||
def qml_from_obspyDMT(path):
|
||||
import pickle
|
||||
from obspy.core.event import Event, Magnitude, Origin
|
||||
|
||||
if not os.path.exists(path):
|
||||
return IOError('Could not find Event at {}'.format(path))
|
||||
infile = open(path, 'rb')
|
||||
event_dmt = pickle.load(infile)
|
||||
ev = Event(resource_id=event_dmt['event_id'])
|
||||
origin = Origin(resource_id=event_dmt['origin_id'], time=event_dmt['datetime'], longitude=event_dmt['longitude'],
|
||||
latitude=event_dmt['latitude'], depth=event_dmt['depth'])
|
||||
mag = Magnitude(mag=event_dmt['magnitude'], magnitude_type=event_dmt['magnitude_type'],
|
||||
origin_id=event_dmt['origin_id'])
|
||||
ev.magnitudes.append(mag)
|
||||
ev.origins.append(origin)
|
||||
return ev
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user