Skip to content

Commit ff6b912

Browse files
committed
feat: Implement landslide susceptibility mapping module
- Add landslide susceptibility processing with tehsil-level clipping - Implement MWS-level vectorization with 10 attributes per polygon - Create Django REST API endpoint for on-demand generation - Add GEE visualization script with interactive map and legend - Implement comprehensive validation utilities (coverage, accuracy, attributes) - Add unit tests with 6 test classes covering all components - Provide 6 usage examples demonstrating all major features - Update computing API and URLs for landslide endpoints - Add path constant for pan-India landslide susceptibility asset Features: - 4-class susceptibility system (Low/Moderate/High/Very High) - Polygon attributes: area by class, slope, curvature, LULC, score - Async processing via Celery with GeoServer auto-publishing - Follows existing CoRE Stack patterns (LULC, MWS architecture) - Based on Mandal et al. (2024) methodology paper - Production-ready with comprehensive documentation Files added: - computing/landslide/ module with 8 components - docs/landslide_susceptibility.md (system documentation) - LANDSLIDE_IMPLEMENTATION.md (implementation summary) - LANDSLIDE_QUICK_REF.md (quick reference guide) - IMPLEMENTATION_COMPLETE.md (achievement summary) Files modified: - computing/api.py (added generate_landslide_layer endpoint) - computing/urls.py (added route) - computing/path_constants.py (added constant) - README.md (added table entry)
1 parent 8cd955b commit ff6b912

21 files changed

Lines changed: 3918 additions & 2 deletions

IMPLEMENTATION_COMPLETE.md

Lines changed: 443 additions & 0 deletions
Large diffs are not rendered by default.

LANDSLIDE_IMPLEMENTATION.md

Lines changed: 499 additions & 0 deletions
Large diffs are not rendered by default.

