Newer
Older
#!/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 (){
ipsl="ipsl camelot climserv ciclad"
idris="idris jean-zay"
h=$(hostname -d)
if [[ "$h" == *"ipsl"* ]] ; then
echo "IPSL"
eval "$1='ipsl'"
elif [[ "$h" == *"idris"* ]] ; then
echo "IDRIS"
eval "$1='idris'"
else
echo "unknown : $h"
eval "$1='unknown'"
fi
}
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
import cartopy
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
#
loc=''
hasanaconda loc
if [ loc != "unknown" ] ; then
#
# Make sure the right version of Python
#
62
63
64
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
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
fi
#
# Verify we can load all the needed modules.