Skip to content
Snippets Groups Projects
Commit a4290153 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Merge branch 'cdo_2.4_miniconda' into 'main'

Cdo 2.4 miniconda

See merge request !1
parents a6c394b9 31accdff
No related branches found
No related tags found
1 merge request!1Cdo 2.4 miniconda
...@@ -4,3 +4,4 @@ ...@@ -4,3 +4,4 @@
.env .env
.venv .venv
mapfile/*.map mapfile/*.map
last_run_timestamp
...@@ -180,7 +180,7 @@ subprocess.run(f'cdo -s -aexpr,"WARNING_STATUS = WHS <= 0 ? 0 : -1; WARNING_STAT ...@@ -180,7 +180,7 @@ subprocess.run(f'cdo -s -aexpr,"WARNING_STATUS = WHS <= 0 ? 0 : -1; WARNING_STAT
if os.getenv("MASK_FILE") is not None: if os.getenv("MASK_FILE") is not None:
mask_file = os.getenv("MASK_FILE") mask_file = os.getenv("MASK_FILE")
print(f"Applying mask file {mask_file} to result.nc") print(f"Applying mask file {mask_file} to result.nc")
subprocess.run(f'cdo -maskregion,{mask_file} {tmpfile_path}result_unmasked.nc {tmpfile_path}result.nc', shell=True) subprocess.run(f'cdo -P 6 -maskregion,{mask_file} {tmpfile_path}result_unmasked.nc {tmpfile_path}result.nc', shell=True)
else: else:
os.rename(f"{tmpfile_path}result_unmasked.nc", f"{tmpfile_path}result.nc") os.rename(f"{tmpfile_path}result_unmasked.nc", f"{tmpfile_path}result.nc")
#""" #"""
......
name: SEPTREFHUM
channels:
- conda-forge
dependencies:
- cdo=2.4.0
- Jinja2
- netCDF4
- pytz
- python-dotenv
\ No newline at end of file
...@@ -18,42 +18,55 @@ ...@@ -18,42 +18,55 @@
# Configures environment and logging before running the model # Configures environment and logging before running the model
# @author: Tor-Einar Skog <tor-einar.skog@nibio.no> # @author: Tor-Einar Skog <tor-einar.skog@nibio.no>
# Defines HOME_DIR
source .env
# Check for HOME_DIR
# First: Test that we have CDO and GDAL installed if [ -z "${HOME_DIR}" ]
if ! command -v cdo &> /dev/null
then then
echo "ERROR: CDO could not be found. Exiting." echo "ERROR: \$HOME_DIR is not set. Please declare it in an .env file"
exit exit
fi fi
# Paths to scripts and requirements
LOG_FILE=${HOME_DIR}log/SEPTREFHUM.log
REQUIREMENTS=${HOME_DIR}requirements.txt
CDO_VERSION=2.4.0
# Test that we have GDAL and Miniconda installed
if ! command -v gdal_merge.py &> /dev/null if ! command -v gdal_merge.py &> /dev/null
then then
echo "ERROR: GDAL is either not installed, or not built with Python support. Exiting." echo "ERROR: GDAL is either not installed, or not built with Python support. Exiting."
exit exit
fi fi
# Defines HOME_DIR if ! command -v conda &> /dev/null
source .env
# Check for HOME_DIR
if [ -z "${HOME_DIR}" ]
then then
echo "ERROR: \$HOME_DIR is not set. Please declare it in an .env file" echo "ERROR: Miniconda is not installed. Pleare read: https://code.mpimet.mpg.de/projects/cdo/wiki/Anaconda"
exit exit
fi fi
# Paths to scripts and requirements
LOG_FILE=${HOME_DIR}log/SEPTREFHUM.log
REQUIREMENTS=${HOME_DIR}requirements.txt
cd $HOME_DIR cd $HOME_DIR
# Create and activate the virtual environment # Check if we need to create the virtual environment
python3 -m venv .venv eval "$(conda shell.bash hook)"
. .venv/bin/activate now=$(date +%s)
python3 -m pip install -q --upgrade pip if ! conda env list | grep -q "SEPTREFHUM "; then
pip install -q -r $REQUIREMENTS echo "Conda env not found, creating it"
conda env create -f conda_environment.yml
conda activate SEPTREFHUM
else
# Make sure we catch/update changes in dependencies
if [ -e last_run_timestamp ]; then
last_run_timestamp=$(<last_run_timestamp)
last_modified_env_file=$(stat -c "%Y" conda_environment.yml)
if [ $((last_run_timestamp - last_modified_env_file)) -lt 0 ]; then
echo "conda_environment.yml file has been updated. Updating the conda env. This may take a while"
conda env update --prune -f conda_environment.yml
fi
fi
conda activate SEPTREFHUM
fi
# Run the model # Run the model
echo "==== `date`: Running model" &>> "$LOG_FILE" echo "==== `date`: Running model" &>> "$LOG_FILE"
...@@ -61,4 +74,7 @@ python3 ${HOME_DIR}SEPTREFHUM.py &>> "$LOG_FILE" ...@@ -61,4 +74,7 @@ python3 ${HOME_DIR}SEPTREFHUM.py &>> "$LOG_FILE"
echo "==== `date`: DONE running model" &>> "$LOG_FILE" echo "==== `date`: DONE running model" &>> "$LOG_FILE"
# Deactivate the virtual environment # Deactivate the virtual environment
deactivate conda deactivate
# Log this to compare with changes in conda_environment.yml
echo $now > last_run_timestamp
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment