Skip to content

Commit

Permalink
implemented MAD using scipy (#153)
Browse files Browse the repository at this point in the history
* implemented MAD using scipy

* refactored _mad using scipy

* added changelog entry

* added changelogs
  • Loading branch information
Ayush-Devs authored Aug 24, 2024
1 parent 82390ac commit 6e5c369
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ authors:
- given-names: Nabil
family-names: Alibou
affiliation: 'Biotrial, Neuroscience Department, Rennes, France'
- given-names: Ayush
family-names: Agarwal
affiliation: 'Techno India University, India'
type: software
repository-code: 'https://github.com/sappelhoff/pyprep'
license: MIT
Expand Down
2 changes: 2 additions & 0 deletions docs/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Version 0.5.0 (Unreleased)
Changelog
~~~~~~~~~
- :meth:`~pyprep.NoisyChannels.find_bad_by_nan_flat` now accepts a ``flat_threshold`` argument, by `Nabil Alibou`_ (:gh:`144`)
- changed _mad function in utils.py to use median_abs_deviation from the sciPy module, by `Ayush Agarwal`_ (:gh:`153`).

Bug
~~~
Expand Down Expand Up @@ -234,3 +235,4 @@ Changelog
.. _Mathieu Scheltienne: https://github.com/mscheltienne
.. _Ole Bialas: https://github.com/OleBialas
.. _Nabil Alibou: https://github.com/nabilalibou
.. _Ayush Agarwal: https://github.com/Ayush-Devs
7 changes: 2 additions & 5 deletions pyprep/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from psutil import virtual_memory
from scipy import linalg
from scipy.signal import firwin, lfilter, lfilter_zi
from scipy.stats import median_abs_deviation


def _union(list1, list2):
Expand Down Expand Up @@ -487,11 +488,7 @@ def _mad(x, axis=None):
raise ValueError(e.format(x.ndim))

# Calculate the median absolute deviation from the median
med = np.median(x, axis=axis)
if axis == 1:
med = med.reshape(-1, 1) # Transposes array to allow subtraction below
mad = np.median(np.abs(x - med), axis=axis)

mad = median_abs_deviation(x, axis=axis)
return mad


Expand Down

0 comments on commit 6e5c369

Please sign in to comment.