Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented MAD using scipy #153

Merged
merged 4 commits into from
Aug 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 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 @@ -480,19 +481,14 @@ def _mad(x, axis=None):
the MAD for each index along the specified axis.

"""
# Ensure array is either 1D or 2D
Ayush-Devs marked this conversation as resolved.
Show resolved Hide resolved
x = np.asarray(x)
if x.ndim > 2:
e = "Only 1D and 2D arrays are supported (input has {0} dimensions)"
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)

return mad
# Calculate the MAD using SciPy
mad = median_abs_deviation(x, axis=axis, keepdims=True)
return mad.squeeze() # Remove singleton dimensions if needed


def _filter_design(N_order, amp, freq):
Expand Down
Loading