Skip to content

Commit 2357d8f

Browse files
committed
Init
0 parents  commit 2357d8f

37 files changed

Lines changed: 3452 additions & 0 deletions
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Deploy Frontend to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
build-and-deploy:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v3
19+
with:
20+
node-version: '18'
21+
cache: 'npm'
22+
cache-dependency-path: frontend/package-lock.json
23+
24+
- name: Install dependencies
25+
working-directory: ./frontend
26+
run: npm ci
27+
28+
- name: Build application
29+
working-directory: ./frontend
30+
env:
31+
REACT_APP_API_URL: ${{ secrets.REACT_APP_API_URL }}
32+
run: npm run build
33+
34+
- name: Deploy to GitHub Pages
35+
uses: peaceiris/actions-gh-pages@v3
36+
with:
37+
github_token: ${{ secrets.GITHUB_TOKEN }}
38+
publish_dir: ./frontend/build
39+
cname: ${{ secrets.CUSTOM_DOMAIN }} # Optional: only if using custom domain

.gitignore

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
build/
8+
develop-eggs/
9+
dist/
10+
downloads/
11+
eggs/
12+
.eggs/
13+
lib/
14+
lib64/
15+
parts/
16+
sdist/
17+
var/
18+
wheels/
19+
*.egg-info/
20+
.installed.cfg
21+
*.egg
22+
MANIFEST
23+
24+
# Virtual environments
25+
venv/
26+
ENV/
27+
env/
28+
.venv
29+
30+
# Environment variables
31+
.env
32+
.env.local
33+
.env.production
34+
*.env
35+
36+
# Google Earth Engine credentials
37+
backend/credentials/
38+
*.json
39+
!package*.json
40+
!tsconfig.json
41+
!frontend/src/data/*.json
42+
43+
# IDEs
44+
.vscode/
45+
.idea/
46+
*.swp
47+
*.swo
48+
*~
49+
50+
# Node
51+
node_modules/
52+
npm-debug.log*
53+
yarn-debug.log*
54+
yarn-error.log*
55+
.pnpm-debug.log*
56+
57+
# React build
58+
frontend/build/
59+
frontend/.env.local
60+
frontend/.env.production.local
61+
frontend/.env.development.local
62+
63+
# Misc
64+
.DS_Store
65+
*.log
66+
.cache/
67+
68+
# Docker
69+
*.dockerignore
70+
71+
# Cloud Run
72+
.gcloudignore

README.md

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
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

Comments
 (0)