Environment 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/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 (){
17 18
    ipsl="ipsl camelot climserv ciclad"
    idris="idris jean-zay"
POLCHER Jan's avatar
POLCHER Jan committed
19 20 21 22 23 24
    case $(hostname -d) in
	climserv*|private.ipsl.fr|ipsl.polytechnique.fr)
	    echo "IPSL"
	    eval  "$1='ipsl'"
	    ;;
	idris*|jean-zay*)
25 26
	    echo "IDRIS"
	    eval "$1='idris'"
POLCHER Jan's avatar
POLCHER Jan committed
27 28 29
	    ;;
	*)
	    echo "unknown machine : $(hostname -d)"
30
	    eval "$1='unknown'"
POLCHER Jan's avatar
POLCHER Jan committed
31
    esac
32
}
POLCHER Jan's avatar
POLCHER Jan committed
33

34 35 36 37 38 39 40 41 42 43
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
44
import cartopy
45 46 47 48 49 50 51 52 53 54 55 56 57
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
#
58 59 60 61
loc=''
hasanaconda loc

if [ loc != "unknown" ] ; then
62 63 64
    #
    # Make sure the right version of Python
    #
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    case $loc in
	"ipsl")
	    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 cartopy
		conda install -y --channel astropy spherical-geometry
	    else
		source activate MPI
	    fi
	    ;;
	"idris")
	    module load python/3.7.3
	    if [[ -L ${HOME}/.conda && -d ${HOME}/.conda ]] ; then
		if [ ! -e ${WORK}/.conda/envs/MPI ] ; then
		    conda create -y -n MPI mpi4py numba astropy netcdf4 matplotlib basemap ConfigParser cartopy
		    conda activate MPI
		    if [[ -L ${HOME}/.local && -d ${HOME}/.local ]] ; then
			export PYTHONUSERBASE=$WORK/.local
			if [ $(find $PYTHONUSERBASE -name spherical_geometry -ls | wc -l) -le 0 ] ; then
			    git clone https://github.com/spacetelescope/spherical_geometry.git
			    cd spherical_geometry
			    python setup.py install --user
			fi
		    else
			echo "Make sure \$HOME/.link is a link to your \$WORK/.local"
		    fi
		else
		    conda activate MPI
		fi
	    else
		echo "Make sure \$HOME/.conda is a link to your \$WORK/.conda"
	    fi
	    ;;
	*)
	    echo "Environment for $loc is not foreseen yet"
	    exit
	    ;;
	esac
112 113 114
fi
#
# Verify we can load all the needed modules.
115 116
	#
	
117
checkenv