feature/port-to-py3 #11

Merged
marcel merged 59 commits from feature/port-to-py3 into develop 2022-03-21 15:30:06 +01:00
9 changed files with 71 additions and 40 deletions
Showing only changes of commit d236d3d80f - Show all commits

View File

@ -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')
@ -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)

View File

@ -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))

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env pyth n
# -*- coding: utf-8 -*-
import copy
@ -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')

View File

@ -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,

View File

@ -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,

View File

@ -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 '

View File

@ -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'

View File

@ -101,3 +101,4 @@ def make_pen(picktype, phase, key, quality):
linestyle, width = pick_linestyle_pg(picktype, key)
pen = pg.mkPen(rgba, width=width, style=linestyle)
return pen

View File

@ -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()
@ -2704,7 +2704,10 @@ class PickDlg(QDialog):
# 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))
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):