Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sphinx gallery #509

Merged
merged 33 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
22e1c85
start sphinx gallery
clewis7 May 29, 2024
71c1eaf
relevant file changes
clewis7 May 29, 2024
c8eb15d
progress
clewis7 May 30, 2024
e97f37b
edit setup.py to include missing dependencies
clewis7 May 30, 2024
5e0d08c
attempt to fix rtd
clewis7 May 30, 2024
1acbbfb
remove large heatmap example that breaks rtd
clewis7 May 30, 2024
372e466
fix linter, attempt to fix quickstart bug
clewis7 May 30, 2024
b4dbc94
fix gridplot examples and gallery structure
clewis7 Jun 3, 2024
0fc05dd
remove nbsphinx
clewis7 Jun 4, 2024
2856365
remove nbsphinx and quickstart.ipynb from docs
clewis7 Jun 4, 2024
dacc382
remove init files from examples
clewis7 Jun 4, 2024
985eb2e
update examples and conf.py
clewis7 Jun 5, 2024
79b6e7f
add animation examples, edit conf.py, fix scatter examples
clewis7 Jun 5, 2024
9c447de
add sklearn to docs, example needs it
clewis7 Jun 5, 2024
c92e5b7
Update setup.py
clewis7 Jun 5, 2024
676a481
Update setup.py
clewis7 Jun 5, 2024
09acb24
remove from gallery, kills readthedocs runner
clewis7 Jun 5, 2024
f749ef3
update canvas size so thumbnails render better
clewis7 Jun 5, 2024
59ec3fb
change scatter examples, remove sklearn from docs dependencies
clewis7 Jun 5, 2024
d0852f4
add iris scatter examples, exclude from screenshot tests
clewis7 Jun 5, 2024
7efad6b
add more animation examples, add to tests
clewis7 Jun 5, 2024
16c712c
add simple multigraphic gridplot example
clewis7 Jun 5, 2024
98d5280
add simple event, fix multigraphic gridplot
clewis7 Jun 6, 2024
ff3f429
Update line3d_animation.py
clewis7 Jun 6, 2024
1fba2c4
add simple event example
clewis7 Jun 6, 2024
3ff1982
resolve merge conflicts, change fig to figure for gallery
clewis7 Jun 17, 2024
26d85e4
minor changes
clewis7 Jun 18, 2024
ea298dc
replace screenshots and fix small bug
clewis7 Jun 18, 2024
950d4b4
fix scatter examples for CI build
clewis7 Jun 18, 2024
64aaca7
fix screenshots
clewis7 Jun 18, 2024
27c90aa
add sklearn as docs dependency, include iris scatter examples in gallery
clewis7 Jun 18, 2024
ee2d8f1
Update examples/desktop/misc/simple_event.py
clewis7 Jun 18, 2024
0e199ea
update screenshots
clewis7 Jun 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# Force offscreen rendering
import os

os.environ["WGPU_FORCE_OFFSCREEN"] = "1"
clewis7 marked this conversation as resolved.
Show resolved Hide resolved

import fastplotlib
from pygfx.utils.gallery_scraper import find_examples_for_gallery
from pathlib import Path
import sys
from sphinx_gallery.sorting import ExplicitOrder

ROOT_DIR = Path(__file__).parents[1].parents[0] # repo root
EXAMPLES_DIR = ROOT_DIR / "examples" / "desktop"
clewis7 marked this conversation as resolved.
Show resolved Hide resolved

sys.path.insert(0, str(ROOT_DIR))

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
Expand All @@ -24,8 +39,31 @@
"sphinx_copybutton",
"sphinx_design",
"nbsphinx",
clewis7 marked this conversation as resolved.
Show resolved Hide resolved
"sphinx_gallery.gen_gallery"
]

sphinx_gallery_conf = {
"gallery_dirs": "_gallery",
"backreferences_dir": "_gallery/backreferences",
"doc_module": ("fastplotlib",),
"image_scrapers": ("pygfx",),
"remove_config_comments": True,
"subsection_order": ExplicitOrder(
[
"../../examples/desktop/image",
"../../examples/desktop/gridplot",
"../../examples/desktop/line",
"../../examples/desktop/line_collection",
"../../examples/desktop/scatter",
"../../examples/desktop/heatmap"
]
),
"ignore_pattern": r'__init__\.py',
}

