new functions added for event creation purposes:

getHash - returns a hash string from an UTCDateTime object
	createResourceID - returns a valid PyLoT resourceID for arbitrary types of event data
	createOrigin - returns an ObsPy Origin object (work in progress)
	createEvent - returns an ObsPy Event object (work in progress)
	createPick - returns an ObsPy Pick object (work in progress)
	createArrival - returns an ObsPy Arrival object (work in progress)
	createMagnitude - returns an ObsPy Magnitude object (work in progress)
	createAmplitude - returns an ObsPy Amplitude object (work in progress)
testing should be carried out as a next step
This commit is contained in:
2015-02-09 13:24:55 +01:00
parent f6bf37c920
commit 46a20a10e6
3 changed files with 247 additions and 106 deletions

View File

@@ -2,11 +2,14 @@
# -*- coding: utf-8 -*-
import os
import glob
import scipy.io as sio
import obspy.core.event as ope
from obspy.core import UTCDateTime
from pylot.core.util import getOwner, createPick, createArrival, createEvent
from pylot.core.util import getOwner, createPick, createArrival, createEvent, \
createOrigin, createMagnitude
def readPILOTEvent(phasfn=None, locfn=None, authority_id=None, **kwargs):
"""
@@ -61,7 +64,7 @@ def readPILOTEvent(phasfn=None, locfn=None, authority_id=None, **kwargs):
minute = int(loc['mm'])
second = int(loc['ss'])
if UTCDateTime(year=year+2000) < UTCDateTime.utcnow():
if UTCDateTime(year=year + 2000) < UTCDateTime.utcnow():
year += 2000
else:
year += 1900
@@ -71,30 +74,31 @@ def readPILOTEvent(phasfn=None, locfn=None, authority_id=None, **kwargs):
stations = [stat for stat in phases['stat'][0:-1:3]]
eventid = 'loc/' + eventNum
evresID = ope.ResourceIdentifier(id=eventid)
evresID.convertIDToQuakeMLURI(authority_id=authority_id)
event = ope.Event(resource_id=evresID)
event.creation_info = loccinfo
etype = ope.EventType('earthquake')
event.event_type = etype
event = createEvent(eventDate, loccinfo, 'earthquake', eventNum,
authority_id)
lat = float(loc['LAT'])
lon = float(loc['LON'])
dep = float(loc['DEP'])
origin = createOrigin(eventDate, loccinfo, lat, lon, dep, eventNum)
for n, pick in enumerate(phases['Ptime']):
kwargs = {'year':int(pick[0]),
'month':int(pick[1]),
'day':int(pick[2]),
'hour':int(pick[3]),
'minute':int(pick[4]),
'second':int(str(pick[5]).split('.')[0]),
'microsecond':int(str(pick[5]).split('.')[1][0:6])}
kwargs = {'year': int(pick[0]),
'month': int(pick[1]),
'day': int(pick[2]),
'hour': int(pick[3]),
'minute': int(pick[4]),
'second': int(str(pick[5]).split('.')[0]),
'microsecond': int(str(pick[5]).split('.')[1][0:6])}
spick = phases['Stime'][n]
if spick[0] > 0:
skwargs = {'year':int(spick[0]),
'month':int(spick[1]),
'day':int(spick[2]),
'hour':int(spick[3]),
'minute':int(spick[4]),
'second':int(str(spick[5]).split('.')[0]),
'microsecond':int(str(spick[5]).split('.')[1][0:6])}
skwargs = {'year': int(spick[0]),
'month': int(spick[1]),
'day': int(spick[2]),
'hour': int(spick[3]),
'minute': int(spick[4]),
'second': int(str(spick[5]).split('.')[0]),
'microsecond': int(str(spick[5]).split('.')[1][0:6])}
spicktime = UTCDateTime(**skwargs)
else:
spicktime = None
@@ -102,69 +106,34 @@ def readPILOTEvent(phasfn=None, locfn=None, authority_id=None, **kwargs):
for picktime, phase in [(ppicktime, 'P'), (spicktime, 'S')]:
if phase == 'P':
wffn = os.path.join([sdir, '{0}*{1}*'.format(stations[n], 'z')])
wffn = os.path.join([sdir, '{0}*{1}*'.format(stations[n],
'z')])
else:
wffn = os.path.join([sdir, '{0}*{1}*'.format(stations[n], '[ne]')])
pick, arrival, np = createArrival(np, picktime, eventNum,
stations[n], pickcinfo, phase,
wffn, authority_id)
wffn = os.path.join([sdir, '{0}*{1}*'.format(stations[n],
'[ne]')])
pick = createPick(eventDate, np, picktime, eventNum, pickcinfo,
phase,
stat[n], wffn, authority_id)
event.picks.append(pick)
pickID = pick.get('resource_id')
arrival = createArrival(pickID, eventNum, pickcinfo, phase,
stat[n], authority_id)
origin.arrivals.append(arrival)
np += 1
origID = 'orig/' + genID
origresID = ResourceIdentifier(id=origID)
origresID.convertIDToQuakeMLURI(authority_id='BUG')
origin = Origin()
origin.resource_id = origresID
otime = self.location[eventid]['Location']['Origin time']
origin.time = UTCDateTime(otime)
origin.creation_info = self.cinfo
HW = self.location[eventid]['Location']['Hochwert']
RW = self.location[eventid]['Location']['Rechtswert']
LAT, LON = coordTrans(HW, RW, tosys=GPS)
origin.latitude = LAT
origin.longitude = LON
origin.depth = 1000.
origin.depth_type = OriginDepthType('operator assigned')
origin.evaluation_mode = 'automatic'
origin.arrivals.append(arrival)
magnitude = createMagnitude(origin.get('resource_id'), eventDate,
loccinfo,
authority_id)
magnitude.mag = float(loc['Mnet'])
magnitude.magnitude_type = 'Ml'
amplID = 'corrampl/' + genID
amplresID = ResourceIdentifier(id=amplID)
amplresID.convertIDToQuakeMLURI(authority_id='BUG')
amplitude = Amplitude()
amplitude.resource_id = amplresID
amplitude.creation_info = self.cinfo
amp = self.data[eventid][phase]['Amplitude']*1e-9
amplitude.generic_amplitude = amp
amplitude.unit = AmplitudeUnit('m/s')
amplitude.magnitude_hint = 'Ml'
amplitude.type = AmplitudeCategory('point')
amplitude.pick_id = pickresID
event.picks.append(pick)
event.origins.append(origin)
event.magnitudes.append(magnitude)
magnID = 'corrmag/' + genID
magnresID = ResourceIdentifier(id=magnID)
magnresID.convertIDToQuakeMLURI(authority_id='BUG')
magnitude = Magnitude()
magnitude.resource_id = magnresID
magnitude.creation_info = self.cinfo
magnitude.origin_id = origresID
mag = self.location[eventid]['Ml']
magnitude.mag = mag
magnitude.magnitude_type = 'Ml'
event = Event(resource_id=evresID)
event.creation_info = self.cinfo
etype = EventType('earthquake')
event.event_type = etype
edesc = EventDescription(text='Prosper Haniel (induced)')
event.event_descriptions.append(edesc)
event.picks.append(pick)
event.origins.append(origin)
event.magnitudes.append(magnitude)
event.amplitudes.append(amplitude)
except AttributeError, e:
raise AttributeError('{0} - Matlab LOC file contain \
insufficient data!'.format(e))
raise AttributeError('{0} - Matlab LOC files {1} and {2} contains \
insufficient data!'.format(e, phasfn, locfn))