diff --git a/PyLoT.py b/PyLoT.py index 2880680f..8ba8d7a6 100755 --- a/PyLoT.py +++ b/PyLoT.py @@ -487,7 +487,8 @@ class MainWindow(QMainWindow): icon=qualities_icon, tip='Histogram of pick qualities') self.qualities_action.setEnabled(False) # MP MP not yet implemented, therefore hide: - self.qualities_action.setVisible(False) + # LK will be implemented soon, basic script has already (03/2021) been finished + self.qualities_action.setVisible(True) printAction = self.createAction(self, "&Print event ...", self.show_event_information, QKeySequence.Print, @@ -1529,7 +1530,6 @@ class MainWindow(QMainWindow): event = self.get_current_event() if not type(outformats) == list: outformats = [outformats] - def getSavePath(event, directory, outformats): if not directory: title = 'Save event data as {} to directory ...'.format(outformats) @@ -1548,13 +1548,13 @@ class MainWindow(QMainWindow): uppererrorP = self._inputs['timeerrorsP'] uppererrorS = self._inputs['timeerrorsS'] - + # Inserted to prevent Bug in Eventlist + self.get_data().setEvtData(event) try: self.get_data().applyEVTData(event, typ='event') # getPicks()) except OverwriteError: self.get_data().resetPicks() return self.saveData(event, directory, outformats) - fcheck = ['auto', 'manual', 'origins', 'magnitude'] saved_as = str() @@ -1570,7 +1570,6 @@ class MainWindow(QMainWindow): msg = 'Event {} saved as {} in format(s) {}'.format(event.pylot_id, fbasename, saved_as.strip()) self.update_status(msg) print(msg) - event.dirty = False self.fill_eventbox() return True @@ -3045,7 +3044,6 @@ class MainWindow(QMainWindow): self.locate_event() ctrfile = os.path.join(locroot, 'run', parameter['ctrfile']) - ttt = parameter['ttpatter'] outfile = parameter['outpatter'] eventname = self.get_current_event_name() @@ -3061,7 +3059,6 @@ class MainWindow(QMainWindow): print(e.message) # finally: # os.remove(phasefile) - self.get_data().applyEVTData(lt.read_location(locpath), typ='event') for event in self.calc_magnitude(): self.get_data().applyEVTData(event, typ='event') @@ -3244,7 +3241,7 @@ class MainWindow(QMainWindow): # iterate through eventlist and generate items for table rows self.project._table = [] - for index, event in enumerate(eventlist): + for index, event in enumerate(eventlist): phaseErrors = {'P': self._inputs['timeerrorsP'], 'S': self._inputs['timeerrorsS']} @@ -3297,17 +3294,24 @@ class MainWindow(QMainWindow): item_depth.setText(str(origin.depth)) if hasattr(event, 'magnitudes'): if event.magnitudes: - moment_magnitude = event.magnitudes[0] - moment_magnitude.mag = '%4.1f' % moment_magnitude.mag - moment_mag = str(moment_magnitude.mag) if len(event.magnitudes) > 1: + moment_magnitude = event.magnitudes[0] + moment_magnitude.mag = '%4.1f' % moment_magnitude.mag + item_momentmag.setText(str(moment_magnitude.mag)) local_magnitude = event.magnitudes[1] local_magnitude.mag = '%4.1f' % local_magnitude.mag - local_mag = str(local_magnitude.mag) + item_localmag.setText(str(local_magnitude.mag)) else: - local_mag = None - item_momentmag.setText(moment_mag) - item_localmag.setText(local_mag) + # check type of magnitude + if event.magnitudes[0].magnitude_type == 'Mw': + moment_magnitude = event.magnitudes[0] + moment_magnitude.mag = '%4.1f' % moment_magnitude.mag + item_momentmag.setText(str(moment_magnitude.mag)) + elif event.magnitudes[0].magnitude_type == 'ML': + local_magnitude = event.magnitudes[0] + local_magnitude.mag = '%4.1f' % local_magnitude.mag + item_localmag.setText(str(local_magnitude.mag)) + item_notes.setText(event.notes) set_enabled(item_path, True, False) diff --git a/pylot/core/analysis/magnitude.py b/pylot/core/analysis/magnitude.py index 4b1fd6fe..3b8119c4 100644 --- a/pylot/core/analysis/magnitude.py +++ b/pylot/core/analysis/magnitude.py @@ -221,11 +221,16 @@ class LocalMagnitude(Magnitude): power = [np.power(tr.data, 2) for tr in st if tr.stats.channel[-1] not in 'Z3'] - if len(power) != 2: - raise ValueError('Wood-Anderson amplitude defintion only valid for ' - 'two horizontals: {0} given'.format(len(power))) - power_sum = power[0] + power[1] - # + # checking horizontal count and calculating power_sum accordingly + if len(power) == 1: + print ('WARNING: Only one horizontal found for station {0}.'.format(st[0].stats.station)) + power_sum = power[0] + elif len(power) == 2: + power_sum = power[0] + power[1] + else: + raise ValueError('Wood-Anderson aomplitude defintion only valid for' + ' up to two horizontals: {0} given'.format(len(power))) + sqH = np.sqrt(power_sum) # get time array @@ -277,12 +282,13 @@ class LocalMagnitude(Magnitude): for a in self.arrivals: if a.phase not in 'sS': continue + pick = a.pick_id.get_referred_object() + station = pick.waveform_id.station_code # make sure calculating Ml only from reliable onsets # NLLoc: time_weight = 0 => do not use onset! if a.time_weight == 0: + print("Uncertain pick at Station {}, do not use it!".format(station)) continue - pick = a.pick_id.get_referred_object() - station = pick.waveform_id.station_code wf = select_for_phase(self.stream.select( station=station), a.phase) if not wf: @@ -394,24 +400,28 @@ class MomentMagnitude(Magnitude): print("WARNING: No instrument corrected data available," " no magnitude calculation possible! Go on.") continue - scopy = self.stream.copy() - wf = scopy.select(station=station) + wf = self.stream.select(station=station) if not wf: continue + try: + scopy = wf.copy() + except AssertionError: + print("WARNING: Something's wrong with the data," + "station {}," + "no calculation of moment magnitude possible! Go on.".format(station)) + continue onset = pick.time distance = degrees2kilometers(a.distance) azimuth = a.azimuth incidence = a.takeoff_angle - w0, fc = calcsourcespec(wf, onset, self.p_velocity, distance, + w0, fc = calcsourcespec(scopy, onset, self.p_velocity, distance, azimuth, incidence, self.p_attenuation, self.plot_flag, self.verbose) if w0 is None or fc is None: if self.verbose: print("WARNING: insufficient frequency information") continue - WF = select_for_phase(self.stream.select( - station=station), a.phase) - WF = select_for_phase(WF, "P") + WF = select_for_phase(scopy, "P") m0, mw = calcMoMw(WF, w0, self.rock_density, self.p_velocity, distance, self.verbose) self.moment_props = (station, dict(w0=w0, fc=fc, Mo=m0)) diff --git a/pylot/core/io/data.py b/pylot/core/io/data.py index fab5b22a..11a627aa 100644 --- a/pylot/core/io/data.py +++ b/pylot/core/io/data.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env pyth n # -*- coding: utf-8 -*- import copy @@ -264,7 +264,7 @@ class Data(object): can be a str or a list of strings of ['manual', 'auto', 'origin', 'magnitude'] """ from pylot.core.util.defaults import OUTPUTFORMATS - + if not type(fcheck) == list: fcheck = [fcheck] @@ -297,7 +297,9 @@ class Data(object): return self.checkEvent(event, fcheck) self.setEvtData(event) + self.get_evt_data().write(fnout + fnext, format=evtformat) + # try exporting event else: evtdata_org = self.get_evt_data() @@ -361,6 +363,14 @@ class Data(object): header = '# EQEVENT: Label: EQ%s Loc: X 0.00 Y 0.00 Z 10.00 OT 0.00 \n' % evid nllocfile = open(fnout + fnext) l = nllocfile.readlines() + # Adding A0/Generic Amplitude to .obs file + #l2 = [] + #for li in l: + # for amp in evtdata_org.amplitudes: + # if amp.waveform_id.station_code == li[0:5].strip(): + # li = li[0:64] + '{:0.2e}'.format(amp.generic_amplitude) + li[73:-1] + '\n' + # l2.append(li) + #l = l2 nllocfile.close() l.insert(0, header) nllocfile = open(fnout + fnext, 'w') diff --git a/pylot/core/io/default_parameters.py b/pylot/core/io/default_parameters.py index 0a5996c1..62e59536 100644 --- a/pylot/core/io/default_parameters.py +++ b/pylot/core/io/default_parameters.py @@ -511,7 +511,7 @@ defaults = {'rootpath': {'type': str, 'taup_model': {'type': str, 'tooltip': 'Define TauPy model for traveltime estimation. Possible values: 1066a, 1066b, ak135, ak135f, herrin, iasp91, jb, prem, pwdk, sp6', - 'value': 'iasp91', + 'value': None, 'namestring': 'TauPy model'}, 'taup_phases': {'type': str, diff --git a/pylot/core/io/phases.py b/pylot/core/io/phases.py index 89dec6c4..a6329697 100644 --- a/pylot/core/io/phases.py +++ b/pylot/core/io/phases.py @@ -543,6 +543,7 @@ def writephases(arrivals, fformat, filename, parameter=None, eventinfo=None): try: if arrivals[key]['P']['weight'] >= 4: pweight = 0 # do not use pick + print("Station {}: Uncertain pick, do not use it!".format(key)) except KeyError as e: print(e.message + '; no weight set during processing') fid.write('%s ? ? ? P %s %d%02d%02d %02d%02d %7.4f GAU 0 0 0 0 %d \n' % (key, @@ -805,7 +806,7 @@ def writephases(arrivals, fformat, filename, parameter=None, eventinfo=None): return stime = eventsource['time'] event = parameter.get('eventID') - hddID = event.split('.')[0][1:5] + hddID = event.split('.')[0][1:5] # write header fid.write('# %d %d %d %d %d %5.2f %7.4f +%6.4f %7.4f %4.2f 0.1 0.5 %4.2f %s\n' % ( stime.year, stime.month, stime.day, stime.hour, stime.minute, stime.second, diff --git a/pylot/core/loc/nll.py b/pylot/core/loc/nll.py index 4a9f8b27..5ed9d101 100644 --- a/pylot/core/loc/nll.py +++ b/pylot/core/loc/nll.py @@ -81,7 +81,6 @@ def locate(fnin, parameter=None): :param fnin: external program name :return: None """ - exe_path = which('NLLoc', parameter) if exe_path is None: raise NLLocError('NonLinLoc executable not found; check your ' diff --git a/pylot/core/pick/utils.py b/pylot/core/pick/utils.py index 9cdbdb64..9419e618 100644 --- a/pylot/core/pick/utils.py +++ b/pylot/core/pick/utils.py @@ -7,6 +7,7 @@ :author: Ludger Kueperkoch, BESTEC GmbH """ + import warnings import matplotlib.pyplot as plt import numpy as np @@ -595,6 +596,8 @@ def select_for_phase(st, phase): alter_comp = compclass.getCompPosition(comp) alter_comp = str(alter_comp[0]) sel_st += st.select(component=comp) + if len(sel_st) < 1: + sel_st += st.select(component="Q") sel_st += st.select(component=alter_comp) elif phase.upper() == 'S': comps = 'NE' diff --git a/pylot/core/util/gui.py b/pylot/core/util/gui.py index c80d8706..04bd6fd7 100644 --- a/pylot/core/util/gui.py +++ b/pylot/core/util/gui.py @@ -53,7 +53,7 @@ def which(program, parameter): settings = QSettings() for key in settings.allKeys(): if 'binPath' in key: - os.environ['PATH'] += ':{0}'.format(settings.value(key)) + os.environ['PATH'] += ':{0}'.format(settings.value(key)) nllocpath = ":" + parameter.get('nllocbin') os.environ['PATH'] += nllocpath except Exception as e: @@ -73,7 +73,7 @@ def which(program, parameter): return program else: for path in os.environ["PATH"].split(os.pathsep): - exe_file = os.path.join(path, program) + exe_file = os.path.join(path, program) for candidate in ext_candidates(exe_file): if is_exe(candidate): return candidate @@ -100,4 +100,5 @@ def make_pen(picktype, phase, key, quality): rgba = pick_color(picktype, phase, quality) linestyle, width = pick_linestyle_pg(picktype, key) pen = pg.mkPen(rgba, width=width, style=linestyle) - return pen \ No newline at end of file + return pen + diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index e3d0e5cc..ea8b6a9d 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -1594,7 +1594,7 @@ class PickDlg(QDialog): def __init__(self, parent=None, data=None, station=None, network=None, location=None, picks=None, autopicks=None, rotate=False, parameter=None, embedded=False, metadata=None, - event=None, filteroptions=None, model='iasp91', wftype=None): + event=None, filteroptions=None, model=None, wftype=None): super(PickDlg, self).__init__(parent, Qt.Window) self.orig_parent = parent self.setAttribute(Qt.WA_DeleteOnClose) @@ -1719,7 +1719,7 @@ class PickDlg(QDialog): # init expected picks using obspy Taup try: - if self.metadata: + if self.metadata and model is not None: self.model = TauPyModel(model) self.get_arrivals() self.drawArrivals() @@ -2703,8 +2703,11 @@ class PickDlg(QDialog): ax.plot(mpp, ylims[0], color=color, marker='^', zorder=baseorder + 3) # append phase text (if textOnly: draw with current ylims) self.phaseText.append(ax.text(mpp, ylims[1], phase, color=color, zorder=baseorder + 10)) - # indicate first motion - self.phaseText.append(ax.text(mpp - 0.03 * mpp, ylims[1] - ylims[1] / 12, picks['fm'], color=color, zorder=baseorder + 10)) + # indicate first motion + fm = picks.get('fm') + if fm: + self.phaseText.append(ax.text(mpp - 0.03 * mpp, ylims[1] - ylims[1] / 12, fm, color=color, + zorder=baseorder + 10)) ax.legend(loc=1) def connect_mouse_motion(self):