PyNumDiff
PyNumDiff: A Python package for numerical differentiation of noisy time-series data - Published in JOSS (2022)
Science Score: 100.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 7 DOI reference(s) in README and JOSS metadata -
✓Academic publication links
Links to: ieee.org, joss.theoj.org, zenodo.org -
✓Committers with academic emails
1 of 8 committers (12.5%) from academic institutions -
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Keywords from Contributors
Scientific Fields
Repository
Methods for numerical differentiation of noisy data in python
Basic Info
Statistics
- Stars: 122
- Watchers: 5
- Forks: 20
- Open Issues: 3
- Releases: 9
Metadata Files
README.md
PyNumDiff
Python methods for numerical differentiation of noisy data, including multi-objective optimization routines for automated parameter selection.
Introduction
PyNumDiff is a Python package that implements various methods for computing numerical derivatives of noisy data, which can be a critical step in developing dynamic models or designing control. There are seven different families of methods implemented in this repository:
- convolutional smoothing followed by finite difference calculation
- polynomial-fit-based methods
- iterated finite differencing
- total variation regularization of a finite difference derivative
- Kalman (RTS) smoothing
- basis-function-based methods
- linear local approximation with linear model
Most of these methods have multiple parameters, so we take a principled approach and propose a multi-objective optimization framework for choosing parameters that minimize a loss function to balance the faithfulness and smoothness of the derivative estimate. For more details, refer to this paper.
Installing
Dependencies are listed in pyproject.toml. They include the usual suspects like numpy and scipy, but also optionally cvxpy.
The code is compatible with >=Python 3.10. Install from PyPI with pip install pynumdiff, from source with pip install git+https://github.com/florisvb/PyNumDiff, or from local download with pip install .. Call pip install pynumdiff[advanced] to automatically install optional dependencies from the advanced list, like CVXPY.
Usage
For more details, read our Sphinx documentation. The basic pattern of all differentiation methods is:
python
somethingdiff(x, dt, **kwargs)
where x is data, dt is a step size, and various keyword arguments control the behavior. Some methods support variable step size, in which case the second parameter is renamed _t and can receive either a constant step size or an array of values to denote sample locations.
You can provide the parameters: ```python from pynumdiff.submodule import method
xhat, dxdthat = method(x, dt, param1=val1, param2=val2, ...)
```
Or you can find parameter by calling the multi-objective optimization algorithm from the optimize module:
```python
from pynumdiff.optimize import optimize
estimate cutoff_frequency by (a) counting the number of true peaks per second in the data or (b) look at power spectra and choose cutoff
tvgamma = np.exp(-1.6np.log(cutoff_frequency) -0.71np.log(dt) - 5.1) # see https://ieeexplore.ieee.org/abstract/document/9241009
params, val = optimize(somethingdiff, x, dt, tvgamma=tvgamma, # smoothness hyperparameter which defaults to None if dxdttruth given dxdttruth=None, # give ground truth data if available, in which case tvgamma goes unused searchspaceupdates={'param1':[vals], 'param2':[vals], ...})
print('Optimal parameters: ', params)
xhat, dxdthat = somethingdiff(x, dt, **params)
``
If nosearchspaceupdatesis given, a default search space is used. See the top of_optimize.py`.
The following heuristic works well for choosing tvgamma, where cutoff_frequency is the highest frequency content of the signal in your data, and dt is the timestep: tvgamma=np.exp(-1.6*np.log(cutoff_frequency)-0.71*np.log(dt)-5.1). Larger values of tvgamma produce smoother derivatives. The value of tvgamma is largely universal across methods, making it easy to compare method results. Be aware the optimization is a fairly heavy process.
Notebook examples
Much more extensive usage is demonstrated in Jupyter notebooks: * Differentiation with different methods: 1basictutorial.ipynb * Parameter Optimization with known ground truth (only for demonstration purpose): 2aoptimizingparameterswithdxdt_known.ipynb * Parameter Optimization with unknown ground truth: 2boptimizingparameterswithdxdt_unknown.ipynb * Automatic method suggestion: 3automaticmethod_suggestion.ipynb
Repo Structure
.github/workflowscontains.yamlthat configures our GitHub Actions continuous integration (CI) runs.docs/containsmakefiles and.rstfiles to govern the waysphinxbuilds documentation, either locally by navigating to this folder and callingmake htmlor in the cloud byreadthedocs.io.examples/contains Jupyter notebooks that demonstrate some usage of the library.pynumdiff/contains the source code. For a full list of modules and further navigation help, see the readme in this subfolder..editorconfigensures tabs are displayed as 4 characters wide..gitignoreensures files generated by localpip installs, Jupyter notebook runs, caches from code runs, virtual environments, and more are not picked up bygitand accidentally added to the repo..pylintrcconfigurespylint, a tool for autochecking code quality..readthedocs.yamlconfiguresreadthedocsand is necessary for documentation to get auto-rebuilt.CITATION.cffis citation information for the Journal of Open-Source Software (JOSS) paper associated with this project.LICENSE.txtallows free usage of this project.README.mdis the text you're reading, hello.linting.pyis a script to runpylint.pyproject.tomlgoverns how this package is set up and installed, including dependencies.
Citation
See CITATION.cff file as well as the following references.
PyNumDiff python package:
@article{PyNumDiff2022,
doi = {10.21105/joss.04078},
url = {https://doi.org/10.21105/joss.04078},
year = {2022},
publisher = {The Open Journal},
volume = {7},
number = {71},
pages = {4078},
author = {Floris van Breugel and Yuying Liu and Bingni W. Brunton and J. Nathan Kutz},
title = {PyNumDiff: A Python package for numerical differentiation of noisy time-series data},
journal = {Journal of Open Source Software}
}
Optimization algorithm:
@article{ParamOptimizationDerivatives2020,
doi={10.1109/ACCESS.2020.3034077}
author={F. {van Breugel} and J. {Nathan Kutz} and B. W. {Brunton}},
journal={IEEE Access},
title={Numerical differentiation of noisy data: A unifying multi-objective optimization framework},
year={2020}
}
Running the tests
We are using GitHub Actions for continuous intergration testing.
Run tests locally by navigating to the repo in a terminal and calling ```bash
pytest -s ```
Add the flag --plot to see plots of the methods against test functions. Add the flag --bounds to print $\log$ error bounds (useful when changing method behavior).
License
This project utilizes the MIT LICENSE. 100% open-source, feel free to utilize the code however you like.
Owner
- Name: Floris van Breugel
- Login: florisvb
- Kind: user
- Location: Reno, NV
- Company: University of Nevada, Reno
- Website: https://florisvanbreugel.com/
- Repositories: 56
- Profile: https://github.com/florisvb
I use software to study insect behavior and biomechanics. I am currently an Asst. Prof. in Mech. Eng. at the University of Nevada, Reno.
JOSS Publication
PyNumDiff: A Python package for numerical differentiation of noisy time-series data
Authors
Department of Mechanical Engineering, University of Nevada at Reno
Department of Applied Mathematics, University of Washington
Department of Biology, University of Washington
Department of Applied Mathematics, University of Washington
Tags
numerical differentiation denoising dynamics time series machine learningCitation (CITATION.cff)
cff-version: 1.1.0
message: "If you use this software, please at least cite the JOSS publication referenced below."
authors:
- family-names: van Breugel
given-names: Floris
- family-names: Liu
given-names: Yuying
- family-names: Brunton
given-names: Bing W.
- family-names: Kutz
given-names: J. Nathan
title: "PyNumDiff: A Python package for numerical differentiation of noisy time-series data"
version: 0.1.2.4
date-released: 2022-03-21
doi: 10.5281/zenodo.6374098
references:
- type: article
title: "PyNumDiff: A Python package for numerical differentiation of noisy time-series data"
authors:
- family-names: van Breugel
given-names: Floris
- family-names: Liu
given-names: Yuying
- family-names: Brunton
given-names: Bing W.
- family-names: Kutz
given-names: J. Nathan
journal: Journal of Open Source Software
year: 2022
volume: 7
number: 71
pages: 4078
doi: 10.21105/joss.04078
GitHub Events
Total
- Create event: 34
- Release event: 1
- Issues event: 68
- Watch event: 11
- Delete event: 31
- Member event: 1
- Issue comment event: 106
- Push event: 136
- Pull request review event: 98
- Pull request review comment event: 97
- Pull request event: 66
- Fork event: 4
Last Year
- Create event: 34
- Release event: 1
- Issues event: 68
- Watch event: 11
- Delete event: 31
- Member event: 1
- Issue comment event: 106
- Push event: 136
- Pull request review event: 98
- Pull request review comment event: 97
- Pull request event: 66
- Fork event: 4
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Floris van Breugel | f****b@g****m | 180 |
| pavelkomarov | p****v@g****m | 142 |
| luckystarufo | l****o@g****m | 56 |
| dependabot[bot] | 4****] | 28 |
| Jake Stevens-Haas | 3****s | 7 |
| asteppke | a****e@g****m | 2 |
| Daniel S. Katz | d****z@i****g | 2 |
| fossabot | b****s@f****o | 1 |
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 61
- Total pull requests: 112
- Average time to close issues: 2 months
- Average time to close pull requests: 2 months
- Total issue authors: 7
- Total pull request authors: 8
- Average comments per issue: 1.69
- Average comments per pull request: 0.59
- Merged pull requests: 78
- Bot issues: 0
- Bot pull requests: 48
Past Year
- Issues: 44
- Pull requests: 70
- Average time to close issues: 18 days
- Average time to close pull requests: 12 days
- Issue authors: 2
- Pull request authors: 4
- Average comments per issue: 1.39
- Average comments per pull request: 0.76
- Merged pull requests: 43
- Bot issues: 0
- Bot pull requests: 12
Top Authors
Issue Authors
- pavelkomarov (43)
- pmli (11)
- billtubbs (3)
- Jacob-Stevens-Haas (1)
- aminihamed (1)
- sameervk (1)
- calebclayreagor (1)
Pull Request Authors
- pavelkomarov (54)
- dependabot[bot] (48)
- asteppke (2)
- dguisti (2)
- Jacob-Stevens-Haas (2)
- danielskatz (2)
- luckystarufo (1)
- fossabot (1)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- actions/checkout v3 composite
- actions/setup-python v3 composite
- matplotlib *
- numpy *
- scipy *
