|
| 1 | +# SAR Flood Detection Application |
| 2 | + |
| 3 | +A web application for detecting surface water and flooding events using free Sentinel-1 SAR (Synthetic Aperture Radar) data from Google Earth Engine. |
| 4 | + |
| 5 | +## 🎯 Overview |
| 6 | + |
| 7 | +This application enables users to: |
| 8 | +- Draw an Area of Interest (AOI) anywhere on Earth |
| 9 | +- Automatically fetch the latest Sentinel-1 SAR imagery |
| 10 | +- Detect surface water using adaptive Otsu thresholding |
| 11 | +- Visualize results interactively with dual basemap options |
| 12 | +- Download detected water polygons as GeoJSON |
| 13 | + |
| 14 | +## 🏗️ Architecture |
| 15 | + |
| 16 | +``` |
| 17 | +┌─────────────────────────┐ |
| 18 | +│ Frontend (GitHub Pages) │ |
| 19 | +│ - React + Leaflet │ |
| 20 | +│ - AOI drawing │ |
| 21 | +│ - Basemap toggle │ |
| 22 | +└─────────────┬───────────┘ |
| 23 | + │ GeoJSON AOI + params |
| 24 | + ▼ |
| 25 | +┌─────────────────────────┐ |
| 26 | +│ Backend (Cloud Run) │ |
| 27 | +│ - FastAPI │ |
| 28 | +│ - Google Earth Engine │ |
| 29 | +│ - Sentinel-1 SAR │ |
| 30 | +│ - Water detection │ |
| 31 | +└─────────────┬───────────┘ |
| 32 | + │ GeoJSON water polygons |
| 33 | + ▼ |
| 34 | +┌─────────────────────────┐ |
| 35 | +│ Visualization │ |
| 36 | +│ - Water overlay │ |
| 37 | +│ - Metadata display │ |
| 38 | +│ - GeoJSON download │ |
| 39 | +└─────────────────────────┘ |
| 40 | +``` |
| 41 | + |
| 42 | +## 🚀 Features |
| 43 | + |
| 44 | +- **Adaptive Water Detection**: Otsu thresholding automatically adjusts to local conditions |
| 45 | +- **Manual Overrides**: Advanced users can fine-tune detection parameters |
| 46 | +- **Dual Basemaps**: Toggle between OpenStreetMap and Esri World Imagery |
| 47 | +- **Test AOIs**: Pre-loaded test locations including historical flood events |
| 48 | +- **Real-time Processing**: Results typically return in 30-60 seconds |
| 49 | +- **No Caching**: Stateless design - download results as needed |
| 50 | +- **Free Data**: Uses Copernicus Sentinel-1 SAR imagery via Google Earth Engine |
| 51 | + |
| 52 | +## 🛠️ Technology Stack |
| 53 | + |
| 54 | +### Backend |
| 55 | +- **FastAPI**: Modern Python web framework |
| 56 | +- **Google Earth Engine**: SAR imagery access and processing |
| 57 | +- **Pydantic**: Request/response validation |
| 58 | +- **Google Cloud Run**: Serverless deployment |
| 59 | + |
| 60 | +### Frontend |
| 61 | +- **React 18**: UI framework |
| 62 | +- **Leaflet**: Interactive mapping |
| 63 | +- **Leaflet Draw**: AOI drawing tools |
| 64 | +- **Turf.js**: Geospatial calculations |
| 65 | +- **Axios**: API communication |
| 66 | + |
| 67 | +## 📋 Prerequisites |
| 68 | + |
| 69 | +### Backend |
| 70 | +- Python 3.10+ |
| 71 | +- Google Cloud Platform account |
| 72 | +- Google Earth Engine service account |
| 73 | +- gcloud CLI (for deployment) |
| 74 | + |
| 75 | +### Frontend |
| 76 | +- Node.js 16+ |
| 77 | +- npm or yarn |
| 78 | + |
| 79 | +## 🔧 Setup Instructions |
| 80 | + |
| 81 | +### 1. Google Earth Engine Service Account |
| 82 | + |
| 83 | +Follow the detailed guide in [docs/GEE_SETUP.md](docs/GEE_SETUP.md) to: |
| 84 | +1. Create a GCP project |
| 85 | +2. Enable Earth Engine API |
| 86 | +3. Create a service account |
| 87 | +4. Download credentials JSON |
| 88 | +5. Set up for local development and Cloud Run |
| 89 | + |
| 90 | +### 2. Backend Setup |
| 91 | + |
| 92 | +```bash |
| 93 | +cd backend |
| 94 | + |
| 95 | +# Create virtual environment |
| 96 | +python -m venv venv |
| 97 | +source venv/bin/activate # On Windows: venv\Scripts\activate |
| 98 | + |
| 99 | +# Install dependencies |
| 100 | +pip install -r requirements.txt |
| 101 | + |
| 102 | +# Create .env file |
| 103 | +cp .env.example .env |
| 104 | + |
| 105 | +# Edit .env and set: |
| 106 | +# GEE_SERVICE_ACCOUNT_PATH=./credentials/gee-service-account.json |
| 107 | + |
| 108 | +# Place your GEE service account JSON in backend/credentials/ |
| 109 | + |
| 110 | +# Run locally |
| 111 | +python run_local.py |
| 112 | +``` |
| 113 | + |
| 114 | +Backend will be available at http://localhost:8000 |
| 115 | + |
| 116 | +### 3. Frontend Setup |
| 117 | + |
| 118 | +```bash |
| 119 | +cd frontend |
| 120 | + |
| 121 | +# Install dependencies |
| 122 | +npm install |
| 123 | + |
| 124 | +# Run development server |
| 125 | +npm start |
| 126 | +``` |
| 127 | + |
| 128 | +Frontend will be available at http://localhost:3000 |
| 129 | + |
| 130 | +## 🧪 Testing with Sample AOIs |
| 131 | + |
| 132 | +The application includes 4 pre-loaded test AOIs: |
| 133 | + |
| 134 | +1. **Ahrweiler, Germany (2021 Floods)** - European flash flooding event |
| 135 | +2. **Sindh, Pakistan (2022 Floods)** - Massive monsoon flooding |
| 136 | +3. **Venice Lagoon, Italy** - Permanent water baseline |
| 137 | +4. **Sahara Desert, Algeria** - Dry control area (minimal water) |
| 138 | + |
| 139 | +Select these from the sidebar to quickly test the application. |
| 140 | + |
| 141 | +## 🚀 Deployment |
| 142 | + |
| 143 | +### Backend to Google Cloud Run |
| 144 | + |
| 145 | +```bash |
| 146 | +# From project root |
| 147 | +./deploy.sh |
| 148 | + |
| 149 | +# Or manually: |
| 150 | +cd backend |
| 151 | +gcloud run deploy sar-flood-api \ |
| 152 | + --source . \ |
| 153 | + --region us-central1 \ |
| 154 | + --platform managed \ |
| 155 | + --timeout 300s \ |
| 156 | + --memory 1Gi \ |
| 157 | + --allow-unauthenticated \ |
| 158 | + --set-secrets GEE_SERVICE_ACCOUNT=gee-service-account:latest |
| 159 | +``` |
| 160 | + |
| 161 | +### Frontend to GitHub Pages |
| 162 | + |
| 163 | +```bash |
| 164 | +cd frontend |
| 165 | + |
| 166 | +# Update .env.production with your Cloud Run URL |
| 167 | +# REACT_APP_API_URL=https://your-cloud-run-url |
| 168 | + |
| 169 | +# Deploy |
| 170 | +npm run deploy |
| 171 | +``` |
| 172 | + |
| 173 | +Or use the GitHub Actions workflow (see `.github/workflows/deploy-frontend.yml`) |
| 174 | + |
| 175 | +## 📊 Water Detection Algorithm |
| 176 | + |
| 177 | +1. **Data Ingestion**: Fetch most recent Sentinel-1 GRD imagery (last 30 days) |
| 178 | +2. **Preprocessing**: |
| 179 | + - Radiometric calibration |
| 180 | + - Terrain correction (SRTM) |
| 181 | + - dB conversion |
| 182 | + - Lee speckle filtering |
| 183 | +3. **Feature Derivation**: |
| 184 | + - VV and VH polarizations |
| 185 | + - VV-VH difference |
| 186 | + - Texture (local std dev) |
| 187 | + - Slope |
| 188 | +4. **Adaptive Detection**: |
| 189 | + - Otsu thresholding (or manual override) |
| 190 | + - Polarization rules |
| 191 | + - Terrain masking |
| 192 | + - Texture filtering |
| 193 | +5. **Refinement**: |
| 194 | + - Morphological operations |
| 195 | + - Small object removal |
| 196 | + - Geometry simplification |
| 197 | +6. **Vectorization**: Convert to GeoJSON polygons |
| 198 | + |
| 199 | +## 🎨 Advanced Parameters |
| 200 | + |
| 201 | +For fine-tuning detection (accessible via collapsible panel): |
| 202 | + |
| 203 | +- **VV Threshold (dB)**: Primary water backscatter threshold |
| 204 | +- **VH Threshold (dB)**: Secondary polarization threshold |
| 205 | +- **VV-VH Difference**: Polarization ratio limit |
| 206 | +- **Max Slope (degrees)**: Exclude steep terrain |
| 207 | +- **Min Area (pixels)**: Remove small noise objects |
| 208 | +- **Texture Window**: Spatial texture analysis window size |
| 209 | + |
| 210 | +## ⚠️ Limitations |
| 211 | + |
| 212 | +- **AOI Size**: Maximum 50×50 km (2500 km²) for real-time processing |
| 213 | +- **Temporal**: Uses most recent acquisition (last 30 days) |
| 214 | +- **Orbit**: ASCENDING pass only for consistency |
| 215 | +- **Resolution**: 10m Sentinel-1 ground resolution |
| 216 | +- **False Positives**: May occur in urban areas, wet soil, low-wind conditions |
| 217 | +- **Processing Time**: 30-120 seconds depending on AOI size |
| 218 | + |
| 219 | +## 🔮 Future Enhancements |
| 220 | + |
| 221 | +- [ ] Temporal change detection (before/after flooding) |
| 222 | +- [ ] Multi-temporal stacking for stability |
| 223 | +- [ ] Sentinel-2 optical cross-validation |
| 224 | +- [ ] Permanent water vs flood water classification |
| 225 | +- [ ] Export to Shapefile/KML formats |
| 226 | +- [ ] Time-series animation |
| 227 | +- [ ] Email alerts for new detections |
| 228 | +- [ ] Mobile-responsive design improvements |
| 229 | + |
| 230 | +## 📄 License |
| 231 | + |
| 232 | +MIT License - Free for educational and commercial use |
| 233 | + |
| 234 | +## 🙏 Acknowledgments |
| 235 | + |
| 236 | +- **Copernicus Sentinel-1** mission for free SAR data |
| 237 | +- **Google Earth Engine** for cloud-based processing |
| 238 | +- **OpenStreetMap** and **Esri** for basemap tiles |
| 239 | + |
| 240 | +## 📧 Contact |
| 241 | + |
| 242 | +For questions, issues, or collaborations, please open an issue on GitHub. |
| 243 | + |
| 244 | +--- |
| 245 | + |
| 246 | +**Note**: This is a portfolio/demonstration project. For operational flood monitoring, consider additional validation and temporal analysis. |
0 commit comments