Skip to content

Commit

Permalink
style: trying to convince Codacy that I'm an A coder. But, it's last.
Browse files Browse the repository at this point in the history
  • Loading branch information
laszukdawid committed Sep 5, 2021
1 parent 83ed35c commit f7ce47a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 42 deletions.
1 change: 0 additions & 1 deletion PyEMD/CEEMDAN.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ def ceemdan(self, S: np.ndarray, T: Optional[np.ndarray] = None, max_imf: int =
-------
components : np.ndarray
CEEMDAN components.
"""

scale_s = np.std(S)
Expand Down
2 changes: 1 addition & 1 deletion PyEMD/EMD_matlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def emd(self, S, T=None, maxImf=None):
# Stops after default stopping criteria are meet.
else:

mP,mV,MP,MV, indzer = self.findExtrema(T, imf)
mP, _, MP, _, indzer = self.findExtrema(T, imf)
extNo = len(mP)+len(MP)
nzm = len(indzer)

Expand Down
3 changes: 1 addition & 2 deletions PyEMD/splines.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import division

import numpy as np
from scipy.interpolate import Akima1DInterpolator

Expand All @@ -8,7 +9,6 @@ def cubic_spline_3pts(x, y, T):
Apparently scipy.interpolate.interp1d does not support
cubic spline for less than 4 points.
"""

x0, x1, x2 = x
y0, y1, y2 = y

Expand Down Expand Up @@ -48,4 +48,3 @@ def cubic_spline_3pts(x, y, T):
def akima(X, Y, x):
spl = Akima1DInterpolator(X,Y)
return spl(x)

8 changes: 4 additions & 4 deletions PyEMD/tests/test_extrema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

from __future__ import print_function

import unittest

import numpy as np
from PyEMD import EMD
import unittest


class ExtremaTest(unittest.TestCase):

Expand Down Expand Up @@ -40,9 +42,7 @@ def test_wrong_extrema_detection_type(self):
emd.find_extrema(t, s)

def test_find_extrema_simple(self):
"""
Simple test for extrema.
"""
"""Simple test for extrema."""
emd = EMD()
emd.extrema_detection = "simple"

Expand Down
26 changes: 13 additions & 13 deletions PyEMD/tests/test_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ def test_instantiation2(self):
emd.emd(S, t)
imfs, res = emd.get_imfs_and_residue()
vis = Visualisation(emd)
assert (vis.imfs == imfs).all()
assert (vis.residue == res).all()
self.assertTrue(np.alltrue(vis.imfs == imfs))
self.assertTrue(np.alltrue(vis.residue == res))

def test_check_imfs(self):
vis = Visualisation()
imfs = np.arange(50).reshape(2,25)
res = np.arange(25)
imfs, res = vis._check_imfs(imfs, res, False)
assert len(imfs) == 2
self.assertEqual(len(imfs), 2)

def test_check_imfs2(self):
vis = Visualisation()
Expand All @@ -42,7 +42,11 @@ def test_check_imfs2(self):
def test_check_imfs3(self):
vis = Visualisation()
imfs = np.arange(50).reshape(2,25)
vis._check_imfs(imfs, None, False)

out_imfs, out_res = vis._check_imfs(imfs, None, False)

self.assertTrue(np.alltrue(imfs == out_imfs))
self.assertIsNone(out_res)

def test_check_imfs4(self):
vis = Visualisation()
Expand All @@ -58,8 +62,8 @@ def test_check_imfs5(self):
imfs, res = emd.get_imfs_and_residue()
vis = Visualisation(emd)
imfs2, res2 = vis._check_imfs(imfs, res, False)
assert (imfs == imfs2).all()
assert (res == res2).all()
self.assertTrue(np.alltrue(imfs == imfs2))
self.assertTrue(np.alltrue(res == res2))

def test_plot_imfs(self):
vis = Visualisation()
Expand Down Expand Up @@ -97,7 +101,7 @@ def test_calc_instant_phase3(self):
imfs = emd.emd(S, t)
vis = Visualisation()
with self.assertRaises(AssertionError):
phase = vis._calc_inst_phase(imfs, 0.8)
_ = vis._calc_inst_phase(imfs, 0.8)

def test_calc_instant_freq_alphaNone(self):
t = np.linspace(0, 1, 50)
Expand All @@ -106,7 +110,7 @@ def test_calc_instant_freq_alphaNone(self):
imfs = emd.emd(S, t)
vis = Visualisation()
freqs = vis._calc_inst_freq(imfs, t, False, None)
assert imfs.shape == freqs.shape
self.assertEqual(imfs.shape, freqs.shape)

def test_calc_instant_freq(self):
t = np.linspace(0, 1, 50)
Expand All @@ -115,14 +119,10 @@ def test_calc_instant_freq(self):
imfs = emd.emd(S, t)
vis = Visualisation()
freqs = vis._calc_inst_freq(imfs, t, False, 0.4)
assert imfs.shape == freqs.shape
self.assertEqual(imfs.shape, freqs.shape)

def test_plot_instant_freq(self):
vis = Visualisation()
t = np.arange(20)
with self.assertRaises(AttributeError):
vis.plot_instant_freq(t)


if __name__ == "__main__":
unittest.main()
3 changes: 1 addition & 2 deletions PyEMD/visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ def plot_imfs(self, imfs=None, residue=None, t=None, include_residue=True):
plt.tight_layout()

def plot_instant_freq(self, t, imfs=None, order=False, alpha=None):
"""
Plots and shows instantaneous frequencies for all provided imfs.
"""Plots and shows instantaneous frequencies for all provided imfs.
The necessary parameter is `t` which is the time array used to compute the EMD.
One should pass `imfs` if no `emd` instances is passed when creating the Visualisation object.
Expand Down
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,43 @@
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/f56b6fc3f855476dbaebd3c02ae88f3e)](https://www.codacy.com/gh/laszukdawid/PyEMD/dashboard?utm_source=github.com&utm_medium=referral&utm_content=laszukdawid/PyEMD&utm_campaign=Badge_Grade)
[![DOI](https://zenodo.org/badge/65324353.svg)](https://zenodo.org/badge/latestdoi/65324353)


# PyEMD

## Links

- Online documentation: <https://pyemd.readthedocs.org>
- Issue tracker: <https://github.com/laszukdawid/pyemd/issues>
- Source code repository: <https://github.com/laszukdawid/pyemd>
- Online documentation: <https://pyemd.readthedocs.org>
- Issue tracker: <https://github.com/laszukdawid/pyemd/issues>
- Source code repository: <https://github.com/laszukdawid/pyemd>

## Introduction

This is yet another Python implementation of Empirical Mode
Decomposition (EMD). The package contains many EMD variations and
intends to deliver more in time.

### EMD variations:
- Ensemble EMD (EEMD),
- "Complete Ensemble EMD" (CEEMDAN)
- different settings and configurations of vanilla EMD.
- Image decomposition (EMD2D & BEMD) (experimental, no support)
### EMD variations
- Ensemble EMD (EEMD),
- "Complete Ensemble EMD" (CEEMDAN)
- different settings and configurations of vanilla EMD.
- Image decomposition (EMD2D & BEMD) (experimental, no support)

*PyEMD* allows to use different splines for envelopes, stopping criteria
and extrema interpolation.

### Available splines
- Natural cubic [default]
- Pointwise cubic
- Akima
- Linear
- Natural cubic (**default**)
- Pointwise cubic
- Akima
- Linear

### Available stopping criteria
- Cauchy convergence [default]
- Fixed number of iterations
- Number of consecutive proto-imfs
- Cauchy convergence (**default**)
- Fixed number of iterations
- Number of consecutive proto-imfs

### Extrema detection
- Discrete extrema [default]
- Parabolic interpolation
- Discrete extrema (**default**)
- Parabolic interpolation

## Installation

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def main():
},
)

dist = setup(**setup_params)
_ = setup(**setup_params)

if __name__=="__main__":
main()

0 comments on commit f7ce47a

Please sign in to comment.