Predicting biodiversity in the South African Cape Region
# Gaia: A Masked Vision Transformer for Species Richness Prediction from Hyperspectral Imagery
Gaia is a masked spatial-spectral vision transformer fine-tuned on EnMAP foundation weights to predict animal species richness (birds, frogs, and insects) from AVIRIS-NG hyperspectral imagery across the Greater Cape Floristic Region (South Africa) using NASA BioSCape data.
## QuickStart
### 1. Prerequisites
- **Python 3.10+** (Recommend a virtual env)
- **CUDA GPU** with at least 8GB VRAM.
- **NASA Earthdata Account**: Register here.
### 2. Environment Setup
```bash
pip install -r requirements.txt
```
### 3. Data Acquisition (Smart Sync)
Downloads AVIRIS-NG granules, applies Dr. Clark's Bad Band List (BBL), and optionally downsamples.
Data is automatically organized by resolution: `data/bioscape/30m/` and `data/bioscape/5m/`.
#### Option A: Targeted Sync (Recommended, ~535 labeled granules)
```bash
# 1. Generate the labeled inventory
python src/generate_labeled_inventory.py
# 2. Download 30m (default, ~35MB each, fast local training)
python src/smart_sync.py --local
# 3. Download 5m (original resolution, ~1.3GB each, for supercomputer)
python src/smart_sync.py --local --res 5
```
#### Option B: Full Dataset Sync (3,648 granules, 500GB+)
```bash
python src/smart_sync.py --inventory full_inventory.txt --local --res 30
```
#### Option C: S3 Upload (for NRP Nautilus)
```bash
python src/smart_sync.py --res 30
```
### 4. Model Training
Gaia uses a Masked Spatial-Spectral Transformer (SST) with EnMAP foundation weights.
```bash
# Train on 30m data (default, from config)
python src/train_production.py --epochs 250
# Train on 5m data (override directory)
python src/train_production.py --nc_dir data/bioscape/5m --epochs 250
# Quick test run (2 granules, 1 epoch)
python src/train_production.py --test-run
```
### 5. Evaluation
Evaluates the best checkpoint on a held-out validation set (10%, same split as training).
```bash
python src/evaluate.py --nc_dir data/bioscape/ …