From 56f1b0f4bd92f885370b50ab307c2edcbe45255d Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 5 Aug 2021 08:32:11 +0100 Subject: [PATCH 1/5] Fix doc example --- doc/conf.py | 3 ++- doc/index.rst | 18 ++++++++++++++---- setup.cfg | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 9f53bd3..eeac4bf 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -24,7 +24,7 @@ # -- Project information ----------------------------------------------------- project = 'streamtracer' -copyright = '2019, David Stansby' +copyright = '2019-2021, David Stansby' author = 'David Stansby' # The full version, including alpha/beta/rc tags @@ -40,6 +40,7 @@ # ones. extensions = ['sphinx_automodapi.automodapi', 'numpydoc', + 'jupyter_sphinx', ] numpydoc_show_class_members = False diff --git a/doc/index.rst b/doc/index.rst index 4ffcbe4..bbbaf69 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -5,22 +5,32 @@ streamtracer is a python package for rapid streamline tracing. It is a wrapper to compiled fortran code that does the heavy lifting, and is therefore relatively fast. -To use, create a :class:`streamtracer.StreamTracer` object:: +To use, create a :class:`streamtracer.StreamTracer` object + +.. jupyter-execute:: + + import numpy as np + from streamtracer import StreamTracer, VectorGrid nsteps = 10000 step_size = 0.1 tracer = StreamTracer(nsteps, step_size) -and a :class:`streamtracer.VectorGrid`:: +and a :class:`streamtracer.VectorGrid` + +.. jupyter-execute:: field = np.ones((10, 10, 10, 3)) grid_spacing = [1, 2, 1] grid = VectorGrid(field, grid_spacing) -This can then be used to trace lines through a 3D cartesian vector field:: +This can then be used to trace lines through a 3D cartesian vector field + +.. jupyter-execute:: seeds = np.array([[0, 0, 0], [0, 0, 1]]) - streamlines = StreamTracer.trace(seeds, grid) + streamlines = tracer.trace(seeds, grid) + print(streamlines) For more information see the :mod:`streamtracer` API docs. diff --git a/setup.cfg b/setup.cfg index aa8e8b5..6936f70 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,6 +21,7 @@ tests = pytest pytest-cov docs = + jupyter-sphinx numpydoc sphinx sphinx-automodapi From 8856c086ff8077f1c7829393523d361a591742fd Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 5 Aug 2021 08:34:46 +0100 Subject: [PATCH 2/5] Add changelog --- doc/index.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/index.rst b/doc/index.rst index bbbaf69..cf720d8 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -62,6 +62,10 @@ Code reference Changelog ========= +1.1.2 +----- +Fixed the example code listed above. + 1.1.1 ----- Fixed wheel building to use the oldest supported version of numpy for each From 3fe6fb409190fb6832b3daff7672950f4b1d53c0 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 5 Aug 2021 08:44:07 +0100 Subject: [PATCH 3/5] Try RTD requirements file --- .readthedocs.yml | 5 +---- doc/requirements.txt | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 doc/requirements.txt diff --git a/.readthedocs.yml b/.readthedocs.yml index 3ec8ab9..25fc682 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -5,7 +5,4 @@ sphinx: python: install: - - method: pip - path: . - extra_requirements: - - docs + - requirements: doc/requirements.txt diff --git a/doc/requirements.txt b/doc/requirements.txt new file mode 100644 index 0000000..08d6fda --- /dev/null +++ b/doc/requirements.txt @@ -0,0 +1,6 @@ +jupyter-sphinx +numpydoc +sphinx +sphinx-automodapi +sphinx_rtd_theme +streamtracer From 94c42307f823a515eda8150e31b933c6a9c80e0f Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 5 Aug 2021 08:52:15 +0100 Subject: [PATCH 4/5] Use pydata theme --- doc/conf.py | 2 +- doc/index.rst | 4 ++-- doc/requirements.txt | 1 + setup.cfg | 1 + streamtracer/streamline.py | 1 + 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index eeac4bf..ee3b0d7 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -58,7 +58,7 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'sphinx_rtd_theme' +html_theme = 'pydata_sphinx_theme' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, diff --git a/doc/index.rst b/doc/index.rst index cf720d8..1ba5375 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -29,8 +29,8 @@ This can then be used to trace lines through a 3D cartesian vector field .. jupyter-execute:: seeds = np.array([[0, 0, 0], [0, 0, 1]]) - streamlines = tracer.trace(seeds, grid) - print(streamlines) + tracer.trace(seeds, grid) + print(tracer.xs) For more information see the :mod:`streamtracer` API docs. diff --git a/doc/requirements.txt b/doc/requirements.txt index 08d6fda..8bcf348 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -1,5 +1,6 @@ jupyter-sphinx numpydoc +pydata-sphinx-theme sphinx sphinx-automodapi sphinx_rtd_theme diff --git a/setup.cfg b/setup.cfg index 6936f70..eb4a48c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -23,6 +23,7 @@ tests = docs = jupyter-sphinx numpydoc + pydata-sphinx-theme sphinx sphinx-automodapi sphinx_rtd_theme diff --git a/streamtracer/streamline.py b/streamtracer/streamline.py index d79bcf2..18d5f0e 100755 --- a/streamtracer/streamline.py +++ b/streamtracer/streamline.py @@ -144,6 +144,7 @@ class StreamTracer: def __init__(self, max_steps, step_size): self.max_steps = max_steps self.ds = step_size + self.xs = None @property def max_steps(self): From 123663d364a42a117a5d2bd083a5fe1bbc78a044 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 5 Aug 2021 08:56:06 +0100 Subject: [PATCH 5/5] Improve doc example --- doc/index.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/index.rst b/doc/index.rst index 1ba5375..fa501b1 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -30,7 +30,14 @@ This can then be used to trace lines through a 3D cartesian vector field seeds = np.array([[0, 0, 0], [0, 0, 1]]) tracer.trace(seeds, grid) - print(tracer.xs) + +and the traced field lines can be accessed via. the ``.xs`` attribute + +.. jupyter-execute:: + + print(f'Number of traced lines: {len(tracer.xs)}') + line_lengths = [len(x) for x in tracer.xs] + print(f'Line lengths: {line_lengths}') For more information see the :mod:`streamtracer` API docs.