Skip to content

Commit 8c63926

Browse files
authored
Merge pull request #728 from agriyakhetarpal/test-interactive-docs
Initial steps towards interactive documentation via JupyterLite
2 parents c1ab574 + 7977ff8 commit 8c63926

File tree

11 files changed

+105
-30
lines changed

11 files changed

+105
-30
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ __pycache__
1010
*.egg-info
1111
dist
1212
build
13+
_build
1314
.installed.cfg
1415

1516
# Installer logs
@@ -19,6 +20,11 @@ pip-log.txt
1920
.coverage
2021
.tox
2122

23+
# Sphinx documentation
24+
doc/_build/
25+
doc/build/
26+
.jupyterlite.doit.db
27+
2228
# Editors
2329
.idea
2430
.project

doc/source/_static/pywavelets.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Custom CSS rules for the interactive documentation button */
2+
3+
.try_examples_button {
4+
color: white;
5+
background-color: #0054a6;
6+
border: none;
7+
padding: 5px 10px;
8+
border-radius: 10px;
9+
margin-bottom: 5px;
10+
box-shadow: 0 2px 5px rgba(108,108,108,0.2);
11+
font-weight: bold;
12+
font-size: small;
13+
}
14+
15+
.try_examples_button:hover {
16+
background-color: #0066cc;
17+
transform: scale(1.02);
18+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
19+
cursor: pointer;
20+
}
21+
22+
.try_examples_button_container {
23+
display: flex;
24+
justify-content: flex-start;
25+
gap: 10px;
26+
margin-bottom: 20px;
27+
}

