spectral-derivatives
Python code to take derivatives by spectral methods using the Chebyshev, Fourier, Legendre, and Bernstein bases.
Science Score: 57.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 3 DOI reference(s) in README -
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (14.1%) to scientific vocabulary
Repository
Python code to take derivatives by spectral methods using the Chebyshev, Fourier, Legendre, and Bernstein bases.
Basic Info
Statistics
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
- Releases: 12
Metadata Files
README.md

This repository is home to Python code that can take spectral derivatives using the Chebyshev, Fourier, Legendre, and Bernstein bases, grounded in some pretty elegant, deep math. That is, given a vector representing samples of a smooth function, the code returns numerical derivatives, indicating slope, curvature, etc. at the sample points of an interpolation built from the basis functions.
When using the Fourier basis, spectral derivatives require periodic boundaries, but the polynomial bases (fastest to fit being the Chebyshev basis) allow arbitrary boundaries, extending the method to a much wider class of functions (albeit best with nonuniform sampling).
This package can be useful any time you want to take a derivative numerically, such as for doing PDE simulations. For taking derivatives of noisy data, spectral methods naturally enable global filtering by weighting basis function contributions, although polynomial bases suffer some weakness.
Note these methods are best for situations when you don't know the generating function of your data; if the generator is known, then autodifferentiation tools like JAX are your friend.
Installation and Usage
The package is a single module containing derivative functions. To install, execute:
shell
python3 -m pip install spectral-derivatives
or from the source code
shell
python3 -m pip install .
You should now be able to
```python
from specderiv import * import numpy as np
xn = np.cos(np.arange(21) * np.pi / 20) # cosine-spaced, includes last point yn = np.sin(xn) # can be periodic or aperiodic on domain [a, b] dyn = chebderiv(yn, x_n, 1)
thn = np.arange(20) * 2*np.pi / 20 # equispaced, excludes last point yn = np.sin(th_n) # must be periodic on domain [a, b) dyn = fourierderiv(yn, thn, 1) ``` For further usage examples, including in higher dimension, see the Jupyter notebooks: Chebyshev, Fourier, Legendre, and Bernstein.
Note that for fastest and most accurate results you should use equispaced samples on an open periodic interval with fourier_deriv and cosine-spaced points with cheb_deriv. legendre_deriv and bern_deriv are slower. All methods support arbitrary domains by internally performing an affine transformation to some canonical domain.
All methods support differentiating multidimensional data along an axis.
References
- Trefethen, N., 2000, Spectral Methods in Matlab, https://epubs.siam.org/doi/epdf/10.1137/1.9780898719598.ch8
- Johnson, S., 2011, Notes on FFT-based differentiation, https://math.mit.edu/~stevenj/fft-deriv.pdf
- Kutz, J.N., 2023, Data-Driven Modeling & Scientific Computation, Ch. 11, https://faculty.washington.edu/kutz/kutzbookv2.pdf
- Breuer, K. & Everson, R., 1990, On the errors incurred calculating derivatives using Chebyshev polynomials, https://doi.org/10.1016/0021-9991(92)90274-3
Owner
- Name: Pavel Komarov
- Login: pavelkomarov
- Kind: user
- Location: Seattle, Salt Lake City, Melbourne FL, Atlanta, Mountain View, Bradenton
- Company: University of Washington, BioIntelliSense, Miim/SafeX/Banjo, Northrop Grumman, Georgia Institute of Technology, Microsoft
- Website: pavelkomarov.com
- Repositories: 26
- Profile: https://github.com/pavelkomarov
I like people, math, reading, getting lost in a problem, code when it isn't painful, skiing, climbing, riding my bike, music, and progress.
Citation (CITATION.md)
# Citing Spectral-Derivatives
If you use this project in publications, please cite the following:
@misc{spectral-derivatives,
title={Spectral derivatives software},
author={Pavel Komarov},
url={http://www.github.com/pavelkomarov/spectral-derivatives},
note={Version 0.1},
year={2024}}
If you wish to cite the mathematical explanation, use:
@article{spectral-derivatives-math
title={Spectral Derivatives},
author={Pavel Komarov},
url={https://pavelkomarov.com/spectral-derivatives/math.pdf},
year={2024}}
GitHub Events
Total
- Create event: 20
- Commit comment event: 1
- Release event: 18
- Issues event: 36
- Watch event: 5
- Delete event: 6
- Issue comment event: 43
- Push event: 516
- Fork event: 1
Last Year
- Create event: 20
- Commit comment event: 1
- Release event: 18
- Issues event: 36
- Watch event: 5
- Delete event: 6
- Issue comment event: 43
- Push event: 516
- Fork event: 1
Issues and Pull Requests
Last synced: 10 months ago
All Time
- Total issues: 15
- Total pull requests: 0
- Average time to close issues: about 1 month
- Average time to close pull requests: N/A
- Total issue authors: 1
- Total pull request authors: 0
- Average comments per issue: 2.8
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 15
- Pull requests: 0
- Average time to close issues: about 1 month
- Average time to close pull requests: N/A
- Issue authors: 1
- Pull request authors: 0
- Average comments per issue: 2.8
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- pavelkomarov (15)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 40 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 13
- Total maintainers: 1
pypi.org: spectral-derivatives
Functions to take spectral derivatives with the Chebyshev and Fourier bases
- Documentation: https://pavelkomarov.com/spectral-derivatives
- License: BSD License
-
Latest release: 0.7.4
published over 1 year ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v4 composite
- actions/setup-python v5 composite
- peaceiris/actions-gh-pages v4 composite
- tj-actions/changed-files v45 composite
- actions/checkout v4 composite
- actions/setup-python v5 composite
- matplotlib *
- numpy *
- pytest *
- scipy *