bugfix: correct erroneous and add new doctests
This commit is contained in:
parent
554afc5a81
commit
221743fe20
15
PyLoT.py
15
PyLoT.py
@ -496,6 +496,7 @@ class MainWindow(QMainWindow):
|
|||||||
icon=eventlist_xml_icon,
|
icon=eventlist_xml_icon,
|
||||||
tip='Create an Eventlist from a XML File')
|
tip='Create an Eventlist from a XML File')
|
||||||
self.eventlist_xml_action.setEnabled(False)
|
self.eventlist_xml_action.setEnabled(False)
|
||||||
|
|
||||||
printAction = self.createAction(self, "&Print event ...",
|
printAction = self.createAction(self, "&Print event ...",
|
||||||
self.show_event_information, QKeySequence.Print,
|
self.show_event_information, QKeySequence.Print,
|
||||||
print_icon,
|
print_icon,
|
||||||
@ -1403,8 +1404,6 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
for id, event in enumerate(self.project.eventlist):
|
for id, event in enumerate(self.project.eventlist):
|
||||||
event_path = event.path
|
event_path = event.path
|
||||||
#phaseErrors = {'P': self._inputs['timeerrorsP'],
|
|
||||||
# 'S': self._inputs['timeerrorsS']}
|
|
||||||
|
|
||||||
man_au_picks = {'manual': event.pylot_picks,
|
man_au_picks = {'manual': event.pylot_picks,
|
||||||
'auto': event.pylot_autopicks}
|
'auto': event.pylot_autopicks}
|
||||||
@ -1473,7 +1472,6 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
for picktype, item_np in [('manual', item_nmp), ('auto', item_nap)]:
|
for picktype, item_np in [('manual', item_nmp), ('auto', item_nap)]:
|
||||||
npicks_str = f"{npicks[picktype]['P']}|{npicks[picktype]['S']}"
|
npicks_str = f"{npicks[picktype]['P']}|{npicks[picktype]['S']}"
|
||||||
#npicks_str += f"({npicks_total[picktype]['P']}/{npicks_total[picktype]['S']})"
|
|
||||||
item_np.setText(npicks_str)
|
item_np.setText(npicks_str)
|
||||||
|
|
||||||
item_ref = QStandardItem() # str(event_ref))
|
item_ref = QStandardItem() # str(event_ref))
|
||||||
@ -1718,8 +1716,6 @@ class MainWindow(QMainWindow):
|
|||||||
for tr in self.get_data().wfdata.select(component=ch).traces:
|
for tr in self.get_data().wfdata.select(component=ch).traces:
|
||||||
traces[tr.stats.station][ch] = tr
|
traces[tr.stats.station][ch] = tr
|
||||||
|
|
||||||
names.sort()
|
|
||||||
a = self.get_current_event()
|
|
||||||
|
|
||||||
print (self.get_data().wfdata.traces[0])
|
print (self.get_data().wfdata.traces[0])
|
||||||
|
|
||||||
@ -1729,14 +1725,6 @@ class MainWindow(QMainWindow):
|
|||||||
self.tabs.setCurrentIndex(3)
|
self.tabs.setCurrentIndex(3)
|
||||||
figCanvas = test.makeSpecFig(direction=self.dispComponent, height = height, width = width, parent = self.tabs.widget)
|
figCanvas = test.makeSpecFig(direction=self.dispComponent, height = height, width = width, parent = self.tabs.widget)
|
||||||
return figCanvas
|
return figCanvas
|
||||||
#self.spectro_layout.addWidget()
|
|
||||||
# self.get_data().wfdata.spectrogram()
|
|
||||||
# self.tabs.addTab(figCanvas, 'Spectrogram')
|
|
||||||
# self.tabs[3] = figCanvas
|
|
||||||
# self.refreshTabs()
|
|
||||||
# test.show()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def compareMulti(self):
|
def compareMulti(self):
|
||||||
if not self.compareoptions:
|
if not self.compareoptions:
|
||||||
@ -1896,7 +1884,6 @@ class MainWindow(QMainWindow):
|
|||||||
# which will read in data input twice. Therefore current tab is changed to 0
|
# which will read in data input twice. Therefore current tab is changed to 0
|
||||||
# in loadProject before calling this function.
|
# in loadProject before calling this function.
|
||||||
self.fill_eventbox()
|
self.fill_eventbox()
|
||||||
#print(f'{self.get_current_event()=}')
|
|
||||||
plotted = False
|
plotted = False
|
||||||
if self.tabs.currentIndex() == 2:
|
if self.tabs.currentIndex() == 2:
|
||||||
self.init_event_table()
|
self.init_event_table()
|
||||||
|
@ -275,7 +275,7 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0, fig=None, linecolor='k'):
|
|||||||
try:
|
try:
|
||||||
P1 = np.polyfit(xslope1, xraw[islope1], 1)
|
P1 = np.polyfit(xslope1, xraw[islope1], 1)
|
||||||
datafit1 = np.polyval(P1, xslope1)
|
datafit1 = np.polyval(P1, xslope1)
|
||||||
except Exception as e:
|
except ValueError as e:
|
||||||
print("fmpicker: Problems with data fit! {}".format(e))
|
print("fmpicker: Problems with data fit! {}".format(e))
|
||||||
print("Skip first motion determination!")
|
print("Skip first motion determination!")
|
||||||
return FM
|
return FM
|
||||||
@ -321,7 +321,7 @@ def fmpicker(Xraw, Xfilt, pickwin, Pick, iplot=0, fig=None, linecolor='k'):
|
|||||||
try:
|
try:
|
||||||
P2 = np.polyfit(xslope2, xfilt[islope2], 1)
|
P2 = np.polyfit(xslope2, xfilt[islope2], 1)
|
||||||
datafit2 = np.polyval(P2, xslope2)
|
datafit2 = np.polyval(P2, xslope2)
|
||||||
except Exception as e:
|
except ValueError as e:
|
||||||
emsg = 'fmpicker: polyfit failed: {}'.format(e)
|
emsg = 'fmpicker: polyfit failed: {}'.format(e)
|
||||||
print(emsg)
|
print(emsg)
|
||||||
return FM
|
return FM
|
||||||
|
@ -333,18 +333,37 @@ def get_bool(value):
|
|||||||
"""
|
"""
|
||||||
Convert string representations of bools to their true boolean value
|
Convert string representations of bools to their true boolean value
|
||||||
:param value:
|
:param value:
|
||||||
:type value: str, bool
|
:type value: str, bool, int, float
|
||||||
:return: true boolean value
|
:return: true boolean value
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
|
|
||||||
|
>>> get_bool(True)
|
||||||
|
True
|
||||||
|
>>> get_bool(False)
|
||||||
|
False
|
||||||
|
>>> get_bool(0)
|
||||||
|
False
|
||||||
|
>>> get_bool(0.)
|
||||||
|
False
|
||||||
|
>>> get_bool(0.1)
|
||||||
|
True
|
||||||
|
>>> get_bool(2)
|
||||||
|
True
|
||||||
|
>>> get_bool(-1)
|
||||||
|
False
|
||||||
|
>>> get_bool(-0.3)
|
||||||
|
False
|
||||||
"""
|
"""
|
||||||
if type(value) is bool:
|
if type(value) == bool:
|
||||||
return value
|
return value
|
||||||
elif value in ['True', 'true']:
|
elif value in ['True', 'true']:
|
||||||
return True
|
return True
|
||||||
elif value in ['False', 'false']:
|
elif value in ['False', 'false']:
|
||||||
return False
|
return False
|
||||||
|
elif value > 0. or value > 0:
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
return bool(value)
|
return False
|
||||||
|
|
||||||
def four_digits(year):
|
def four_digits(year):
|
||||||
"""
|
"""
|
||||||
@ -355,8 +374,8 @@ def four_digits(year):
|
|||||||
:return: four digit year correspondent
|
:return: four digit year correspondent
|
||||||
:rtype: int
|
:rtype: int
|
||||||
|
|
||||||
>>> four_digits(20)
|
>>> four_digits(75)
|
||||||
1920
|
1975
|
||||||
>>> four_digits(16)
|
>>> four_digits(16)
|
||||||
2016
|
2016
|
||||||
>>> four_digits(00)
|
>>> four_digits(00)
|
||||||
@ -513,6 +532,11 @@ def is_executable(fn):
|
|||||||
:param fn: path to the file to be tested
|
:param fn: path to the file to be tested
|
||||||
:return: True or False
|
:return: True or False
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
|
|
||||||
|
>>> is_executable('/bin/ls')
|
||||||
|
True
|
||||||
|
>>> is_executable('/var/log/system.log')
|
||||||
|
False
|
||||||
"""
|
"""
|
||||||
return os.path.isfile(fn) and os.access(fn, os.X_OK)
|
return os.path.isfile(fn) and os.access(fn, os.X_OK)
|
||||||
|
|
||||||
@ -619,13 +643,13 @@ def find_horizontals(data):
|
|||||||
:param data: waveform data
|
:param data: waveform data
|
||||||
:type data: `obspy.core.stream.Stream`
|
:type data: `obspy.core.stream.Stream`
|
||||||
:return: components list
|
:return: components list
|
||||||
:rtype: list
|
:rtype: List(str)
|
||||||
|
|
||||||
..example::
|
..example::
|
||||||
|
|
||||||
>>> st = read()
|
>>> st = read()
|
||||||
>>> find_horizontals(st)
|
>>> find_horizontals(st)
|
||||||
[u'N', u'E']
|
['N', 'E']
|
||||||
"""
|
"""
|
||||||
rval = []
|
rval = []
|
||||||
for tr in data:
|
for tr in data:
|
||||||
@ -819,6 +843,19 @@ def trim_station_components(data, trim_start=True, trim_end=True):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def merge_stream(stream):
|
||||||
|
gaps = stream.get_gaps()
|
||||||
|
if gaps:
|
||||||
|
# list of merged stations (seed_ids)
|
||||||
|
merged = ['{}.{}.{}.{}'.format(*gap[:4]) for gap in gaps]
|
||||||
|
stream.merge(method=1)
|
||||||
|
print('Merged the following stations because of gaps:')
|
||||||
|
for merged_station in merged:
|
||||||
|
print(merged_station)
|
||||||
|
|
||||||
|
return stream, gaps
|
||||||
|
|
||||||
|
|
||||||
def check4gapsAndRemove(data):
|
def check4gapsAndRemove(data):
|
||||||
"""
|
"""
|
||||||
check for gaps in Stream and remove them
|
check for gaps in Stream and remove them
|
||||||
@ -839,12 +876,12 @@ def check4gapsAndRemove(data):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def check_for_gaps_and_merge(data):
|
def check4gapsAndMerge(data):
|
||||||
"""
|
"""
|
||||||
check for gaps in Stream and merge if gaps are found
|
check for gaps in Stream and merge if gaps are found
|
||||||
:param data: stream of seismic data
|
:param data: stream of seismic data
|
||||||
:type data: `~obspy.core.stream.Stream`
|
:type data: `~obspy.core.stream.Stream`
|
||||||
:return: data stream, gaps returned from obspy get_gaps
|
:return: data stream
|
||||||
:rtype: `~obspy.core.stream.Stream`
|
:rtype: `~obspy.core.stream.Stream`
|
||||||
"""
|
"""
|
||||||
gaps = data.get_gaps()
|
gaps = data.get_gaps()
|
||||||
@ -855,7 +892,7 @@ def check_for_gaps_and_merge(data):
|
|||||||
for merged_station in merged:
|
for merged_station in merged:
|
||||||
print(merged_station)
|
print(merged_station)
|
||||||
|
|
||||||
return data, gaps
|
return data
|
||||||
|
|
||||||
|
|
||||||
def check4doubled(data):
|
def check4doubled(data):
|
||||||
@ -927,11 +964,11 @@ def get_possible_pylot_eventfile_extensions(event, fext):
|
|||||||
|
|
||||||
def get_stations(data):
|
def get_stations(data):
|
||||||
"""
|
"""
|
||||||
Get list of all station names in data stream
|
Get list of all station names in data-stream
|
||||||
:param data: stream containing seismic traces
|
:param data: stream containing seismic traces
|
||||||
:type data: `~obspy.core.stream.Stream`
|
:type data: `~obspy.core.stream.Stream`
|
||||||
:return: list of all station names in data, no duplicates
|
:return: list of all station names in data, no duplicates
|
||||||
:rtype: list of str
|
:rtype: List(str)
|
||||||
"""
|
"""
|
||||||
stations = []
|
stations = []
|
||||||
for tr in data:
|
for tr in data:
|
||||||
@ -987,7 +1024,7 @@ def check4rotated(data, metadata=None, verbosity=1):
|
|||||||
if len(wfs_in) < 3:
|
if len(wfs_in) < 3:
|
||||||
print(f"Stream {wfs_in=}, has not enough components to rotate.")
|
print(f"Stream {wfs_in=}, has not enough components to rotate.")
|
||||||
return wfs_in
|
return wfs_in
|
||||||
|
|
||||||
# check if any traces in this station need to be rotated
|
# check if any traces in this station need to be rotated
|
||||||
trace_ids = [trace.id for trace in wfs_in]
|
trace_ids = [trace.id for trace in wfs_in]
|
||||||
if not rotation_required(trace_ids):
|
if not rotation_required(trace_ids):
|
||||||
@ -1155,7 +1192,6 @@ def identifyPhase(phase):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@lru_cache
|
|
||||||
def identifyPhaseID(phase):
|
def identifyPhaseID(phase):
|
||||||
"""
|
"""
|
||||||
Returns phase id (capital P or S)
|
Returns phase id (capital P or S)
|
||||||
|
@ -897,8 +897,6 @@ class WaveformWidgetPG(QtWidgets.QWidget):
|
|||||||
else:
|
else:
|
||||||
st_select = wfdata
|
st_select = wfdata
|
||||||
|
|
||||||
# st_select, gaps = check_for_gaps_and_merge(st_select) #MP MP commented because probably done twice
|
|
||||||
|
|
||||||
# list containing tuples of network, station, channel (for sorting)
|
# list containing tuples of network, station, channel (for sorting)
|
||||||
nslc = []
|
nslc = []
|
||||||
for trace in st_select:
|
for trace in st_select:
|
||||||
@ -5788,10 +5786,7 @@ class ChooseWaveFormWindow(QWidget):
|
|||||||
def submit(self):
|
def submit(self):
|
||||||
matplotlib.pyplot.close(self.currentSpectro)
|
matplotlib.pyplot.close(self.currentSpectro)
|
||||||
t = self.chooseBoxTraces.currentText() + " " + self.chooseBoxComponent.currentText()
|
t = self.chooseBoxTraces.currentText() + " " + self.chooseBoxComponent.currentText()
|
||||||
#self.currentSpectro = self.traces[
|
self.applyFFT()
|
||||||
# self.chooseBoxTraces.currentText()[3:]][self.chooseBoxComponent.currentText()].spectrogram(show=False, title=t)
|
|
||||||
#self.currentSpectro.show()
|
|
||||||
applyFFT()
|
|
||||||
|
|
||||||
def applyFFT(self, trace):
|
def applyFFT(self, trace):
|
||||||
tra = self.traces[self.chooseBoxTraces.currentText()[3:]]['Z']
|
tra = self.traces[self.chooseBoxTraces.currentText()[3:]]['Z']
|
||||||
@ -5886,21 +5881,6 @@ class SpectrogramTab(QWidget):
|
|||||||
colors='m', linestyles='dashed',
|
colors='m', linestyles='dashed',
|
||||||
linewidth=2)
|
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]))
|
grams.append(tra.spectrogram(show=False, axes=axis[i]))
|
||||||
i+=1
|
i+=1
|
||||||
|
|
||||||
@ -5909,24 +5889,8 @@ class SpectrogramTab(QWidget):
|
|||||||
fC = FigureCanvas(figure)
|
fC = FigureCanvas(figure)
|
||||||
return fC
|
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__':
|
if __name__ == '__main__':
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
doctest.testmod()
|
doctest.testmod()
|
Loading…
Reference in New Issue
Block a user