Skip to content

Commit

Permalink
ENH: Remove resampy dependency. Resample is now done with scipy.signa…
Browse files Browse the repository at this point in the history
…l module
  • Loading branch information
juansulloa committed Jan 25, 2025
1 parent 2823930 commit 5e2aa9c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Installation instructions
-------------------------

**scikit-maad** is built on top of popular Python packages for scientific computing and digital signal processing, such as numpy, scipy, pandas, scikit-image and resampy. Package managers like pip and conda can take care of these automatically.
**scikit-maad** is built on top of popular Python packages for scientific computing and digital signal processing, such as numpy, scipy, pandas, scikit-image. Package managers like pip and conda can take care of these automatically.


1. Standard installation
Expand Down
15 changes: 6 additions & 9 deletions maad/sound/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
# Import external modules
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.signal import hilbert
from scipy.signal import periodogram, welch
import scipy
import resampy
from warnings import warn

# import internal modules
Expand Down Expand Up @@ -219,7 +217,7 @@ def spectrum(s, fs, nperseg=256, noverlap=None, nfft=None, window='hann', method
return pxx, f_idx

#%%
def resample(s, fs, target_fs, res_type = 'kaiser_best', **kwargs):
def resample(s, fs, target_fs, res_type = 'scipy_poly', **kwargs):
"""
Changes the sample rate of an audio file or any time series.
Expand All @@ -242,8 +240,8 @@ def resample(s, fs, target_fs, res_type = 'kaiser_best', **kwargs):
'scipy_poly' Resample using polyphase filtering and an FIR filter.
kwargs : additional keyword arguments
If `res_type='sinc_window'`, additional keyword arguments to pass to
`resampy.resample`.
If `res_type='scipy'`, additional keyword arguments to pass to
`scipy.signal.resample`.
Returns
-------
Expand All @@ -252,14 +250,14 @@ def resample(s, fs, target_fs, res_type = 'kaiser_best', **kwargs):
See Also
--------
resampy.resample
scipy.signal.resample
Examples
--------
Resample an audio file from sample rate of 44100 kHz to 22050.
>>> from maad import sound
>>> s, fs = sound.load('../data/spinetail.wav')
>>> s_resamp = sound.resample(s, fs, target_fs=fs/2)
>>> print('Number of samples - original audio:', s.shape[0],
Expand All @@ -286,11 +284,10 @@ def resample(s, fs, target_fs, res_type = 'kaiser_best', **kwargs):
res_data = scipy.signal.resample_poly(s, num, den)

elif res_type in ('kaiser_best', 'kaiser_fast'):
warn("Methods 'kaiser_fast' and 'kaiser_best' are deprecated and will be removed from future versions.", DeprecationWarning)
res_data = resampy.resample(s, fs, target_fs, filter=res_type, axis=-1, **kwargs)
raise ValueError("'kaiser_best' and 'kaiser_fast' methods are deprecated. Valid resample methods are 'scipy', 'scipy_poly', not res_type={}".format(res_type))

else:
raise ValueError("Valid resample methods are 'scipy', 'scipy_poly', 'kaiser_best', 'kaiser_fast', not res_type={}".format(res_type))
raise ValueError("Valid resample methods are 'scipy', 'scipy_poly', not res_type={}".format(res_type))

return np.ascontiguousarray(res_data, dtype=s.dtype)

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ dependencies = [
"scipy >=1.8",
"scikit-image >=0.19",
"pandas >=1.5",
"resampy >=0.4",
"matplotlib >=3.6"
]
classifiers = [
Expand Down
5 changes: 1 addition & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ scikit-image>=0.19
pandas>=1.5

# -- plotting -- #
matplotlib>=3.6

# -- resample -- #
resampy>=0.4
matplotlib>=3.6

0 comments on commit 5e2aa9c

Please sign in to comment.