Bugfixxes, spectogram tab wip

This commit is contained in:
2023-06-14 13:11:54 +02:00
parent e4e7afa996
commit a1f6c5ffca
5 changed files with 155 additions and 104 deletions
+23 -16
View File
@@ -260,11 +260,6 @@ class Data(object):
can be a str or a list of strings of ['manual', 'auto', 'origin', 'magnitude']
"""
from pylot.core.util.defaults import OUTPUTFORMATS
import sys
sys.stdout = sys.__stdout__
print ( fnext )
if not type(fcheck) == list:
fcheck = [fcheck]
@@ -325,18 +320,25 @@ class Data(object):
if lendiff != 0:
print("Manual as well as automatic picks available. Prefered the {} manual ones!".format(lendiff))
no_uncertainties_p = []
no_uncertainties_s = []
if upperErrors:
# check for pick uncertainties exceeding adjusted upper errors
# Picks with larger uncertainties will not be saved in output file!
for j in range(len(picks)):
for i in range(len(picks_copy)):
if picks_copy[i].phase_hint[0] == 'P':
print(picks_copy[i].time_errors)
# Testing if exporting works without upper_uncertatinty
# Skipping pick if no upper_uncertainty is found and warning user
if picks_copy[i].time_errors['upper_uncertainty'] is None:
break
#print("{1} P-Pick of station {0} does not have upper_uncertainty and cant be checked".format(
# picks_copy[i].waveform_id.station_code,
# picks_copy[i].method_id))
if not picks_copy[i].waveform_id.station_code in no_uncertainties_p:
no_uncertainties_p.append(picks_copy[i].waveform_id.station_code)
continue
#print ("checking for upper_uncertainty")
if (picks_copy[i].time_errors['uncertainty'] is None) or \
(picks_copy[i].time_errors['upper_uncertainty'] >= upperErrors[0]):
print("Uncertainty exceeds or equal adjusted upper time error!")
@@ -345,14 +347,19 @@ class Data(object):
print("{1} P-Pick of station {0} will not be saved in outputfile".format(
picks_copy[i].waveform_id.station_code,
picks_copy[i].method_id))
print("#######")
del picks_copy[i]
break
if picks_copy[i].phase_hint[0] == 'S':
# Testing if exporting works without upper_uncertatinty
# Skipping pick if no upper_uncertainty is found and warning user
if picks_copy[i].time_errors['upper_uncertainty'] is None:
break
#print("{1} S-Pick of station {0} does not have upper_uncertainty and cant be checked".format(
#picks_copy[i].waveform_id.station_code,
#picks_copy[i].method_id))
if not picks_copy[i].waveform_id.station_code in no_uncertainties_s:
no_uncertainties_s.append(picks_copy[i].waveform_id.station_code)
continue
if (picks_copy[i].time_errors['uncertainty'] is None) or \
(picks_copy[i].time_errors['upper_uncertainty'] >= upperErrors[1]):
@@ -362,9 +369,12 @@ class Data(object):
print("{1} S-Pick of station {0} will not be saved in outputfile".format(
picks_copy[i].waveform_id.station_code,
picks_copy[i].method_id))
print("#")
del picks_copy[i]
break
for s in no_uncertainties_p:
print("P-Pick of station {0} does not have upper_uncertainty and cant be checked".format(s))
for s in no_uncertainties_s:
print("S-Pick of station {0} does not have upper_uncertainty and cant be checked".format(s))
if fnext == '.obs':
try:
@@ -788,12 +798,9 @@ class GenericDataStructure(object):
"""
expandList = []
for item in self.getExpandFields():
print ( item )
expandList.append(self.getFieldValue(item))
if self.hasSuffix():
expandList.append('*%s' % self.getFieldValue('suffix'))
print ( expandList )
print ( self.getFields() )
return os.path.join(*expandList)
def getCatalogName(self):
-1
View File
@@ -1014,7 +1014,6 @@ def chooseArrivals(arrivals):
:return: arrivals but with the manual picks prefered if possible
"""
# If len of arrivals is greater than 2 it comes from autopicking so only autopicks are available
print("=== CHOOSE ===")
if len(arrivals) > 2:
return arrivals
if arrivals['auto'] and arrivals['manual']:
+2 -1
View File
@@ -41,7 +41,8 @@ class Thread(QThread):
exctype, value = sys.exc_info()[:2]
self._executedErrorInfo = '{} {} {}'. \
format(exctype, value, traceback.format_exc())
sys.stdout = self.old_stdout
if self.redirect_stdout:
sys.stdout = self.old_stdout
def showProgressbar(self):
if self.progressText:
+82 -69
View File
@@ -5667,9 +5667,8 @@ class ChooseWaveFormWindow(QWidget):
# self.chooseBoxTraces.currentText()[3:]][self.chooseBoxComponent.currentText()].spectrogram(show=False, title=t)
#self.currentSpectro.show()
applyFFT()
def applyFFT(self, trace):
sys.stdout = sys.__stdout__
tra = self.traces[self.chooseBoxTraces.currentText()[3:]]['Z']
transformed = abs(np.fft.rfft(tra.data))
print ( transformed )
@@ -5677,36 +5676,11 @@ class ChooseWaveFormWindow(QWidget):
matplotlib.pyplot.show()
def applyFFTs(self, tra):
sys.stdout = sys.__stdout__
transformed = abs(np.fft.rfft(tra.data))
print ( transformed )
matplotlib.pyplot.plot ( transformed )
matplotlib.pyplot.show()
def applyFFT2(self, trace):
sys.stdout = sys.__stdout__
tra = self.traces[self.chooseBoxTraces.currentText()[3:]]['Z']
from pylot.core.pick.utils import select_for_phase
zdat = select_for_phase(tra, "P")
freq = zdat[0].stats.sampling_rate
# fft
fny = freq / 2
# l = len(xdat) / freq
# number of fft bins after Bath
# n = freq * l
# find next power of 2 of data length
m = pow(2, np.ceil(np.log(len(zdat)) / np.log(2)))
N = min(int(np.power(m, 2)), 16384)
# N = int(np.power(m, 2))
y = dt * np.fft.fft(zdat, N)
Y = abs(y[: int(N / 2)])
#L = (N - 1) / freq
#f = np.arange(0, fny, 1 / L)
matplotlib.pyplot.plot (Y)
matplotlib.pyplot.show()
def submitN(self):
matplotlib.pyplot.close(self.currentSpectro)
t = self.chooseBoxTraces.currentText() + " " + self.chooseBoxComponent.currentText()
@@ -5714,54 +5688,13 @@ class ChooseWaveFormWindow(QWidget):
self.chooseBoxTraces.currentText()[3:]]['N'].spectrogram(show=False, title=t)
self.currentSpectro.show()
def submitE2(self):
def submitE(self):
matplotlib.pyplot.close(self.currentSpectro)
t = self.chooseBoxTraces.currentText() + " " + self.chooseBoxComponent.currentText()
self.currentSpectro = self.traces[
self.chooseBoxTraces.currentText()[3:]]['E'].spectrogram(show=False, title=t)
self.currentSpectro.show()
def submitE(self):
sys.stdout = sys.__stdout__
matplotlib.pyplot.close(self.currentSpectro)
#t = self.chooseBoxTraces.currentText() + " " + self.chooseBoxComponent.currentText()
#self.currentSpectro = self.traces[
# self.chooseBoxTraces.currentText()[3:]]['Z'].spectrogram(show=False, title=t)
#self.currentSpectro.show()
#self.applyFFT('s')
i = 0
figure, axis = matplotlib.pyplot.subplots(len(self.traces), sharex=True)
for t in self.traces:
tra = self.traces[t]['Z']
transformed = abs(np.fft.rfft(tra.data))
axis[i].plot(transformed, label = t)
#axis[i].tick_params(labelbottom=False)
axis[i].spines['top'].set_visible(False)
axis[i].spines['right'].set_visible(False)
axis[i].spines['left'].set_visible(False)
if not (len(self.traces) == i - 1) :
axis[i].spines['bottom'].set_visible(False)
axis[i].set_yticks([])
axis[i].set_ylabel(t,loc='center', rotation='horizontal')
#axis[i].axis('off')
i += 1
#self.applyFFTs(t)
matplotlib.pyplot.margins(0)
return FigureCanvas(figure)
#return figure, axis
matplotlib.pyplot.show()
def submitZ(self):
matplotlib.pyplot.close(self.currentSpectro)
#t = self.chooseBoxTraces.currentText() + " " + self.chooseBoxComponent.currentText()
#self.currentSpectro = self.traces[
# self.chooseBoxTraces.currentText()[3:]]['Z'].spectrogram(show=False, title=t)
#self.currentSpectro.show()
self.applyFFT2('s')
# Creates a QComboBox and adds all traces provided
def createComboBoxTraces(self):
if len(self.wFs) <= 0:
@@ -5788,6 +5721,86 @@ class ChooseWaveFormWindow(QWidget):
pass
class SpectrogramTab(QWidget):
def __init__(self, traces, wfdata, parent=None):
super(SpectrogramTab, self).__init__(parent)
self.setupUi()
self.traces = traces
self.wfdata = wfdata
def setupUi(self):
pass
def makeSpecFig(self, direction = 'Z', height = 0, width = 0, parent = None):
i = 0
grams = []
figure, axis = matplotlib.pyplot.subplots(len(self.traces), sharex=True)
start, end = full_range(self.wfdata)
if height != 0 and width != 0:
figure.figsize = (width, height)
figure.set_figwidth = width
figure.set_figheight = height
#figure.tight_layout()
for t in self.traces:
tra = self.traces[t][direction]
#print(start, end)
# Set Title
if i == 0:
if direction == 'Z':
figure.suptitle("section: vertical components")
elif direction == 'E':
figure.suptitle("section: east-west components")
elif direction == 'N':
figure.suptitle("section: north-south components")
axis[i].vlines(0, axis[i].get_ylim()[0], axis[i].get_ylim()[1],
colors='m', linestyles='dashed',
linewidth=2)
# Different axis settings for visual improvements
# axis[i].set_xlim(left=0, right=end - start)
# axis[i].spines['top'].set_visible(False)
# axis[i].spines['right'].set_visible(False)
# # axis[i].spines['left'].set_visible(False)
# axis[i].tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False)
# if not (len(self.traces) == i - 1):
# axis[i].spines['bottom'].set_visible(False)
# axis[i].set_yticks([])
# axis[i].set_ylabel(t, loc='center', rotation='horizontal')
#ax.axhline(n, color="0.5", lw=0.5)
grams.append(tra.spectrogram(show=False, axes=axis[i]))
i+=1
#figure.setXLims([0, end - start])
figure.set_tight_layout(True)
fC = FigureCanvas(figure)
return fC
#for t in self.traces:
# tra = self.traces[t]['Z']
# transformed = abs(np.fft.rfft(tra.data))
# axis[i].plot(transformed, label=t)
# # axis[i].tick_params(labelbottom=False)
# axis[i].spines['top'].set_visible(False)
# axis[i].spines['right'].set_visible(False)
# axis[i].spines['left'].set_visible(False)
# if not (len(self.traces) == i - 1):
# axis[i].spines['bottom'].set_visible(False)
# axis[i].set_yticks([])
# axis[i].set_ylabel(t, loc='center', rotation='horizontal')
# # axis[i].axis('off')
# i += 1
# # self.applyFFTs(t)
if __name__ == '__main__':
import doctest