#!/bin/bash # ######################################### # # Script to build and maintain en environment to run # the python code in this directory. We verify that # all needed packages are available. # This is based on the anaconda python system : https://www.anaconda.com/distribution/ # # Usage : source Environment # ######################################### # # Functions # function hasanaconda (){ condahost="camelot climserv ciclad" h=$(hostname) res=1 for ch in ${condahost} ; do if [ $(echo $h | grep ${ch} | wc -c) != "0" ] ; then res=0 fi done return $res } function checkenv (){ rm -f checkenv.py cat <<EOF > checkenv.py import mpi4py import spherical_geometry import netCDF4 import matplotlib import mpl_toolkits import configparser import numba print ("OK") EOF python checkenv.py > /dev/null if [ $? -gt 0 ] ; then echo "Environment not OK. Some packages must be missing." echo "This was tested with the checkenv.py code." else rm -f checkenv.py fi } # # Main # if ( hasanaconda ) ; then # # Make sure the right version of Python # module unload python module load python/3.6-anaconda50 # # Test if the MPI environment is installed. # if [ ! -e ${HOME}/.conda/envs/MPI ] ; then # # Create the MPI environment as it does not exist. # conda create -y -n MPI mpi4py numba astropy netcdf4 matplotlib basemap ConfigParser source activate MPI conda install -y --channel astropy spherical-geometry fi # # Activate the MPI environment # source activate MPI fi # # Verify we can load all the needed modules. # checkenv