diff --git a/PSILARTEMP.py b/PSILARTEMP.py index 278e6961a70c803e9256280e979d0aad0d37a289..8b15c067b222de4f0fcf214efc111a9d37a2c929 100755 --- a/PSILARTEMP.py +++ b/PSILARTEMP.py @@ -25,9 +25,9 @@ from jinja2 import Environment, FileSystemLoader load_dotenv() -weatherdata_path="in/" -tmp_path="tmp/" -out_path="out/" +weatherdata_path = os.getenv("WEATHER_DATA_DIR") +tmp_path = "tmp/" +out_path = os.getenv("DATA_DIR") # TODO: Make this truly independent of time zones/Norwegian conditions? utc_offset = "+02:00" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..222acb6b40f5f293dba1fe4592ae578604cefa3f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +Jinja2 +netCDF4 +pytz +python-dotenv \ No newline at end of file diff --git a/run_PSILARTEMP.sh b/run_PSILARTEMP.sh new file mode 100644 index 0000000000000000000000000000000000000000..b1e17f2b2e899a5ac2431cc59c22162380d8e604 --- /dev/null +++ b/run_PSILARTEMP.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +# Copyright (C) 2023 NIBIO <http://www.nibio.no/>. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +# Configures environment and logging before running the model +# @author: Tor-Einar Skog <tor-einar.skog@nibio.no> + + + +# First: Test that we have CDO and GDAL installed +if ! command -v cdo &> /dev/null +then + echo "ERROR: CDO could not be found. Exiting." + exit +fi + +if ! command -v gdal_merge.py &> /dev/null +then + echo "ERROR: GDAL is either not installed, or not built with Python support. Exiting." + exit +fi + +# Defines HOME_DIR +source .env + +# Check for HOME_DIR +if [ -z "${HOME_DIR}" ] +then + echo "ERROR: \$HOME_DIR is not set. Please declare it in an .env file" + exit +fi + +# Paths to scripts and requirements +APP_PATH=${HOME_DIR}PSILARTEMP/ +LOG_FILE=${APP_PATH}log/PSILARTEMP.log +REQUIREMENTS=${APP_PATH}requirements.txt + +cd $APP_PATH + +# Create and activate the virtual environment +python3 -m venv .venv +. .venv/bin/activate +python3 -m pip install --upgrade pip +pip install -r $REQUIREMENTS + +# Run the model +echo "==== `date`: Running model" &>> "$LOG_FILE" +python3 $APP_PATH/PSILARTEMP.py &>> "$LOG_FILE" +echo "==== `date`: DONE running model" &>> "$LOG_FILE" + +# Deactivate the virtual environment +deactivate