Skip to content

Commit 5336241

Browse files
Move docs to mkdocs, include notebook w/ source link (#64)
* Update to docs, include notebook w/ source link * Add nbsphinx to dev dependencies * Disable "edit on github". * Add extra links to ToC * Update logo. Try prolog * Update docstrings, notebooks * Move to mkdocs * Set rtd config to use mkdocs * Fix docs build, use mkdocs * Remove duplicate notebooks from main dir * Update readme, dependencies, gitignore
1 parent 031b99c commit 5336241

23 files changed

Lines changed: 354 additions & 431 deletions

.github/workflows/documentation.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ jobs:
3030
python3 -m pip install --upgrade pip setuptools
3131
python3 -m pip install .[dev,publishing]
3232
- name: Install pandoc using apt
33-
run: sudo apt install pandoc
33+
run: sudo apt install pandoc
3434
- name: Build documentation
35-
run: make coverage doctest html
36-
working-directory: docs
35+
run: mkdocs build

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ instance/
7272
# Scrapy stuff:
7373
.scrapy
7474

75-
# Sphinx documentation
76-
docs/_build/
77-
7875
# PyBuilder
7976
target/
8077

.readthedocs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ build:
55
tools:
66
python: "3.9"
77

8+
mkdocs:
9+
configuration: mkdocs.yml
10+
fail_on_warning: false
11+
812
python:
913
install:
1014
- method: pip

PyStemmusScope/save.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
"""PyStemmusScope save module.
22
3-
Module designed to create a netcdf file following `ALMA
4-
convention <https://web.lmd.jussieu.fr/~polcher/ALMA/>`_ from csv files following
5-
`SCOPE format <https://scope-model.readthedocs.io/en/latest/outfiles.html>`_ in
6-
the output directory.
3+
Module designed to create a netcdf file following the
4+
[ALMA convention](https://web.lmd.jussieu.fr/~polcher/ALMA/)
5+
from csv files following the
6+
[SCOPE format](https://scope-model.readthedocs.io/en/latest/outfiles.html)
7+
in the output directory.
78
89
The file
9-
`required_netcf_variables.csv <https://github.com/EcoExtreML/STEMMUS_SCOPE/blob/main/utils/csv_to_nc/required_netcf_variables.csv>`_
10-
lists required variable names and their attributes based on `ALMA+CF
11-
convention table <https://docs.google.com/spreadsheets/d/1CA3aTvI9piXqRqO-3MGrsH1vW-Sd87D8iZXHGrqK42o/edit#gid=2085475627>`_.
10+
[`required_netcf_variables.csv`](https://github.com/EcoExtreML/STEMMUS_SCOPE/blob/main/utils/csv_to_nc/required_netcf_variables.csv)
11+
lists required variable names and their attributes based on the
12+
[ALMA+CF convention table](https://docs.google.com/spreadsheets/d/1CA3aTvI9piXqRqO-3MGrsH1vW-Sd87D8iZXHGrqK42o/edit#gid=2085475627).
1213
13-
Example:
14-
See notebooks/run_model_in_notebook.ipynb in
15-
`STEMMUS_SCOPE_Processing repository <https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing>`_
14+
Note:
15+
See notebooks/run_model_in_notebook.ipynb in the
16+
[STEMMUS_SCOPE_Processing repository](https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing).
1617
1718
"""
1819
import logging
@@ -182,10 +183,10 @@ def _update_dataset_attrs_dims(dataset: xr.Dataset, forcing_dict: Dict) -> xr.Da
182183
"""Update dimentions of a dataset according to ALMA conventions.
183184
184185
Args:
185-
dataset(xr.Dataset): a dataset with varaibles in ALMA conventions.
186+
dataset: a dataset with varaibles in ALMA conventions.
186187
187188
Returns:
188-
xr.Dataset: the dataset with dimensions ("time", "x", "y").
189+
The dataset with dimensions ("time", "x", "y").
189190
"""
190191

191192
# add x/y dims to the dataset
@@ -237,11 +238,11 @@ def to_netcdf(config_file: str, cf_filename: str) -> str:
237238
information provided by ALMA conventions.
238239
239240
Args:
240-
config_file(str): Path to the config file.
241-
cf_filename(str): Path to a csv file for ALMA conventions.
241+
config_file: Path to the config file.
242+
cf_filename: Path to a csv file for ALMA conventions.
242243
243244
Returns:
244-
str: path to a csv file under the output directory.
245+
Path to a csv file under the output directory.
245246
"""
246247
config = config_io.read_config(config_file)
247248
forcing_filename = utils.get_forcing_file(config)

PyStemmusScope/stemmus_scope.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _is_model_src_exe(model_src_path: Path):
3434
msg = (
3535
"Provide a valid path to an executable file or "
3636
"to a directory containing model source codes, "
37-
"see the `documentaion<https://pystemmusscope.readthedocs.io/>`_.")
37+
"see the `documentation<https://pystemmusscope.readthedocs.io/>`_.")
3838
raise ValueError(msg)
3939

4040

@@ -43,7 +43,7 @@ def _check_interpreter(interpreter: str):
4343
msg = (
4444
"Set `interpreter` as Octave or Matlab to run the model using source codes."
4545
"Otherwise set `model_src_path` to the model executable file, "
46-
"see the `documentaion<https://pystemmusscope.readthedocs.io/>`_.")
46+
"see the `documentation<https://pystemmusscope.readthedocs.io/>`_.")
4747
raise ValueError(msg)
4848

4949

@@ -73,22 +73,24 @@ def _run_sub_process(args: list, cwd):
7373

7474
class StemmusScope():
7575
"""PyStemmusScope wrapper around Stemmus_Scope model.
76-
see https://gmd.copernicus.org/articles/14/1379/2021/
7776
78-
Configures the model and prepares forcing and soil data for the model run.
77+
For a detailed model description, look at
78+
[this publication](https://gmd.copernicus.org/articles/14/1379/2021/).
7979
80-
Args:
81-
config_file(str): path to Stemmus_Scope configuration file. An example
82-
config_file can be found in tests/test_data in `STEMMUS_SCOPE_Processing
83-
repository <https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing>`_
84-
model_src_path(str): path to Stemmus_Scope executable file or to a
85-
directory containing model source codes.
86-
interpreter(str, optional): use `Matlab` or `Octave`. Only required if
87-
`model_src_path` is a path to model source codes.
80+
Configures the model and prepares forcing and soil data for the model run.
81+
82+
Arguments:
83+
config_file (str): Path to Stemmus_Scope configuration file. An example
84+
config_file can be found in tests/test_data in [STEMMUS_SCOPE_Processing
85+
repository](https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing).
86+
model_src_path (str): Path to Stemmus_Scope executable file or to a
87+
directory containing model source codes.
88+
interpreter (str, optional): Use `Matlab` or `Octave`. Only required if
89+
`model_src_path` is a path to model source codes.
8890
8991
Example:
90-
See notebooks/run_model_in_notebook.ipynb in `STEMMUS_SCOPE_Processing
91-
repository <https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing>`_
92+
See notebooks/run_model_in_notebook.ipynb at the [STEMMUS_SCOPE_Processing
93+
repository](https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing)
9294
"""
9395

9496
def __init__(self, config_file: str, model_src_path: str, interpreter: str = None):
@@ -121,12 +123,13 @@ def setup(
121123
1. Creates config file and input/output directories based on the config template.
122124
2. Prepare forcing and soil data
123125
124-
Args:
126+
Arguments:
125127
WorkDir: path to a directory where input/output directories should be created.
126128
ForcingFileName: forcing file name. Forcing file should be in netcdf format.
127-
StartTime: Start time of the model run. It must be in
129+
StartTime: Start time of the model run. It must be in
128130
ISO format (e.g. 2007-01-01T00:00).
129-
EndTime: End time of the model run. It must be in ISO format (e.g. 2007-01-01T00:00).
131+
EndTime: End time of the model run. It must be in ISO format
132+
(e.g. 2007-01-01T00:00).
130133
131134
Returns:
132135
Path to the config file
@@ -163,7 +166,7 @@ def run(self) -> str:
163166
Args:
164167
165168
Returns:
166-
string, the model log
169+
The model log.
167170
"""
168171
if self.exe_file:
169172
# run using MCR

README.md

Lines changed: 4 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -26,158 +26,8 @@ The model source code, executable file and utility files are available in the [S
2626

2727
The input datasets are available on Snellius and CRIB. First, make sure you have
2828
right access to the repository and data. Then, see the notebook
29-
[run_model_in_notebook.ipynb](https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/blob/main/notebooks/run_model_in_notebook.ipynb)
30-
which provides different options to run the model, see [Run the
31-
model](#run-the-model).
29+
[run_model_in_notebook.ipynb](https://pystemmusscope.readthedocs.io/en/latest/readme_link.html)
30+
which provides different options to run the model.
3231

33-
## Run the model
34-
35-
1. Using executable file: As a user, you don't need to have a MATLAB license to
36-
run the STEMMUS-SCOPE model. If `PyStemmusScope` and `MATLAB Runtime` are
37-
installed on a Unix-like system (e.g. your own machine, Snellius or WSL), you
38-
can run STEMMUS_SCOPE using the executable file.
39-
2. Using Matlab: If `PyStemmusScope` and `Matlab` are installed, you can run
40-
STEMMUS_SCOPE from the source code, for example on Snellius or CRIB.
41-
3. Using Octave: If `PyStemmusScope` and latest `Octave` including required
42-
packages are installed, you can run STEMMUS_SCOPE from its source code, for
43-
example on CRIB or your own machine.
44-
45-
See section [Installations](#installations) for required packages.
46-
47-
## Installations
48-
49-
### On Snellius
50-
51-
[Snellius](https://servicedesk.surfsara.nl/wiki/display/WIKI/Snellius) is the
52-
Dutch National supercomputer hosted at SURF. MATLAB and MATLAB Runtime are
53-
installed on Snellius, see the script
54-
[`run_jupyter_lab_snellius.sh`](https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/blob/main/run_jupyter_lab_snellius.sh)
55-
on how to load the module. Also, use the same script to create a jupyter lab
56-
server for running notebooks interactively. The script activates the conda
57-
environment `pystemmusscope`. Make sure that you create the `pystemmusscope`
58-
conda environment before submitting the the bash script. See
59-
[Create pystemmusscope conda environment](#create-pystemmusscope-conda-environment).
60-
61-
### On CRIB
62-
63-
[CRIB](https://crib.utwente.nl/) is the ITC Geospatial Computing Platform. You
64-
can run the model using `Matlab` or `Octave`. Currently, running the
65-
exceutable file on CRIB is not supported because MATLAB Runtime can not be
66-
installed there. See [Install PyStemmusScope](#install-pystemmusscope).
67-
68-
### On your own machine
69-
70-
Choose how do you want to run the model, see [Run the model](#run-the-model).
71-
72-
### Install PyStemmusScope
73-
74-
Run the commands below in a terminal (On Windows, use `python` instead of
75-
`python3`):
76-
77-
```sh
78-
python3 -m pip install pystemmusscope
79-
```
80-
81-
or
82-
83-
Open a jupyter notebook and run the code below in a cell:
84-
85-
```python
86-
!pip install pystemmusscope
87-
```
88-
89-
### Install jupyterlab
90-
91-
Jupyterlab is needed to run notebooks. Run the commands below in a terminal:
92-
93-
```sh
94-
python3 -m pip install jupyterlab
95-
96-
```
97-
98-
Open a terminal, make sure the environment is activated. Then, run `jupyter lab`:
99-
100-
```sh
101-
jupyter lab
102-
```
103-
104-
JupyterLab will open automatically in your browser. Now, you can run the
105-
notebook
106-
[run_model_in_notebook.ipynb](https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/blob/main/notebooks/run_model_in_notebook.ipynb).
107-
108-
### Install MATLAB Runtime
109-
110-
To run the STEMMUS_SCOPE, you need MATLAB Runtime version `2021a` and a Unix-like system.
111-
112-
In a terminal:
113-
114-
```sh
115-
# Download MATLAB Runtime for Linux
116-
wget https://ssd.mathworks.com/supportfiles/downloads/R2021a/Release/6/deployment_files/installer/complete/glnxa64/MATLAB_Runtime_R2021a_Update_6_glnxa64.zip
117-
118-
# Unzip the file
119-
unzip MATLAB_Runtime_R2021a_Update_6_glnxa64.zip -d MATLAB_Runtime
120-
121-
# Install it
122-
cd MATLAB_Runtime
123-
sudo -H ./install -mode silent -agreeToLicense yes
124-
```
125-
126-
For more information on how to download and install MATLAB Runtime, see the links below:
127-
- [download](https://nl.mathworks.com/products/compiler/matlab-runtime.html)
128-
- [installation](https://nl.mathworks.com/help/compiler/install-the-matlab-runtime.html)
129-
130-
### Install WSL
131-
132-
As the STEMMUS-SCOPE executable only supports Unix-like systems, Windows users
133-
cannot run STEMMUS-SCOPE natively. However, users of Windows 10 and newer can
134-
use WSL ([Windows Subsystem for
135-
Linux](https://docs.microsoft.com/en-us/windows/wsl/)) to run the model.
136-
Check the <a
137-
href="https://docs.microsoft.com/en-us/windows/wsl/install">Microsoft Guide</a>
138-
for a compatibility information and for general WSL instructions.
139-
If no installation exists, a Ubuntu distribution can be installed using the following commands:
140-
```sh
141-
wsl --install
142-
```
143-
144-
After installation, you can start up the WSL instance and update the default software:
145-
146-
```sh
147-
sudo apt update && sudo apt upgrade
148-
```
149-
150-
You can now set up a python environment using either python's `venv`, or use Conda/Mamba.
151-
Note that the command to run python and pip can be `python3` and `pip3` by default.
152-
153-
For the rest of the installation instructions simply follow the steps below.
154-
Note that it is possible to access files from the Windows filesystem from within
155-
WSL, by accessing, e.g., `/mnt/c/` instead of `C:\`. This means that large input
156-
data files can be stored on your Windows installation instead of inside the WSL
157-
distro. However, WSL does not have write permission. Therefore, output data will
158-
be stored within WSL. Make sure that `WorkDir` in the model config file is set
159-
correctly.
160-
161-
### Create pystemmusscope conda environment
162-
163-
If a conda environment is neeed, run the commands below in a terminal:
164-
165-
```sh
166-
# Download and install Mamba on linux
167-
wget https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-pypy3-Linux-x86_64.sh
168-
bash Mambaforge-pypy3-Linux-x86_64.sh -b -p ~/mamba
169-
170-
# Update base environment
171-
. ~/mamba/bin/activate
172-
mamba update --name base mamba
173-
174-
# Download environment file
175-
wget https://raw.githubusercontent.com/EcoExtreML/STEMMUS_SCOPE_Processing/main/environment.yml
176-
177-
# Create a conda environment called 'pystemmusscope' with all required dependencies
178-
mamba env create -f environment.yml
179-
180-
# The environment can be activated with
181-
. ~/mamba/bin/activate pystemmusscope
182-
183-
```
32+
More information on the setup and installation, including for own machine, is available
33+
in the [documentation](https://pystemmusscope.readthedocs.io/).

CONTRIBUTING.md renamed to docs/CONTRIBUTING.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Contributing Guide
22

3-
This repository includes the python package `PyStemmusScope` for running the STEMMUS-SCOPE model.
3+
If you want to contribute to `PyStemmusScope`, you will need to set up your development
4+
environment the right way. The instructions below will guide you though the steps
5+
required.
46

57
## Configure the python package for development and testing
68

@@ -23,7 +25,7 @@ cd STEMMUS_SCOPE_Processing
2325
python3 -m install -e .[dev]
2426
```
2527

26-
### Run tests
28+
### Running tests
2729

2830
The testing framework used here is [PyTest](https://pytest.org). You can run
2931
tests as (On Windows, use `python` instead of `python3`):
@@ -32,16 +34,18 @@ tests as (On Windows, use `python` instead of `python3`):
3234
python3 -m pytest
3335
```
3436

35-
### Build documentation
37+
### Building the documentation
3638

37-
To build the documentation locally:
39+
To edit the documentation locally, do:
3840

3941
```sh
40-
cd docs/
41-
make html
42+
mkdocs serve
4243
```
4344

44-
Then open `_build/html/index.html` in a web broser to preview the documentation.
45+
Then open the local hyperlink displayed in the terminal, e.g.:
46+
```
47+
INFO - [13:23:44] Serving on http://127.0.0.1:8000/
48+
```
4549

4650
### Run formatting tools
4751

docs/Makefile

Lines changed: 0 additions & 20 deletions
This file was deleted.

docs/_templates/.gitignore

Whitespace-only changes.

0 commit comments

Comments
 (0)