doc/source/conf.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
# Add any Sphinx extension module names here, as strings. They can be extensions
3535
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
3636
extensions = [
37+
'jupyterlite_sphinx',
3738
'matplotlib.sphinxext.plot_directive',
3839
'numpydoc',
3940
'sphinx.ext.autodoc',
@@ -193,6 +194,12 @@
193194
# so a file named "default.css" will overwrite the builtin "default.css".
194195
html_static_path = ['_static']
195196

197+
# CSS files to include in the build. The file path should be relative to the
198+
# _static directory.
199+
html_css_files = [
200+
"pywavelets.css",
201+
]
202+
196203
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
197204
# using the given strftime format.
198205
html_last_updated_fmt = '%b %d, %Y'
@@ -282,8 +289,22 @@
282289

283290
# -- Options for intersphinx extension ---------------------------------------
284291

285-
# Intersphinx to get Numpy and other targets
292+
# Intersphinx to get NumPy, SciPy, and other targets
286293
intersphinx_mapping = {
287294
'numpy': ('https://numpy.org/devdocs', None),
288-
'scipy': ('https://docs.scipy.org/doc/scipy/reference', None),
295+
'scipy': ('https://docs.scipy.org/doc/scipy/', None),
289296
}
297+
298+
# -- Options for JupyterLite -------------------------------------------------
299+
300+
global_enable_try_examples = True
301+
try_examples_global_button_text = "Try it in your browser!"
302+
try_examples_global_warning_text = (
303+
"""These interactive examples with JupyterLite are experimental and
304+
may not always work as expected. The execution of cells containing import
305+
statements can result in high bandwidth usage and may take a long time to
306+
load. They may not be in sync with the latest PyWavelets release.
307+
308+
Shall you encounter any issues, please feel free to report them on the
309+
[PyWavelets issue tracker](https://github.com/PyWavelets/pywt/issues)."""
310+
)

doc/source/ref/cwt.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ Continuous Wavelet Families
8989
A variety of continuous wavelets have been implemented. A list of the available
9090
wavelet names compatible with ``cwt`` can be obtained by:
9191

92-
.. sourcecode:: python
92+
.. try_examples::
93+
:button_text: Try it in your browser!
9394

94-
wavlist = pywt.wavelist(kind='continuous')
95+
>>> import pywt
96+
>>> wavelist = pywt.wavelist(kind='continuous')
9597

9698
Here is an overview of all available wavelets for ``cwt``. Note, that they can be
9799
customized by passing parameters such as ``center_frequency`` and ``bandwidth_frequency``
@@ -205,7 +207,8 @@ sampled at 100 Hz, a center frequency of 1.0 corresponds to ~100 Hz at
205207
``scale = 1``. This is above the Nyquist rate of 50 Hz, so for this
206208
particular wavelet, one would analyze a signal using ``scales >= 2``.
207209

208-
.. sourcecode:: python
210+
.. try_examples::
211+
:button_text: Try it in your browser!
209212

210213
>>> import numpy as np
211214
>>> import pywt
@@ -235,7 +238,8 @@ the input frequency in this function is normalized by 1/dt, or the sampling
235238
frequency fs. This function is useful for specifying the transform as a function
236239
of frequency directly.
237240

238-
.. sourcecode:: python
241+
.. try_examples::
242+
:button_text: Try it in your browser!
239243

240244
>>> import numpy as np
241245
>>> import pywt

doc/source/ref/other-functions.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,3 @@ Each can be loaded via a function of the same name.
6464

6565
.. currentmodule:: pywt.data
6666
.. autofunction:: demo_signal
67-
68-
**Example:**
69-
70-
.. sourcecode:: python
71-
72-
>>> import pywt
73-
>>> camera = pywt.data.camera()
74-
>>> doppler = pywt.data.demo_signal('doppler', 1024)
75-
>>> available_signals = pywt.data.demo_signal('list')

doc/source/ref/signal-extension-modes.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ computations can be performed with the `periodization`_ mode:
8787
smallest possible number of decomposition coefficients. :ref:`IDWT <ref-idwt>` must be
8888
performed with the same mode.
8989

90-
**Example:**
90+
**Example:**
9191

92-
.. sourcecode:: python
92+
.. try_examples::
93+
:button_text: Try it in your browser!
9394

9495
>>> import pywt
9596
>>> print(pywt.Modes.modes)
@@ -104,7 +105,8 @@ signal to an even length prior to using periodic boundary conditions.
104105
Notice that you can use any of the following ways of passing wavelet and mode
105106
parameters:
106107

107-
.. sourcecode:: python
108+
.. try_examples::
109+
:button_text: Try it in your browser!
108110

109111
>>> import pywt
110112
>>> (a, d) = pywt.dwt([1,2,3,4,5,6], 'db2', 'smooth')
@@ -142,8 +144,8 @@ Padding using PyWavelets Signal Extension Modes - ``pad``
142144

143145
.. autofunction:: pad
144146

145-
Pywavelets provides a function, :func:`pad`, that operate like
146-
:func:`numpy.pad`, but supporting the PyWavelets signal extension modes
147+
Pywavelets provides a function, :func:`pad`, that operates like
148+
:func:`numpy.pad`, but supports the PyWavelets signal extension modes
147149
discussed above. For efficiency, the DWT routines in PyWavelets do not
148150
expclitly create padded signals using this function. It can be used to manually
149151
prepad signals to reduce boundary effects in functions such as :func:`cwt` and

doc/source/ref/wavelets.rst

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ Custom discrete wavelets are also supported through the
4848

4949
**Example:**
5050

51-
.. sourcecode:: python
51+
.. try_examples::
52+
:button_text: Try it in your browser!
5253

5354
>>> import pywt
5455
>>> wavelet = pywt.Wavelet('db1')
@@ -128,7 +129,8 @@ Custom discrete wavelets are also supported through the
128129

129130
**Example:**
130131

131-
.. sourcecode:: python
132+
.. try_examples::
133+
:button_text: Try it in your browser!
132134

133135
>>> def format_array(arr):
134136
... return "[%s]" % ", ".join(["%.14f" % x for x in arr])
@@ -171,7 +173,8 @@ Approximating wavelet and scaling functions - ``Wavelet.wavefun()``
171173

172174
**Example:**
173175

174-
.. sourcecode:: python
176+
.. try_examples::
177+
:button_text: Try it in your browser!
175178

176179
>>> import pywt
177180
>>> wavelet = pywt.Wavelet('db2')
@@ -186,7 +189,8 @@ Approximating wavelet and scaling functions - ``Wavelet.wavefun()``
186189

187190
**Example:**
188191

189-
.. sourcecode:: python
192+
.. try_examples::
193+
:button_text: Try it in your browser!
190194

191195
>>> import pywt
192196
>>> wavelet = pywt.Wavelet('bior3.5')
@@ -239,7 +243,8 @@ from plain Python lists of filter coefficients and a *filter bank-like* object.
239243

240244
**Example:**
241245

242-
.. sourcecode:: python
246+
.. try_examples::
247+
:button_text: Try it in your browser!
243248

244249
>>> import pywt, math
245250
>>> c = math.sqrt(2)/2
@@ -273,7 +278,8 @@ from plain Python lists of filter coefficients and a *filter bank-like* object.
273278

274279
**Example:**
275280

276-
.. sourcecode:: python
281+
.. try_examples::
282+
:button_text: Try it in your browser!
277283

278284
>>> import pywt
279285
>>> wavelet = pywt.ContinuousWavelet('gaus1')
@@ -328,7 +334,8 @@ from plain Python lists of filter coefficients and a *filter bank-like* object.
328334

329335
**Example:**
330336

331-
.. sourcecode:: python
337+
.. try_examples::
338+
:button_text: Try it in your browser!
332339

333340
>>> import pywt
334341
>>> wavelet = pywt.ContinuousWavelet('gaus1')
@@ -358,7 +365,8 @@ Approximating wavelet functions - ``ContinuousWavelet.wavefun()``
358365

359366
**Example:**
360367

361-
.. sourcecode:: python
368+
.. try_examples::
369+
:button_text: Try it in your browser!
362370

363371
>>> import pywt
364372
>>> wavelet = pywt.ContinuousWavelet('gaus1')
@@ -375,7 +383,8 @@ Approximating wavelet functions - ``ContinuousWavelet.wavefun()``
375383

376384
**Example:**
377385

378-
.. sourcecode:: python
386+
.. try_examples::
387+
:button_text: Try it in your browser!
379388

380389
>>> import pywt
381390
>>> wavelet = pywt.DiscreteContinuousWavelet('db1')

doc/source/try_examples.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"global_min_height": "600px"
3+
}

pywt/_cwt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1):
9696
>>> coef, freqs=pywt.cwt(y,np.arange(1,129),'gaus1')
9797
>>> plt.matshow(coef) # doctest: +SKIP
9898
>>> plt.show() # doctest: +SKIP
99-
----------
99+
100100
>>> import pywt
101101
>>> import numpy as np
102102
>>> import matplotlib.pyplot as plt

pywt/data/_wavelab_signals.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ def demo_signal(name='Bumps', n=None):
6363
test signals are provided with permission of Dr. Donoho to encourage
6464
reproducible research.
6565
66+
Examples
67+
--------
68+
>>> import pywt
69+
>>> camera = pywt.data.camera()
70+
>>> doppler = pywt.data.demo_signal('doppler', 1024)
71+
>>> available_signals = pywt.data.demo_signal('list')
72+
>>> print(available_signals)
73+
74+
75+
6676
"""
6777
if name.lower() == 'list':
6878
return _implemented_signals

util/readthedocs/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
cython
22
docutils<0.18
3+
jupyterlite-sphinx
4+
jupyterlite-pyodide-kernel
35
pydata-sphinx-theme
46
pytest
57
matplotlib

0 commit comments

Comments
 (0)