Skip to content

Commit 68ce624

Browse files
update
1 parent 11aa5e3 commit 68ce624

1 file changed

Lines changed: 33 additions & 17 deletions

File tree

notebooks/geopandas_flood_frequncy.ipynb

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,9 @@
313313
" 'date_diff_days': date_diff_days,\n",
314314
"})\n",
315315
"\n",
316-
"ndays = 15 # This will be our threshold for \"nearby\" dates in the next step\n",
317-
"# Filter to pairs whose dates are within ±15 days of each other\n",
316+
"ndays = 7 # This will be our threshold for \"nearby\" dates in the next step\n",
317+
"\n",
318+
"# Filter to pairs whose dates are within ndays of each other\n",
318319
"nearby = pairs[pairs['date_diff_days'] <= ndays].reset_index(drop=True)\n",
319320
"print(f'Intersecting polygon pairs with dates within ±{ndays} days: {len(nearby):>10,}')\n",
320321
"nearby.head(10)"
@@ -363,12 +364,32 @@
363364
"gf"
364365
]
365366
},
367+
{
368+
"cell_type": "markdown",
369+
"id": "1a7b15e6",
370+
"metadata": {},
371+
"source": [
372+
"## Aggregate Flood Events to Grid\n",
373+
"\n",
374+
"We now count the number of unique flood events per grid cell."
375+
]
376+
},
366377
{
367378
"cell_type": "markdown",
368379
"id": "c56357b6",
369380
"metadata": {},
370381
"source": [
371-
"Reproject the filtered flood points to EPSG:7755 — done once as a shared step before comparing both counting approaches."
382+
"Reproject the filtered flood points to the chosen CRS."
383+
]
384+
},
385+
{
386+
"cell_type": "code",
387+
"execution_count": null,
388+
"id": "76c29140",
389+
"metadata": {},
390+
"outputs": [],
391+
"source": [
392+
"gf_reprojected = gf.to_crs(grid_crs)"
372393
]
373394
},
374395
{
@@ -386,7 +407,6 @@
386407
"metadata": {},
387408
"outputs": [],
388409
"source": [
389-
"gf_reprojected = gf.to_crs(grid_crs)\n",
390410
"joined = gpd.sjoin(grid_india, gf_reprojected, how='inner', predicate='intersects')\n",
391411
"joined"
392412
]
@@ -398,11 +418,10 @@
398418
"metadata": {},
399419
"outputs": [],
400420
"source": [
401-
"counts_a = joined.groupby(joined.index)['flood_event'].nunique().rename('flood_count')\n",
421+
"counts = joined.groupby(joined.index)['flood_event'].nunique().rename('flood_count')\n",
402422
"\n",
403-
"grid_india_a = grid_india.copy()\n",
404-
"grid_india_a['flood_count'] = grid_india_a.index.map(counts_a).fillna(0).astype(int)\n",
405-
"print(grid_india_a['flood_count'].describe())"
423+
"grid_country['flood_count'] = grid_country.index.map(counts).fillna(0).astype(int)\n",
424+
"grid_country.head()"
406425
]
407426
},
408427
{
@@ -415,31 +434,28 @@
415434
"from matplotlib.cm import ScalarMappable\n",
416435
"from matplotlib.patches import Patch\n",
417436
"\n",
418-
"plot_data = grid_india_a.copy()\n",
419-
"plot_data['flood_count'] = plot_data['flood_count'].fillna(0).astype(int)\n",
420-
"\n",
421437
"fig, ax = plt.subplots(figsize=(10, 12))\n",
422438
"\n",
423439
"# Cells with no observations in neutral grey\n",
424-
"plot_data[plot_data['flood_count'] == 0].plot(\n",
440+
"grid_country[grid_country['flood_count'] == 0].plot(\n",
425441
" ax=ax, color='#d9d9d9', linewidth=0\n",
426442
")\n",
427443
"\n",
428-
"# Cells with observations coloured on a log scale\n",
444+
"# Cells with observations coloured by flood count\n",
429445
"# (flood counts are heavily right-skewed; log scale reveals spatial variation)\n",
430-
"non_zero = plot_data[plot_data['flood_count'] > 0]\n",
431-
"vmax = non_zero['flood_count'].max()\n",
446+
"norm = mcolors.LogNorm(vmin=1, vmax=grid_country['flood_count'].max())\n",
432447
"cmap = 'YlOrRd'\n",
433448
"\n",
449+
"non_zero = grid_country[grid_country['flood_count'] > 0]\n",
434450
"non_zero.plot(\n",
435451
" ax=ax, column='flood_count',\n",
436-
" cmap=cmap, vmin=1, vmax=50, linewidth=0\n",
452+
" cmap=cmap, norm=norm, linewidth=0\n",
437453
")\n",
438454
"\n",
439455
"# Country boundary\n",
440456
"country_proj.plot(ax=ax, facecolor='none', edgecolor='#333333', linewidth=0.8)\n",
441457
"\n",
442-
"ax.set_title('Flood Risk Map — India (2000–2025)\\n10 km × 10 km grid, observation count per cell', fontsize=13, pad=12)\n",
458+
"ax.set_title('Flood Frequency Map (2000–2025)', fontsize=13, pad=12)\n",
443459
"ax.axis('off')\n",
444460
"plt.tight_layout()\n",
445461
"plt.show()"

0 commit comments

Comments
 (0)