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 #902
Sphinx gallery #902
Changes from all commits
fb52ad0
9617fc8
74e241f
0c98fa6
2f5b9de
b4d77ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from bs4 import BeautifulSoup as bs | ||
|
||
path_html = 'build/html/gallery/index.html' | ||
with open(path_html, 'r') as ff: | ||
html = bs(ff.read(), "lxml") | ||
|
||
# Search for thumbnails that link to __init__ files | ||
thumbs = html.find_all('div', attrs={'class': 'sphx-glr-thumbcontainer'}) | ||
for div in thumbs: | ||
links = div.find_all('a') | ||
|
||
# If you find any, add a class that will make it invisible | ||
any_init = any('__init__' in ilink.attrs['href'] for ilink in links) | ||
if any_init: | ||
div.attrs['class'] += ['dontshow'] | ||
|
||
# Now update the HTML | ||
with open(path_html, 'w') as ff: | ||
out_html = html.prettify(html.original_encoding) | ||
ff.write(out_html) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
netCDF4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I included an extra There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't there be |
||
iris | ||
cf_units | ||
sphinx | ||
sphinx-gallery | ||
beautifulsoup4 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{{ fullname | escape | underline}} | ||
|
||
|
||
.. automodule:: {{ fullname }} | ||
:no-members: | ||
:no-inherited-members: | ||
|
||
{% block classes %} | ||
{% if classes %} | ||
|
||
Classes | ||
------- | ||
|
||
.. autosummary:: | ||
:template: autosummary.rst | ||
:toctree: | ||
{% for item in classes %}{% if item not in ['zip', 'map', 'reduce'] %} | ||
{{ item }}{% endif %}{% endfor %} | ||
{% endif %} | ||
{% endblock %} | ||
|
||
{% block functions %} | ||
{% if functions %} | ||
|
||
Functions | ||
--------- | ||
|
||
.. autosummary:: | ||
:template: autosummary.rst | ||
:toctree: | ||
|
||
{% for item in functions %}{% if item not in ['zip', 'map', 'reduce'] %} | ||
{{ item }}{% endif %}{% endfor %} | ||
{% endif %} | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{{ fullname | escape | underline}} | ||
|
||
|
||
.. currentmodule:: {{ module }} | ||
|
||
.. auto{{ objtype }}:: {{ objname }} | ||
|
||
{% if objtype in ['class', 'method', 'function'] %} | ||
|
||
.. include:: {{module}}.{{objname}}.examples | ||
|
||
.. raw:: html | ||
|
||
<div class="clearer"></div> | ||
|
||
{% endif %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# (C) British Crown Copyright 2011 - 2016, Met Office | ||
# (C) British Crown Copyright 2011 - 2017, Met Office | ||
# | ||
# This file is part of cartopy. | ||
# | ||
|
@@ -45,19 +45,20 @@ | |
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. | ||
extensions = [ | ||
'cartopy.sphinxext.summarise_package', | ||
'cartopy.sphinxext.gallery', | ||
'sphinx.ext.autodoc', | ||
'sphinx.ext.doctest', | ||
'sphinx.ext.intersphinx', | ||
'sphinx.ext.coverage', | ||
'sphinx.ext.viewcode', | ||
'sphinx.ext.extlinks', | ||
'sphinx.ext.autosummary', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind removing this from the PR? My prior experience suggests that in certain situations having autogenerated docs is worse than having no docs at all - cartopy is no shining start wrt its docs, but what is documented is generally more readable than most autogenerated API summary (e.g. http://scitools.org.uk/iris/docs/latest/iris/iris.html. To be clear - I implemented that autosummary generation for iris, so I'm explicitly not bad-mouthing anybody else 😉 ). I'm expecting to be able to invest some significant effort on cartopy's manually crafted docs over the coming months, and so keeping the autosummary would mask the shortcomings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the main reason for autosummary is that it lets you auto-generate mini-galleries for functions etc with sphinx-gallery. In conjunction with the template files in this PR, that will generate pages like this matplotlib example. Usually I don't use automodule either, but instead do it class-by-class (or function-by-function) to get the most modularity over my docs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pelson what's the decision on this? Do you want the autosummary removed or not? IMO it should be removed; I'm not convinced enough by @choldgraf's justification for keeping it in. |
||
#'sphinxcontrib.napoleon', (Needs work before this can be enabled.) | ||
# 'matplotlib.sphinxext.plot_directive' | ||
# We use a local copy of the plot_directive until | ||
# https://github.com/matplotlib/matplotlib/pull/6213 is available in order | ||
# to benefit from cached rebuilds of plots. | ||
'sphinxext.plot_directive' | ||
'sphinxext.plot_directive', | ||
'sphinx_gallery.gen_gallery', | ||
] | ||
|
||
import matplotlib | ||
|
@@ -89,6 +90,20 @@ | |
# The full version, including alpha/beta/rc tags. | ||
release = cartopy.__version__ | ||
|
||
# Sphinx gallery configuration | ||
sphinx_gallery_conf = { | ||
'examples_dirs': ['../../lib/cartopy/examples'], | ||
'filename_pattern': '^((?!sgskip).)*$', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any file that includes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It just takes a long time to reproject things, about 2 minutes for me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah I see - I wonder if this is just because I'm working on a relatively underpowered laptop...I'll remove the sgskip and will add some print statements so it doesn't look like it's hanging There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we can now remove this line, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line should stay in case you ever want to have an example that isn't run by sphinx-gallery...it's a configuration option so won't change the behavior of the docs unless "sgskip" is in a file name |
||
'gallery_dirs': ['gallery'], | ||
'doc_module': ('cartopy',), | ||
'reference_url': {'matplotlib': 'http://matplotlib.org', | ||
'numpy': 'http://docs.scipy.org/doc/numpy/reference', | ||
'scipy': 'http://docs.scipy.org/doc/scipy/reference', | ||
'shapely': 'http://toblerity.org/shapely', | ||
'cartopy': None}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two lines should be removable at this point? (the second line is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you want to remove the |
||
'backreferences_dir': 'api/_as_gen', # Not currently used but kept for future | ||
} | ||
|
||
# The language for content autogenerated by Sphinx. Refer to documentation | ||
# for a list of supported languages. | ||
#language = None | ||
|
@@ -324,8 +339,8 @@ | |
|
||
# Example configuration for intersphinx: refer to the Python standard library. | ||
intersphinx_mapping = {'python': ('https://docs.python.org/3', None), | ||
'matplotlib': ('http://matplotlib.org', None), | ||
'shapely': ('http://toblerity.org/shapely', None),} | ||
'matplotlib': ('https://matplotlib.org', None), | ||
'shapely': ('https://toblerity.org/shapely', None),} | ||
|
||
|
||
|
||
|
@@ -347,14 +362,6 @@ | |
summarise_package_fnames = ['cartopy_outline.rst'] | ||
|
||
|
||
############ gallery/examples extension ########### | ||
|
||
#gallery_allowed_tags = None | ||
#gallery_tag_order = None | ||
gallery_name = 'gallery.rst' | ||
examples_package_name = 'cartopy.examples' | ||
|
||
|
||
############ plot directive ############## | ||
|
||
plot_html_show_formats = False | ||
|
@@ -363,10 +370,10 @@ | |
'figure.subplot.top': 0.96, | ||
'figure.subplot.left': 0.04, | ||
'figure.subplot.right': 0.96} | ||
plot_formats = (('thumb.png', 20), | ||
plot_formats = [('thumb.png', 20), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This kept giving me a warning when building the site saying it should be a list, so I updated it |
||
'png', | ||
'pdf' | ||
) | ||
] | ||
|
||
|
||
############ autodoc config ############## | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,13 @@ Some of the key features of cartopy are: | |
* object oriented projection definitions | ||
* point, line, vector, polygon and image transformations between projections | ||
* integration to expose advanced mapping in matplotlib with a simple and intuitive interface | ||
* powerful vector data handling by integrating shapefile reading with Shapely capabilities | ||
* powerful vector data handling by integrating shapefile reading with Shapely capabilities | ||
|
||
Cartopy is licensed under `GNU Lesser General Public License <https://www.gnu.org/licenses/lgpl.html>`_ | ||
and is at version |version|. You can find the source code for cartopy on | ||
`our github page <https://github.com/SciTools/cartopy>`_. | ||
|
||
.. _getting-started: | ||
|
||
Getting started | ||
=============== | ||
|
@@ -66,23 +67,23 @@ outlines recent changes, new features, and future development plans. | |
Getting involved | ||
================ | ||
|
||
Cartopy was originally developed at the UK Met Office to allow scientists to visualise | ||
their data on maps quickly, easily and most importantly, accurately. | ||
Cartopy was originally developed at the UK Met Office to allow scientists to visualise | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe all of these are just trailing whitespace updates that my editor apparently auto-corrected. LMK if you want me to revert these for some reason |
||
their data on maps quickly, easily and most importantly, accurately. | ||
Cartopy has been made freely available under the terms of the | ||
`GNU Lesser General Public License <https://www.gnu.org/licenses/lgpl.html>`_. It is suitable to be used in a variety | ||
of scientific fields and has an :doc:`active development community <contributors>`. | ||
|
||
There are many ways to get involved in the development of cartopy: | ||
|
||
* If you write a paper which makes use of cartopy, please consider :doc:`citing <citation>` it. | ||
* If you publish the maps and plots, please consider the required :ref:`attribution of copyright <referencing_copyright>` for the data. | ||
* If you publish the maps and plots, please consider the required :ref:`attribution of copyright <referencing_copyright>` for the data. | ||
* Report bugs to https://github.com/SciTools/cartopy/issues (please look to see if there are any outstanding | ||
bugs which cover the issue before making a new one). | ||
* Help others with support questions on `stackoverflow <https://stackoverflow.com/questions/tagged/cartopy>`_. | ||
* Contribute to the documentation fixing typos, adding examples, explaining things more clearly, or even | ||
re-designing its layout/logos etc.. | ||
* Contribute bug fixes (:issues:`a list of outstanding bugs can be found on github <bug>`). | ||
* Contribute enhancements and new features | ||
* Contribute enhancements and new features | ||
(:issues:`a wish list of features can also be found on github <wishlist>`). | ||
|
||
Development discussion takes place on the `matplotlib-devel mailing list | ||
|
@@ -95,8 +96,7 @@ subjects prefixed with "cartopy: ". | |
:glob: | ||
:hidden: | ||
|
||
gallery | ||
examples/* | ||
gallery/* | ||
citation | ||
copyright | ||
contributors |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,10 @@ More advanced mapping with cartopy and matplotlib | |
From the outset, cartopy's purpose has been to simplify and improve the quality of | ||
mapping visualisations available for scientific data. Thanks to the simplicity of the cartopy | ||
interface, in many cases the hardest part of producing such visualisations is getting | ||
hold of the data in the first place. To address this, a Python package, | ||
`Iris <http://scitools.org.uk/iris/>`_, has been created to make loading and saving data from a | ||
variety of gridded datasets easier. Some of the following examples make use of the Iris | ||
loading capabilities, while others use the netCDF4 Python package so as to show a range | ||
hold of the data in the first place. To address this, a Python package, | ||
`Iris <http://scitools.org.uk/iris/>`_, has been created to make loading and saving data from a | ||
variety of gridded datasets easier. Some of the following examples make use of the Iris | ||
loading capabilities, while others use the netCDF4 Python package so as to show a range | ||
of different approaches to data loading. | ||
|
||
|
||
|
@@ -139,16 +139,18 @@ visualising vector fields: | |
:meth:`streamplots <cartopy.mpl.geoaxes.GeoAxes.streamplot>` (:ref:`example <examples-streamplot>`) | ||
each with their own benefits for displaying certain vector field forms. | ||
|
||
.. literalinclude:: /examples/arrows.py | ||
.. plot:: examples/arrows.py | ||
.. figure:: ../gallery/vector_data/images/sphx_glr_arrows_001.png | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are updated so that old figures generated with the |
||
:target: ../gallery/vector_data/arrows.html | ||
:align: center | ||
:scale: 50 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems too small. |
||
|
||
Since both :meth:`~cartopy.mpl.geoaxes.GeoAxes.quiver` and :meth:`~cartopy.mpl.geoaxes.GeoAxes.barbs` | ||
are visualisations which draw every vector supplied, there is an additional option to "regrid" the | ||
vector field into a regular grid on the target projection (done via | ||
:func:`cartopy.vector_transform.vector_scalar_to_grid`). This is enabled with the ``regrid_shape`` | ||
keyword and can have a massive impact on the effectiveness of the visualisation: | ||
keyword and can have a massive impact on the effectiveness of the visualisation: | ||
|
||
|
||
.. literalinclude:: /examples/regridding_arrows.py | ||
|
||
.. plot:: examples/regridding_arrows.py | ||
.. figure:: ../gallery/vector_data/images/sphx_glr_regridding_arrows_001.png | ||
:target: ../gallery/vector_data/regridding_arrows.html | ||
:align: center | ||
:scale: 50 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also a bit small. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
The cartopy Feature interface | ||
============================= | ||
|
||
The :ref:`data copyright, license and attribution <referencing_copyright>` can be blended on the map using `text annotations (mpl docs) <http://matplotlib.org/users/annotations_intro.html>`_ as shown in `feature_creation <../examples/feature_creation.html>`_. | ||
The :ref:`data copyright, license and attribution <referencing_copyright>` can be blended on the map using `text annotations (mpl docs) <http://matplotlib.org/users/annotations_intro.html>`_ as shown in `feature_creation <../gallery/lines_and_polygons/feature_creation.html>`_. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It isn't ideal to change the URL of the examples (because of StackOverflow/Google links etc.). Any way of avoiding it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmm, not without changing the directory structure of the examples. In other projects where we've implemented sphinx gallery we just kinda took a "rip the band-aid off" approach...I agree that's unfortunate :-/ |
||
|
||
.. currentmodule:: cartopy.feature | ||
|
||
|
@@ -19,15 +19,15 @@ Natural Earth or GSHHS shapefiles. | |
|
||
|
||
.. autoclass:: ShapelyFeature | ||
|
||
.. autoclass:: NaturalEarthFeature | ||
|
||
.. autoclass:: GSHHSFeature | ||
|
||
---------- | ||
|
||
To simplify some very common cases, some pre-defined Features exist as :mod:`cartopy.feature` | ||
constants. The pre-defined Features are all small-scale (1:110m) | ||
constants. The pre-defined Features are all small-scale (1:110m) | ||
`Natural Earth <http://www.naturalearthdata.com>`_ datasets, and can be added with methods | ||
such as :func:`GeoAxes.add_feature <cartopy.mpl.geoaxes.GeoAxes.add_feature>`: | ||
|
||
|
@@ -47,7 +47,7 @@ Name Description | |
Any Natural Earth dataset can easily be used by creating an | ||
instance of :class:`cartopy.feature.NaturalEarthFeature`. For | ||
example:: | ||
|
||
import cartopy.feature as cfeature | ||
land_50m = cfeature.NaturalEarthFeature('physical', 'land', '50m', | ||
edgecolor='face', | ||
|
@@ -63,15 +63,15 @@ For a full list of names in this dictionary: | |
>>> import cartopy.feature | ||
>>> sorted(cartopy.feature.COLORS.keys()) | ||
['land', 'land_alt1', 'water'] | ||
|
||
|
||
------------ | ||
|
||
|
||
Example of using the Feature class with the matplotlib interface | ||
---------------------------------------------------------------- | ||
|
||
.. literalinclude:: /examples/feature_creation.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I definitely think we need to have a separation between what should live in the gallery, and what is useful as inline examples within the context of a chapter. Cartopy hasn't got this completely right though - for example, there are a number of inline examples that really should be in the gallery: http://scitools.org.uk/cartopy/docs/v0.15/matplotlib/advanced_plotting.html#block-plots Could we do the promotion of inline/contextual examples -> gallery examples as a separate PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could also include the |
||
|
||
.. plot:: examples/feature_creation.py | ||
|
||
.. figure:: ../gallery/lines_and_polygons/images/sphx_glr_feature_creation_001.png | ||
:target: ../gallery/lines_and_polygons/feature_creation.html | ||
:align: center | ||
:scale: 50 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also small. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this api section is auto-generated by sphinx-gallery and can be used to build mini-galleries for specific functions / classes if desired