#!/bin/bash

# Run some trainings on synopsis datasets for all different tasks + targets + grids + models

# Check if running inside the pixi environment
which autogluon >/dev/null 2>&1
if [ $? -ne 0 ]; then
    echo "This script must be run inside the pixi environment."
    exit 1
fi

for grid in hex healpix; do
    if [ "$grid" = "hex" ]; then
        levels=(3 4 5 6)
    else
        levels=(6 7 8 9 10)
    fi
    for level in "${levels[@]}"; do
        # Only apply ERA5 filter for hex-3, hex-4, healpix-6 and healpix-7
        if { [ "$grid" = "hex" ] && { [ "$level" -eq 3 ] || [ "$level" -eq 4 ]; }; } || { [ "$grid" = "healpix" ] && { [ "$level" -eq 6 ] || [ "$level" -eq 7 ]; }; }; then
            era5_dimension_filters="--dimension-filters.ERA5-shoulder.aggregations=median --dimension-filters.ERA5-seasonal.aggregations=median --dimension-filters.ERA5-yearly.aggregations=median"
        else
            era5_dimension_filters=""
        fi

        for target in darts_v1 darts_mllabels; do
            for task in binary density count; do
                echo
                echo "----------------------------------------"
                echo "Running autogluon training for grid=$grid, level=$level, target=$target, task=$task"
                autogluon --grid "$grid" --level "$level" --target "$target" --task "$task" --time-limit 600 --temporal-mode synopsis --experiment "static-variables-autogluon" --dimension-filters.ArcticDEM.aggregations=median --dimension-filters.AlphaEarth.agg=median $era5_dimension_filters
                echo "----------------------------------------"
                echo
            done
        done
    done
done
