Skip to content

Commit

Permalink
DOC: Polish tutorials (pik-copan#213)
Browse files Browse the repository at this point in the history
Package sdist & repository:
- add tutorial sources
- remove generated files
- remove datasets

Code:
- download datasets within notebooks
- reduce redundancy
- group dual pairs of plots
- adjust some parameters
- rerun notebooks

Text & math:
- fix typos, edit lightly, update references
- fix TeX parsing errors in `nbsphinx`
- optimise outline hierarchy for `nbsphinx
  • Loading branch information
ntfrgl committed Feb 6, 2024
1 parent aa39cf3 commit c5de131
Show file tree
Hide file tree
Showing 20 changed files with 982 additions and 1,512 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ instance/

# Sphinx documentation
docs/_build/
docs/source/tutorials/images/

# PyBuilder
.pybuilder/
Expand Down Expand Up @@ -164,5 +165,6 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Calculation dumps
# cached data
*.data
examples/tutorials/data
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ recursive-include src/pyunicorn/*/_ext *.pxd *.pyx src_*.c

include *.rst *.txt docs/Makefile
graft docs/source
recursive-include examples *.py
recursive-include examples *.py *.ipynb *.png
prune docs/source/tutorials/images
prune **/.ipynb_checkpoints

recursive-include tests *.py
3 changes: 1 addition & 2 deletions docs/source/sitemap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ Sitemap
=======

.. toctree::
:maxdepth: 2
:includehidden:
:maxdepth: 3

index
download
Expand Down
9 changes: 4 additions & 5 deletions docs/source/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ Tutorials
The tutorials are designed to be self-explanatory, and are set up as Jupyter
notebooks that can be accessed read-only through the links below. The original,
executable notebook files can be found in the folder ``pyunicorn/examples``.
For further details on the used classes and methods, please refer to the
:doc:`api_doc` documentation.

.. toctree::
:maxdepth: 1
:maxdepth: 2
:glob:

tutorials/*

For further details on the used classes and methods, please refer to the
:doc:`api_doc` documentation.
tutorials/*
Binary file removed docs/source/tutorials/images/Characteristics_rP.png
Binary file not shown.
Binary file removed docs/source/tutorials/images/ECA.png
Binary file not shown.
Binary file not shown.
Binary file removed docs/source/tutorials/images/REcurrencePlot_v2.png
Binary file not shown.
69 changes: 34 additions & 35 deletions examples/tutorials/ClimateNetworks.ipynb

Large diffs are not rendered by default.

853 changes: 266 additions & 587 deletions examples/tutorials/CoupledClimateNetworks.ipynb

Large diffs are not rendered by default.

436 changes: 185 additions & 251 deletions examples/tutorials/EventSeriesAnalysis.ipynb

Large diffs are not rendered by default.

636 changes: 236 additions & 400 deletions examples/tutorials/RecurrenceNetworks.ipynb

Large diffs are not rendered by default.

445 changes: 219 additions & 226 deletions examples/tutorials/VisibilityGraphs.ipynb

Large diffs are not rendered by default.

Binary file removed examples/tutorials/data/air.mon.mean.nc
Binary file not shown.
Binary file removed examples/tutorials/images/HVG.PNG
Binary file not shown.
File renamed without changes
Binary file removed examples/tutorials/images/SimpleVG.PNG
Binary file not shown.
File renamed without changes
28 changes: 27 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,40 @@
# and J. Kurths, "Unified functional network and nonlinear time series analysis
# for complex systems science: The pyunicorn package"

from pathlib import Path

import requests
import pytest


@pytest.fixture(scope="session",
params=["supremum", "euclidean", "manhattan"])
def metric(request):
def metric(request) -> str:
'''
A fixture for creating parametrized fixtures of classes that have a
`metric` argument, as in `RecurrencePlot` and its child classes.
'''
return request.param


@pytest.fixture(scope="session")
def reanalysis_data() -> Path:
"""
Locate, and potentially download, a small NOAA dataset. Currently used in:
- `tests/test_climate/test_map_plot.py`
- `examples/tutorials/ClimateNetworks.ipynb`
"""
name = "air.mon.mean.nc"
path = Path("./examples/tutorials/data") / name
if not path.exists():
service = "https://psl.noaa.gov/repository/entry/get"
query = (
"entryid=synth%3Ae570c8f9-ec09-4e89-93b4-"
"babd5651e7a9%3AL25jZXAucmVhbmFseXNpcy5kZXJpdm"
"VkL3N1cmZhY2UvYWlyLm1vbi5tZWFuLm5j")
url = f"{service}/{name}?{query}"
res = requests.get(url, timeout=(20, 20))
res.raise_for_status()
with open(path, 'wb') as f:
f.write(res.content)
return path
7 changes: 4 additions & 3 deletions tests/test_climate/test_map_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# and J. Kurths, "Unified functional network and nonlinear time series analysis
# for complex systems science: The pyunicorn package"

from pathlib import Path

import matplotlib.pyplot as plt

from pyunicorn.climate.climate_data import ClimateData
Expand All @@ -26,20 +28,19 @@ class TestMapPlot:
"""

@staticmethod
def test_plot():
def test_plot(reanalysis_data: Path):
"""
Check error-free execution.
"""
# prepare ClimateNetwork fixture
# (select subset of data to speed up loading and calculation)
title = "ncep_ncar_reanalysis"
file = 'examples/tutorials/data/air.mon.mean.nc'
window = {
"time_min": 0., "time_max": 0.,
"lat_min": 30, "lon_min": 0,
"lat_max": 50, "lon_max": 30}
data = ClimateData.Load(
file_name=file, observable_name="air",
file_name=reanalysis_data, observable_name="air",
file_type="NetCDF", window=window, time_cycle=12)
net = TsonisClimateNetwork(data, threshold=.05, winter_only=False)

Expand Down

0 comments on commit c5de131

Please sign in to comment.