Skip to content

Commit

Permalink
Add test example to doc build
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby committed Aug 2, 2021
1 parent 6c533d6 commit 4af889c
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 70 deletions.
52 changes: 12 additions & 40 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

"""
Configuration file for the Sphinx documentation builder.
"""
import warnings
import numpy as np
import pyvista
# Use the sunpy theme
# from sunpy_sphinx_theme.conf import *
from packaging.version import Version
from sunkit_pyvista import __version__
import os
from datetime import datetime

# -- Project information -----------------------------------------------------
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
os.environ['HIDE_PARFIVE_PROGESS'] = 'True'
Expand All @@ -14,22 +19,15 @@
copyright = '{}, {}'.format(datetime.now().year, author)

# The full version, including alpha/beta/rc tags
from sunkit_pyvista import __version__
from packaging.version import Version
release = __version__
sunkit_pyvista_version = Version(__version__)
is_release = not(sunkit_pyvista_version.is_prerelease or sunkit_pyvista_version.is_devrelease)

# Use the sunpy theme
from sunpy_sphinx_theme.conf import *
from sphinx_gallery.sorting import ExampleTitleSortKey

# -- General configuration ---------------------------------------------------
extensions = [
'sphinx_automodapi.automodapi',
'sphinx_automodapi.smart_resolver',
'sphinx_changelog',
'sphinx_gallery.gen_gallery',
'sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.doctest',
Expand Down Expand Up @@ -80,6 +78,7 @@
('py:class', 'string'),
('py:class', 'floats'),
]

# -- Options for intersphinx extension ---------------------------------------
intersphinx_mapping = {
"python": (
Expand All @@ -99,37 +98,10 @@
"pyvista": ("https://docs.pyvista.org/", None),
}

# -- Options for Gallery output ----------------------------------------------
sphinx_gallery_conf = {
'filename_pattern': '^((?!skip_).)*$',
'examples_dirs': os.path.join('..', 'examples'),
'within_subsection_order': ExampleTitleSortKey,
'gallery_dirs': os.path.join('generated', 'gallery'),
'default_thumb_file': os.path.join(html_static_path[0], 'img', 'sunpy_icon_128x128.png'),
'abort_on_example_error': False,
'only_warn_on_example_error': True,
'plot_gallery': False if on_rtd else True,
'remove_config_comments': True,
'doc_module': ('sunkit_pyvista'),
}

# -- pyvista configuration ---------------------------------------------------
import pyvista
import numpy as np

# Manage errors
pyvista.set_error_output_file("errors.txt")
# necessary when building the sphinx gallery
pyvista.BUILDING_GALLERY = True
pyvista.OFF_SCREEN = True # Not necessary - simply an insurance policy
# Preferred plotting style for documentation
pyvista.set_plot_theme("document")
pyvista.global_theme.window_size = np.array([512, 512]) * 2

# SG warnings
import warnings
warnings.filterwarnings(
"ignore",
category=UserWarning,
message="Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.",
)
10 changes: 10 additions & 0 deletions docs/examples/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
***************
Example Gallery
***************

This gallery contains examples of how to use sunkit-pyvista.

.. toctree::
:glob:

*
28 changes: 28 additions & 0 deletions docs/examples/test.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
=======================================
Three dimensional plots with sunpy Maps
=======================================

Using sunkit-pyvista, one can interface with the `pyvista` package to
produce interactive 3D plots for sunpy Maps.

.. jupyter-execute::
:hide-code:

import pyvista
pyvista.set_jupyter_backend('ipygany')

.. jupyter-execute::

import astropy.constants as const
import astropy.units as u
from astropy.coordinates import SkyCoord
from sunpy.data.sample import AIA_193_IMAGE
from sunpy.map import Map

from sunkit_pyvista import SunpyPlotter

m = Map(AIA_193_IMAGE).resample([512, 512] * u.pixel)

p = SunpyPlotter()
p.plot_map(m)
p.show(jupyter_backend='ipygany')
17 changes: 1 addition & 16 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,13 @@
sunkit-pyvista Documentation
****************************

.. jupyter-execute::
:hide-code:

# using ipyvtk as it loads faster
import pyvista
pyvista.set_jupyter_backend('ipygany')

`sunkit-pyvista` is a python package for visualizing solar physics data in 3D.
As a quick example:

.. jupyter-execute::

grid = pyvista.Sphere()
plotter = pyvista.Plotter()
plotter.add_mesh(grid)
plotter.show()

.. toctree::
:maxdepth: 2

api
generated/gallery/index
examples/index
changelog

Indexes
Expand Down
10 changes: 0 additions & 10 deletions examples/README.txt

This file was deleted.

1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ docs =
sphinx-automodapi
sphinx-automodapi
sphinx-changelog
sphinx-gallery
sunpy-sphinx-theme

[options.package_data]
Expand Down
5 changes: 2 additions & 3 deletions sunkit_pyvista/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def plot_map(self, m, clip_interval: u.percent = None, **kwargs):
**kwargs :
Keyword arguments are handed to `pyvista.Plotter.add_mesh`.
"""
cmap = kwargs.pop('cmap', m.cmap)
kwargs.pop('cmap', m.cmap)
map_mesh = self._pyvista_mesh(m)
if clip_interval is not None:
if len(clip_interval) == 2:
Expand All @@ -215,8 +215,7 @@ def plot_map(self, m, clip_interval: u.percent = None, **kwargs):
"specified as two numbers.")
else:
clim = [0, 1]
map_mesh.add_field_array([cmap], 'color')
self.plotter.add_mesh(map_mesh, cmap=cmap, clim=clim, **kwargs)
self.plotter.add_mesh(map_mesh, cmap="RdYlBu", clim=clim, **kwargs)
self._add_mesh_to_dict(block_name='maps', mesh=map_mesh)

def plot_coordinates(self, coords, radius=0.05, **kwargs):
Expand Down

0 comments on commit 4af889c

Please sign in to comment.