Running the STEMMUS_SCOPE model with different dataset on CRIB using MATLAB¶
This notebook shows how to run the STEMMUS_SCOPE model uisng source code, including preprocessing and postprocessing. For postprocesisng, the file required_netcdf_variables.csv can be found at https://github.com/EcoExtreML/STEMMUS_SCOPE/blob/main/utils/csv_to_nc/required_netcdf_variables.csv.
See the Running the STEMMUS_SCOPE model on a system for different ways e.g. Executable file, Matlab, Octave.
Which datasets are available?¶
The config file shows how to set the paths to different data needed by the model. Check the data source on Snelius and CRIB and modify the config file accordingly:
On CRIB¶
- Site data:
- path to data:
/data/shared/EcoExtreML/STEMMUS_SCOPEv1.0.0/input
, - config file template: https://github.com/EcoExtreML/STEMMUS_SCOPE/blob/main/config_file_crib.txt
- path to data:
- Global data:
- path to data
/data/shared/EcoExtreML/STEMMUS_SCOPEv1.0.0/global_data
, - config file template: https://github.com/EcoExtreML/STEMMUS_SCOPE/blob/main/config_file_crib_global.txt
- path to data
On Snellius¶
- Site data:
- path to data:
/projects/0/ttse0619/
, - config file template: https://github.com/EcoExtreML/STEMMUS_SCOPE/blob/main/run_model_on_snellius/config_file_snellius.txt
- path to data:
- Global data:
- path to data:
/projects/0/ttse0619/global_data
, - config file template: https://github.com/EcoExtreML/STEMMUS_SCOPE/blob/main/run_model_on_snellius/config_file_snellius_global.txt
- path to data:
Choose how do you want to run the model with MATLAB on CRIB:
1. Using site data¶
import os
from PyStemmusScope import StemmusScope
from PyStemmusScope import save
# user must provide the correct path
path_to_config_file = "./config_file_crib.txt"
path_to_model_src = "/home/jovyan/private/Sarah/STEMMUS_SCOPE/src"
# create an an instance of the model
model = StemmusScope(config_file=path_to_config_file, model_src_path=path_to_model_src, interpreter="Matlab")
# setup the model
# here you can change the location and start & end time
config_path = model.setup(
Location="ZA-Kru",
StartTime="2001-01-01T00:00",
EndTime="2001-01-02T01:30",
)
# new config file genertaed to run the model
print(f"New config file {config_path}")
# see input and output paths generated by the model
print(f'Model input dir {model.config["InputPath"]}')
print(f'Model output dir {model.config["OutputPath"]}')
New config file /data/private/test_run/input/ZA-Kru_2024-01-29-1142/ZA-Kru_2024-01-29-1142_config.txt Model input dir /data/private/test_run/input/ZA-Kru_2024-01-29-1142/ Model output dir /data/private/test_run/output/ZA-Kru_2024-01-29-1142/
If you are on CRIB, to use Jupyter interface and MATLAB license manager at the same time, first perform <echo $DISPLAY> in a terminal in the Remote Desktop of Crib Platform, and check the output which should be similar to :1.0 . Then execute the following line accordingly.
# For CRIB users
%env DISPLAY=:1.0
env: DISPLAY=:1.0
# run the model
result = model.run()
result
'\n < M A T L A B (R) >\n Copyright 1984-2021 The MathWorks, Inc.\n R2021a (9.10.0.1602886) 64-bit (glnxa64)\n February 17, 2021\n\n \nTo get started, type doc.\nFor product information, visit www.mathworks.com.\n \nReading config from /data/private/test_run/input/ZA-Kru_2024-01-29-1142/ZA-Kru_2024-01-29-1142_config.txt\nFinished model initialization\nThe calculations start now\nFinalizing STEMMUS_SCOPE\n'
# save output in netcdf format
required_netcdf_variables = "/home/jovyan/private/Sarah/STEMMUS_SCOPE/utils/csv_to_nc/required_netcdf_variables.csv"
nc_file_name = save.to_netcdf(config_path, required_netcdf_variables)
print(nc_file_name)
/data/private/test_run/output/ZA-Kru_2024-01-29-1142/ZA-Kru_2024-01-29-1142_STEMMUS_SCOPE.nc
2. Using global data¶
import os
from PyStemmusScope import StemmusScope
from PyStemmusScope import save
# user must provide the correct path
path_to_config_file = "./config_file_crib_global.txt"
path_to_model_src = "/home/jovyan/private/Sarah/STEMMUS_SCOPE/src"
# create an an instance of the model
model = StemmusScope(config_file=path_to_config_file, model_src_path=path_to_model_src, interpreter="Matlab")
# setup the model
config_path = model.setup(
Location="(61.8474, 24.2948)",
StartTime="2014-01-01T00:00",
EndTime="2014-01-15T00:00",
)
# new config file genertaed to run the model
print(f"New config file {config_path}")
# see input and output paths generated by the model
print(f'Model input dir {model.config["InputPath"]}')
print(f'Model output dir {model.config["OutputPath"]}')
If you are on CRIB, to use Jupyter interface and MATLAB license manager at the same time, first perform <echo $DISPLAY> in a terminal in the Remote Desktop of Crib Platform, and check the output which should be similar to :1.0 . Then execute the following line accordingly.
# for CRIB users
%env DISPLAY=:1.0
env: DISPLAY=:1.0
# run the model
result = model.run()
result
b'MATLAB is selecting SOFTWARE OPENGL rendering.\nOpening log file: /home/alidoost/java.log.37351\n\n < M A T L A B (R) >\n Copyright 1984-2021 The MathWorks, Inc.\n R2021a Update 3 (9.10.0.1684407) 64-bit (glnxa64)\n May 27, 2021\n\n \nTo get started, type doc.\nFor product information, visit www.mathworks.com.\n \nReading config from /gpfs/home2/alidoost/test_matlab/input/ZA-Kru_2022-10-27-1651/ZA-Kru_2022-10-27-1651_config.txt\nThe calculations start now\nThe calculations end now\n'
# save output in netcdf format
required_netcdf_variables = "/home/jovyan/private/Sarah/STEMMUS_SCOPE/utils/csv_to_nc/required_netcdf_variables.csv"
nc_file_name = save.to_netcdf(config_path, required_netcdf_variables)
print(nc_file_name)