Last active
April 6, 2021 18:04
-
-
Save daniellivingston/6ea3ffaee574ca523cc61c247131a9bb to your computer and use it in GitHub Desktop.
Set up WRF-Hydro via Spack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# =============================== # | |
# WRF-HYDRO SPACK INSTALLER | |
# ------------------------------- | |
# CONFIGURES AND INSTALLS WRF-HYDRO | |
# AND ALL REQUIRED DEPENDENCIES | |
# ------------------------------- | |
# CONTACT: | |
# livingston@lanl.gov | |
# =============================== # | |
# Extra Spack packages to install | |
# (besides WRF-Hydro) | |
spack_packages=( | |
r@3.5.0:3.9.9 | |
python@3.6.0:3.9.9 | |
py-pip | |
) | |
# Python modules to install | |
python_libs=( | |
netcdf4 | |
pandas | |
numpy | |
psycopg2 | |
psutil | |
) | |
# R packages to install | |
r_libs=( | |
data.table | |
ncdf4 | |
glue | |
scales | |
vctrs | |
tibble | |
ggplot2 | |
gridextra | |
plyr | |
hydrogof | |
) | |
install_r_packages () { | |
arr=("$@") | |
pkgs_list=$(printf "\"%s\"\n,\n" "${arr[@]}" | head -n-1 | paste -sd '') | |
repo="https://cran.rstudio.com" | |
echo "update.packages(ask = FALSE, repos=\"${repo}\")" | R --no-save | |
echo "install.packages(c(${pkgs_list}), repos=\"${repo}\")" | R --no-save | |
} | |
install_spack () { | |
_cwd=$(pwd) | |
_neworigin=wrfhydro | |
export SPACK_ROOT=$1/spack | |
git clone https://github.com/spack/spack.git ${SPACK_ROOT} | |
cd ${SPACK_ROOT} | |
git remote add $_neworigin https://github.com/daniellivingston/spack.git | |
git pull $_neworigin develop | |
. ${SPACK_ROOT}/share/spack/setup-env.sh | |
cd $_cwd | |
echo "INFO" | |
echo "===================" | |
echo "Add to the bottom of your ~/.bashrc or ~/.bash_profile:" | |
echo "" | |
echo "export SPACK_ROOT=${SPACK_ROOT}" | |
echo '. ${SPACK_ROOT}/share/spack/setup-env.sh' | |
} | |
# ============================== # | |
# 0. Download Spack and pull the | |
# WRF-Hydro package from my | |
# fork | |
# ============================== # | |
# Will download and install Spack to cwd | |
install_spack $(pwd) | |
# ============================== # | |
# 1. Create and activate a Spack | |
# environment | |
# ============================== # | |
# You may want to add `spack env activate wrf-hydro-dev` | |
# to the bottom of your ~/.bash_profile | |
spack env create wrf-hydro-dev | |
spack env activate wrf-hydro-dev | |
# ============================== # | |
# 2. Build WRF-Hydro | |
# ============================== # | |
# Install and test WRF-Hydro | |
# ------------------------------ # | |
# IMPORTANT: if on HPC, OpenMPI or | |
# MPICH need to be configured specially: | |
spack install openmpi schedulers=slurm +pmi | |
# Comment the above line out if not | |
# on Darwin/HPC. | |
# ------------------------------ # | |
spack install --test=all wrf-hydro | |
# ============================== # | |
# 2.1 Build Python and R into | |
# the Spack environment | |
# ============================== # | |
# Install Python, pip, and R | |
for package in "${spack_packages[@]}" | |
do | |
spack install $package | |
done | |
# Concretize the environment | |
spack concretize | |
# ============================== # | |
# 3. Install R packages # | |
# ============================== # | |
install_r_packages "${r_libs[@]}" | |
# ============================== # | |
# 4. Install Python packages | |
# ============================== # | |
pip install "${py_packages[*]}" | |
# ============================== # | |
# 5. Wrap-up | |
# ============================== # | |
echo ">> Spack has been installed to: ${SPACK_ROOT}" | |
echo ">> Currently active Spack environment: $(spack env status)" | |
echo ">> Path to WRF-Hydro:"; spack find --paths wrf-hydro | |
export WRF_HYDRO_DIR=$(spack find --paths wrf-hydro | tail -1 | awk '{print $2}') | |
echo "(Please note that important files, like hydro.namelist, are in" | |
echo "${WRF_HYDRO_DIR}/trunk/NDHMS/Run/" | |
echo ">> Path to R: $(which R)" | |
echo ">> Path to Python: $(which python)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment