Skip to content

Commit 1c44596

Browse files
Merge pull request #7 from EcoExtreML/run_nb_dev_mode
Add a notebook and a matlab script to run the model in development mode
2 parents 647e8c1 + b0d191b commit 1c44596

8 files changed

Lines changed: 728 additions & 40 deletions

CONTRIBUTING.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# processing
2+
3+
This repositary includes python modules for running the STEMMUS-SCOPE model in a
4+
notebook.
5+
6+
The workflow is executed using python and MATLAB on a Unix-like system.
7+
The python packages are listed in the
8+
[`environment.yml`](https://github.com/EcoExtreML/processing/blob/main/environment.yml)
9+
file. Follow the instructions below to create conda environment and install
10+
MATLAB Runtime.
11+
12+
<details>
13+
<summary>Create conda environment </summary>
14+
15+
Run the commands below in a terminal:
16+
17+
```sh
18+
# Download and install Conda
19+
wget https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-pypy3-Linux-x86_64.sh
20+
bash Mambaforge-pypy3-Linux-x86_64.sh
21+
-b -p ~/mamba
22+
23+
# Update base environment
24+
. ~/mamba/bin/activate
25+
mamba update --name base mamba
26+
27+
# Clone this repository
28+
git clone https://github.com/EcoExtreML/processing.git
29+
30+
# Create a conda environment called 'stemmus' with all required dependencies
31+
cd processing
32+
mamba env create
33+
34+
# The environment can be activated with
35+
. ~/mamba/bin/activate stemmus
36+
37+
```
38+
</details>
39+
40+
<details>
41+
<summary>Use MATLAB </summary>
42+
43+
To run the STEMMUS_SCOPE, you need MATLAB version `>=2019`.
44+
45+
**On Snellius:**
46+
47+
[Snellius](https://servicedesk.surfsara.nl/wiki/display/WIKI/Snellius) is the
48+
Dutch National supercomputer hosted at SURF. MATLAB Runtime is installed on
49+
Snellius, see the script
50+
[`run_jupyter_lab_snellius_dev.sh`](https://github.com/EcoExtreML/processing/blob/main/run_jupyter_lab_snellius_dev.sh)
51+
on how to load the module.
52+
</details>
53+
54+
# Run jupyter notebook
55+
56+
**On Snellius:**
57+
58+
Use the script
59+
[`run_jupyter_lab_snellius_dev.sh`](https://github.com/EcoExtreML/processing/blob/main/run_jupyter_lab_snellius_dev.sh)
60+
to create a jupyter lab server on Snellius for running the notebook
61+
interactively.
62+
63+
**On CRIB:**
64+
65+
[CRIB](https://crib.utwente.nl/) is the ITC Geospatial Computing Platform.
66+
67+
1. Log in CRIB with your username and password and select a proper compute unit.
68+
2. Check `config_file_crib.txt` and change the paths if needed, specifically
69+
"InputPath" and "OutputPath".
70+
3. click on the `Remote Desktop` in the
71+
Launcher. Click on the `Applications`. You will find the 'MATLAB' software under
72+
the `Research`.
73+
4. After clicking on 'MATLAB', it asks for your account information that is
74+
connected to a MATLAB license.
75+
5. Open the file `run_model_in_matlab_dev.m` and set the paths inside the script.
76+
6. Then, run the main script `run_model_in_matlab_dev.m`.
77+
78+
# Recipe of model execution
79+
80+
The execution of the model includes following steps:
81+
82+
- Update/set config files
83+
- Create input directories, prepare input files
84+
- Run the model
85+
- Create output directories, prepare output files
86+
- Create exe file

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,17 @@ Run the commands below in a terminal:
3535
```sh
3636
# Download and install Conda
3737
wget https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-pypy3-Linux-x86_64.sh
38-
bash Mambaforge-pypy3-Linux-x86_64.sh
39-
-b -p ~/mamba
38+
bash Mambaforge-pypy3-Linux-x86_64.sh -b -p ~/mamba
4039

4140
# Update base environment
4241
. ~/mamba/bin/activate
4342
mamba update --name base mamba
4443

4544
# Clone this repository
46-
git clone https://github.com/EcoExtreML/processing.git
45+
git clone https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing.git
4746

4847
# Create a conda environment called 'stemmus' with all required dependencies
49-
cd processing
48+
cd STEMMUS_SCOPE_Processing
5049
mamba env create
5150

5251
# The environment can be activated with
@@ -83,7 +82,7 @@ For more information on how to download and install it, see the links below:
8382
[Snellius](https://servicedesk.surfsara.nl/wiki/display/WIKI/Snellius) is the
8483
Dutch National supercomputer hosted at SURF. MATLAB Runtime is installed on
8584
Snellius, see the script
86-
[`run_jupyter_lab_on_compute_node.sh`](https://github.com/EcoExtreML/processing/blob/main/run_jupyter_lab_on_compute_node.sh)
85+
[`run_jupyter_lab_on_compute_node.sh`](https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/blob/main/run_jupyter_lab_on_compute_node.sh)
8786
on how to load the module.
8887
</details>
8988

@@ -100,11 +99,11 @@ JupyterLab will open automatically in your browser.
10099
**On Snellius:**
101100

102101
Use the script
103-
[`run_jupyter_lab_on_compute_node.sh`](https://github.com/EcoExtreML/processing/blob/main/run_jupyter_lab_on_compute_node.sh)
102+
[`run_jupyter_lab_snellius.sh`](https://github.com/EcoExtreML/STEMMUS_SCOPE_Processing/blob/main/run_jupyter_lab_on_compute_node.sh)
104103
to create a jupyter lab server on Snellius for running the notebook
105104
interactively.
106105

107-
# Run jupyter notebook on CRIB
106+
**On CRIB:**
108107

109108
[CRIB](https://crib.utwente.nl/) is the ITC Geospatial Computing Platform.
110109
Currently, running the notebook on CRIB is not supported because MATLAB Runtime
@@ -114,7 +113,6 @@ can not be installed there.
114113

115114
The execution of the model includes following steps:
116115

117-
- Create exe file
118116
- Update/set config files
119117
- Create input directories, prepare input files
120118
- Run the model

docs/CONTRIBUTING.md

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,78 @@
1-
# Contributing guidelines
1+
# STEMMUS_SCOPE processing
22

3-
We welcome any kind of contribution to our software, from simple comment or question to a full fledged [pull request](https://help.github.com/articles/about-pull-requests/). Please read and follow our [Code of Conduct](CODE_OF_CONDUCT.md).
3+
This document illustrates how to run the model STEMMUS_SCOPE as a developer.
4+
The workflow is executed using python and MATLAB on a Unix-like system where a MATLAB license is available.
5+
To run the STEMMUS_SCOPE, you need MATLAB version `>=2019`.
46

5-
A contribution can be one of the following cases:
7+
The python packages are listed in the
8+
[`environment.yml`](https://github.com/EcoExtreML/processing/blob/main/environment.yml)
9+
file. Follow the instructions below to create conda environment.
610

7-
1. you have a question;
8-
1. you think you may have found a bug (including unexpected behavior);
9-
1. you want to make some kind of change to the code base (e.g. to fix a bug, to add a new feature, to update documentation);
10-
1. you want to make a new release of the code base.
11+
<details>
12+
<summary>Create conda environment </summary>
1113

12-
The sections below outline the steps in each case.
14+
Run the commands below in a terminal:
1315

14-
## You have a question
16+
```sh
17+
# Download and install Conda
18+
wget https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-pypy3-Linux-x86_64.sh
19+
bash Mambaforge-pypy3-Linux-x86_64.sh
20+
-b -p ~/mamba
1521

16-
1. use the search functionality [here](https://github.com/EcoExtreML/stemmus_scope_processing/issues) to see if someone already filed the same issue;
17-
2. if your issue search did not yield any relevant results, make a new issue;
18-
3. apply the "Question" label; apply other labels when relevant.
22+
# Update base environment
23+
. ~/mamba/bin/activate
24+
mamba update --name base mamba
1925

20-
## You think you may have found a bug
26+
# Clone this repository
27+
git clone https://github.com/EcoExtreML/processing.git
2128

22-
1. use the search functionality [here](https://github.com/EcoExtreML/stemmus_scope_processing/issues) to see if someone already filed the same issue;
23-
1. if your issue search did not yield any relevant results, make a new issue, making sure to provide enough information to the rest of the community to understand the cause and context of the problem. Depending on the issue, you may want to include:
24-
- the [SHA hashcode](https://help.github.com/articles/autolinked-references-and-urls/#commit-shas) of the commit that is causing your problem;
25-
- some identifying information (name and version number) for dependencies you're using;
26-
- information about the operating system;
27-
1. apply relevant labels to the newly created issue.
29+
# Create a conda environment called 'stemmus' with all required dependencies
30+
cd processing
31+
mamba env create
2832

29-
## You want to make some kind of change to the code base
33+
# The environment can be activated with
34+
. ~/mamba/bin/activate stemmus
3035

31-
1. (**important**) announce your plan to the rest of the community *before you start working*. This announcement should be in the form of a (new) issue;
32-
1. (**important**) wait until some kind of consensus is reached about your idea being a good idea;
33-
1. if needed, fork the repository to your own Github profile and create your own feature branch off of the latest master commit. While working on your feature branch, make sure to stay up to date with the master branch by pulling in changes, possibly from the 'upstream' repository (follow the instructions [here](https://help.github.com/articles/configuring-a-remote-for-a-fork/) and [here](https://help.github.com/articles/syncing-a-fork/));
34-
1. make sure the existing tests still work by running ``pytest``;
35-
1. add your own tests (if necessary);
36-
1. update or expand the documentation;
37-
1. update the `CHANGELOG.md` file with change;
38-
1. push your feature branch to (your fork of) the PyStemmusScope repository on GitHub;
39-
1. create the pull request, e.g. following the instructions [here](https://help.github.com/articles/creating-a-pull-request/).
36+
```
37+
</details>
4038

41-
In case you feel like you've made a valuable contribution, but you don't know how to write or run tests for it, or how to generate the documentation: don't let this discourage you from making the pull request; we can help you! Just go ahead and submit the pull request, but keep in mind that you might be asked to append additional commits to your pull request.
39+
40+
# Run model in a Jupyter notebook
41+
42+
**On Snellius:**
43+
44+
[Snellius](https://servicedesk.surfsara.nl/wiki/display/WIKI/Snellius) is the
45+
Dutch National supercomputer hosted at SURF.
46+
47+
The notebook [run_model_in_notebook_dev.ipynb](./notebooks/run_model_in_notebook_dev.ipynb) shows how to run the model.
48+
Use the script
49+
[`run_jupyter_lab_snellius_dev.sh`](https://github.com/EcoExtreML/processing/blob/main/run_jupyter_lab_snellius_dev.sh)
50+
to create a Jupyter lab server on Snellius for running the notebook
51+
interactively.
52+
53+
# Run model in a MATLAB script
54+
55+
**On CRIB:**
56+
57+
[CRIB](https://crib.utwente.nl/) is the ITC Geospatial Computing Platform.
58+
59+
1. Log in CRIB with your username and password and select a proper compute unit.
60+
2. Check `config_file_crib.txt` and change the paths if needed, specifically
61+
"InputPath" and "OutputPath".
62+
3. click on the `Remote Desktop` in the
63+
Launcher. Click on the `Applications`. You will find the 'MATLAB' software under
64+
the `Research`.
65+
4. After clicking on 'MATLAB', it asks for your account information that is
66+
connected to a MATLAB license.
67+
5. Open the file `run_model_in_matlab_dev.m` and set the paths inside the script.
68+
6. Then, run the main script `run_model_in_matlab_dev.m`.
69+
70+
# Recipe of model execution
71+
72+
The execution of the model includes following steps:
73+
74+
- Update/set config files
75+
- Create input directories, prepare input files
76+
- Run the model
77+
- Create output directories, prepare output files
78+
- Create exe file
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""This script is an example that is used by the script run_model_in_matlab_dev.m"""
2+
3+
import shutil
4+
from pathlib import Path
5+
import time
6+
7+
8+
def read_config(config_file_path):
9+
config = {}
10+
with open(config_file_path, "r") as f:
11+
for line in f:
12+
(key, val) = line.split("=")
13+
config[key] = val.rstrip('\n')
14+
return config
15+
16+
17+
def input_dir(ncfile, config):
18+
"""Create input directory and prepare input files
19+
"""
20+
# get start time with the format Y-M-D-HM
21+
timestamp = time.strftime('%Y%m%d_%H%M')
22+
station_name = ncfile.split('_')[0]
23+
# create input directory
24+
work_dir = Path(f"{config['InputPath']}{station_name}_{timestamp}")
25+
Path(work_dir).mkdir(parents=True, exist_ok=True)
26+
print(f"Prepare work directory {work_dir} for the station: {station_name}")
27+
# copy model parameters to work directory
28+
shutil.copytree(config["VegetationPropertyPath"], work_dir, dirs_exist_ok=True)
29+
# update config file for ForcingFileName and InputPath
30+
config_file_path = Path(work_dir, f"{station_name}_{timestamp}_config.txt")
31+
with open(config_file_path, 'w') as f:
32+
for i in config.keys():
33+
if i == "ForcingFileName":
34+
f.write(i + "=" + ncfile + "\n")
35+
elif i == "InputPath":
36+
f.write(i + "=" + str(work_dir) + "/" + "\n")
37+
else:
38+
f.write(i + "=" + config[i] + "\n")
39+
40+
return str(work_dir)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
%%% This script is an example that shows how to call user-defined Python module from MATLAB
2+
3+
%% activate the stemmus environment
4+
pe = pyenv('Version','~/mamba/envs/stemmus/bin/python');
5+
6+
%% add the current folder to the Python search path
7+
insert(py.sys.path,int64(0),'');
8+
9+
%% path to config file
10+
config_file_path = "path_to_config_file_crib.txt";
11+
12+
%% read config file
13+
config = py.example_python_modules.read_config(config_file_path);
14+
15+
%% create working directory
16+
forcing_filename = config{'ForcingFileName'};
17+
work_dir = py.example_python_modules.input_dir(forcing_filename, config);
18+
19+
%% path to model source code
20+
model_source_codes = "path_to/STEMMUS_SCOPE/src";
21+
22+
%% add it to the top of your search path
23+
addpath(model_source_codes);
24+
25+
%% run the model
26+
STEMMUS_SCOPE_exe(config_file_path);
27+
28+
%% TODO csv to netcdf files

0 commit comments

Comments
 (0)