WALL-E --- Small robot, big job! Restructuring the code and preparing implementation of a re-assessment tool for PILOT phases.
This commit is contained in:
parent
72fa9e8feb
commit
edd8920d54
@ -40,10 +40,10 @@ from PySide.QtGui import QMainWindow, QInputDialog, QIcon, QFileDialog, \
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from obspy import UTCDateTime
|
from obspy import UTCDateTime
|
||||||
|
|
||||||
from pylot.core.read.data import Data
|
from pylot.core.io.data import Data
|
||||||
from pylot.core.read.inputs import FilterOptions, AutoPickParameter
|
from pylot.core.io.inputs import FilterOptions, AutoPickParameter
|
||||||
from pylot.core.pick.autopick import autopickevent
|
from pylot.core.pick.autopick import autopickevent
|
||||||
from pylot.core.read.io import picks_from_evt
|
from pylot.core.io.phases import picks_from_evt
|
||||||
from pylot.core.loc.nll import locate as locateNll
|
from pylot.core.loc.nll import locate as locateNll
|
||||||
from pylot.core.util.defaults import FILTERDEFAULTS, COMPNAME_MAP,\
|
from pylot.core.util.defaults import FILTERDEFAULTS, COMPNAME_MAP,\
|
||||||
AUTOMATIC_DEFAULTS
|
AUTOMATIC_DEFAULTS
|
||||||
|
20
autoPyLoT.py
20
autoPyLoT.py
@ -2,20 +2,20 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import os
|
|
||||||
import argparse
|
import argparse
|
||||||
import glob
|
import glob
|
||||||
import subprocess
|
|
||||||
import string
|
import string
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from obspy.core import read, UTCDateTime
|
|
||||||
from pylot.core.read.data import Data
|
|
||||||
from pylot.core.read.inputs import AutoPickParameter
|
|
||||||
from pylot.core.util.structure import DATASTRUCTURE
|
|
||||||
from pylot.core.pick.autopick import autopickevent, iteratepicker
|
|
||||||
from pylot.core.loc.nll import *
|
|
||||||
from pylot.core.util.version import get_git_version as _getVersionString
|
|
||||||
from pylot.core.analysis.magnitude import M0Mw
|
from pylot.core.analysis.magnitude import M0Mw
|
||||||
|
from pylot.core.io.data import Data
|
||||||
|
from pylot.core.io.inputs import AutoPickParameter
|
||||||
|
from pylot.core.loc.nll import *
|
||||||
|
from pylot.core.pick.autopick import autopickevent, iteratepicker
|
||||||
|
from pylot.core.util.structure import DATASTRUCTURE
|
||||||
|
from pylot.core.util.version import get_git_version as _getVersionString
|
||||||
|
|
||||||
__version__ = _getVersionString()
|
__version__ = _getVersionString()
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ def autoPyLoT(inputfile):
|
|||||||
|
|
||||||
:param inputfile: path to the input file containing all parameter
|
:param inputfile: path to the input file containing all parameter
|
||||||
information for automatic picking (for formatting details, see.
|
information for automatic picking (for formatting details, see.
|
||||||
`~pylot.core.read.input.AutoPickParameter`
|
`~pylot.core.io.inputs.AutoPickParameter`
|
||||||
:type inputfile: str
|
:type inputfile: str
|
||||||
:return:
|
:return:
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ from pylot.core.pick.utils import getsignalwin, crossings_nonzero_all
|
|||||||
from pylot.core.util.utils import getPatternLine
|
from pylot.core.util.utils import getPatternLine
|
||||||
from scipy.optimize import curve_fit
|
from scipy.optimize import curve_fit
|
||||||
from scipy import integrate, signal
|
from scipy import integrate, signal
|
||||||
from pylot.core.read.data import Data
|
from pylot.core.io.data import Data
|
||||||
|
|
||||||
|
|
||||||
class Magnitude(object):
|
class Magnitude(object):
|
||||||
|
@ -9,7 +9,7 @@ from obspy.core import read, Stream, UTCDateTime
|
|||||||
from obspy import read_events, read_inventory
|
from obspy import read_events, read_inventory
|
||||||
from obspy.core.event import Event, ResourceIdentifier, Pick, WaveformStreamID
|
from obspy.core.event import Event, ResourceIdentifier, Pick, WaveformStreamID
|
||||||
|
|
||||||
from pylot.core.read.io import readPILOTEvent
|
from pylot.core.io.phases import readPILOTEvent
|
||||||
from pylot.core.util.utils import fnConstructor, getGlobalTimes
|
from pylot.core.util.utils import fnConstructor, getGlobalTimes
|
||||||
from pylot.core.util.errors import FormatError, OverwriteError
|
from pylot.core.util.errors import FormatError, OverwriteError
|
||||||
|
|
@ -40,13 +40,13 @@ class AutoPickParameter(object):
|
|||||||
'''
|
'''
|
||||||
Initialize parameter object:
|
Initialize parameter object:
|
||||||
|
|
||||||
read content of an ASCII file an form a type consistent dictionary
|
io content of an ASCII file an form a type consistent dictionary
|
||||||
contain all parameters.
|
contain all parameters.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
self.__filename = fnin
|
self.__filename = fnin
|
||||||
parFileCont = {}
|
parFileCont = {}
|
||||||
# read from parsed arguments alternatively
|
# io from parsed arguments alternatively
|
||||||
for key, val in kwargs.items():
|
for key, val in kwargs.items():
|
||||||
parFileCont[key] = val
|
parFileCont[key] = val
|
||||||
|
|
385
pylot/core/io/phases.py
Normal file
385
pylot/core/io/phases.py
Normal file
@ -0,0 +1,385 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
import scipy.io as sio
|
||||||
|
import obspy.core.event as ope
|
||||||
|
from obspy.core import UTCDateTime
|
||||||
|
|
||||||
|
from pylot.core.util.utils import getOwner, createPick, createArrival, \
|
||||||
|
createEvent, createOrigin, createMagnitude
|
||||||
|
|
||||||
|
|
||||||
|
def readPILOTEvent(phasfn=None, locfn=None, authority_id=None, **kwargs):
|
||||||
|
"""
|
||||||
|
readPILOTEvent - function
|
||||||
|
|
||||||
|
Reads Matlab PHASES and LOC files written by Matlab versions of PILOT and
|
||||||
|
converts the data into an ObsPy Event object which is returned to the
|
||||||
|
calling program.
|
||||||
|
|
||||||
|
:rtype : ~obspy.core.event.Event
|
||||||
|
:param eventID:
|
||||||
|
:param authority:
|
||||||
|
:param kwargs:
|
||||||
|
:param phasfn: filename of the old PILOT Matlab PHASES file
|
||||||
|
:param locfn: filename of the old PILOT Matlab LOC file
|
||||||
|
:return event: event object containing event and phase information
|
||||||
|
"""
|
||||||
|
sdir = os.path.split(phasfn)[0]
|
||||||
|
if phasfn is not None and os.path.isfile(phasfn):
|
||||||
|
phases = sio.loadmat(phasfn)
|
||||||
|
phasctime = UTCDateTime(os.path.getmtime(phasfn))
|
||||||
|
phasauthor = getOwner(phasfn)
|
||||||
|
else:
|
||||||
|
phases = None
|
||||||
|
phasctime = None
|
||||||
|
phasauthor = None
|
||||||
|
if locfn is not None and os.path.isfile(locfn):
|
||||||
|
loc = sio.loadmat(locfn)
|
||||||
|
locctime = UTCDateTime(os.path.getmtime(locfn))
|
||||||
|
locauthor = getOwner(locfn)
|
||||||
|
else:
|
||||||
|
loc = None
|
||||||
|
locctime = None
|
||||||
|
locauthor = None
|
||||||
|
pickcinfo = ope.CreationInfo(agency_id=authority_id,
|
||||||
|
author=phasauthor,
|
||||||
|
creation_time=phasctime)
|
||||||
|
loccinfo = ope.CreationInfo(agency_id=authority_id,
|
||||||
|
author=locauthor,
|
||||||
|
creation_time=locctime)
|
||||||
|
np = 0
|
||||||
|
try:
|
||||||
|
eventNum = loc['ID'][0]
|
||||||
|
|
||||||
|
# retrieve eventID for the actual database
|
||||||
|
idsplit = eventNum.split('.')
|
||||||
|
|
||||||
|
# retrieve date information
|
||||||
|
julday = int(idsplit[1])
|
||||||
|
year = int(idsplit[2])
|
||||||
|
hour = int(loc['hh'])
|
||||||
|
minute = int(loc['mm'])
|
||||||
|
second = int(loc['ss'])
|
||||||
|
|
||||||
|
if year + 2000 < UTCDateTime.utcnow().year:
|
||||||
|
year += 2000
|
||||||
|
else:
|
||||||
|
year += 1900
|
||||||
|
|
||||||
|
eventDate = UTCDateTime(year=year, julday=julday, hour=hour,
|
||||||
|
minute=minute, second=second)
|
||||||
|
|
||||||
|
stations = [stat for stat in phases['stat'][0:-1:3]]
|
||||||
|
|
||||||
|
event = createEvent(eventDate, loccinfo, etype='earthquake', resID=eventNum,
|
||||||
|
authority_id=authority_id)
|
||||||
|
|
||||||
|
lat = float(loc['LAT'])
|
||||||
|
lon = float(loc['LON'])
|
||||||
|
dep = float(loc['DEP'])
|
||||||
|
|
||||||
|
origin = createOrigin(eventDate, loccinfo, lat, lon, dep)
|
||||||
|
for n, pick in enumerate(phases['Ptime']):
|
||||||
|
if pick[0] > 0:
|
||||||
|
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])}
|
||||||
|
spicktime = UTCDateTime(**skwargs)
|
||||||
|
else:
|
||||||
|
spicktime = None
|
||||||
|
ppicktime = UTCDateTime(**kwargs)
|
||||||
|
|
||||||
|
for picktime, phase in [(ppicktime, 'P'), (spicktime, 'S')]:
|
||||||
|
if picktime is not None:
|
||||||
|
if phase == 'P':
|
||||||
|
wffn = os.path.join(sdir, '{0}*{1}*'.format(
|
||||||
|
stations[n].strip(), 'z'))
|
||||||
|
else:
|
||||||
|
wffn = os.path.join(sdir, '{0}*{1}*'.format(
|
||||||
|
stations[n].strip(), '[ne]'))
|
||||||
|
print(wffn)
|
||||||
|
pick = createPick(eventDate, np, picktime, eventNum, pickcinfo,
|
||||||
|
phase, stations[n], wffn, authority_id)
|
||||||
|
event.picks.append(pick)
|
||||||
|
pickID = pick.get('id')
|
||||||
|
arrival = createArrival(pickID, pickcinfo, phase)
|
||||||
|
origin.arrivals.append(arrival)
|
||||||
|
np += 1
|
||||||
|
|
||||||
|
magnitude = createMagnitude(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
|
||||||
|
|
||||||
|
except AttributeError as e:
|
||||||
|
raise AttributeError('{0} - Matlab LOC files {1} and {2} contains \
|
||||||
|
insufficient data!'.format(e, phasfn, locfn))
|
||||||
|
|
||||||
|
|
||||||
|
def picks_from_pilot(fn):
|
||||||
|
picks = dict()
|
||||||
|
phases_pilot = sio.loadmat(fn)
|
||||||
|
stations = stations_from_pilot(phases_pilot['stat'])
|
||||||
|
for n, station in enumerate(stations):
|
||||||
|
phases = dict()
|
||||||
|
for onset_name in 'PS':
|
||||||
|
onset_label = '{0}time'.format(onset_name)
|
||||||
|
pick = phases_pilot[onset_label][n]
|
||||||
|
if not pick[0]:
|
||||||
|
continue
|
||||||
|
pick = convert_pilot_times(pick)
|
||||||
|
phases[onset_name] = dict(mpp=pick)
|
||||||
|
picks[station] = phases
|
||||||
|
|
||||||
|
return picks
|
||||||
|
|
||||||
|
|
||||||
|
def stations_from_pilot(stat_array):
|
||||||
|
stations = list()
|
||||||
|
cur_stat = None
|
||||||
|
for stat in stat_array:
|
||||||
|
if stat == cur_stat:
|
||||||
|
continue
|
||||||
|
cur_stat = stat
|
||||||
|
stations.append(stat.strip())
|
||||||
|
|
||||||
|
return stations
|
||||||
|
|
||||||
|
|
||||||
|
def convert_pilot_times(time_array):
|
||||||
|
times = [int(time) for time in time_array]
|
||||||
|
microseconds = int((time_array[-1] - times[-1]) * 1e6)
|
||||||
|
times.append(microseconds)
|
||||||
|
return UTCDateTime(*times)
|
||||||
|
|
||||||
|
|
||||||
|
def picks_from_obs(fn):
|
||||||
|
picks = dict()
|
||||||
|
station_name = str()
|
||||||
|
for line in open(fn, 'r'):
|
||||||
|
if line.startswith('#'):
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
phase_line = line.split()
|
||||||
|
if not station_name == phase_line[0]:
|
||||||
|
phase = dict()
|
||||||
|
station_name = phase_line[0]
|
||||||
|
phase_name = phase_line[4].upper()
|
||||||
|
pick = UTCDateTime(phase_line[6] + phase_line[7] + phase_line[8])
|
||||||
|
phase[phase_name] = dict(mpp=pick, fm=phase_line[5])
|
||||||
|
picks[station_name] = phase
|
||||||
|
return picks
|
||||||
|
|
||||||
|
|
||||||
|
def picks_from_evt(evt):
|
||||||
|
'''
|
||||||
|
Takes an Event object and return the pick dictionary commonly used within
|
||||||
|
PyLoT
|
||||||
|
:param evt: Event object contain all available information
|
||||||
|
:type evt: `~obspy.core.event.Event`
|
||||||
|
:return: pick dictionary
|
||||||
|
'''
|
||||||
|
picks = {}
|
||||||
|
for pick in evt.picks:
|
||||||
|
phase = {}
|
||||||
|
station = pick.waveform_id.station_code
|
||||||
|
try:
|
||||||
|
onsets = picks[station]
|
||||||
|
except KeyError as e:
|
||||||
|
print(e)
|
||||||
|
onsets = {}
|
||||||
|
mpp = pick.time
|
||||||
|
lpp = mpp + pick.time_errors.upper_uncertainty
|
||||||
|
epp = mpp - pick.time_errors.lower_uncertainty
|
||||||
|
spe = pick.time_errors.uncertainty
|
||||||
|
phase['mpp'] = mpp
|
||||||
|
phase['epp'] = epp
|
||||||
|
phase['lpp'] = lpp
|
||||||
|
phase['spe'] = spe
|
||||||
|
try:
|
||||||
|
picker = str(pick.method_id)
|
||||||
|
if picker.startswith('smi:local/'):
|
||||||
|
picker = picker.split('smi:local/')[1]
|
||||||
|
phase['picker'] = picker
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
onsets[pick.phase_hint] = phase.copy()
|
||||||
|
picks[station] = onsets.copy()
|
||||||
|
return picks
|
||||||
|
|
||||||
|
|
||||||
|
def writephases(arrivals, fformat, filename):
|
||||||
|
'''
|
||||||
|
Function of methods to write phases to the following standard file
|
||||||
|
formats used for locating earthquakes:
|
||||||
|
|
||||||
|
HYPO71, NLLoc, VELEST, HYPOSAT, and hypoDD
|
||||||
|
|
||||||
|
:param: arrivals
|
||||||
|
:type: dictionary containing all phase information including
|
||||||
|
station ID, phase, first motion, weight (uncertainty),
|
||||||
|
....
|
||||||
|
|
||||||
|
:param: fformat
|
||||||
|
:type: string, chosen file format (location routine),
|
||||||
|
choose between NLLoc, HYPO71, HYPOSAT, VELEST,
|
||||||
|
HYPOINVERSE, and hypoDD
|
||||||
|
|
||||||
|
:param: filename, full path and name of phase file
|
||||||
|
:type: string
|
||||||
|
'''
|
||||||
|
|
||||||
|
if fformat == 'NLLoc':
|
||||||
|
print ("Writing phases to %s for NLLoc" % filename)
|
||||||
|
fid = open("%s" % filename, 'w')
|
||||||
|
# write header
|
||||||
|
fid.write('# EQEVENT: Label: EQ001 Loc: X 0.00 Y 0.00 Z 10.00 OT 0.00 \n')
|
||||||
|
for key in arrivals:
|
||||||
|
# P onsets
|
||||||
|
if arrivals[key]['P']:
|
||||||
|
fm = arrivals[key]['P']['fm']
|
||||||
|
if fm == None:
|
||||||
|
fm = '?'
|
||||||
|
onset = arrivals[key]['P']['mpp']
|
||||||
|
year = onset.year
|
||||||
|
month = onset.month
|
||||||
|
day = onset.day
|
||||||
|
hh = onset.hour
|
||||||
|
mm = onset.minute
|
||||||
|
ss = onset.second
|
||||||
|
ms = onset.microsecond
|
||||||
|
ss_ms = ss + ms / 1000000.0
|
||||||
|
if arrivals[key]['P']['weight'] < 4:
|
||||||
|
pweight = 1 # use pick
|
||||||
|
else:
|
||||||
|
pweight = 0 # do not use pick
|
||||||
|
fid.write('%s ? ? ? P %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 %d \n' % (key,
|
||||||
|
fm,
|
||||||
|
year,
|
||||||
|
month,
|
||||||
|
day,
|
||||||
|
hh,
|
||||||
|
mm,
|
||||||
|
ss_ms,
|
||||||
|
pweight))
|
||||||
|
# S onsets
|
||||||
|
if arrivals[key]['S']:
|
||||||
|
fm = '?'
|
||||||
|
onset = arrivals[key]['S']['mpp']
|
||||||
|
year = onset.year
|
||||||
|
month = onset.month
|
||||||
|
day = onset.day
|
||||||
|
hh = onset.hour
|
||||||
|
mm = onset.minute
|
||||||
|
ss = onset.second
|
||||||
|
ms = onset.microsecond
|
||||||
|
ss_ms = ss + ms / 1000000.0
|
||||||
|
if arrivals[key]['S']['weight'] < 4:
|
||||||
|
sweight = 1 # use pick
|
||||||
|
else:
|
||||||
|
sweight = 0 # do not use pick
|
||||||
|
fid.write('%s ? ? ? S %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 %d \n' % (key,
|
||||||
|
fm,
|
||||||
|
year,
|
||||||
|
month,
|
||||||
|
day,
|
||||||
|
hh,
|
||||||
|
mm,
|
||||||
|
ss_ms,
|
||||||
|
sweight))
|
||||||
|
|
||||||
|
fid.close()
|
||||||
|
|
||||||
|
elif fformat == 'HYPO71':
|
||||||
|
print ("Writing phases to %s for HYPO71" % filename)
|
||||||
|
fid = open("%s" % filename, 'w')
|
||||||
|
# write header
|
||||||
|
fid.write(' EQ001\n')
|
||||||
|
for key in arrivals:
|
||||||
|
if arrivals[key]['P']['weight'] < 4:
|
||||||
|
Ponset = arrivals[key]['P']['mpp']
|
||||||
|
Sonset = arrivals[key]['S']['mpp']
|
||||||
|
pweight = arrivals[key]['P']['weight']
|
||||||
|
sweight = arrivals[key]['S']['weight']
|
||||||
|
fm = arrivals[key]['P']['fm']
|
||||||
|
if fm is None:
|
||||||
|
fm = '-'
|
||||||
|
Ao = arrivals[key]['S']['Ao']
|
||||||
|
if Ao is None:
|
||||||
|
Ao = ''
|
||||||
|
else:
|
||||||
|
Ao = str('%7.2f' % Ao)
|
||||||
|
year = Ponset.year
|
||||||
|
if year >= 2000:
|
||||||
|
year = year - 2000
|
||||||
|
else:
|
||||||
|
year = year - 1900
|
||||||
|
month = Ponset.month
|
||||||
|
day = Ponset.day
|
||||||
|
hh = Ponset.hour
|
||||||
|
mm = Ponset.minute
|
||||||
|
ss = Ponset.second
|
||||||
|
ms = Ponset.microsecond
|
||||||
|
ss_ms = ss + ms / 1000000.0
|
||||||
|
if pweight < 2:
|
||||||
|
pstr = 'I'
|
||||||
|
elif pweight >= 2:
|
||||||
|
pstr = 'E'
|
||||||
|
if arrivals[key]['S']['weight'] < 4:
|
||||||
|
Sss = Sonset.second
|
||||||
|
Sms = Sonset.microsecond
|
||||||
|
Sss_ms = Sss + Sms / 1000000.0
|
||||||
|
Sss_ms = str('%5.02f' % Sss_ms)
|
||||||
|
if sweight < 2:
|
||||||
|
sstr = 'I'
|
||||||
|
elif sweight >= 2:
|
||||||
|
sstr = 'E'
|
||||||
|
fid.write('%s%sP%s%d %02d%02d%02d%02d%02d%5.2f %s%sS %d %s\n' % (key,
|
||||||
|
pstr,
|
||||||
|
fm,
|
||||||
|
pweight,
|
||||||
|
year,
|
||||||
|
month,
|
||||||
|
day,
|
||||||
|
hh,
|
||||||
|
mm,
|
||||||
|
ss_ms,
|
||||||
|
Sss_ms,
|
||||||
|
sstr,
|
||||||
|
sweight,
|
||||||
|
Ao))
|
||||||
|
else:
|
||||||
|
fid.write('%s%sP%s%d %02d%02d%02d%02d%02d%5.2f %s\n' % (key,
|
||||||
|
pstr,
|
||||||
|
fm,
|
||||||
|
pweight,
|
||||||
|
year,
|
||||||
|
month,
|
||||||
|
day,
|
||||||
|
hh,
|
||||||
|
mm,
|
||||||
|
ss_ms,
|
||||||
|
Ao))
|
||||||
|
|
||||||
|
fid.close()
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
from pylot.core.pick.utils import writephases
|
from pylot.core.io.phases import writephases
|
||||||
from pylot.core.util.utils import getPatternLine
|
from pylot.core.util.utils import getPatternLine
|
||||||
from pylot.core.util.version import get_git_version as _getVersionString
|
from pylot.core.util.version import get_git_version as _getVersionString
|
||||||
|
|
||||||
|
@ -11,14 +11,14 @@ function conglomerate utils.
|
|||||||
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from pylot.core.read.inputs import AutoPickParameter
|
from pylot.core.io.inputs import AutoPickParameter
|
||||||
from pylot.core.pick.picker import AICPicker, PragPicker
|
from pylot.core.pick.picker import AICPicker, PragPicker
|
||||||
from pylot.core.pick.charfuns import CharacteristicFunction
|
from pylot.core.pick.charfuns import CharacteristicFunction
|
||||||
from pylot.core.pick.charfuns import HOScf, AICcf, ARZcf, ARHcf, AR3Ccf
|
from pylot.core.pick.charfuns import HOScf, AICcf, ARZcf, ARHcf, AR3Ccf
|
||||||
from pylot.core.pick.utils import checksignallength, checkZ4S, earllatepicker, \
|
from pylot.core.pick.utils import checksignallength, checkZ4S, earllatepicker, \
|
||||||
getSNR, fmpicker, checkPonsets, wadaticheck
|
getSNR, fmpicker, checkPonsets, wadaticheck
|
||||||
from pylot.core.util.utils import getPatternLine
|
from pylot.core.util.utils import getPatternLine
|
||||||
from pylot.core.read.data import Data
|
from pylot.core.io.data import Data
|
||||||
from pylot.core.analysis.magnitude import WApp
|
from pylot.core.analysis.magnitude import WApp
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import matplotlib.pyplot as plt
|
|||||||
|
|
||||||
from obspy import read_events
|
from obspy import read_events
|
||||||
|
|
||||||
from pylot.core.read.io import picks_from_evt
|
from pylot.core.io.phases import picks_from_evt
|
||||||
from pylot.core.util.pdf import ProbabilityDensityFunction
|
from pylot.core.util.pdf import ProbabilityDensityFunction
|
||||||
from pylot.core.util.version import get_git_version as _getVersionString
|
from pylot.core.util.version import get_git_version as _getVersionString
|
||||||
|
|
||||||
@ -251,9 +251,3 @@ class PDFDictionary(object):
|
|||||||
|
|
||||||
return pdf_picks
|
return pdf_picks
|
||||||
|
|
||||||
|
|
||||||
#comp_obj = Comparison(manual='/home/sebastianp/Data/Insheim/e0019.048.13.xml',
|
|
||||||
# auto='/data/Geothermie/Insheim/EVENT_DATA/LOCAL/RefDB/e0019.048.13/autoPyLoT.xml')
|
|
||||||
#comp_obj.plot()
|
|
||||||
#comp_obj.hist_expectation()
|
|
||||||
#comp_obj.hist_standard_deviation()
|
|
||||||
|
@ -9,11 +9,12 @@
|
|||||||
:author: Ludger Kueperkoch / MAGS2 EP3 working group
|
:author: Ludger Kueperkoch / MAGS2 EP3 working group
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
from obspy.core import Stream, UTCDateTime
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
from obspy.core import Stream, UTCDateTime
|
||||||
|
|
||||||
|
|
||||||
def earllatepicker(X, nfac, TSNR, Pick1, iplot=None, stealthMode=False):
|
def earllatepicker(X, nfac, TSNR, Pick1, iplot=None, stealthMode=False):
|
||||||
'''
|
'''
|
||||||
@ -937,162 +938,6 @@ def checkZ4S(X, pick, zfac, checkwin, iplot):
|
|||||||
return returnflag
|
return returnflag
|
||||||
|
|
||||||
|
|
||||||
def writephases(arrivals, fformat, filename):
|
|
||||||
'''
|
|
||||||
Function of methods to write phases to the following standard file
|
|
||||||
formats used for locating earthquakes:
|
|
||||||
|
|
||||||
HYPO71, NLLoc, VELEST, HYPOSAT, and hypoDD
|
|
||||||
|
|
||||||
:param: arrivals
|
|
||||||
:type: dictionary containing all phase information including
|
|
||||||
station ID, phase, first motion, weight (uncertainty),
|
|
||||||
....
|
|
||||||
|
|
||||||
:param: fformat
|
|
||||||
:type: string, chosen file format (location routine),
|
|
||||||
choose between NLLoc, HYPO71, HYPOSAT, VELEST,
|
|
||||||
HYPOINVERSE, and hypoDD
|
|
||||||
|
|
||||||
:param: filename, full path and name of phase file
|
|
||||||
:type: string
|
|
||||||
'''
|
|
||||||
|
|
||||||
if fformat == 'NLLoc':
|
|
||||||
print ("Writing phases to %s for NLLoc" % filename)
|
|
||||||
fid = open("%s" % filename, 'w')
|
|
||||||
# write header
|
|
||||||
fid.write('# EQEVENT: Label: EQ001 Loc: X 0.00 Y 0.00 Z 10.00 OT 0.00 \n')
|
|
||||||
for key in arrivals:
|
|
||||||
# P onsets
|
|
||||||
if arrivals[key]['P']:
|
|
||||||
fm = arrivals[key]['P']['fm']
|
|
||||||
if fm == None:
|
|
||||||
fm = '?'
|
|
||||||
onset = arrivals[key]['P']['mpp']
|
|
||||||
year = onset.year
|
|
||||||
month = onset.month
|
|
||||||
day = onset.day
|
|
||||||
hh = onset.hour
|
|
||||||
mm = onset.minute
|
|
||||||
ss = onset.second
|
|
||||||
ms = onset.microsecond
|
|
||||||
ss_ms = ss + ms / 1000000.0
|
|
||||||
if arrivals[key]['P']['weight'] < 4:
|
|
||||||
pweight = 1 # use pick
|
|
||||||
else:
|
|
||||||
pweight = 0 # do not use pick
|
|
||||||
fid.write('%s ? ? ? P %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 %d \n' % (key,
|
|
||||||
fm,
|
|
||||||
year,
|
|
||||||
month,
|
|
||||||
day,
|
|
||||||
hh,
|
|
||||||
mm,
|
|
||||||
ss_ms,
|
|
||||||
pweight))
|
|
||||||
# S onsets
|
|
||||||
if arrivals[key]['S']:
|
|
||||||
fm = '?'
|
|
||||||
onset = arrivals[key]['S']['mpp']
|
|
||||||
year = onset.year
|
|
||||||
month = onset.month
|
|
||||||
day = onset.day
|
|
||||||
hh = onset.hour
|
|
||||||
mm = onset.minute
|
|
||||||
ss = onset.second
|
|
||||||
ms = onset.microsecond
|
|
||||||
ss_ms = ss + ms / 1000000.0
|
|
||||||
if arrivals[key]['S']['weight'] < 4:
|
|
||||||
sweight = 1 # use pick
|
|
||||||
else:
|
|
||||||
sweight = 0 # do not use pick
|
|
||||||
fid.write('%s ? ? ? S %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 %d \n' % (key,
|
|
||||||
fm,
|
|
||||||
year,
|
|
||||||
month,
|
|
||||||
day,
|
|
||||||
hh,
|
|
||||||
mm,
|
|
||||||
ss_ms,
|
|
||||||
sweight))
|
|
||||||
|
|
||||||
fid.close()
|
|
||||||
|
|
||||||
elif fformat == 'HYPO71':
|
|
||||||
print ("Writing phases to %s for HYPO71" % filename)
|
|
||||||
fid = open("%s" % filename, 'w')
|
|
||||||
# write header
|
|
||||||
fid.write(' EQ001\n')
|
|
||||||
for key in arrivals:
|
|
||||||
if arrivals[key]['P']['weight'] < 4:
|
|
||||||
Ponset = arrivals[key]['P']['mpp']
|
|
||||||
Sonset = arrivals[key]['S']['mpp']
|
|
||||||
pweight = arrivals[key]['P']['weight']
|
|
||||||
sweight = arrivals[key]['S']['weight']
|
|
||||||
fm = arrivals[key]['P']['fm']
|
|
||||||
if fm is None:
|
|
||||||
fm = '-'
|
|
||||||
Ao = arrivals[key]['S']['Ao']
|
|
||||||
if Ao is None:
|
|
||||||
Ao = ''
|
|
||||||
else:
|
|
||||||
Ao = str('%7.2f' % Ao)
|
|
||||||
year = Ponset.year
|
|
||||||
if year >= 2000:
|
|
||||||
year = year - 2000
|
|
||||||
else:
|
|
||||||
year = year - 1900
|
|
||||||
month = Ponset.month
|
|
||||||
day = Ponset.day
|
|
||||||
hh = Ponset.hour
|
|
||||||
mm = Ponset.minute
|
|
||||||
ss = Ponset.second
|
|
||||||
ms = Ponset.microsecond
|
|
||||||
ss_ms = ss + ms / 1000000.0
|
|
||||||
if pweight < 2:
|
|
||||||
pstr = 'I'
|
|
||||||
elif pweight >= 2:
|
|
||||||
pstr = 'E'
|
|
||||||
if arrivals[key]['S']['weight'] < 4:
|
|
||||||
Sss = Sonset.second
|
|
||||||
Sms = Sonset.microsecond
|
|
||||||
Sss_ms = Sss + Sms / 1000000.0
|
|
||||||
Sss_ms = str('%5.02f' % Sss_ms)
|
|
||||||
if sweight < 2:
|
|
||||||
sstr = 'I'
|
|
||||||
elif sweight >= 2:
|
|
||||||
sstr = 'E'
|
|
||||||
fid.write('%s%sP%s%d %02d%02d%02d%02d%02d%5.2f %s%sS %d %s\n' % (key,
|
|
||||||
pstr,
|
|
||||||
fm,
|
|
||||||
pweight,
|
|
||||||
year,
|
|
||||||
month,
|
|
||||||
day,
|
|
||||||
hh,
|
|
||||||
mm,
|
|
||||||
ss_ms,
|
|
||||||
Sss_ms,
|
|
||||||
sstr,
|
|
||||||
sweight,
|
|
||||||
Ao))
|
|
||||||
else:
|
|
||||||
fid.write('%s%sP%s%d %02d%02d%02d%02d%02d%5.2f %s\n' % (key,
|
|
||||||
pstr,
|
|
||||||
fm,
|
|
||||||
pweight,
|
|
||||||
year,
|
|
||||||
month,
|
|
||||||
day,
|
|
||||||
hh,
|
|
||||||
mm,
|
|
||||||
ss_ms,
|
|
||||||
Ao))
|
|
||||||
|
|
||||||
fid.close()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
|
@ -1,191 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
import scipy.io as sio
|
|
||||||
import obspy.core.event as ope
|
|
||||||
from obspy.core import UTCDateTime
|
|
||||||
|
|
||||||
from pylot.core.util.utils import getOwner, createPick, createArrival, \
|
|
||||||
createEvent, createOrigin, createMagnitude
|
|
||||||
|
|
||||||
|
|
||||||
def readPILOTEvent(phasfn=None, locfn=None, authority_id=None, **kwargs):
|
|
||||||
"""
|
|
||||||
readPILOTEvent - function
|
|
||||||
|
|
||||||
Reads Matlab PHASES and LOC files written by Matlab versions of PILOT and
|
|
||||||
converts the data into an ObsPy Event object which is returned to the
|
|
||||||
calling program.
|
|
||||||
|
|
||||||
:rtype : ~obspy.core.event.Event
|
|
||||||
:param eventID:
|
|
||||||
:param authority:
|
|
||||||
:param kwargs:
|
|
||||||
:param phasfn: filename of the old PILOT Matlab PHASES file
|
|
||||||
:param locfn: filename of the old PILOT Matlab LOC file
|
|
||||||
:return event: event object containing event and phase information
|
|
||||||
"""
|
|
||||||
sdir = os.path.split(phasfn)[0]
|
|
||||||
if phasfn is not None and os.path.isfile(phasfn):
|
|
||||||
phases = sio.loadmat(phasfn)
|
|
||||||
phasctime = UTCDateTime(os.path.getmtime(phasfn))
|
|
||||||
phasauthor = getOwner(phasfn)
|
|
||||||
else:
|
|
||||||
phases = None
|
|
||||||
phasctime = None
|
|
||||||
phasauthor = None
|
|
||||||
if locfn is not None and os.path.isfile(locfn):
|
|
||||||
loc = sio.loadmat(locfn)
|
|
||||||
locctime = UTCDateTime(os.path.getmtime(locfn))
|
|
||||||
locauthor = getOwner(locfn)
|
|
||||||
else:
|
|
||||||
loc = None
|
|
||||||
locctime = None
|
|
||||||
locauthor = None
|
|
||||||
pickcinfo = ope.CreationInfo(agency_id=authority_id,
|
|
||||||
author=phasauthor,
|
|
||||||
creation_time=phasctime)
|
|
||||||
loccinfo = ope.CreationInfo(agency_id=authority_id,
|
|
||||||
author=locauthor,
|
|
||||||
creation_time=locctime)
|
|
||||||
np = 0
|
|
||||||
try:
|
|
||||||
eventNum = loc['ID'][0]
|
|
||||||
|
|
||||||
# retrieve eventID for the actual database
|
|
||||||
idsplit = eventNum.split('.')
|
|
||||||
|
|
||||||
# retrieve date information
|
|
||||||
julday = int(idsplit[1])
|
|
||||||
year = int(idsplit[2])
|
|
||||||
hour = int(loc['hh'])
|
|
||||||
minute = int(loc['mm'])
|
|
||||||
second = int(loc['ss'])
|
|
||||||
|
|
||||||
if year + 2000 < UTCDateTime.utcnow().year:
|
|
||||||
year += 2000
|
|
||||||
else:
|
|
||||||
year += 1900
|
|
||||||
|
|
||||||
eventDate = UTCDateTime(year=year, julday=julday, hour=hour,
|
|
||||||
minute=minute, second=second)
|
|
||||||
|
|
||||||
stations = [stat for stat in phases['stat'][0:-1:3]]
|
|
||||||
|
|
||||||
event = createEvent(eventDate, loccinfo, etype='earthquake', resID=eventNum,
|
|
||||||
authority_id=authority_id)
|
|
||||||
|
|
||||||
lat = float(loc['LAT'])
|
|
||||||
lon = float(loc['LON'])
|
|
||||||
dep = float(loc['DEP'])
|
|
||||||
|
|
||||||
origin = createOrigin(eventDate, loccinfo, lat, lon, dep)
|
|
||||||
for n, pick in enumerate(phases['Ptime']):
|
|
||||||
if pick[0] > 0:
|
|
||||||
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])}
|
|
||||||
spicktime = UTCDateTime(**skwargs)
|
|
||||||
else:
|
|
||||||
spicktime = None
|
|
||||||
ppicktime = UTCDateTime(**kwargs)
|
|
||||||
|
|
||||||
for picktime, phase in [(ppicktime, 'P'), (spicktime, 'S')]:
|
|
||||||
if picktime is not None:
|
|
||||||
if phase == 'P':
|
|
||||||
wffn = os.path.join(sdir, '{0}*{1}*'.format(
|
|
||||||
stations[n].strip(), 'z'))
|
|
||||||
else:
|
|
||||||
wffn = os.path.join(sdir, '{0}*{1}*'.format(
|
|
||||||
stations[n].strip(), '[ne]'))
|
|
||||||
print wffn
|
|
||||||
pick = createPick(eventDate, np, picktime, eventNum, pickcinfo,
|
|
||||||
phase, stations[n], wffn, authority_id)
|
|
||||||
event.picks.append(pick)
|
|
||||||
pickID = pick.get('id')
|
|
||||||
arrival = createArrival(pickID, pickcinfo, phase)
|
|
||||||
origin.arrivals.append(arrival)
|
|
||||||
np += 1
|
|
||||||
|
|
||||||
magnitude = createMagnitude(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
|
|
||||||
|
|
||||||
except AttributeError as e:
|
|
||||||
raise AttributeError('{0} - Matlab LOC files {1} and {2} contains \
|
|
||||||
insufficient data!'.format(e, phasfn, locfn))
|
|
||||||
|
|
||||||
def picks_from_obs(fn):
|
|
||||||
picks = dict()
|
|
||||||
station_name = str()
|
|
||||||
for line in open(fn, 'r'):
|
|
||||||
if line.startswith('#'):
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
phase_line = line.split()
|
|
||||||
if not station_name == phase_line[0]:
|
|
||||||
phase = dict()
|
|
||||||
station_name = phase_line[0]
|
|
||||||
phase_name = phase_line[4].upper()
|
|
||||||
pick = UTCDateTime(phase_line[6] + phase_line[7] + phase_line[8])
|
|
||||||
phase[phase_name] = dict(mpp=pick, fm=phase_line[5])
|
|
||||||
picks[station_name] = phase
|
|
||||||
return picks
|
|
||||||
|
|
||||||
|
|
||||||
def picks_from_evt(evt):
|
|
||||||
'''
|
|
||||||
Takes an Event object and return the pick dictionary commonly used within
|
|
||||||
PyLoT
|
|
||||||
:param evt: Event object contain all available information
|
|
||||||
:type evt: `~obspy.core.event.Event`
|
|
||||||
:return: pick dictionary
|
|
||||||
'''
|
|
||||||
picks = {}
|
|
||||||
for pick in evt.picks:
|
|
||||||
phase = {}
|
|
||||||
station = pick.waveform_id.station_code
|
|
||||||
try:
|
|
||||||
onsets = picks[station]
|
|
||||||
except KeyError as e:
|
|
||||||
print(e)
|
|
||||||
onsets = {}
|
|
||||||
mpp = pick.time
|
|
||||||
lpp = mpp + pick.time_errors.upper_uncertainty
|
|
||||||
epp = mpp - pick.time_errors.lower_uncertainty
|
|
||||||
spe = pick.time_errors.uncertainty
|
|
||||||
phase['mpp'] = mpp
|
|
||||||
phase['epp'] = epp
|
|
||||||
phase['lpp'] = lpp
|
|
||||||
phase['spe'] = spe
|
|
||||||
try:
|
|
||||||
picker = str(pick.method_id)
|
|
||||||
if picker.startswith('smi:local/'):
|
|
||||||
picker = picker.split('smi:local/')[1]
|
|
||||||
phase['picker'] = picker
|
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
onsets[pick.phase_hint] = phase.copy()
|
|
||||||
picks[station] = onsets.copy()
|
|
||||||
return picks
|
|
@ -6,7 +6,7 @@ Created on Wed Jan 26 17:47:25 2015
|
|||||||
@author: sebastianw
|
@author: sebastianw
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pylot.core.read.data import SeiscompDataStructure, PilotDataStructure
|
from pylot.core.io.data import SeiscompDataStructure, PilotDataStructure
|
||||||
|
|
||||||
DATASTRUCTURE = {'PILOT': PilotDataStructure, 'SeisComP': SeiscompDataStructure,
|
DATASTRUCTURE = {'PILOT': PilotDataStructure, 'SeisComP': SeiscompDataStructure,
|
||||||
None: None}
|
None: None}
|
||||||
|
@ -24,7 +24,7 @@ from PySide.QtGui import QAction, QApplication, QComboBox, QDateTimeEdit, \
|
|||||||
from PySide.QtCore import QSettings, Qt, QUrl, Signal, Slot
|
from PySide.QtCore import QSettings, Qt, QUrl, Signal, Slot
|
||||||
from PySide.QtWebKit import QWebView
|
from PySide.QtWebKit import QWebView
|
||||||
from obspy import Stream, UTCDateTime
|
from obspy import Stream, UTCDateTime
|
||||||
from pylot.core.read.inputs import FilterOptions
|
from pylot.core.io.inputs import FilterOptions
|
||||||
from pylot.core.pick.utils import getSNR, earllatepicker, getnoisewin, \
|
from pylot.core.pick.utils import getSNR, earllatepicker, getnoisewin, \
|
||||||
getResolutionWindow
|
getResolutionWindow
|
||||||
from pylot.core.util.defaults import OUTPUTFORMATS, FILTERDEFAULTS, LOCTOOLS, \
|
from pylot.core.util.defaults import OUTPUTFORMATS, FILTERDEFAULTS, LOCTOOLS, \
|
||||||
|
18
scripts/pylot-reasses-pilot-event.py
Normal file
18
scripts/pylot-reasses-pilot-event.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
from pylot.core.util.version import get_git_version as _getVersionString
|
||||||
|
from pylot.core.io.phases import reasses_pilot_event
|
||||||
|
|
||||||
|
__version__ = _getVersionString()
|
||||||
|
__author__ = 'sebastianw'
|
||||||
|
|
||||||
|
def reassess_pilot_event():
|
||||||
|
pass
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
reasses_pilot_event(args.id)
|
2
setup.py
2
setup.py
@ -4,7 +4,7 @@ setup(
|
|||||||
name='PyLoT',
|
name='PyLoT',
|
||||||
version='0.1a1',
|
version='0.1a1',
|
||||||
packages=['pylot', 'pylot.core', 'pylot.core.loc', 'pylot.core.pick',
|
packages=['pylot', 'pylot.core', 'pylot.core.loc', 'pylot.core.pick',
|
||||||
'pylot.core.read', 'pylot.core.util', 'pylot.core.active',
|
'pylot.core.io', 'pylot.core.util', 'pylot.core.active',
|
||||||
'pylot.core.analysis', 'pylot.testing'],
|
'pylot.core.analysis', 'pylot.testing'],
|
||||||
url='dummy',
|
url='dummy',
|
||||||
license='LGPLv3',
|
license='LGPLv3',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user