Skip to content

Commit f377ec4

Browse files
Merge pull request #118 from EcoExtreML/update_docs
Update docs and fix some issues
2 parents 43c5e60 + 79206f1 commit f377ec4

29 files changed

Lines changed: 505 additions & 744 deletions

.github/workflows/markdown-link-check.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212

1313
markdown-link-check:
1414
name: Check markdown links
15-
runs-on: ubuntu-latest
15+
runs-on: ubuntu-22.04 # there is an issue with ubuntu-latest and linkspector
1616
steps:
17-
- uses: actions/checkout@v3
18-
- uses: gaurav-nelson/github-action-markdown-link-check@v1
17+
- uses: actions/checkout@v4
18+
- uses: umbrelladocs/action-linkspector@v1
1919
with:
20-
config-file: '.mlc-config.json'
20+
config_file: '.linkspector.yml'
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#
2+
name: Create and publish the PyStemmusScope container image 📦
3+
4+
on:
5+
release:
6+
types: [published]
7+
workflow_dispatch:
8+
9+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
15+
jobs:
16+
build-and-push-image:
17+
runs-on: ubuntu-latest
18+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
19+
permissions:
20+
contents: read
21+
packages: write
22+
attestations: write
23+
id-token: write
24+
#
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
29+
- name: Log in to the Container registry
30+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
31+
with:
32+
registry: ${{ env.REGISTRY }}
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
36+
- name: Extract metadata (tags, labels) for Docker
37+
id: meta
38+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
39+
with:
40+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
41+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
42+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
43+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
44+
- name: Build and push Docker image
45+
id: push
46+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
47+
with:
48+
context: .
49+
push: true
50+
tags: ${{ steps.meta.outputs.tags }}
51+
labels: ${{ steps.meta.outputs.labels }}
52+
53+
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
54+
- name: Generate artifact attestation
55+
uses: actions/attest-build-provenance@v1
56+
with:
57+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
58+
subject-digest: ${{ steps.push.outputs.digest }}
59+
push-to-registry: true

.github/workflows/python-publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ name: Upload Python Package
1111
on:
1212
release:
1313
types: [published]
14+
workflow_dispatch:
1415

1516
permissions:
1617
contents: read

.linkspector.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
dirs:
2+
- ./docs
3+
excludedDirs:
4+
- ./docs/notebooks
5+
- ./docs/overrides
6+
ignorePatterns:
7+
- pattern: "^http://localhost"
8+
- pattern: "^https://doi.org/<replace-with-created-DOI>"
9+
- pattern: "^https://github.com/.*/settings/secrets/actions$"
10+
- pattern: "^https://github.com/organizations/.*/repositories/new"
11+
- pattern: "^https://test.pypi.org"
12+
- pattern: "^https://bestpractices.coreinfrastructure.org/projects/<replace-with-created-project-identifier>"
13+
- pattern: "^https://readthedocs.org/dashboard/import.*"
14+
useGitIgnore: true

.mlc-config.json

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