extra_conf = find_examples_for_gallery(EXAMPLES_DIR)
sphinx_gallery_conf.update(extra_conf)

autosummary_generate = True

templates_path = ["_templates"]
Expand All @@ -52,7 +90,7 @@
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"pygfx": ("https://pygfx.readthedocs.io/en/latest", None),
"pygfx": ("https://pygfx.com/stable/", None),
"wgpu": ("https://wgpu-py.readthedocs.io/en/latest", None),
}

Expand Down
6 changes: 6 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ Welcome to fastplotlib's documentation!
Utils <api/utils>
GPU <api/gpu>

.. toctree::
:caption: Gallery
:maxdepth: 2

Gallery <_gallery/index>

Summary
=======

Expand Down
14 changes: 13 additions & 1 deletion docs/source/quickstart.ipynb
clewis7 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@
"import imageio.v3 as iio"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "46a9a80b-0481-4788-975b-4ff364a03033",
"metadata": {},
"outputs": [],
"source": [
"### For the purpose of rendering our documentation, we need to manually make sure that offscreen rendering is not being used!\n",
"import os\n",
"os.environ[\"WGPU_FORCE_OFFSCREEN\"] = \"false\""
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -1665,7 +1677,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.12.3"
}
},
"nbformat": 4,
Expand Down
2 changes: 2 additions & 0 deletions examples/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Examples that use fastplotlib
=============================
Empty file added examples/desktop/README.rst
Empty file.
2 changes: 2 additions & 0 deletions examples/desktop/gridplot/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GridPlot Examples
=================
5 changes: 4 additions & 1 deletion examples/desktop/gridplot/gridplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
import imageio.v3 as iio


fig = fpl.Figure(shape=(2, 2))

im = iio.imread("imageio:clock.png")
Expand All @@ -22,6 +22,9 @@
fig[1, 0].add_image(data=im3)
fig[1, 1].add_image(data=im4)

# set canvas variable for sphinx_gallery to properly generate examples
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specifiy that this line isn't required for users, or see if there's a way for the pygfx scraper to look for fig.canvas instead of canvas?

in all examples

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think perhaps we can use figure instead...

pygfx scraper looks for one of ["renderer", "canvas"] to be defined, but will also look through proxy objects such as "figure", "display", "disp", "plot"

So I will try that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried changing fig to figure so then the scraper would look for figure.canvas...but then writing the thumbnails failed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for now, we should just to canvas = fig.canvas and have a note saying that it is not required for users and after FENS I can look into fixing them

canvas = fig.canvas

fig.show()

fig.canvas.set_logical_size(800, 800)
Expand Down
5 changes: 4 additions & 1 deletion examples/desktop/gridplot/gridplot_non_square.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
import imageio.v3 as iio


fig = fpl.Figure(shape=(2, 2), controller_ids="sync")

im = iio.imread("imageio:clock.png")
Expand All @@ -22,6 +22,9 @@

fig.show()

# set canvas variable for sphinx_gallery to properly generate examples
canvas = fig.canvas

fig.canvas.set_logical_size(800, 800)

for subplot in fig:
Expand Down
2 changes: 2 additions & 0 deletions examples/desktop/heatmap/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Heatmap Examples
================
5 changes: 4 additions & 1 deletion examples/desktop/heatmap/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
import numpy as np
from wgpu.gui.offscreen import WgpuCanvas

canvas = WgpuCanvas()

fig = fpl.Figure()
fig = fpl.Figure(canvas=canvas)
clewis7 marked this conversation as resolved.
Show resolved Hide resolved

xs = np.linspace(0, 1_000, 10_000)

Expand Down
5 changes: 4 additions & 1 deletion examples/desktop/heatmap/heatmap_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
import numpy as np
from wgpu.gui.offscreen import WgpuCanvas

canvas = WgpuCanvas()

fig = fpl.Figure()
fig = fpl.Figure(canvas=canvas)
clewis7 marked this conversation as resolved.
Show resolved Hide resolved

xs = np.linspace(0, 1_000, 10_000)

Expand Down
5 changes: 4 additions & 1 deletion examples/desktop/heatmap/heatmap_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'hidden'

import fastplotlib as fpl
import numpy as np
from wgpu.gui.offscreen import WgpuCanvas

canvas = WgpuCanvas()

