Skip to content

Commit

Permalink
fix amplitude envelope window size crash
Browse files Browse the repository at this point in the history
  • Loading branch information
tensionhead committed Jan 7, 2021
1 parent 4f32de8 commit d90fd90
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pyboat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys, os
import argparse

__version__ = '0.9.0'
__version__ = '0.9.1'

# the object oriented API
from .api import WAnalyzer
Expand Down
11 changes: 9 additions & 2 deletions pyboat/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,13 @@ def sliding_window_amplitude(signal, window_size, dt, SGsmooth=True):
# get the underlying array
vector = np.array(signal)

if window_size > (len(signal) - 1) * dt:
window_size = (len(signal) - 1) * dt
print(f'Warning, setting window_size to {window_size}!')

# window size in sampling interval units
window_size = int(window_size / dt)

# has to be odd
if window_size % 2 != 1:
window_size = window_size + 1
Expand Down Expand Up @@ -619,7 +623,10 @@ def normalize_with_envelope(dsignal, window_size, dt):
# mean subtraction
signal = dsignal - dsignal.mean()


if window_size > (len(signal) - 1) * dt:
window_size = (len(signal) - 1) * dt
print(f'Warning, setting window_size to {window_size}!')

# ampl. normalization
env = sliding_window_amplitude(signal, window_size, dt)
ANsignal = 1 / env * dsignal
Expand Down
63 changes: 32 additions & 31 deletions pyboat/ui/data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,17 +445,16 @@ def toggle_trend(self, state):
self.doPlot()

def toggle_envelope(self, state):

# trying to plot the trend
if state == Qt.Checked:
window_size = self.get_wsize(self.wsize_edit)
if not window_size:
self.cb_envelope.setChecked(False)
self.cb_use_envelope.setChecked(False)



# signal selected?
if self.signal_id:
# trying to plot the envelope
if state == Qt.Checked:
window_size = self.get_wsize(self.wsize_edit)
if not window_size:
self.cb_envelope.setChecked(False)
self.cb_use_envelope.setChecked(False)

self.doPlot()

# connected to unit_edit
Expand Down Expand Up @@ -541,15 +540,38 @@ def get_wsize(self, wsize_edit):
msgBox = QMessageBox()
msgBox.setWindowTitle('Missing Parameter')
msgBox.setText(
'Envelope parameter not set properly, specify a sliding window size!')
'Amplitude envelope parameter not set, specify a sliding window size!')

msgBox.exec()

if self.debug:
print("window_size ValueError", window_size)
return None

if window_size / self.dt < 4:

msgBox = QMessageBox()
msgBox.setWindowTitle("Out of Bounds")
msgBox.setText(
f'''Minimal sliding window size for envelope estimation is {4*self.dt} {self.time_unit}!''')
msgBox.exec()

return None

if window_size / self.dt > self.df.shape[0]:
max_window_size = self.df.shape[0] * self.dt

msgBox = QMessageBox()
msgBox.setWindowTitle("Out of Bounds")
msgBox.setText(
f"Maximal sliding window size for envelope estimation is {max_window_size:.2f} {self.time_unit}!")
msgBox.exec()

return None

if self.debug:
print("window_size set to:", window_size)

return window_size

def set_initial_periods(self, force=False):
Expand Down Expand Up @@ -809,27 +831,6 @@ def calc_envelope(self):
if self.debug:
print("Calculating envelope with window_size = ", window_size)

if window_size / self.dt < 4:

msgBox = QMessageBox()
msgBox.setWindowTitle("Out of Bounds")
msgBox.setText(
f'''Minimal sliding window size is {4*self.dt}{self.time_unit}!''')
msgBox.exec()

window_size = None
return

if window_size / self.dt > self.df.shape[0]:
max_window_size = self.df.shape[0] * self.dt

msgBox = QMessageBox()
msgBox.setWindowTitle("Out of Bounds")
msgBox.setText(
f"Maximum sliding window size is {max_window_size:.2f} {self.time_unit}!")
msgBox.exec()

return

# cut of frequency set?!
if self.get_T_c(self.T_c_edit):
Expand Down
2 changes: 1 addition & 1 deletion pyboat/ui/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
'window_size' : None,
'Tmin' : None,
'Tmax' : None,
'nT' : 100,
'nT' : 200,
'pow_max' : None
}

Expand Down

0 comments on commit d90fd90

Please sign in to comment.