PyStemmusScope/bmi/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Documentation about StemmusScopeBmi."""
2+
from .implementation import StemmusScopeBmi
3+
4+
5+
__all__ = ["StemmusScopeBmi"]

PyStemmusScope/bmi/local_process.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def __init__(self, cfg_file: str) -> None:
104104
env = {
105105
"LD_LIBRARY_PATH": lib_path,
106106
"MATLAB_LOG_DIR": str(config["OutputPath"]),
107+
"MCR_CACHE_ROOT": str(os.getenv("MCR_CACHE_ROOT")),
107108
}
108109

109110
self.process = subprocess.Popen(

README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,11 @@
1818
[![cffconvert](https://github.com/EcoExtreML/stemmus_scope_processing/actions/workflows/cffconvert.yml/badge.svg)](https://github.com/EcoExtreML/stemmus_scope_processing/actions/workflows/cffconvert.yml)
1919
[![markdown-link-check](https://github.com/EcoExtreML/stemmus_scope_processing/actions/workflows/markdown-link-check.yml/badge.svg)](https://github.com/EcoExtreML/stemmus_scope_processing/actions/workflows/markdown-link-check.yml) -->
2020

21-
This repository includes the python package `PyStemmusScope` for running the
22-
STEMMUS-SCOPE model.
21+
This repository includes the python package `PyStemmusScope` for preparing data
22+
nd running the STEMMUS-SCOPE model.
2323

2424
<!-- markdown-link-check-disable-next-line -->
2525
The model source code, executable file and utility files are available in the [STEMMUS_SCOPE repository](https://github.com/EcoExtreML/STEMMUS_SCOPE).
2626

27-
The input datasets are available on Snellius and CRIB. First, make sure you have
28-
right access to the repository and data. Then, see the notebook
29-
[run_model_on_different_infra.ipynb](./docs/notebooks/run_model_on_different_infra.ipynb)
30-
which provides different ways to run the model depending on your system and
31-
[run_model_with_different_dataset.ipynb](./docs/notebooks/run_model_with_different_dataset.ipynb)
32-
on how to use different datasets e.g. site or global data.
33-
3427
More information on the setup and installation, including for own machine, is available
3528
in the [documentation](https://pystemmusscope.readthedocs.io/).

docs/CONTRIBUTING.md

Lines changed: 155 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,81 @@
11
# Contributing Guide
22

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
3+
We welcome any kind of contributions to our software, from simple
4+
comment or question to a full fledged [pull
5+
request](https://help.github.com/articles/about-pull-requests/). Please
6+
read and follow our [Code of Conduct](./CODE_OF_CONDUCT.md).
7+
8+
A contribution can be one of the following cases:
9+
10+
1. you have a question;
11+
2. you think you may have found a bug (including unexpected behavior);
12+
3. you want to make some kind of change to the code base (e.g. to fix a
13+
bug, to add a new feature, to update documentation).
14+
4. you want to make a release
15+
16+
The sections below outline the steps in each case.
17+
18+
## You have a question
19+
20+
1. use the search functionality
21+
[here](https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/issues) to see if
22+
someone already filed the same issue;
23+
2. if your issue search did not yield any relevant results, make a new issue;
24+
3. apply the \"Question\" label; apply other labels when relevant.
25+
26+
## You think you may have found a bug
27+
28+
1. use the search functionality
29+
[here](https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/issues) to see
30+
if someone already filed the same issue;
31+
2. if your issue search did not yield any relevant results, make a new issue,
32+
making sure to provide enough information to the rest of the community to
33+
understand the cause and context of the problem. Depending on the issue, you
34+
may want to include: - the [SHA
35+
hashcode](https://help.github.com/articles/autolinked-references-and-urls/#commit-shas)
36+
of the commit that is causing your problem; - some identifying information
37+
(name and version number) for dependencies you\'re using; - information
38+
about the operating system;
39+
3. apply relevant labels to the newly created issue.
40+
41+
## You want to make some kind of change to the code base
42+
43+
1. (**important**) announce your plan to the rest of the community
44+
*before you start working*. This announcement should be in the form
45+
of a (new) issue;
46+
2. (**important**) wait until some kind of consensus is reached about
47+
your idea being a good idea;
48+
3. if needed, fork the repository to your own Github profile and create your own
49+
feature branch off of the latest main commit. While working on your feature
50+
branch, make sure to stay up to date with the main branch by pulling in
51+
changes, possibly from the \'upstream\' repository (follow the instructions
52+
[here](https://help.github.com/articles/configuring-a-remote-for-a-fork/)
53+
and [here](https://help.github.com/articles/syncing-a-fork/));
54+
4. If you are using [Visual Studio Code](https://code.visualstudio.com), some
55+
extensions will be recommended and you are offered to run inside a
56+
[DevContainer](https://containers.dev) in which the dependencies are already
57+
installed;
58+
59+
In case you feel like you\'ve made a valuable contribution, but you
60+
don\'t know how to write or run tests for it, or how to generate the
61+
documentation: don\'t let this discourage you from making the pull
62+
request; we can help you! Just go ahead and submit the pull request, but
63+
keep in mind that you might be asked to append additional commits to
64+
your pull request.
65+
66+
If you want to contribute to `PyStemmusScope`, we recommend installing
67+
the package in editable mode. The instructions below will guide you though the steps
568
required.
669

7-
## Configure the python package for development and testing
70+
### Dependencies
871

9-
To contribute to the development of the python package, we recommend installing
10-
the package in development mode.
72+
Check the package `dependencies` and `optional dependencies` in the
73+
`pyproject.toml` file in the root directory of the repository. The package
74+
dependecies are those packages that are required to build the package as a
75+
software. The optional dependencies are those packages that are required to run
76+
the tests, build the documentation, and format the code.
1177

12-
13-
### Installation
78+
### Installation in editable mode
1479

1580
First, clone this repository:
1681

@@ -36,23 +101,39 @@ python3 -m pytest
36101

37102
### Building the documentation
38103

104+
To install the documentation dependencies (On Windows, use `python` instead of `python3`):
105+
106+
```sh
107+
cd STEMMUS_SCOPE_Processing
108+
python3 -m install -e .[docs]
109+
```
110+
39111
To edit the documentation locally, do:
40112

41113
```sh
42114
mkdocs serve
43115
```
44116

45117
Then open the local hyperlink displayed in the terminal, e.g.:
118+
46119
```
47120
INFO - [13:23:44] Serving on http://127.0.0.1:8000/
48121
```
49122

50123
### Run formatting tools
51124

52-
You can use `prospector` to get information about errors, potential problems and convention violations. To run:
125+
Formatting configs are listed in the `pyproject.toml` file. You can use `ruff`
126+
to get information about errors, potential problems and convention violations.
127+
To run:
53128

54129
```sh
55-
prospector
130+
ruff check .
131+
```
132+
133+
It is possible to fix some of the errors automatically. To do so, run:
134+
135+
```sh
136+
ruff check --fix .
56137
```
57138

58139
To format the import statements, you can use `isort` as:
@@ -61,7 +142,69 @@ To format the import statements, you can use `isort` as:
61142
isort
62143
```
63144

64-
## Development of STEMMUS_SCOPE model
145+
### BMI Developer instructions
146+
147+
The Python BMI implemented in this package communicates with the Matlab code
148+
through STDIN/STDOUT, or via a socket to the Docker container.
149+
Over this interface, three commands can be sent to Matlab:
150+
151+
1. `initialize "path_to_cfg_file.txt"`
152+
2. `update`
153+
3. `finalize`
154+
155+
After the initialize and update steps, the Matlab process writes the state of
156+
any BMI exposed variables to an hdf5-file in the directory of `OutputPath` as
157+
defined in the configuration file.
158+
159+
The Python BMI interfaces with this file to allow the variables to be read and set.
160+
161+
#### Adding/changing exposed variables
162+
163+
Step one of changing the exposed variables is to change the Matlab code and
164+
generating a new MCR executable (and possibly Docker image). The exposed
165+
variables are defined in
166+
[`STEMMUS_SCOPE/src/STEMMUS_SCOPE_exe.m`](https://github.com/EcoExtreML/STEMMUS_SCOPE/blob/main/src/STEMMUS_SCOPE_exe.m).
167+
Under the `bmiVarNames` variable. Make sure that you add the model variable
168+
here, as well as any info on the variable's grid.
169+
170+
The available variable names (`MODEL_INPUT_VARNAMES`, `MODEL_OUTPUT_VARNAMES`),
171+
their units (`VARNAME_UNITS`), datatypes (`VARNAME_DTYPE`) and grids
172+
(`VARNAME_GRID`) are defined in constants at the top of the file
173+
`PyStemmusScope/bmi/implementation.py`. These have to be updated to reflect the
174+
changes in the state file.
175+
176+
Lastly you have to update the `get_variable` and `set_variable` functions in
177+
`PyStemmusScope/bmi/implementation.py`. Here you define how the python code can
178+
access them. While writing the code you can inspect the state using
179+
`model.state`, which allows you to view the full contents of the HDF5 file for
180+
easier debugging.
181+
182+
After implementing the BMI changes, a new [STEMMUS_SCOPE Docker
183+
image](https://github.com/EcoExtreML/STEMMUS_SCOPE/pkgs/container/stemmus_scope)
184+
should be released that is compatible with the new BMI implementation. A new
185+
release usually includes a new tag. Then, you need to update the
186+
`compatible_tags` variable of the class `StemmusScopeDocker` in
187+
`PyStemmusScope/bmi/docker_process.py`.
188+
189+
## Making a release
190+
191+
This section describes how to make a release in 3 parts:
192+
193+
1. preparation
194+
1. making a release on GitHub
195+
196+
### (1/2) Preparation
197+
198+
1. Update the <CHANGELOG.md> (don't forget to update links at bottom of page)
199+
2. Verify that the information in `CITATION.cff` is correct, and that `.zenodo.json` contains equivalent data
200+
3. Make sure the version has been updated.
201+
4. Run the unit tests with `pytest -v`
202+
203+
### (2/2) GitHub
65204

66-
<!-- markdown-link-check-disable-next-line -->
67-
To contribute to the STEMMUS_SCOPE model, you need access to the model source code that is stored in the repository [STEMMUS_SCOPE](https://github.com/EcoExtreML/STEMMUS_SCOPE).
205+
Don't forget to also make a [release on
206+
GitHub](https://github.com/EcoExtreML/stemmus_scope_processing/releases/new).
207+
This will trigger the github action `python-publish.yml` that publishes the
208+
package on PyPI. If your repository uses the GitHub-Zenodo integration this will
209+
also trigger Zenodo into making a snapshot of your repository and sticking a DOI
210+
on it.

0 commit comments

Comments
 (0)