#######################################################################################
## Commands for setting up the conda environment for the "RayMan_CERRA" implementation
## Authors: Christos Giannaros*, UoA
##          Ilias Agathangelidis, UoA
## * e-mail: cgiannaros@phys.uoa.gr
## DOI: https://doi.org/10.5281/zenodo.10252280
## Licence: CC BY 4.0 
#######################################################################################

# Note that the current conda installation has been configured to be performed on a Linux 64-bit system
# For installations on different systems the script has to be adjusted accordingly
# See here: https://docs.conda.io/en/latest/miniconda.html for a starting point

# Download the conda latest installer script
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

# Make the installer script executable
chmod +x Miniconda3-latest-Linux-x86_64.sh

# Execute the installer script (installation steps: (a) accept the licence terms, (b) provide the installation location, 
#                                                   (c) initialize conda (conda init)
./Miniconda3-latest-Linux-x86_64.sh

# Built and activate the "RayMan_CERRA" conda environment (two options are available):
# (A) using the provided YAML file
conda env create -f RayMan_CERRA.yml
conda activate RayMan_CERRA
ln -s ~/miniconda3/envs/RayMan_CERRA/lib/libjasper.so.7 ~/miniconda3/envs/RayMan_CERRA/lib/libjasper.so.1 
ln -s ~/miniconda3/envs/RayMan_CERRA/lib/libnetcdf.so.19 ~/miniconda3/envs/RayMan_CERRA/lib/libnetcdf.so.13

# (B) from scratch (slower installation)
conda create -n RayMan_CERRA python=3.11
conda install -n RayMan_CERRA -c conda-forge cdsapi
conda install -n RayMan_CERRA -c conda-forge wgrib2
conda install -n RayMan_CERRA -c conda-forge geopandas
conda install -n RayMan_CERRA -c conda-forge rasterio
conda install -n RayMan_CERRA -c conda-forge rioxarray
conda install -n RayMan_CERRA -c conda-forge cfgrib
conda activate RayMan_CERRA

# Configure the cdsapi key (more info can be found here: https://cds.climate.copernicus.eu/api-how-to)
cat <<EOF >$HOME/.cdsapirc
url: https://cds.climate.copernicus.eu/api/v2
key: {uid}:{api-key} 
EOF
