[task] further steps to implement pick comparison from QtPyLoT
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import glob
|
||||
|
||||
from obspy.io.xseed import Parser
|
||||
from obspy.core import read, Stream, UTCDateTime
|
||||
import os
|
||||
from obspy import read_events, read_inventory
|
||||
from obspy.core.event import Event, ResourceIdentifier, Pick, WaveformStreamID
|
||||
from obspy.core import read, Stream, UTCDateTime
|
||||
from obspy.core.event import Event
|
||||
from obspy.io.xseed import Parser
|
||||
|
||||
from pylot.core.io.phases import readPILOTEvent, picks_from_picksdict
|
||||
from pylot.core.util.utils import fnConstructor, getGlobalTimes
|
||||
from pylot.core.io.phases import readPILOTEvent, picks_from_picksdict, \
|
||||
picks_from_pilot
|
||||
from pylot.core.util.errors import FormatError, OverwriteError
|
||||
from pylot.core.util.utils import fnConstructor, getGlobalTimes
|
||||
|
||||
|
||||
class Data(object):
|
||||
@@ -36,17 +36,36 @@ class Data(object):
|
||||
self.wfdata = Stream()
|
||||
self._new = False
|
||||
if isinstance(evtdata, Event):
|
||||
self.evtdata = evtdata
|
||||
pass
|
||||
elif isinstance(evtdata, dict):
|
||||
evt = readPILOTEvent(**evtdata)
|
||||
self.evtdata = evt
|
||||
elif evtdata:
|
||||
cat = read_events(evtdata)
|
||||
self.evtdata = cat[0]
|
||||
evtdata = evt
|
||||
elif isinstance(evtdata, str):
|
||||
try:
|
||||
cat = read_events(evtdata)
|
||||
if len(cat) is not 1:
|
||||
raise ValueError('ambiguous event information for file: '
|
||||
'{file}'.format(file=evtdata))
|
||||
evtdata = cat[0]
|
||||
except TypeError as e:
|
||||
if 'Unknown format for file' in e.message:
|
||||
if 'PHASES' in evtdata:
|
||||
picks = picks_from_pilot(evtdata)
|
||||
evtdata = Event()
|
||||
evtdata.picks = picks_from_picksdict(picks)
|
||||
elif 'LOC' in evtdata:
|
||||
raise NotImplementedError('PILOT location information '
|
||||
'read support not yet '
|
||||
'implemeted.')
|
||||
else:
|
||||
raise e
|
||||
else:
|
||||
raise e
|
||||
else: # create an empty Event object
|
||||
self.setNew()
|
||||
self.evtdata = Event()
|
||||
self.getEvtData().picks = []
|
||||
evtdata = Event()
|
||||
evtdata.picks = []
|
||||
self.evtdata = evtdata
|
||||
self.wforiginal = None
|
||||
self.cuttimes = None
|
||||
self.dirty = False
|
||||
|
||||
@@ -11,10 +11,10 @@ from obspy.core import UTCDateTime
|
||||
from pylot.core.io.location import create_arrival, create_event, \
|
||||
create_magnitude, create_origin, create_pick
|
||||
from pylot.core.pick.utils import select_for_phase
|
||||
from pylot.core.util.utils import getOwner, getGlobalTimes
|
||||
from pylot.core.util.utils import getOwner, getGlobalTimes, four_digits
|
||||
|
||||
|
||||
def readPILOTEvent(phasfn=None, locfn=None, authority_id=None, **kwargs):
|
||||
def readPILOTEvent(phasfn=None, locfn=None, authority_id='RUB', **kwargs):
|
||||
"""
|
||||
readPILOTEvent - function
|
||||
|
||||
@@ -67,18 +67,15 @@ def readPILOTEvent(phasfn=None, locfn=None, authority_id=None, **kwargs):
|
||||
minute = int(loc['mm'])
|
||||
second = int(loc['ss'])
|
||||
|
||||
if year + 2000 < UTCDateTime.utcnow().year:
|
||||
year += 2000
|
||||
else:
|
||||
year += 1900
|
||||
year = four_digits(year)
|
||||
|
||||
eventDate = UTCDateTime(year=year, julday=julday, hour=hour,
|
||||
minute=minute, second=second)
|
||||
|
||||
stations = [stat for stat in phases['stat'][0:-1:3]]
|
||||
|
||||
event = create_event(eventDate, loccinfo, etype='earthquake', resID=eventNum,
|
||||
authority_id=authority_id)
|
||||
event = create_event(eventDate, loccinfo, etype='earthquake',
|
||||
resID=eventNum, authority_id=authority_id)
|
||||
|
||||
lat = float(loc['LAT'])
|
||||
lon = float(loc['LON'])
|
||||
@@ -123,13 +120,13 @@ def readPILOTEvent(phasfn=None, locfn=None, authority_id=None, **kwargs):
|
||||
pickID = pick.get('id')
|
||||
arrival = create_arrival(pickID, pickcinfo, phase)
|
||||
origin.arrivals.append(arrival)
|
||||
event.picks.append(pick)
|
||||
np += 1
|
||||
|
||||
magnitude = create_magnitude(origin.get('id'), loccinfo)
|
||||
magnitude.mag = float(loc['Mnet'])
|
||||
magnitude.magnitude_type = 'Ml'
|
||||
|
||||
event.picks.append(pick)
|
||||
event.origins.append(origin)
|
||||
event.magnitudes.append(magnitude)
|
||||
return event
|
||||
|
||||
@@ -93,6 +93,14 @@ def fnConstructor(s):
|
||||
return fn
|
||||
|
||||
|
||||
def four_digits(year):
|
||||
if year + 2000 < UTCDateTime.utcnow().year:
|
||||
year += 2000
|
||||
else:
|
||||
year += 1900
|
||||
return year
|
||||
|
||||
|
||||
def getGlobalTimes(stream):
|
||||
'''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user