Commit 57eb8afa authored by Gregor Moenke's avatar Gregor Moenke

fixed Fourier, plotting styles

parent d88b7099
......@@ -3,7 +3,7 @@
import sys,os
import argparse
__version__ = '0.8.1.3'
__version__ = '0.8.1.5'
# the object oriented API
from .api import WAnalyzer
......
......@@ -440,7 +440,7 @@ def smooth(x, window_len=11, window="flat", data=None):
if window_len < 3:
raise ValueError("window must not be shorter than 3")
if window_len % 2 is 0:
if window_len % 2 == 0:
raise ValueError("window_len should be odd")
if not window in ["flat", "extern"]:
......@@ -596,7 +596,7 @@ def normalize_with_envelope(dsignal, window_size, dt):
----------
dsignal : ndarray, the (detrended) signal
window_size : int, the window size in time units
window_size : int, the window size in sampling time units
dt : float, the sampling interval
"""
......
......@@ -14,29 +14,33 @@ TREND_COLOR = rgb_2mpl(165, 105, 189) # orchidy
ENVELOPE_COLOR = 'orange'
DETREND_COLOR = 'black'
FOURIER_COLOR = 'slategray'
FOURIER_COLOR = 'cadetblue'
RIDGE_COLOR = "crimson"
COI_COLOR = '0.6' # light gray
# average power histogram
HIST_COLOR = 'lightslategray'
HIST_COLOR = 'cadetblue'
# the readouts
PERIOD_COLOR = 'cornflowerblue'
PHASE_COLOR = 'crimson'
AMPLITUDE_COLOR = 'k'
POWER_COLOR = 'gray'
POWERKDE_COLOR = rgba_2mpl(10,10,10,180)
POWER_COLOR = 'cadetblue'
POWERKDE_COLOR = rgba_2mpl(10,10,10,160)
# the colormap for the wavelet spectra
CMAP = "YlGnBu_r"
# CMAP = 'cividis'
# CMAP = 'magma'
# --- max size of signal to plot also the sample points
Nmax = 250
# --- define line widths ---
TREND_LW = 1.5
SIGNAL_LW = 1.5
MARKER_SIZE = 4
# --- standard sizes ---
label_size = 18
......@@ -47,6 +51,19 @@ tick_label_size = 16
# match dimensions of spectrum and signal plots
x_size = 6.5
# signal plot style, markers only for short signals
def get_marker_lw(signal):
if len(signal) <= Nmax:
m = 'o'
lw = 1.2
else:
m = ''
lw = SIGNAL_LW
return m, lw
# --- Signal and Trend -----------------------------------------------
......@@ -69,14 +86,17 @@ def mk_signal_ax(time_unit="a.u.", fig=None):
return ax
def draw_signal(ax, time_vector, signal):
ax.plot(time_vector, signal, lw=SIGNAL_LW,
color=SIG_COLOR, alpha=0.8, label="signal")
def draw_signal(ax, time_vector, signal, label = "signal"):
m, lw = get_marker_lw(signal)
ax.plot(time_vector, signal, lw=lw, marker = m, ms = MARKER_SIZE,
color=SIG_COLOR, alpha=0.8, label=label)
def draw_trend(ax, time_vector, trend):
ax.plot(time_vector, trend, color=TREND_COLOR, alpha=0.8, lw=TREND_LW, label="trend")
def draw_trend(ax, time_vector, trend, label = 'trend'):
ax.plot(time_vector, trend, color=TREND_COLOR,
alpha=0.8, lw=TREND_LW, label=label)
def draw_envelope(ax, time_vector, envelope):
ax.plot(time_vector, envelope, color=ENVELOPE_COLOR,
......@@ -85,9 +105,11 @@ def draw_envelope(ax, time_vector, envelope):
def draw_detrended(ax, time_vector, detrended):
m, lw = get_marker_lw(detrended)
ax2 = ax.twinx()
ax2.plot(time_vector, detrended, "-",
color=DETREND_COLOR, lw=1.5, alpha=0.6, label = 'detrended')
ax2.plot(time_vector, detrended, "-", marker = m, ms = MARKER_SIZE,
color=DETREND_COLOR, lw=lw, alpha=0.6, label = 'detrended')
ax2.set_ylabel("detrended", fontsize=label_size)
ax2.ticklabel_format(style="sci", axis="y", scilimits=(0, 0))
......@@ -223,7 +245,11 @@ def plot_signal_modulus(axs, time_vector, signal, modulus, periods, p_max=None):
# Plot Signal above spectrum
sig_ax.plot(time_vector, signal, color="black", lw=1.5, alpha=0.7)
m, lw = get_marker_lw(signal)
sig_ax.plot(time_vector, signal, color="black",
lw=lw, alpha=0.65, marker = m, ms = MARKER_SIZE)
# sig_ax.plot(time_vector, signal, ".", color="black", ms=2.0, alpha=0.5)
sig_ax.ticklabel_format(style="sci", axis="y", scilimits=(0, 0))
sig_ax.tick_params(axis="both", labelsize=tick_label_size)
......@@ -380,12 +406,13 @@ def plot_readout(ridge_data, time_unit="a.u.", draw_coi = False, fig=None):
ax3.tick_params(axis="both", labelsize=tick_label_size)
# powers
ax4.plot(ridge_t.loc[i_left:i_right], powers.loc[i_left:i_right], "k-", lw=2.5, alpha=0.5,
ax4.plot(ridge_t.loc[i_left:i_right], powers.loc[i_left:i_right],
lw=2.5, alpha=0.8, color = POWER_COLOR,
ls = lstyle, marker = mstyle, ms = 1.5)
# inside COI
ax4.plot(ridge_t.loc[:i_left], powers.loc[:i_left], '--',color='gray', alpha=0.6, ms = 2.5)
ax4.plot(ridge_t.loc[i_right:], powers.loc[i_right:], '--', color='gray', alpha=0.6, ms = 2.5)
ax4.plot(ridge_t.loc[:i_left], powers.loc[:i_left], '--',color=POWER_COLOR, alpha=0.6, ms = 2.5)
ax4.plot(ridge_t.loc[i_right:], powers.loc[i_right:], '--', color=POWER_COLOR, alpha=0.6, ms = 2.5)
ax4.set_ylim((0, 1.1 * powers.max()))
ax4.set_ylabel("Power (wnp)", fontsize=label_size)
......@@ -478,7 +505,6 @@ def plot_power_distribution(powers, kde = True, fig = None):
dens(support),
color = POWERKDE_COLOR,
lw = 2.,
alpha = 0.8,
label = 'KDE'
)
......
......@@ -64,7 +64,8 @@ class FourierAnalyzer(QWidget):
# plot it
ax = pl.mk_Fourier_ax(self.fCanvas.fig, self.time_unit, self.show_T)
pl.Fourier_spec(ax, self.fft_freqs, self.fpower, self.show_T)
self.fCanvas.fig.subplots_adjust(left = 0.15)
# self.fCanvas.fig.tight_layout()
main_layout = QGridLayout()
main_layout.addWidget(self.fCanvas,0,0,9,1)
......
......@@ -960,7 +960,7 @@ class DataViewer(QWidget):
if self.cb_use_envelope2.isChecked():
L = self.get_L(self.L_edit)
signal = pyboat.normalize_with_envelope(signal, self.L, self.dt)
signal = pyboat.normalize_with_envelope(signal, L, self.dt)
# periods or frequencies?
if self.cb_FourierT.isChecked():
......
......@@ -608,7 +608,7 @@ class SynthSignalGen(QWidget):
print("L ValueError", text)
pass
# transform to sampling intervals
# still in sampling interval units
self.L = int(L)
if self.debug:
......@@ -1076,7 +1076,7 @@ class SynthSignalGen(QWidget):
return
elif self.cb_use_envelope2.isChecked():
signal = pyboat.normalize_with_envelope(signal, self.L)
signal = pyboat.normalize_with_envelope(signal, self.L, self.dt)
# periods or frequencies?
if self.cb_FourierT.isChecked():
......
......@@ -19,7 +19,7 @@ time_unit = 's'
eps = 0.5 # noise intensity
alpha = 0.4 # AR1 parameter
Nt = 500 # number of samples
Nt = 400 # number of samples
signal1 = ssg.create_noisy_chirp(T1 = 30 / dt, T2 = 50 / dt, Nt = Nt, eps = eps, alpha = alpha)
......@@ -37,7 +37,7 @@ detr_signal = signal - trend
# plot the signal/trend
tvec = np.arange(len(signal)) * dt
ax = pl.mk_signal_ax(time_unit = 's')
pl.draw_signal(ax, tvec, signal)
pl.draw_signal(ax, tvec, signal, label = '2 chirps')
# pl.draw_detrended(ax, tvec, signal)
pl.draw_trend(ax, tvec, trend)
ppl.legend(ncol = 2)
......@@ -49,7 +49,7 @@ modulus, wlet = pyboat.compute_spectrum(signal, dt, periods)
# plot spectrum and ridge
ax_sig, ax_spec = pl.mk_signal_modulus_ax(time_unit)
pl.plot_signal_modulus((ax_sig, ax_spec), tvec, signal, modulus, periods)
ppl.tight_layout()
# --- compute spectrum on the detrended signal ---
modulus, wlet = pyboat.compute_spectrum(detr_signal, dt, periods)
......@@ -57,16 +57,19 @@ modulus, wlet = pyboat.compute_spectrum(detr_signal, dt, periods)
# get maximum ridge
ridge_ys = pyboat.get_maxRidge_ys(modulus)
# evaluate along the ridge
# evaluate along the ridge, ridge_results is a pandas DataFrame
ridge_results = pyboat.eval_ridge(ridge_ys, wlet, signal, periods, tvec)
# plot spectrum and ridge
ax_sig2, ax_spec2 = pl.mk_signal_modulus_ax(time_unit)
pl.plot_signal_modulus((ax_sig2, ax_spec2), tvec, signal, modulus, periods)
pl.plot_signal_modulus((ax_sig2, ax_spec2), tvec, detr_signal, modulus, periods)
pl.draw_Wavelet_ridge(ax_spec2, ridge_results)
ppl.tight_layout()
ppl.savefig('detr_signal_spec.png')
# plot readout
pl.plot_readout(ridge_results)
ppl.savefig('detr_signal_readout.png')
......@@ -16,7 +16,7 @@ time_unit = 's'
eps = 0.5 # noise intensity
alpha = 0.4 # AR1 parameter
Nt = 500 # number of samples
Nt = 400 # number of samples
signal1 = ssg.create_noisy_chirp(T1 = 30 / dt, T2 = 50 / dt, Nt = Nt, eps = eps, alpha = alpha)
......@@ -43,6 +43,10 @@ wAn.compute_spectrum(signal)
wAn.get_maxRidge(power_thresh = 5)
wAn.draw_Ridge()
ppl.savefig('detr_signal_spec.png')
wAn.plot_readout(draw_coi = True)
rd = wAn.ridge_data
ppl.savefig('detr_signal_readout.png')
rd = wAn.ridge_data # this is a pandas DataFrame holding the ridge results
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment