diff --git a/README.rst b/README.rst index b500e78..a9571ed 100644 --- a/README.rst +++ b/README.rst @@ -20,17 +20,21 @@ Advanced spline package that provides b-spline bases, their derivatives and inte Installation ------------ -XSpline can be install via +XSpline requires python 3.10 or higher. XSpline only depends on ``numpy>=1.25.1``. +It can be installed via -.. code-block:: bash +.. code:: bash pip install xspline>=0.1.0 +For developers, you can clone the repository and install the package in the +development mode. -Requirements ------------- +.. code:: -XSpline requires python 3.10 or higher. XSpline only depends on ``numpy>=1.25.1``. + git clone https://github.com/zhengp0/xspline.git + cd xspline + pip install -e ".[test,docs]" Usage @@ -38,7 +42,7 @@ Usage You can use XSpline as a univariate function or use it to get design matrix. -.. code-block:: python +.. code:: python import numpy as np import matplotlib.pyplot as plt @@ -51,7 +55,7 @@ You can use XSpline as a univariate function or use it to get design matrix. One is to use XSpline as a univariate function. In this case, user must provide coefficients for the spline bases. -.. code-block:: python +.. code:: python np.random.seed(123) spline.coef = np.random.randn(len(spline)) @@ -61,11 +65,11 @@ coefficients for the spline bases. ax[0].plot(x, y) ax[1].plot(x, design_mat) -.. image:: images/readme_usage_0.png +.. image:: docs/images/readme_usage_0.png XSpline can be used to obtain derivatives. -.. code-block:: python +.. code:: python dy, ddesign_mat = spline(x, order=1), spline.get_design_mat(x, order=1) @@ -73,11 +77,11 @@ XSpline can be used to obtain derivatives. ax[0].plot(x, dy) ax[1].plot(x, ddesign_mat) -.. image:: images/readme_usage_1.png +.. image:: docs/images/readme_usage_1.png XSpline can be used to obtain definite integrals. -.. code-block:: python +.. code:: python iy, idesign_mat = spline(x, order=-1), spline.get_design_mat(x, order=-1) @@ -85,11 +89,11 @@ XSpline can be used to obtain definite integrals. ax[0].plot(x, iy) ax[1].plot(x, idesign_mat) -.. image:: images/readme_usage_2.png +.. image:: docs/images/readme_usage_2.png XSpline can extrapolate with different polynomial options -.. code-block:: python +.. code:: python np.random.seed(123) # constant extrapolation one the left and linear extrapolation on the right @@ -117,4 +121,4 @@ XSpline can extrapolate with different polynomial options color="grey", ) -.. image:: images/readme_usage_3.png +.. image:: docs/images/readme_usage_3.png diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..41c270b --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file diff --git a/docs/_static/css/custom.css b/docs/_static/css/custom.css new file mode 100644 index 0000000..1759363 --- /dev/null +++ b/docs/_static/css/custom.css @@ -0,0 +1,20 @@ +/* reduce the size of the main text */ + +p { + font-size: 0.95rem; +} + +h1, +h2, +h3, +h4, +h5, +h6 { + font-weight: 500; +} + +.sidebar-brand-text { + font-size: 1rem; + font-weight: 500; + margin: auto; +} \ No newline at end of file diff --git a/docs/_static/logo/logo-dark.png b/docs/_static/logo/logo-dark.png new file mode 100644 index 0000000..b321abd Binary files /dev/null and b/docs/_static/logo/logo-dark.png differ diff --git a/docs/_static/logo/logo-light.png b/docs/_static/logo/logo-light.png new file mode 100644 index 0000000..1786e8f Binary files /dev/null and b/docs/_static/logo/logo-light.png differ diff --git a/docs/api_reference/index.rst b/docs/api_reference/index.rst new file mode 100644 index 0000000..f1528f3 --- /dev/null +++ b/docs/api_reference/index.rst @@ -0,0 +1,8 @@ +API Reference +============= + +.. toctree:: + :maxdepth: 2 + :glob: + + * \ No newline at end of file diff --git a/docs/api_reference/xspline.bspl.rst b/docs/api_reference/xspline.bspl.rst new file mode 100644 index 0000000..90c4745 --- /dev/null +++ b/docs/api_reference/xspline.bspl.rst @@ -0,0 +1,7 @@ +xspline.bspl +============ + +.. automodule:: xspline.bspl + :members: + :undoc-members: + :show-inheritance: \ No newline at end of file diff --git a/docs/api_reference/xspline.indi.rst b/docs/api_reference/xspline.indi.rst new file mode 100644 index 0000000..356fe9e --- /dev/null +++ b/docs/api_reference/xspline.indi.rst @@ -0,0 +1,7 @@ +xspline.indi +============= + +.. automodule:: xspline.indi + :members: + :undoc-members: + :show-inheritance: \ No newline at end of file diff --git a/docs/api_reference/xspline.poly.rst b/docs/api_reference/xspline.poly.rst new file mode 100644 index 0000000..ba2e359 --- /dev/null +++ b/docs/api_reference/xspline.poly.rst @@ -0,0 +1,7 @@ +xspline.poly +============= + +.. automodule:: xspline.poly + :members: + :undoc-members: + :show-inheritance: \ No newline at end of file diff --git a/docs/api_reference/xspline.xfunction.rst b/docs/api_reference/xspline.xfunction.rst new file mode 100644 index 0000000..347c4ea --- /dev/null +++ b/docs/api_reference/xspline.xfunction.rst @@ -0,0 +1,7 @@ +xspline.xfunction +================= + +.. automodule:: xspline.xfunction + :members: + :undoc-members: + :show-inheritance: \ No newline at end of file diff --git a/docs/api_reference/xspline.xspl.rst b/docs/api_reference/xspline.xspl.rst new file mode 100644 index 0000000..fa9d091 --- /dev/null +++ b/docs/api_reference/xspline.xspl.rst @@ -0,0 +1,7 @@ +xspline.xspl +============= + +.. automodule:: xspline.xspl + :members: + :undoc-members: + :show-inheritance: \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..c1dd8cd --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,91 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import tomllib + +with open("../pyproject.toml", "rb") as f: + meta = tomllib.load(f)["tool"]["sphinx"] + + +# -- Project information ----------------------------------------------------- + +project = meta["project"] +author = meta["author"] +copyright = meta["copyright"] + + +# The full version, including alpha/beta/rc tags +version = meta["version"] + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named "sphinx.ext.*") or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.autosectionlabel", + "sphinx.ext.extlinks", + "sphinx.ext.intersphinx", + "sphinx.ext.mathjax", + "sphinx.ext.todo", + "sphinx.ext.viewcode", + "sphinx.ext.napoleon", +] +autodoc_typehints = "description" +autodoc_member_order = "bysource" +autodoc_type_aliases = { + "ArrayLike": "ArrayLike", + "NDArray": "NDArray", + "DataFrame": "DataFrame", +} + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = "furo" + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] +html_css_files = ["css/custom.css"] +html_title = f"{project} {version}" +html_theme_options = { + "sidebar_hide_name": False, + "light_logo": "logo/logo-light.png", + "dark_logo": "logo/logo-dark.png", + "light_css_variables": { + "color-brand-primary": "#008080", + "color-brand-content": "#008080", + "color-problematic": "#BF5844", + "color-background-secondary": "#F8F8F8", + }, + "dark_css_variables": { + "color-brand-primary": "#6FD8D1", + "color-brand-content": "#6FD8D1", + "color-problematic": "#FA9F50", + "color-background-secondary": "#202020", + }, +} diff --git a/docs/images/readme_usage_0.png b/docs/images/readme_usage_0.png new file mode 100644 index 0000000..02bbdf1 Binary files /dev/null and b/docs/images/readme_usage_0.png differ diff --git a/docs/images/readme_usage_1.png b/docs/images/readme_usage_1.png new file mode 100644 index 0000000..922d7a0 Binary files /dev/null and b/docs/images/readme_usage_1.png differ diff --git a/docs/images/readme_usage_2.png b/docs/images/readme_usage_2.png new file mode 100644 index 0000000..d8b7a2c Binary files /dev/null and b/docs/images/readme_usage_2.png differ diff --git a/docs/images/readme_usage_3.png b/docs/images/readme_usage_3.png new file mode 100644 index 0000000..6809ce0 Binary files /dev/null and b/docs/images/readme_usage_3.png differ diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..a44d138 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,26 @@ +XSpline +======= + +Advanced spline package that provides b-spline bases, their derivatives and integrals. + + +To get started please check section :ref:`User's Guide`. +And the full reference is provided in section :ref:`Interface Reference`. + +User's guide +------------ + +.. toctree:: + :maxdepth: 2 + + installation + quickstart + + +Interface reference +------------------- + +.. toctree:: + :maxdepth: 2 + + api_reference/index diff --git a/docs/installation.rst b/docs/installation.rst new file mode 100644 index 0000000..ef72c54 --- /dev/null +++ b/docs/installation.rst @@ -0,0 +1,20 @@ +============ +Installation +============ + + +XSpline requires python 3.10 or higher. XSpline only depends on ``numpy>=1.25.1``. +It can be installed via + +.. code:: bash + + pip install xspline>=0.1.0 + +For developers, you can clone the repository and install the package in the +development mode. + +.. code:: + + git clone https://github.com/zhengp0/xspline.git + cd xspline + pip install -e ".[test,docs]" \ No newline at end of file diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..32bb245 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/quickstart.rst b/docs/quickstart.rst new file mode 100644 index 0000000..f76a730 --- /dev/null +++ b/docs/quickstart.rst @@ -0,0 +1,89 @@ +========== +Quickstart +========== + +Usage +----- + +You can use XSpline as a univariate function or use it to get design matrix. + +.. code:: python + + import numpy as np + import matplotlib.pyplot as plt + from xspline import XSpline + + spline = XSpline(knots=[0, 0.25, 0.5, 0.75, 1], degree=3) + x = np.arange(0, 1.01, 0.01) + + +One is to use XSpline as a univariate function. In this case, user must provide +coefficients for the spline bases. + +.. code:: python + + np.random.seed(123) + spline.coef = np.random.randn(len(spline)) + y, design_mat = spline(x), spline.get_design_mat(x) + + fig, ax = plt.subplots(1, 2, figsize=(10, 3)) + ax[0].plot(x, y) + ax[1].plot(x, design_mat) + +.. image:: images/readme_usage_0.png + +XSpline can be used to obtain derivatives. + +.. code:: python + + dy, ddesign_mat = spline(x, order=1), spline.get_design_mat(x, order=1) + + fig, ax = plt.subplots(1, 2, figsize=(10, 3)) + ax[0].plot(x, dy) + ax[1].plot(x, ddesign_mat) + +.. image:: images/readme_usage_1.png + +XSpline can be used to obtain definite integrals. + +.. code:: python + + iy, idesign_mat = spline(x, order=-1), spline.get_design_mat(x, order=-1) + + fig, ax = plt.subplots(1, 2, figsize=(10, 3)) + ax[0].plot(x, iy) + ax[1].plot(x, idesign_mat) + +.. image:: images/readme_usage_2.png + +XSpline can extrapolate with different polynomial options + +.. code:: python + + np.random.seed(123) + # constant extrapolation one the left and linear extrapolation on the right + spline = XSpline( + knots=[0, 0.25, 0.5, 0.75, 1], + degree=3, + ldegree=0, + rdegree=1, + coef=np.random.randn(len(spline)), + ) + x = np.arange(-0.5, 1.51, 0.01) + y, design_mat = spline(x), spline.get_design_mat(x) + + fig, ax = plt.subplots(1, 2, figsize=(10, 3)) + ax[0].plot(x, y) + ax[1].plot(x, design_mat) + for i in range(len(ax)): + ax[i].vlines( + [0, 1], + ymin=0, + ymax=1, + transform=ax[i].get_xaxis_transform(), + linestyle="--", + linewidth=1, + color="grey", + ) + +.. image:: images/readme_usage_3.png \ No newline at end of file