fig = fpl.Figure()
fig = fpl.Figure(canvas=canvas)

xs = np.linspace(0, 1_000, 10_000)

Expand Down
5 changes: 4 additions & 1 deletion examples/desktop/heatmap/heatmap_vmin_vmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
import numpy as np
from wgpu.gui.offscreen import WgpuCanvas

canvas = WgpuCanvas()

fig = fpl.Figure()
fig = fpl.Figure(canvas=canvas)

xs = np.linspace(0, 1_000, 10_000)

Expand Down
2 changes: 2 additions & 0 deletions examples/desktop/image/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Image Examples
==============
9 changes: 7 additions & 2 deletions examples/desktop/image/image_cmap.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""
Simple Plot
============
Image colormap
==============

Example showing simple plot creation and subsequent cmap change with Standard image from imageio.
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
import imageio.v3 as iio
Expand All @@ -18,6 +20,9 @@

fig.show()

# set canvas variable for sphinx_gallery to properly generate examples
canvas = fig.canvas

fig.canvas.set_logical_size(800, 800)

fig[0, 0].auto_scale()
Expand Down
10 changes: 7 additions & 3 deletions examples/desktop/image/image_rgb.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""
Simple Plot
============
RGB Image
=========

Example showing the simple plot creation with 512 x 512 2D RGB image.
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
import imageio.v3 as iio


im = iio.imread("imageio:astronaut.png")

fig = fpl.Figure()
Expand All @@ -19,6 +20,9 @@

fig.show()

# set canvas variable for sphinx_gallery to properly generate examples
canvas = fig.canvas

fig.canvas.set_logical_size(800, 800)

fig[0, 0].auto_scale()
Expand Down
10 changes: 7 additions & 3 deletions examples/desktop/image/image_rgbvminvmax.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""
Simple Plot
============
RGB Image Vmin/Vmax
===================

Example showing the simple plot followed by changing the vmin/vmax with 512 x 512 2D RGB image.
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
import imageio.v3 as iio


im = iio.imread("imageio:astronaut.png")

fig = fpl.Figure()
Expand All @@ -19,6 +20,9 @@

fig.show()

# set canvas variable for sphinx_gallery to properly generate examples
canvas = fig.canvas

fig.canvas.set_logical_size(800, 800)

fig[0, 0].auto_scale()
Expand Down
8 changes: 6 additions & 2 deletions examples/desktop/image/image_simple.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""
Simple Plot
Simple Image
============

Example showing the simple plot creation with Standard imageio image.
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
import imageio.v3 as iio


fig = fpl.Figure()

data = iio.imread("imageio:camera.png")
Expand All @@ -19,6 +20,9 @@

fig.show()

# set canvas variable for sphinx_gallery to properly generate examples
canvas = fig.canvas

fig.canvas.set_logical_size(800, 800)

fig[0, 0].auto_scale()
Expand Down
10 changes: 7 additions & 3 deletions examples/desktop/image/image_vminvmax.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""
Simple Plot
============
Image Vmin/Vmax
===============

Example showing the simple plot creation followed by changing the vmin/vmax with Standard imageio image.
"""

# test_example = true
# sphinx_gallery_pygfx_docs = 'screenshot'

import fastplotlib as fpl
import imageio.v3 as iio


fig = fpl.Figure()

data = iio.imread("imageio:astronaut.png")
Expand All @@ -19,6 +20,9 @@

fig.show()

# set canvas variable for sphinx_gallery to properly generate examples
canvas = fig.canvas

fig.canvas.set_logical_size(800, 800)

fig[0, 0].auto_scale()
Expand Down
7 changes: 6 additions & 1 deletion examples/desktop/image/image_widget.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
"""
Image widget
============

Example showing the image widget in action.
When run in a notebook, or with the Qt GUI backend, sliders are also shown.
"""

# sphinx_gallery_pygfx_docs = 'hidden'

import fastplotlib as fpl
import imageio.v3 as iio # not a fastplotlib dependency, only used for examples


a = iio.imread("imageio:camera.png")
iw = fpl.ImageWidget(data=a, cmap="viridis")
iw.show()

# set canvas variable for sphinx_gallery to properly generate examples
canvas = iw.figure.canvas


if __name__ == "__main__":
print(__doc__)
Expand Down
Loading
Loading