Comments (4)
I started looking into this (because it is a great thing and I wanted it for the atlite examples).
Writing it up here for reuse later.
The package
- Documentation for the SPHINX addon nbsphinx
Quick start from the doc
- Installation:
conda install -c conda-forge nbsphinx
orpip install nbsphinx
- in
doc/conf.py
a) Addnbsphinx
andsphinx.ext.mathjax
(if not already there) as extension
b) Check that the checkpoints from jupyter are included here:
exclude_patterns = ['_build', '**.ipynb_checkpoints']
- Now
*.ipynb
files fromdoc
and sub directories can be included and are rendered.
Important facts to remember
- For long-running cells / cells with download:
a) If you clear all cell output, then the notebook is run by SPHINX before being displayed.
b) If there is >= 1 cell output, then the notebook is not run and only displayed. (I leveraged this for
not downloading cutouts again and again)
c) Behaviour can be explicitly set, but is complicated, involves editing notebook metadata - Do not include large pictures (because of
git
tracking, diffs and size) - Markdown cells > Comments for rendering notebooks
NB: I am currently experiencing problems when nbconvert
wants to run notebooks without cell output (see this issue). To prevent this, I set nbsphinx_execute = 'never'
in the RTD conf.py
.
ToDo / Check
- What else to look out for when using
git
andnbsphinx
, see
https://nbsphinx.readthedocs.io/en/0.4.2/usage.html#Using-Notebooks-with-Git
Including examples/*.ipynb
into docs
I wanted the Examples to be listed in the toctree on readthedocs.org.
Problem
By default, SPHINX only allows for files in doc
and subdirectories to be included.
For RELEASE_NOTES.rst
this can be circumvented using .. include::
black magic (will set this up for atlite tomorrow), but this does not work for notebooks.
One approach would be to use Unix sym-links, but that breaks cross-plattform compatability.
Solution
Another addon called nbsphinx_link
.
I installed it locally and it works nicely and does exactly what I want.
Setting this up with it installed is straight forward:
- Create your
foo.ipynb
e.g. inexamples/foo.ipynb
- Create a linking file where you want it to be, I choose `doc/examples/foo.nblink.
- Edit the
foo.nblink
to contain
{
"path": "../../examples/foo.ipynb"
}
- Reference
doc/examples/foo.nblink
in thedoc/index.rst
as a normal notebook /.rst
file.
Clearing output of Jupyter notebooks
Problem
Usually you don't want the output of Jupyter notebooks commited to the repository,
as they make things harder / larger to diff / edit / store.
Recommendation
Locally install the precommit hook from here into your <repository>/.git/hooks/pre-commit
file:
https://jamesfolberth.org/articles/2017/08/07/git-commit-hook-for-jupyter-notebooks/
If you are in the process of comitting an .ipynb
file with output, it will ask you to confirm (y/n).
"y" if you want the output online, "n" to get another chance to delete it manually.
Other solutions exist (auto-purging, commit blocking), but this one is the simpliest and I think most flexible one for our small projects.
from atlite.
Recommended Workflow
Preparation
- Locally install this precommit hook.
- Install the SPHINX extensions in
conf.py
.
Workflow
- Write a
foo.ipynb
with your desired content. - Do you need the output in the notebook?
- Yes: (for e.g. long running cells, large data ops) Keep it.
- No: "Edit -> Clear all output".
- Is the notebook in the
doc
subdir?
- Yes: Good.
- No: Create an
foo.nblink
with this content and the"path
" pointing to yourfoo.ipynb
:
{"path": "../../examples/foo.ipynb"}
- Link to
foo.ipynb
orfoo.nblnk
in the documentation. - Commit; if the notebook contains the hook kick in: Confirm if you answered 2. with "Yes" or delete the output.
from atlite.
This nicely prepared workflow description should find its own place in the documentation, as a subsection of contributing.rst
or in a new developernotes.rst
, maybe.
from atlite.
I included it into the documentation at
https://atlite.readthedocs.io/en/latest/contributing.html#contributing-examples
Also SPHINX (more precise: Jinja2) now adds a note on top of each documentation file generated from notebooks linking to the original.
Realised using these lines:
Lines 131 to 139 in fc30fb1
Tagging and closing this issue.
from atlite.
Related Issues (20)
- Cutout AttributeError: "EntryPoints" object has no attribute get in Colab HOT 2
- Question about runoff conversion HOT 3
- Include xarray-spatial
- pad_extent leads to rasterio error for global scape
- Licence description on PyPI incorrect HOT 1
- Error cannot convert float nan to int HOT 10
- Issue with build_cutout using alite HOT 5
- reanalysis-era5-single-levels HOT 3
- Atlite errors with ESRI:540060 reprojections and Fiji HOT 7
- Read from url for `excluder.add_raster` and `excluder.add_geometry` HOT 2
- PV conversion: New model based on Bloomfield et al. (2019)
- Wind Conversion: potential bug when power curve does not end with zero after cutout speed HOT 1
- Weather/climate data variable descriptions (for alternate model data use) HOT 2
- Problems with `convert_and_aggregate` for long timespans? HOT 12
- Data type error when building cutout with SARAH v3 HOT 4
- Merging cutouts / Integrate downloaded SARAH data into existing ERA-5 cutout HOT 1
- Setting the "capacity_factor_timeseries = True" the results seem not to change HOT 2
- Time misalignment between ERA5 and SARAH? HOT 6
- "Optimal" orientation does always lead to more output HOT 4
- Migrate to new CDS infrastructure
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from atlite.