Bye, Bye, Bye (SciPy)
Replace SciPy functionality with NumPy equivalents to escape dependency hell.
libatlas is a dependency for installing precompiled SciPy packages for python, but the latest Raspbian/Debian 13 no longer have that package. Instead of requiring the heavy SciPy dependency replace the functionality with direct NumPy calls / a little bit of wrapper code.
- refactor: Replace SciPy pearsonr correlation coefficent with NumPy functionality
- refactor: Use numpy for linear regression calculations
- refactor: Replace scipy.spectrogram with numpy fft
- refactor: Bump numpy version, remove scipy dependency
- refactor: Stop installing scipy sytem dependencies
- docs: Remove scipy from list of dependencies
Summary by Sourcery
Remove SciPy dependency by reimplementing correlation, regression, and spectrogram functionality with pure NumPy, update dependency versions and installation scripts, and clean up documentation accordingly
Enhancements:
- Replace Pearson correlation using SciPy with NumPy's corrcoef
- Replace linear regression using SciPy stats with NumPy polynomial fitting
- Implement FFT-based spectrogram using NumPy in a new helper module instead of SciPy signal
- Remove installation of SciPy and related system libraries (libatlas, libopenblas)
Build:
- Bump NumPy version constraints and drop SciPy from requirements.txt
Documentation:
- Remove SciPy from the list of dependencies in documentation
Reviewer's Guide
This PR removes the SciPy dependency by migrating spectral, regression, and correlation routines to NumPy-based implementations and streamlines dependency management by updating requirements, install scripts, and documentation.
Class diagram for updated spectrogram computation (NumPy-based)
classDiagram
class SpectrogramHelper {
+compute_spectrogram(data)
+spectrogram(x, fs, window, nperseg, noverlap)
+_fft_helper(x, window, nperseg, noverlap, nfft, sides)
+_detrend_constant(data)
}
SpectrogramHelper <|-- compute_spectrogram
SpectrogramHelper <|-- spectrogram
SpectrogramHelper <|-- _fft_helper
SpectrogramHelper <|-- _detrend_constant
Class diagram for updated linear regression direction calculation
classDiagram
class AxesMapComputation {
+_linear_regression_direction(position_x, position_y, position_z)
}
class Polynomial {
+fit(time, position, 1)
+convert()
}
AxesMapComputation --> Polynomial: uses
Class diagram for updated correlation calculation in BeltsComputation
classDiagram
class BeltsComputation {
+compute()
}
BeltsComputation --> numpy: uses corrcoef
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Migrate spectrogram generation from SciPy to a custom NumPy FFT–based implementation |
|
shaketune/helpers/common_func.pyshaketune/helpers/spectrogram.py |
| Replace SciPy linear regression with NumPy Polynomial.fit |
|
shaketune/graph_creators/computations/axes_map_computation.py |
| Swap SciPy’s pearsonr with NumPy’s corrcoef for correlation computation |
|
shaketune/graph_creators/computations/belts_computation.py |
| Remove SciPy from dependencies and clean up installation steps |
|
requirements.txtinstall.shdocs/cli_usage.md |
Tips and commands
Interacting with Sourcery
-
Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
-
Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. -
Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. -
Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. -
Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. -
Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. -
Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
@Frix-x when will this be accepted?
Happy to test this on my machine if we think it's ready
Thank you so much @mjonuschat for this contribution! 🙏
As we discussed on Discord, I've created a hybrid solution merging your more generic approach with some low-RAM optimizations targeting Raspberry Pi (using a pre-allocated buffer approach instead of stride tricks for the spectrogram).
Your changes are now merged into the develop branch. Thanks again for the collaboration!