diff --git a/QtPyLoT.py b/QtPyLoT.py index 285e2ffb..a96d23c3 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -40,10 +40,10 @@ from PySide.QtGui import QMainWindow, QInputDialog, QIcon, QFileDialog, \ import numpy as np from obspy import UTCDateTime -from pylot.core.read.data import Data -from pylot.core.read.inputs import FilterOptions, AutoPickParameter +from pylot.core.io.data import Data +from pylot.core.io.inputs import FilterOptions, AutoPickParameter 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.util.defaults import FILTERDEFAULTS, COMPNAME_MAP,\ AUTOMATIC_DEFAULTS diff --git a/autoPyLoT.py b/autoPyLoT.py index eb218ca7..cf606edf 100755 --- a/autoPyLoT.py +++ b/autoPyLoT.py @@ -2,20 +2,20 @@ # -*- coding: utf-8 -*- from __future__ import print_function -import os + import argparse import glob -import subprocess import string + 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.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() @@ -27,7 +27,7 @@ def autoPyLoT(inputfile): :param inputfile: path to the input file containing all parameter information for automatic picking (for formatting details, see. - `~pylot.core.read.input.AutoPickParameter` + `~pylot.core.io.inputs.AutoPickParameter` :type inputfile: str :return: diff --git a/pylot/core/analysis/magnitude.py b/pylot/core/analysis/magnitude.py index ace6f0aa..1e494560 100644 --- a/pylot/core/analysis/magnitude.py +++ b/pylot/core/analysis/magnitude.py @@ -13,7 +13,7 @@ from pylot.core.pick.utils import getsignalwin, crossings_nonzero_all from pylot.core.util.utils import getPatternLine from scipy.optimize import curve_fit from scipy import integrate, signal -from pylot.core.read.data import Data +from pylot.core.io.data import Data class Magnitude(object): diff --git a/pylot/core/read/__init__.py b/pylot/core/io/__init__.py similarity index 100% rename from pylot/core/read/__init__.py rename to pylot/core/io/__init__.py diff --git a/pylot/core/read/data.py b/pylot/core/io/data.py similarity index 99% rename from pylot/core/read/data.py rename to pylot/core/io/data.py index b7b961d7..2b95048d 100644 --- a/pylot/core/read/data.py +++ b/pylot/core/io/data.py @@ -9,7 +9,7 @@ from obspy.core import read, Stream, UTCDateTime from obspy import read_events, read_inventory 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.errors import FormatError, OverwriteError diff --git a/pylot/core/read/inputs.py b/pylot/core/io/inputs.py similarity index 98% rename from pylot/core/read/inputs.py rename to pylot/core/io/inputs.py index 035835f7..f9ebdfc9 100644 --- a/pylot/core/read/inputs.py +++ b/pylot/core/io/inputs.py @@ -40,13 +40,13 @@ class AutoPickParameter(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. ''' self.__filename = fnin parFileCont = {} - # read from parsed arguments alternatively + # io from parsed arguments alternatively for key, val in kwargs.items(): parFileCont[key] = val diff --git a/pylot/core/io/phases.py b/pylot/core/io/phases.py new file mode 100644 index 00000000..98977b69 --- /dev/null +++ b/pylot/core/io/phases.py @@ -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() diff --git a/pylot/core/loc/nll.py b/pylot/core/loc/nll.py index bd4ba4cf..956e8e50 100644 --- a/pylot/core/loc/nll.py +++ b/pylot/core/loc/nll.py @@ -3,7 +3,7 @@ import subprocess 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.version import get_git_version as _getVersionString diff --git a/pylot/core/pick/autopick.py b/pylot/core/pick/autopick.py index b6fa4d33..f6b5e01f 100755 --- a/pylot/core/pick/autopick.py +++ b/pylot/core/pick/autopick.py @@ -11,14 +11,14 @@ function conglomerate utils. import matplotlib.pyplot as plt 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.charfuns import CharacteristicFunction from pylot.core.pick.charfuns import HOScf, AICcf, ARZcf, ARHcf, AR3Ccf from pylot.core.pick.utils import checksignallength, checkZ4S, earllatepicker, \ getSNR, fmpicker, checkPonsets, wadaticheck 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 diff --git a/pylot/core/pick/compare.py b/pylot/core/pick/compare.py index a5db47c5..27a9f1b0 100644 --- a/pylot/core/pick/compare.py +++ b/pylot/core/pick/compare.py @@ -9,7 +9,7 @@ import matplotlib.pyplot as plt 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.version import get_git_version as _getVersionString @@ -251,9 +251,3 @@ class PDFDictionary(object): 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() diff --git a/pylot/core/pick/utils.py b/pylot/core/pick/utils.py index 9f9ef832..6e7fe2f5 100644 --- a/pylot/core/pick/utils.py +++ b/pylot/core/pick/utils.py @@ -9,11 +9,12 @@ :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 matplotlib.pyplot as plt +import numpy as np +from obspy.core import Stream, UTCDateTime + def earllatepicker(X, nfac, TSNR, Pick1, iplot=None, stealthMode=False): ''' @@ -937,162 +938,6 @@ def checkZ4S(X, pick, zfac, checkwin, iplot): 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__': import doctest diff --git a/pylot/core/read/io.py b/pylot/core/read/io.py deleted file mode 100644 index f34a7616..00000000 --- a/pylot/core/read/io.py +++ /dev/null @@ -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 diff --git a/pylot/core/util/structure.py b/pylot/core/util/structure.py index 05a0c7f9..68a16552 100644 --- a/pylot/core/util/structure.py +++ b/pylot/core/util/structure.py @@ -6,7 +6,7 @@ Created on Wed Jan 26 17:47:25 2015 @author: sebastianw """ -from pylot.core.read.data import SeiscompDataStructure, PilotDataStructure +from pylot.core.io.data import SeiscompDataStructure, PilotDataStructure DATASTRUCTURE = {'PILOT': PilotDataStructure, 'SeisComP': SeiscompDataStructure, None: None} diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index fcbd0ca5..8b0bdfaf 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -24,7 +24,7 @@ from PySide.QtGui import QAction, QApplication, QComboBox, QDateTimeEdit, \ from PySide.QtCore import QSettings, Qt, QUrl, Signal, Slot from PySide.QtWebKit import QWebView 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, \ getResolutionWindow from pylot.core.util.defaults import OUTPUTFORMATS, FILTERDEFAULTS, LOCTOOLS, \ diff --git a/scripts/pylot-reasses-pilot-event.py b/scripts/pylot-reasses-pilot-event.py new file mode 100644 index 00000000..e76de3fa --- /dev/null +++ b/scripts/pylot-reasses-pilot-event.py @@ -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) diff --git a/setup.py b/setup.py index 3687255e..ca588c8e 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setup( name='PyLoT', version='0.1a1', 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'], url='dummy', license='LGPLv3',