#!/bin/bash

# SLURM configuration for MN5
# information about the queue : https://www.bsc.es/supportkc/docs/MareNostrum5/slurm

# HOW to SUBMIT 
# sbatch -A, --account={account} -q, --qos={qos} {job_script} [args]
# sbatch -A bsc32 -q gp_bsces launch_preprocessing.sh

# Single job with a single node (default)
##BATCH --qos=gp_debug
##SBATCH --qos=acc_debug
#SBATCH --qos=gp_bsces
#SBATCH --output=serial_%j.out
#SBATCH --error=serial_%j.err
##SBATCH --ntasks=112
#SBATCH --ntasks=1420
#SBATCH --time=02:00:00
#SBATCH --mail-type=end
#SBATCH --mail-user=amirpasha.mozaffari@bsc.es

# SLURM configuration for NORD3
# more information here : https://earth.bsc.es/wiki/doku.php?id=computing:nord3-v2

# HOW to SUBMIT 
# sbatch -A, --account={account} -q, --qos={qos} {job_script} [args]
# sbatch -A bsc32 -q bsc_es launch_remap_NR3.sh

# Single job with a single node (default)
##SBATCH --qos=bsc_es
##SBATCH --output=serial_%j.out
##SBATCH --error=serial_%j.err
##SBATCH --ntasks=10
##SBATCH --time=01:30:00
##SBATCH --mail-type=end
##SBATCH --mail-user=amirpasha.mozaffari@bsc.es
##SBATCH --constraint=highmem
##SBATCH --exclusive

# Load appropriate modules and activate conda environment
if [ "$BSC_MACHINE" = "mn5" ]; then

    export MODULEPATH=$MODULEPATH:/apps/GPP/EASYBUILD/modules/all
    # module load GDAL/3.8.5-foss-2023b
    # module load NCO/5.2.4-foss-2023b
    # module load miniconda
    # module load hdf5/1.14.1-2
    # module load pnetcdf/1.12.3
    # module load netcdf/2023-06-14
    # module load miniconda
    conda init
    source /apps/GPP/MINICONDA/24.1.2/etc/profile.d/conda.sh
    conda activate /gpfs/projects/bsc32/repository/apps/conda_envs/LAND_may2024_v1
    export PYTHONPATH=/gpfs/projects/bsc32/repository/apps/conda_envs/LAND_may2024_v1/lib/python3.12/site-packages:$PYTHONPATH

elif [ "$BSC_MACHINE" = "nord3v2" ]; then
    module load GDAL/3.3.2-foss-2019b-Python-3.7.4
    module load pycdo/1.5.3-foss-2019b-Python-3.7.4
    module load pynco/0.0.2-foss-2019b-Python-3.7.4
fi

# Launch training script 
# Set parameters
Default_data_path="/gpfs/projects/bsc32/cerise/outputs/bsc032013/0.0089_deg/"
Save_data_path="/gpfs/projects/bsc32/cerise/outputs/bsc032013/ml/CAT_nov_6_2024"
Regions_file_path="/gpfs/scratch/bsc32/bsc032013/cerise/land-use-reclassification/ml/LC/inputs/regions.json" 
START_YEAR=1992
END_YEAR=2015

# List of regions to loop over
#REGIONS=("ES1" "ES2" "ES3" "ES4" "ES5" "ES6" "ES6")
REGIONS=("CAT")

# Loop over each region
for REGION in "${REGIONS[@]}"
do
    echo "Processing region: $REGION"
    
    # Run the Python script for each region
    python preprocessing.py --default_data_path $Default_data_path \
                            --save_data_path $Save_data_path \
                            --regions_file $Regions_file_path \
                            --start_year $START_YEAR \
                            --end_year $END_YEAR \
                            --region $REGION \
                            --include_luh2 \
                            --include_hilda \
                            --overwrite \
                            --inspection \
                            --dtype_ground_truth int16 \
                            --dtype_luh2 float32 \
                            --dtype_hilda float32
done

#REGION="ES6"  

# Run the Python script with arguments
#python preprocessing.py --default_data_path $Default_data_path  --save_data_path $Save_data_path --regions_file $Regions_file_path --start_year $START_YEAR --end_year $END_YEAR --region $REGION  --include_luh2 --include_hilda --overwrite --inspection --dtype_ground_truth int16 --dtype_luh2 float32 --dtype_hilda float32