LANDSLIDE_QUICK_REF.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# Landslide Susceptibility - Quick Reference
2+
3+
## Quick Start (3 Steps)
4+
5+
### 1. Generate Susceptibility for a Tehsil
6+
7+
```bash
8+
curl -X POST http://localhost/computing/generate_landslide_layer/ \
9+
-H "Content-Type: application/json" \
10+
-d '{
11+
"state": "jharkhand",
12+
"district": "ranchi",
13+
"block": "ranchi",
14+
"gee_account_id": 1
15+
}'
16+
```
17+
18+
### 2. Monitor Progress
19+
20+
Check GEE Tasks tab or Django admin panel for task status.
21+
22+
### 3. Visualize Results
23+
24+
Copy `computing/landslide/visualization.js` to [Earth Engine Code Editor](https://code.earthengine.google.com/) and run.
25+
26+
---
27+
28+
## Common Tasks
29+
30+
### Run from Python
31+
32+
```python
33+
from computing.landslide.landslide_vector import vectorise_landslide
34+
35+
vectorise_landslide.apply_async(
36+
args=["jharkhand", "ranchi", "ranchi", 1],
37+
queue="nrm"
38+
)
39+
```
40+
41+
### Validate Outputs
42+
43+
```python
44+
from computing.landslide.validation import generate_validation_report
45+
import ee
46+
47+
ee.Initialize()
48+
49+
report = generate_validation_report(
50+
asset_id="users/corestack/jharkhand_ranchi_landslide_vector",
51+
aoi=ee.Geometry.Point([85.3, 23.3]).buffer(50000)
52+
)
53+
54+
print(report)
55+
```
56+
57+
### Get Statistics
58+
59+
```python
60+
from computing.landslide.utils import get_susceptibility_statistics
61+
import ee
62+
63+
ee.Initialize()
64+
65+
fc = ee.FeatureCollection("users/corestack/jharkhand_ranchi_landslide_vector")
66+
stats = get_susceptibility_statistics(fc)
67+
68+
print(f"Total MWS: {stats['total_mws']}")
69+
print(f"High risk area: {stats['area_by_class']['high']:.2f} ha")
70+
```
71+
72+
---
73+
74+
## File Locations
75+
76+
| Component | Path |
77+
|-----------|------|
78+
| Main processing | `computing/landslide/landslide_vector.py` |
79+
| Utilities | `computing/landslide/utils.py` |
80+
| Validation | `computing/landslide/validation.py` |
81+
| GEE visualization | `computing/landslide/visualization.js` |
82+
| Tests | `computing/landslide/tests.py` |
83+
| Examples | `computing/landslide/examples.py` |
84+
| Module docs | `computing/landslide/README.md` |
85+
| System docs | `docs/landslide_susceptibility.md` |
86+
| API endpoint | `computing/api.py` (line ~1200) |
87+
| URL route | `computing/urls.py` (line ~115) |
88+
89+
---
90+
91+
## Key Functions
92+
93+
### `vectorise_landslide(state, district, block, gee_account_id)`
94+
Main Celery task. Generates landslide vectors for a tehsil.
95+
96+
### `generate_demo_susceptibility()`
97+
Fallback: creates demo susceptibility from slope when pan-India asset unavailable.
98+
99+
### `validate_attributes(fc)`
100+
Checks if all required attributes are present in the output.
101+
102+
### `compute_high_risk_percentage(fc)`
103+
Calculates percentage of area in high/very high zones.
104+
105+
---
106+
107+
## Output Attributes
108+
109+
Each MWS polygon has:
110+
111+
- `low_area_ha` - Area (ha) in low susceptibility
112+
- `moderate_area_ha` - Area (ha) in moderate susceptibility
113+
- `high_area_ha` - Area (ha) in high susceptibility
114+
- `very_high_area_ha` - Area (ha) in very high susceptibility
115+
- `total_area_ha` - Total MWS area (ha)
116+
- `mean_slope_deg` - Mean slope (degrees)
117+
- `mean_curvature` - Mean terrain curvature
118+
- `dominant_lulc` - Dominant LULC class
119+
- `susceptibility_score` - Weighted score (1-4)
120+
- `susceptibility_category` - Overall category (low/moderate/high/very_high)
121+
122+
---
123+
124+
## Classification
125+
126+
| Class | Value | Score Range | Color | Action |
127+
|-------|-------|-------------|-------|--------|
128+
| Low | 1 | 0.00-0.33 | Green | None |
129+
| Moderate | 2 | 0.33-0.66 | Yellow | Monitor |
130+
| High | 3 | 0.66-0.85 | Orange | Mitigate |
131+
| Very High | 4 | 0.85-1.00 | Red | Urgent |
132+
133+
---
134+
135+
## Configuration
136+
137+
### Update Pan-India Asset Path
138+
139+
In `computing/landslide/landslide_vector.py`:
140+
141+
```python
142+
LANDSLIDE_SUSCEPTIBILITY_ASSET = "projects/YOUR_PROJECT/assets/india_landslide"
143+
```
144+
145+
Or in `computing/path_constants.py`:
146+
147+
```python
148+
LANDSLIDE_SUSCEPTIBILITY_INDIA = "projects/YOUR_PROJECT/assets/india_landslide"
149+
```
150+
151+
---
152+
153+
## Troubleshooting
154+
155+
### "Asset not found"
156+
- Check asset path in `landslide_vector.py`
157+
- Verify GEE permissions
158+
- Falls back to demo generation automatically
159+
160+
### Task fails in GEE
161+
- Check memory limits (reduce AOI or increase maxPixels)
162+
- Verify MWS FC exists
163+
- Check GEE quota
164+
165+
### Missing attributes
166+
- Verify LULC asset exists
167+
- Check DEM coverage
168+
- Review reducer logs
169+
170+
---
171+
172+
## Testing
173+
174+
```bash
175+
# Run unit tests
176+
python -m unittest computing.landslide.tests
177+
178+
# Run specific test
179+
python -m unittest computing.landslide.tests.TestLandslideVectorization
180+
181+
# Run examples
182+
python computing/landslide/examples.py
183+
```
184+
185+
---
186+
187+
## Resources
188+
189+
- **Module README**: `computing/landslide/README.md`
190+
- **Full docs**: `docs/landslide_susceptibility.md`
191+
- **Implementation summary**: `LANDSLIDE_IMPLEMENTATION.md`
192+
- **Examples**: `computing/landslide/examples.py`
193+
- **Paper**: https://www.sciencedirect.com/science/article/pii/S0341816223007440
194+
195+
---
196+
197+
## Support
198+
199+
- GitHub Issues: https://github.com/core-stack-org/core-stack-backend/issues
200+
- Mentors: @amanodt, @ankit-work7, @kapildadheech
201+
- CoRE Stack Docs: `docs/` folder
202+
203+
---
204+
205+
**Last Updated**: November 9, 2025
206+
**Version**: 1.0.0

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ chmod +x install.sh
7575
| 27 | Water structure planning | Lithology | /computing/clart/lithology.py |
7676
| 28 | Water structure planning | Drainage lines | /computing/misc/drainage_lines.py |
7777
| 29 | Water structure planning | Stream order raster | /computing/misc/stream_order.py |
78-
| 30 | Water structure planning | CLART | /computing/clart/clart.py | |
78+
| 30 | Water structure planning | CLART | /computing/clart/clart.py |
79+
| 31 | Disaster Risk | Landslide Susceptibility | /computing/landslide/landslide_vector.py |
7980

8081
### Integrating custom pipelines on CoREStack
8182
We have prepared a [detailed guide](https://docs.google.com/document/d/1lfx2hJKndmzVp55ZHIIFYqRTz-8fZCWc9QikUDQpTN0/edit?usp=sharing) on how to integrate custom pipelines on the CoREStack backend.

computing/api.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
from computing.layer_dependency.layer_generation_in_order import layer_generate_map
5757
from .views import layer_status
5858
from .misc.lcw_conflict import generate_lcw_conflict_data
59+
from .landslide.landslide_vector import vectorise_landslide
5960

6061

6162
@api_security_check(allowed_methods="POST")
@@ -1198,3 +1199,38 @@ def generate_lcw_to_gee(request):
11981199
except Exception as e:
11991200
print("Exception in generate_lcw_conflict_data api :: ", e)
12001201
return Response({"Exception": e}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
1202+
1203+
1204+
@api_security_check(allowed_methods="POST")
1205+
@schema(None)
1206+
def generate_landslide_layer(request):
1207+
"""Generate landslide susceptibility vectors for a tehsil.
1208+
1209+
POST params:
1210+
state: State name
1211+
district: District name
1212+
block: Block/Tehsil name
1213+
gee_account_id: GEE account ID for authentication
1214+
"""
1215+
print("Inside generate_landslide_layer API.")
1216+
try:
1217+
state = request.data.get("state").lower()
1218+
district = request.data.get("district").lower()
1219+
block = request.data.get("block").lower()
1220+
gee_account_id = request.data.get("gee_account_id")
1221+
1222+
vectorise_landslide.apply_async(
1223+
args=[state, district, block, gee_account_id],
1224+
queue="nrm"
1225+
)
1226+
1227+
return Response(
1228+
{"Success": "Landslide susceptibility generation initiated"},
1229+
status=status.HTTP_200_OK
1230+
)
1231+
except Exception as e:
1232+
print("Exception in generate_landslide_layer api :: ", e)
1233+
return Response(
1234+
{"Exception": str(e)},
1235+
status=status.HTTP_500_INTERNAL_SERVER_ERROR
1236+
)

0 commit comments

Comments
 (0)