{"id":35878432,"url":"https://github.com/randsley/coastal-flood-modeling","last_synced_at":"2026-01-18T04:36:08.415Z","repository":{"id":332416686,"uuid":"1128660551","full_name":"randsley/coastal-flood-modeling","owner":"randsley","description":"High-resolution coastal flood modeling using morphological reconstruction algorithms","archived":false,"fork":false,"pushed_at":"2026-01-08T15:39:16.000Z","size":76,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-13T20:40:21.914Z","etag":null,"topics":["climate-change","coastal-flooding","dem","flood-modeling","geospatial","gis","julia","morphological-reconstruction","portugal","python"],"latest_commit_sha":null,"homepage":null,"language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/randsley.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":".zenodo.json","notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-06T01:12:38.000Z","updated_at":"2026-01-08T15:40:18.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/randsley/coastal-flood-modeling","commit_stats":null,"previous_names":["randsley/coastal-flood-modeling"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/randsley/coastal-flood-modeling","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/randsley%2Fcoastal-flood-modeling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/randsley%2Fcoastal-flood-modeling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/randsley%2Fcoastal-flood-modeling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/randsley%2Fcoastal-flood-modeling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/randsley","download_url":"https://codeload.github.com/randsley/coastal-flood-modeling/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/randsley%2Fcoastal-flood-modeling/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28529858,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["climate-change","coastal-flooding","dem","flood-modeling","geospatial","gis","julia","morphological-reconstruction","portugal","python"],"created_at":"2026-01-08T17:20:16.480Z","updated_at":"2026-01-18T04:36:08.409Z","avatar_url":"https://github.com/randsley.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Coastal Flood Simulation System\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Julia](https://img.shields.io/badge/Julia-1.10+-purple.svg)](https://julialang.org/)\n[![Python](https://img.shields.io/badge/Python-3.8+-blue.svg)](https://www.python.org/)\n[![GitHub Stars](https://img.shields.io/github/stars/randsley/coastal-flood-modeling?style=social)](https://github.com/randsley/coastal-flood-modeling/stargazers)\n[![GitHub Issues](https://img.shields.io/github/issues/randsley/coastal-flood-modeling)](https://github.com/randsley/coastal-flood-modeling/issues)\n[![DOI](https://img.shields.io/badge/DOI-10.5281%2Fzenodo.18186745-blue)](https://github.com/randsley/coastal-flood-modeling)\n\nHigh-resolution coastal flood modeling for Portuguese coastal zones using 50cm Digital Elevation Models (DEMs) from DGT (Direção-Geral do Território).\n\n## Overview\n\nThis system implements **connected morphological flooding algorithms** to simulate coastal inundation under various sea level scenarios. Unlike simple \"bathtub\" models, it uses morphological reconstruction to ensure only **hydrologically-connected** areas are identified as flooded.\n\n### Key Features\n\n- **High Resolution**: 50cm DEM resolution for detailed flood mapping\n- **Hydrologically Connected**: Uses morphological erosion to prevent isolated depressions from incorrectly appearing flooded\n- **Large Area Support**: Tiled processing for regions \u003e150 km coastline\n- **Multiple Outputs**: GeoTIFF for GIS analysis, interactive HTML maps for visualization\n- **Dual Implementation**: Python and Julia versions for flexibility and performance\n\n## Quick Start\n\n### Small Areas (\u003c 50 km coastline)\n\n**Julia (Recommended):**\n```bash\njulia simul_flood.jl\n```\n\n**Python:**\n```bash\npython Simul_corrected.py\n```\n\n### Large Areas (\u003e 50 km coastline)\n\nFor large regions like Caminha to Aveiro (~150 km):\n\n```bash\njulia simul_flood_tiled.jl\n```\n\nThis automatically:\n- Divides the region into manageable tiles (~16.5 km each)\n- Processes each tile with proper overlap (500m) for flood connectivity\n- Generates individual GeoTIFFs and HTML maps per tile\n- Creates a merged VRT for QGIS viewing\n\n## Installation\n\n### Prerequisites\n\n**Julia Dependencies:**\n```julia\nusing Pkg\nPkg.add([\"Rasters\", \"ArchGDAL\", \"ImageMorphology\", \"Statistics\"])\nPkg.add([\"FileIO\", \"ImageIO\", \"ColorTypes\"])  # For HTML maps\nPkg.add(\"GLMakie\")  # Optional: for interactive plotting\n```\n\n**Python Dependencies:**\n```bash\npip install rasterio numpy folium shapely scikit-image gdal\n```\n\n### Data Setup\n\n**Note**: DEM data files are not included in this repository due to size constraints.\n\n1. **Obtain DEM data**:\n   - Download 50cm resolution DEM tiles from [DGT (Direção-Geral do Território)](https://www.dgterritorio.gov.pt/)\n   - Look for MDT-50cm-*.tif files covering your area of interest\n   - Place tiles in the `DEM/` directory\n\n2. **Build VRT files**:\n   ```bash\n   python makeVRT.py\n   ```\n   This creates:\n   - `portugal_coast_mosaic.vrt` - Native projection\n   - `portugal_coast_wgs84.vrt` - WGS84 for web visualization\n\n## Usage\n\n### Basic Simulation\n\n```julia\nusing Rasters\ninclude(\"simul_flood.jl\")\n\n# Define region and scenario\nbounds = (-8.70, 40.95, -8.60, 41.03)  # (min_lon, min_lat, max_lon, max_lat)\ntide_zh = 3.8    # Highest Astronomical Tide (m, relative to ZH)\nsurge = 0.6      # Storm surge (m)\nslr = 1.13       # Sea level rise (m)\n\n# Run simulation\nresult, transform, metadata = run_simulation_on_vrt(\n    \"portugal_coast_wgs84.vrt\",\n    tide_zh, surge, slr, bounds\n)\n\n# Save outputs\nsave_flood_geotiff(result, \"flood_output.tif\")\nsave_html_map(result, \"flood_map.html\", metadata)\n```\n\n### Tiled Processing for Large Regions\n\n```julia\ninclude(\"simul_flood_tiled.jl\")\n\n# Define large region\nbounds = (-8.90, 40.55, -8.60, 41.87)  # Caminha to Aveiro\n\n# Create tiles\ntiles = create_tiles(bounds, 0.15, overlap=0.005)\n\n# Process all tiles\nresults = process_tiles(\n    \"portugal_coast_wgs84.vrt\",\n    tiles,\n    3.8,   # HAT\n    0.6,   # 50-year surge\n    1.13,  # 2100 SLR\n    output_dir=\"tiles_output\"\n)\n```\n\n## Vertical Datum Information\n\n**Critical for accurate results:**\n\n- **DGT DEMs**: Use Cascais 1938 datum (referenced to NMM - Mean Sea Level)\n- **Tidal data**: Uses Hydrographic Zero (ZH)\n- **DATUM_OFFSET**: 2.00m for Viana/Aveiro coastal zone\n\n**Formula:**\n```\nflood_threshold = (tide_zh + surge + slr) - DATUM_OFFSET\n```\n\n## Algorithm Details\n\n### Connected Morphological Flooding\n\n1. **Seed Creation**: Interior pixels set to maximum elevation, boundaries at actual elevation\n2. **Threshold Application**: Pixels below flood threshold remain as max elevation in seed\n3. **Morphological Erosion**: Reconstructs only hydrologically-connected areas below threshold\n4. **Result**: Binary flood mask showing connected flooded areas\n\nThis ensures flooding propagates from the ocean boundaries only, preventing isolated depressions from appearing flooded.\n\n### Area Calculation\n\nAreas are calculated in **real-world units** (m² and km²), not degrees:\n\nAt Portugal's latitude (~40-41°N):\n- **1° latitude** ≈ 111,320 m (constant)\n- **1° longitude** ≈ 111,320 × cos(latitude) m (varies with latitude)\n\nThe system automatically converts pixel dimensions from degrees to meters for accurate area reporting.\n\n## Output Files\n\n### GeoTIFF Files\n- **Format**: Single-band raster (1=flooded, 0=dry)\n- **Projection**: WGS84 (EPSG:4326)\n- **Use**: Professional GIS analysis in QGIS/ArcGIS\n\n### Interactive HTML Maps\n- **Features**:\n  - Pixel-accurate flood overlay\n  - OpenStreetMap/Satellite basemap\n  - Interactive zoom/pan\n  - Layer control\n  - Simulation statistics panel\n- **Technology**: Leaflet.js with embedded PNG overlay\n- **Use**: Presentations, web sharing, quick visualization\n\n### VRT Mosaics\n- **Merged tiles**: Single virtual dataset from all tiles\n- **Efficient**: No data duplication, instant access\n- **Use**: View entire simulation region in QGIS\n\n## Example Results\n\n**Northern Portugal Coast (Caminha to Aveiro)**\n\nScenario: HAT (3.8m) + 50-year surge (0.6m) + 2100 SLR (1.13m)\n\n- **Total flooded area**: 363.854 km²\n- **Processing time**: ~3 minutes (27 tiles)\n- **Resolution**: 1.5m × 2.0m pixels\n- **Largest flooding**: Ria de Aveiro (88-111 km² per tile)\n\n## File Structure\n\n```\n.\n├── simul_flood.jl              # Main Julia implementation\n├── simul_flood_tiled.jl        # Tiled processing for large areas\n├── Simul_corrected.py          # Python implementation\n├── makeVRT.py                  # VRT file builder\n├── regenerate_html_maps.jl     # Utility to regenerate HTML from GeoTIFFs\n├── DEM/                        # 50cm resolution DEM tiles\n├── tiles_output/               # Tiled simulation outputs\n│   ├── tile_001.tif           # Individual tile GeoTIFFs\n│   ├── tile_001.html          # Individual tile HTML maps\n│   └── ...\n├── merged_flood_*.vrt          # Merged VRT mosaics\n├── tile_index.html            # Tile grid reference map\n├── CLAUDE.md                  # Project guidance for AI assistants\n└── README.md                  # This file\n```\n\n## Performance Tips\n\n### Memory Management\n- **Small regions** (\u003c50 km): Load entire region at once\n- **Large regions** (\u003e50 km): Use tiled approach\n- **Tile size**: 0.15° (~16.5 km) is recommended\n- **Overlap**: 500m minimum for hydrological connectivity\n\n### Recommended Tile Sizes\n- **Standard**: 0.15° (~16.5 km) - good balance\n- **High detail**: 0.10° (~11 km) - more tiles, slower\n- **Low RAM**: 0.05° (~5.5 km) - smallest tiles\n\n## Troubleshooting\n\n### Memory Errors\nIf you encounter \"required memory greater than system memory\" errors:\n- The system automatically disables memory checking (`Rasters.checkmem!(false)`)\n- Uses lazy loading with `view()` for efficient subsetting\n- If issues persist, reduce tile size\n\n### Missing Data Handling\n- DGT DEMs use -9999 or metadata nodata values\n- Replaced with 9999 (high elevation) to prevent false flooding\n- Values \u003c -100m treated as nodata (Portugal has no such elevations)\n\n### HTML Map Issues\n- Requires `FileIO`, `ImageIO`, `ColorTypes` packages for pixel-perfect overlays\n- Falls back to rectangle overlay if packages missing\n- Install with: `using Pkg; Pkg.add([\"FileIO\", \"ImageIO\", \"ColorTypes\"])`\n\n## Citation\n\nIf using this system for research, please cite:\n\n```bibtex\n@software{randsley2026coastal,\n  author       = {Randsley, Nigel},\n  title        = {Coastal Flood Simulation System for Portuguese Coastal Zones},\n  year         = 2026,\n  publisher    = {Zenodo},\n  version      = {1.0.0},\n  doi          = {10.5281/zenodo.XXXXX},\n  url          = {https://doi.org/10.5281/zenodo.XXXXX}\n}\n```\n\n**Note**: Replace `XXXXX` with the actual Zenodo DOI after creating your first release.\n\n### Setting up Zenodo DOI\n\nThis repository is configured for Zenodo archiving. To get a permanent DOI:\n\n1. See the comprehensive guide: [`docs/ZENODO_SETUP.md`](docs/ZENODO_SETUP.md)\n2. Quick checklist: [`docs/ZENODO_CHECKLIST.md`](docs/ZENODO_CHECKLIST.md)\n3. Once published, update the DOI badge at the top of this README\n\n### Additional Citations\n\n- **DEM Data**: DGT (Direção-Geral do Território) - 50cm resolution Digital Elevation Models\n- **Morphological Flooding Algorithm**: Based on scikit-image morphological reconstruction (Python) and ImageMorphology.jl (Julia)\n\n## License\n\nMIT License\n\nCopyright (c) 2026 Nigel Randsley\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n## Contact\n\n**Nigel Randsley, PhD**\nEmail: nigel.randsley@protonmail.com\n\n## Acknowledgments\n\n- DGT for providing high-resolution DEM data\n- Portuguese coastal authorities for tidal datum information\n- Rasters.jl and scikit-image communities\n\n---\n\n**Last Updated**: January 2026\n**Tested with**: Julia 1.10+, Python 3.8+\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frandsley%2Fcoastal-flood-modeling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frandsley%2Fcoastal-flood-modeling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frandsley%2Fcoastal-flood-modeling/lists"}