ndsplines
ndsplines: A Python Library for Tensor-Product B-Splines of Arbitrary Dimension - Published in JOSS (2019)
Science Score: 93.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 4 DOI reference(s) in README and JOSS metadata -
✓Academic publication links
Links to: joss.theoj.org, zenodo.org -
○Committers with academic emails
-
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Keywords from Contributors
brain-computer-interface
electrophysiology
mesh
Scientific Fields
Mathematics
Computer Science -
84% confidence
Last synced: 6 months ago
·
JSON representation
Repository
Multi-dimensional B-splines
Basic Info
- Host: GitHub
- Owner: kb-press
- License: other
- Language: Python
- Default Branch: master
- Homepage: https://ndsplines.readthedocs.io
- Size: 347 KB
Statistics
- Stars: 33
- Watchers: 4
- Forks: 9
- Open Issues: 14
- Releases: 7
Created almost 7 years ago
· Last pushed 6 months ago
Metadata Files
Readme
License
readme.rst
=========
ndsplines
=========
.. image:: https://img.shields.io/pypi/v/ndsplines.svg
:alt: PyPI Package latest release
:target: https://pypi.python.org/pypi/ndsplines
.. image:: https://github.com/kb-press/ndsplines/actions/workflows/test.yml/badge.svg
:target: https://github.com/kb-press/ndsplines/ations/workflows/test.yml
:alt: GitHub Actions Build
.. image:: https://readthedocs.org/projects/ndsplines/badge/?version=latest
:target: https://ndsplines.readthedocs.io/en/latest/?badge=latest
:alt: Documentation status
.. image:: https://joss.theoj.org/papers/10.21105/joss.01745/status.svg
:target: https://doi.org/10.21105/joss.01745
:alt: JOSS DOI
.. image:: https://zenodo.org/badge/172368121.svg
:target: https://zenodo.org/badge/latestdoi/172368121
:alt: Zenodo DOI
This is a Python package for multivariate B-splines with a performant Cython
implementation. For a mathematical overview of tensor product B-splines, see the
|Splines| page of the documentation.
The primary goal of this package is to provide a unified API for tensor product
splines of arbitrary input and output dimension. For a list of related packages
see the |Comparisons| page.
.. |Splines| replace:: `Splines`_
.. _Splines: https://ndsplines.readthedocs.io/en/latest/math.html
.. |Comparisons| replace:: `Comparisons`_
.. _Comparisons: https://ndsplines.readthedocs.io/en/latest/compare.html
Installation
------------
``ndsplines`` is available on PyPI as well as conda-forge.
pip
^^^
Install ``ndsplines`` with pip::
$ pip install ndsplines
Wheels are provided for a range of Python versions and platforms, so no
compilation is required to get the better-performing Cython-based implementation
in many cases.
If no matching wheel is found, pip will install build dependencies and attempt
to compile the Cython-based extension module.
conda
^^^^^
Install ``ndsplines`` with conda::
$ conda install -c conda-forge ndsplines
Usage
-----
The easiest way to use ``ndsplines`` is to use one of the ``make_*``
functions: ``make_interp_spline``, ``make_interp_spline_from_tidy``, or
``make_lsq_spline``, which return an ``NDSpline`` object which can be used to
evaluate the spline. For example, suppose we have data over a two-dimensional
mesh.
.. code:: python
import ndsplines
import numpy as np
# generate grid of independent variables
x = np.array([-1, -7/8, -3/4, -1/2, -1/4, -1/8, 0, 1/8, 1/4, 1/2, 3/4, 7/8, 1])*np.pi
y = np.array([-1, -1/2, 0, 1/2, 1])
meshx, meshy = np.meshgrid(x, y, indexing='ij')
gridxy = np.stack((meshx, meshy), axis=-1)
# evaluate a function to interpolate over input grid
meshf = np.sin(meshx) * (meshy-3/8)**2 + 2
We can then use ``make_interp_spline`` to create an interpolating spline and
evaluate it over a denser mesh.
.. code:: python
# create the interpolating spline
interp = ndsplines.make_interp_spline(gridxy, meshf)
# generate denser grid of independent variables to interpolate
sparse_dense = 2**7
xx = np.concatenate([np.linspace(x[i], x[i+1], sparse_dense) for i in range(x.size-1)])
yy = np.concatenate([np.linspace(y[i], y[i+1], sparse_dense) for i in range(y.size-1)])
gridxxyy = np.stack(np.meshgrid(xx, yy, indexing='ij'), axis=-1)
# evaluate spline over denser grid
meshff = interp(gridxxyy)
Generally, we construct data so that the first ``ndim`` axes index the
independent variables and the remaining axes index output. This is
a generalization of using rows to index time and columns to index output
variables for time-series data.
We can also create an interpolating spline from a `tidy data`_ format:
.. code:: python
tidy_data = np.dstack((gridxy, meshf)).reshape((-1,3))
tidy_interp = ndsplines.make_interp_spline_from_tidy(
tidy_data,
[0,1], # columns to use as independent variable data
[2] # columns to use as dependent variable data
)
print("\nCoefficients all same?",
np.all(tidy_interp.coefficients == interp.coefficients))
print("Knots all same?",
np.all([np.all(k0 == k1) for k0, k1 in zip(tidy_interp.knots, interp.knots)]))
Note however, that the tidy dataset must be over a structured rectangular grid
equivalent to the N-dimensional tensor product representation. Also note that
Pandas dataframes can be used, in which case lists of column names can be used
instead of lists of column indices.
To see examples for creating least-squares regression splines
with ``make_lsq_spline``, see the |1D example| and |2D example|.
Derivatives of constructed splines can be evaluated in two ways: (1) by using
the ``nus`` parameter while calling the interpolator or (2) by creating a new spline
with the ``derivative`` method. In this codeblock, we show both ways of
evaluating derivatives in each direction.
.. code:: python
# two ways to evaluate derivatives x-direction: create a derivative spline or call with nus:
deriv_interp = interp.derivative(0)
deriv1 = deriv_interp(gridxxy)
deriv2 = interp(gridxy, nus=np.array([1,0]))
# two ways to evaluate derivative - y direction
deriv_interp = interp.derivative(1)
deriv1 = deriv_interp(gridxy)
deriv2 = interp(gridxxyy, nus=np.array([0,1]))
The ``NDSpline`` class also has an ``antiderivative`` method for creating a
spline representative of the anti-derivative in the specified direction.
.. code:: python
# Calculus demonstration
interp1 = deriv_interp.antiderivative(0)
coeff_diff = interp1.coefficients - interp.coefficients
print("\nAntiderivative of derivative:\n","Coefficients differ by constant?",
np.allclose(interp1.coefficients+2.0, interp.coefficients))
print("Knots all same?",
np.all([np.all(k0 == k1) for k0, k1 in zip(interp1.knots, interp.knots)]))
antideriv_interp = interp.antiderivative(0)
interp2 = antideriv_interp.derivative(0)
print("\nDerivative of antiderivative:\n","Coefficients the same?",
np.allclose(interp2.coefficients, interp.coefficients))
print("Knots all same?",
np.all([np.all(k0 == k1) for k0, k1 in zip(interp2.knots, interp.knots)]))
.. _tidy data: https://www.jstatsoft.org/article/view/v059i10
.. |1D example| replace:: `1D example`_
.. _1D example: https://ndsplines.readthedocs.io/en/latest/auto_examples/1d-lsq.html
.. |2D example| replace:: `2D example`_
.. _2D example: https://ndsplines.readthedocs.io/en/latest/auto_examples/2d-lsq.html
Contributing
------------
Please feel free to share any thoughts or opinions about the design and
implementation of this software by `opening an issue on GitHub
`_. Constructive feedback is
welcomed and appreciated.
Bug fix pull requests are always welcome. For feature additions, breaking
changes, etc. check if there is an open issue discussing the change and
reference it in the pull request. If there isn't one, it is recommended to open
one with your rationale for the change before spending significant time
preparing the pull request.
Ideally, new/changed functionality should come with tests and documentation. If
you are new to contributing, it is perfectly fine to open a work-in-progress
pull request and have it iteratively reviewed.
Testing
-------
To test, install the package with the ``test`` extras and use ``pytest``::
$ pip install .[test]
$ pytest
Documentation
-------------
Documentation is based on Sphinx and built and served by Read the Docs. To
build locally, install the ``docs`` requirements::
$ pip install .[docs]
$ cd docs
$ make html
Owner
- Name: kb-press
- Login: kb-press
- Kind: organization
- Repositories: 1
- Profile: https://github.com/kb-press
JOSS Publication
ndsplines: A Python Library for Tensor-Product B-Splines of Arbitrary Dimension
Published
October 25, 2019
Volume 4, Issue 42, Page 1745
Authors
Tags
interpolation splineGitHub Events
Total
- Create event: 15
- Release event: 1
- Issues event: 3
- Watch event: 7
- Delete event: 15
- Issue comment event: 14
- Push event: 13
- Pull request event: 32
Last Year
- Create event: 16
- Release event: 1
- Issues event: 3
- Watch event: 7
- Delete event: 15
- Issue comment event: 14
- Push event: 13
- Pull request event: 33
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| ben | b****n@s****m | 198 |
| Kenneth Lyons | i****s@g****m | 74 |
| dependabot[bot] | 4****] | 24 |
| henryfeng98 | 6****8 | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 33
- Total pull requests: 132
- Average time to close issues: about 2 months
- Average time to close pull requests: 15 days
- Total issue authors: 7
- Total pull request authors: 4
- Average comments per issue: 2.24
- Average comments per pull request: 1.04
- Merged pull requests: 88
- Bot issues: 0
- Bot pull requests: 65
Past Year
- Issues: 3
- Pull requests: 36
- Average time to close issues: N/A
- Average time to close pull requests: 13 days
- Issue authors: 2
- Pull request authors: 2
- Average comments per issue: 0.0
- Average comments per pull request: 0.47
- Merged pull requests: 15
- Bot issues: 0
- Bot pull requests: 29
Top Authors
Issue Authors
- sixpearls (21)
- ixjlyons (6)
- ddevetak (2)
- danschef (1)
- amritagos (1)
- sunghjung3 (1)
- ccuetom (1)
Pull Request Authors
- dependabot[bot] (85)
- ixjlyons (49)
- sixpearls (18)
- henryfeng98 (1)
Top Labels
Issue Labels
Pull Request Labels
dependencies (85)
github_actions (14)
don't merge yet (1)
Packages
- Total packages: 1
-
Total downloads:
- pypi 8,184 last-month
- Total dependent packages: 2
- Total dependent repositories: 10
- Total versions: 11
- Total maintainers: 2
pypi.org: ndsplines
Multi-dimensional splines
- Documentation: https://ndsplines.readthedocs.io/
- License: other
-
Latest release: 0.3.0
published 6 months ago
Rankings
Docker downloads count: 1.7%
Dependent packages count: 3.2%
Average: 4.2%
Dependent repos count: 4.6%
Downloads: 7.3%
Last synced:
6 months ago
Dependencies
setup.py
pypi
- numpy *
- scipy *
.github/workflows/dist.yml
actions
- actions/checkout v3 composite
- actions/download-artifact v3 composite
- actions/upload-artifact v3 composite
- pypa/cibuildwheel v2.8.0 composite
- pypa/gh-action-pypi-publish v1.5.1 composite
.github/workflows/test.yml
actions
- actions/checkout v3 composite
- actions/setup-python v4 composite
pyproject.toml
pypi
- numpy *
- scipy *
