From 4af889cbfb07cf39ce7c7c587a09b094ad642686 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Mon, 2 Aug 2021 18:06:20 +0100 Subject: [PATCH] Add test example to doc build --- docs/conf.py | 52 +++++++++------------------------------ docs/examples/index.rst | 10 ++++++++ docs/examples/test.rst | 28 +++++++++++++++++++++ docs/index.rst | 17 +------------ examples/README.txt | 10 -------- setup.cfg | 1 - sunkit_pyvista/plotter.py | 5 ++-- 7 files changed, 53 insertions(+), 70 deletions(-) create mode 100644 docs/examples/index.rst create mode 100644 docs/examples/test.rst delete mode 100644 examples/README.txt diff --git a/docs/conf.py b/docs/conf.py index 235120b..99482e2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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' @@ -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', @@ -80,6 +78,7 @@ ('py:class', 'string'), ('py:class', 'floats'), ] + # -- Options for intersphinx extension --------------------------------------- intersphinx_mapping = { "python": ( @@ -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.", -) diff --git a/docs/examples/index.rst b/docs/examples/index.rst new file mode 100644 index 0000000..41c895c --- /dev/null +++ b/docs/examples/index.rst @@ -0,0 +1,10 @@ +*************** +Example Gallery +*************** + +This gallery contains examples of how to use sunkit-pyvista. + +.. toctree:: + :glob: + + * diff --git a/docs/examples/test.rst b/docs/examples/test.rst new file mode 100644 index 0000000..bbedddc --- /dev/null +++ b/docs/examples/test.rst @@ -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') diff --git a/docs/index.rst b/docs/index.rst index 4da9b6f..3736d66 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -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 diff --git a/examples/README.txt b/examples/README.txt deleted file mode 100644 index cb08c7c..0000000 --- a/examples/README.txt +++ /dev/null @@ -1,10 +0,0 @@ -*************** -Example Gallery -*************** - -This gallery contains examples of how to use sunkit-pyvista. -Most of these examples require the sunpy sample data, which you can download by running:: - - >>> import sunpy.data.sample - -Once downloaded the data will be stored in your user directory and you will not need to download it again. diff --git a/setup.cfg b/setup.cfg index 2cf68ed..7403541 100644 --- a/setup.cfg +++ b/setup.cfg @@ -50,7 +50,6 @@ docs = sphinx-automodapi sphinx-automodapi sphinx-changelog - sphinx-gallery sunpy-sphinx-theme [options.package_data] diff --git a/sunkit_pyvista/plotter.py b/sunkit_pyvista/plotter.py index 5b1959b..39bc825 100644 --- a/sunkit_pyvista/plotter.py +++ b/sunkit_pyvista/plotter.py @@ -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: @@ -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):