From a8be873e413ef425d6275bef4aa1503ca991cbd2 Mon Sep 17 00:00:00 2001 From: Nabil Freij Date: Thu, 16 Mar 2023 14:03:25 -0700 Subject: [PATCH] Undo it again --- .readthedocs.yaml | 1 - docs/conf.py | 31 ++++++++++++++++++++++++++---- docs/examples/3d_functionality.rst | 8 -------- docs/examples/_readme.txt | 13 ------------- docs/examples/assume_spherical.rst | 8 -------- docs/examples/field_lines.rst | 8 -------- docs/examples/index.rst | 10 ---------- docs/examples/setup.py | 3 --- docs/index.rst | 2 +- examples/3d_functionality.py | 1 + examples/README.txt | 3 ++- examples/assume_spherical.py | 15 ++++++++++++++- examples/field_lines.py | 11 +++++++++++ setup.cfg | 3 +-- sunkit_pyvista/tests/conftest.py | 2 +- 15 files changed, 58 insertions(+), 61 deletions(-) delete mode 100644 docs/examples/3d_functionality.rst delete mode 100644 docs/examples/_readme.txt delete mode 100644 docs/examples/assume_spherical.rst delete mode 100644 docs/examples/field_lines.rst delete mode 100644 docs/examples/index.rst delete mode 100644 docs/examples/setup.py diff --git a/.readthedocs.yaml b/.readthedocs.yaml index cb5a7ae..d6aad89 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -7,7 +7,6 @@ build: apt_packages: - xvfb - libgl1-mesa-dev - - mesa-utils conda: environment: .rtd-environment.yml diff --git a/docs/conf.py b/docs/conf.py index e71c12e..14e090d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -30,6 +30,7 @@ "sphinx_automodapi.automodapi", "sphinx_automodapi.smart_resolver", "sphinx_changelog", + "sphinx_gallery.gen_gallery", "sphinx.ext.autodoc", "sphinx.ext.coverage", "sphinx.ext.doctest", @@ -39,7 +40,6 @@ "sphinx.ext.napoleon", "sphinx.ext.todo", "sphinx.ext.viewcode", - "jupyter_sphinx", ] # List of patterns, relative to source directory, that match files and @@ -87,8 +87,31 @@ # -- pyvista configuration --------------------------------------------------- import pyvista -pyvista.OFF_SCREEN = True +# Preferred plotting style for documentation pyvista.set_plot_theme("document") pyvista.global_theme.window_size = [512, 512] -if on_rtd: - pyvista.start_xvfb() +pyvista.global_theme.font.size = 18 +pyvista.global_theme.font.label_size = 18 +pyvista.global_theme.font.title_size = 18 +pyvista.global_theme.return_cpos = False +# Necessary when building the sphinx gallery +pyvista.OFF_SCREEN = True +pyvista.BUILDING_GALLERY = True +pyvista.set_jupyter_backend(None) + +# -- Sphinx Gallery ------------------------------------------------------------ +sphinx_gallery_conf = { + "backreferences_dir": os.path.join("generated", "modules"), + "filename_pattern": "^((?!skip_).)*$", + "examples_dirs": os.path.join("..", "examples"), + "gallery_dirs": os.path.join("generated", "gallery"), + "matplotlib_animations": True, + # Comes from the theme. + "default_thumb_file": png_icon, # NOQA + "abort_on_example_error": False, + "plot_gallery": "True", + "remove_config_comments": True, + "doc_module": ("sunpy"), + "only_warn_on_example_error": True, + "image_scrapers": ("matplotlib", "pyvista"), +} diff --git a/docs/examples/3d_functionality.rst b/docs/examples/3d_functionality.rst deleted file mode 100644 index 4f1fe6e..0000000 --- a/docs/examples/3d_functionality.rst +++ /dev/null @@ -1,8 +0,0 @@ -================================== -Extending functionality from sunpy -================================== - -.. jupyter-execute:: setup.py - :hide-code: - -.. jupyter-execute:: ../../examples/3d_functionality.py diff --git a/docs/examples/_readme.txt b/docs/examples/_readme.txt deleted file mode 100644 index dde9f8a..0000000 --- a/docs/examples/_readme.txt +++ /dev/null @@ -1,13 +0,0 @@ -To create a new example, follow these steps: - -1. Create a new python script for the example in /examples/. You should be - able to run this script by itself, and produce a plot at the end. -2. Create a .rst file in this directory that has: - - A title - - .. jupyter-execute:: setup.py - :hide-code: - - - .. jupyter-execute:: ../../examples/FILENAME.py - - - where FILENAME is the name of the file created in step 1. diff --git a/docs/examples/assume_spherical.rst b/docs/examples/assume_spherical.rst deleted file mode 100644 index 25b66d4..0000000 --- a/docs/examples/assume_spherical.rst +++ /dev/null @@ -1,8 +0,0 @@ -======================== -Ignoring off-limb pixels -======================== - -.. jupyter-execute:: setup.py - :hide-code: - -.. jupyter-execute:: ../../examples/assume_spherical.py diff --git a/docs/examples/field_lines.rst b/docs/examples/field_lines.rst deleted file mode 100644 index 4bd08a1..0000000 --- a/docs/examples/field_lines.rst +++ /dev/null @@ -1,8 +0,0 @@ -================================ -Plotting Field Lines from pfsspy -================================ - -.. jupyter-execute:: setup.py - :hide-code: - -.. jupyter-execute:: ../../examples/field_lines.py diff --git a/docs/examples/index.rst b/docs/examples/index.rst deleted file mode 100644 index 41c895c..0000000 --- a/docs/examples/index.rst +++ /dev/null @@ -1,10 +0,0 @@ -*************** -Example Gallery -*************** - -This gallery contains examples of how to use sunkit-pyvista. - -.. toctree:: - :glob: - - * diff --git a/docs/examples/setup.py b/docs/examples/setup.py deleted file mode 100644 index 044d23c..0000000 --- a/docs/examples/setup.py +++ /dev/null @@ -1,3 +0,0 @@ -import pyvista - -pyvista.global_theme.jupyter_backend = "trame" diff --git a/docs/index.rst b/docs/index.rst index 9060e7d..b62bf38 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -10,6 +10,6 @@ It is built on top of the `pyvista` package, which itself is built as a Python i installing getting_started - examples/index + generated/gallery/index api changelog diff --git a/examples/3d_functionality.py b/examples/3d_functionality.py index fab38fb..c5787a8 100644 --- a/examples/3d_functionality.py +++ b/examples/3d_functionality.py @@ -48,6 +48,7 @@ plotter.plot_quadrangle( bottom_left=bottom_left, width=20 * u.deg, height=60 * u.deg, color="blue" ) + # Set the camera coordinate to view the plot correctly camera_coord = SkyCoord( 30 * u.deg, diff --git a/examples/README.txt b/examples/README.txt index 05157ea..d173547 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -5,4 +5,5 @@ Example Gallery The gallery contains examples of how to use ``sunkit-pyvista``. Each example is a short and self contained how-to guide for performing a specific task. -These files are executed by the documentation build process and the output is embedded. +Unfortunately, the gallery is not interactive on readthedocs. +If you run these locally, you can interact with the plots. diff --git a/examples/assume_spherical.py b/examples/assume_spherical.py index 6fba5fb..5b37a27 100644 --- a/examples/assume_spherical.py +++ b/examples/assume_spherical.py @@ -6,13 +6,16 @@ How to not plot off-limb pixels. By default sunkit-pyvista plots all pixels in a map, using -:meth:`sunpy.coordinates.Helioprojective.assume_spherical_screen` to +:meth:`~sunpy.coordinates.Helioprojective.assume_spherical_screen` to project off-limb pixels on to a spherical screen. This example shows how off-limb pixels can be ignored altogether. """ import astropy.units as u +from astropy.constants import R_sun +from astropy.coordinates import SkyCoord +from sunpy.coordinates import frames from sunkit_pyvista import SunpyPlotter from sunkit_pyvista.sample import LOW_RES_AIA_193 @@ -27,4 +30,14 @@ LOW_RES_AIA_193, clip_interval=[1, 99] * u.percent, assume_spherical_screen=False ) +# Set the camera coordinate to view the plot correctly +camera_coord = SkyCoord( + 0 * u.deg, + 0 * u.deg, + 6 * R_sun, + frame=frames.HeliographicStonyhurst, + obstime=LOW_RES_AIA_193.date, +) +plotter.set_camera_coordinate(camera_coord) + plotter.show() diff --git a/examples/field_lines.py b/examples/field_lines.py index ea3e0b8..b5de823 100644 --- a/examples/field_lines.py +++ b/examples/field_lines.py @@ -20,6 +20,7 @@ import sunpy.map from astropy.constants import R_sun from astropy.coordinates import SkyCoord +from sunpy.coordinates import frames from sunkit_pyvista import SunpyPlotter from sunkit_pyvista.sample import LOW_RES_AIA_193 @@ -75,4 +76,14 @@ def my_fline_color_func(field_line): plotter.plot_field_lines(field_lines, color_func=my_fline_color_func) plotter.plotter.add_mesh(pv.Sphere(radius=1)) +# Set the camera coordinate to view the plot correctly +camera_coord = SkyCoord( + 0 * u.deg, + 0 * u.deg, + 6 * R_sun, + frame=frames.HeliographicStonyhurst, + obstime=LOW_RES_AIA_193.date, +) +plotter.set_camera_coordinate(camera_coord) + plotter.show() diff --git a/setup.cfg b/setup.cfg index 5adc020..9f111f1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -45,14 +45,13 @@ tests = pytest-doctestplus scikit-image docs = - jupyter-sphinx + ipython sphinx sphinx-automodapi sphinx-changelog sphinx-gallery streamtracer sunpy-sphinx-theme - trame [options.package_data] sunkit_pyvista = data/* diff --git a/sunkit_pyvista/tests/conftest.py b/sunkit_pyvista/tests/conftest.py index 592215f..2dbb924 100644 --- a/sunkit_pyvista/tests/conftest.py +++ b/sunkit_pyvista/tests/conftest.py @@ -10,7 +10,7 @@ try: pyvista.start_xvfb() except Exception as e: - print("Could not start xvfb server:") + print("Could not start xvfb server:\n") print(e)