Skip to content

Commit

Permalink
Who looks at examples, eh?
Browse files Browse the repository at this point in the history
  • Loading branch information
laszukdawid committed Mar 16, 2024
1 parent ee52ab3 commit 54158e6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 28 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
LINT_TARGET_DIRS := PyEMD doc example

test:
python -m PyEMD.tests.test_all
Expand All @@ -10,8 +11,11 @@ doc:
cd doc && make html

format:
python -m black PyEMD doc
python -m black $(LINT_TARGET_DIRS)

lint-check:
python -m isort --check PyEMD
python -m black --check PyEMD doc
python -m black --check $(LINT_TARGET_DIRS)

perf/build:
docker build -t pyemd-perf -f perf_test/Dockerfile .
2 changes: 1 addition & 1 deletion example/eemd_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
S += 5 * sin(11, 2.7)
S += 3 * sin(14, 1.6)
S += 1 * np.sin(4 * 2 * np.pi * (t - 0.8) ** 2)
S += t ** 2.1 - t
S += t**2.1 - t

# Assign EEMD to `eemd` variable
eemd = EEMD()
Expand Down
7 changes: 5 additions & 2 deletions example/emd_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
a lot of the same computation within a single execution. For a single script
with a single EMD execution, it's still much more performant to use normal EMD.
"""

import time
import numpy as np

Expand All @@ -17,11 +18,13 @@
t = get_timeline(len(s), s.dtype)
n_repeat = 20

print(f"""Comparing EEMD execution on a larger signal with classic and JIT EMDs.
print(
f"""Comparing EEMD execution on a larger signal with classic and JIT EMDs.
Signal is random (uniform) noise of length: {len(s)}. The test is done by executing
EEMD with either classic or JIT EMD {n_repeat} times and taking the average. Such
setup favouries JitEMD which is compiled once and then reused {n_repeat-1} times.
Compiltion is quite costly.""")
Compiltion is quite costly."""
)

time_0 = time.time()
emd = EMD()
Expand Down
43 changes: 21 additions & 22 deletions example/example_spline_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from PyEMD.utils import get_timeline


def test_spline(X,T,s_kind):
def test_spline(X, T, s_kind):
"""
Test the fitting with the given spline.
Expand Down Expand Up @@ -38,11 +38,11 @@ def test_spline(X,T,s_kind):

emd = EMD()
emd.spline_kind = s_kind
max_env, min_env, eMax, eMin = emd.extract_max_min_spline(T,X)
max_env, min_env, eMax, eMin = emd.extract_max_min_spline(T, X)
return max_env, min_env, eMax, eMin


def test_akima(X,T,ax):
def test_akima(X, T, ax):
"""
test the fitting with akima spline.
Expand All @@ -65,15 +65,15 @@ def test_akima(X,T,ax):

max_env, min_env, eMax, eMin = test_spline(X, T, "akima")

ax.plot(max_env,label='max akima')
ax.plot(min_env,label='min akima')
ax.plot(max_env, label="max akima")
ax.plot(min_env, label="min akima")
return eMax, eMin


def test_cubic(X,T,ax):
def test_cubic(X, T, ax):
"""
test the fitting with cubic spline
Parameters
----------
see 'test_akima'
Expand All @@ -85,14 +85,14 @@ def test_cubic(X,T,ax):

max_env, min_env, eMax, eMin = test_spline(X, T, "cubic")

ax.plot(max_env,label='max cubic')
ax.plot(min_env,label='min cubic')
ax.plot(max_env, label="max cubic")
ax.plot(min_env, label="min cubic")
return eMax, eMin


def test_pchip(X,T,ax):
def test_pchip(X, T, ax):
"""
test the fitting with pchip spline
test the fitting with pchip spline
'Piecewise Cubic Hermite Interpolating Polynomial'
Parameters
Expand All @@ -106,14 +106,14 @@ def test_pchip(X,T,ax):

max_env, min_env, eMax, eMin = test_spline(X, T, "pchip")

ax.plot(max_env,label='max pchip')
ax.plot(min_env,label='min pchip')
ax.plot(max_env, label="max pchip")
ax.plot(min_env, label="min pchip")
return eMax, eMin


def test_cubic_hermite(X,T,ax):
def test_cubic_hermite(X, T, ax):
"""
test the fitting with cubic_hermite spline
test the fitting with cubic_hermite spline
Parameters
----------
Expand All @@ -126,24 +126,23 @@ def test_cubic_hermite(X,T,ax):

max_env, min_env, eMax, eMin = test_spline(X, T, "cubic_hermite")

ax.plot(max_env,label='max cubic_hermite')
ax.plot(min_env,label='min cubic_hermite')
ax.plot(max_env, label="max cubic_hermite")
ax.plot(min_env, label="min cubic_hermite")
return eMax, eMin



if __name__ == "__main__":

X = np.random.normal(size=200)
T = get_timeline(len(X),X.dtype)
T = get_timeline(len(X), X.dtype)
T = EMD._normalize_time(T)

fig, ax = plt.subplots()
ax.plot(X,'--',lw=2,c='k')
ax.plot(X, "--", lw=2, c="k")
emax_akima, emin_akima = test_akima(X, T, ax)
emax_cubic, emin_cubic = test_cubic(X, T, ax)
emax_pchip, emin_pchip = test_pchip(X, T, ax)
emax_chermite, emin_chermite = test_cubic_hermite(X, T, ax)
ax.plot(emax_akima[0],emax_akima[1],'--')
ax.plot(emax_akima[0], emax_akima[1], "--")
ax.legend()
plt.show()
plt.show()
2 changes: 1 addition & 1 deletion example/hht_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def instant_phase(imfs):
S += 5 * sin(11, 2.7)
S += 3 * sin(14, 1.6)
S += 1 * np.sin(4 * 2 * np.pi * (t - 0.8) ** 2)
S += t ** 2.1 - t
S += t**2.1 - t

# Compute IMFs with EMD
emd = EMD()
Expand Down

0 comments on commit 54158e6

Please sign in to comment.