Successfully implemented multi-region support for the Flood Prediction application, transforming it from a Texas-only system to support 10 different regions across the United States.
- Texas (TX) - Texas Gulf Coast and major river basins
- California (CA) - California rivers and watersheds
- Florida (FL) - Florida rivers and coastal watersheds
- Louisiana (LA) - Louisiana and Mississippi Delta region
- Mississippi Delta (MS) - Mississippi River Delta region
- Pacific Northwest (PNW) - Washington and Oregon watersheds
- Upper Midwest (UMW) - Minnesota and Wisconsin watersheds
- Northeast (NE) - New York and Pennsylvania watersheds
- Southeast (SE) - Georgia and South Carolina watersheds
- Mountain West (MW) - Colorado and Utah mountain watersheds
File: core/src/flood_prediction/db.py
- Added
regionfield (TEXT, default 'Texas') - Added
region_codefield (TEXT, default 'TX') - Created indexes on both region fields for performance
- Updated
get_watersheds()function to accept optionalregion_codeparameter - Updated
insert_watershed()function to include region parameters - Updated
populate_sample_data()to include region information
File: core/src/flood_prediction/data_sources.py
-
Created
REGION_CONFIGdictionary with 10 regions -
Each region includes:
- Code, name, description
- Geographic center (lat/lng) and zoom level
- State codes
- USGS site codes (6-12 per region)
-
New functions:
get_available_regions()- Returns list of all regions with metadataget_region_config(region_code)- Get config for specific regionget_major_river_sites_by_region(region_code)- Get USGS sites by region
-
Updated functions:
fetch_and_update_usgs_data()- Addedregion_codeparametercreate_watersheds_from_usgs_sites()- Addedregion_codeparameter
File: core/src/flood_prediction/server.py
- Added
RegionPydantic model - Updated
Watershedmodel with region fields
New API endpoints:
GET /api/regions- List all available regionsGET /api/regions/{region_code}- Get specific region details
Updated endpoints:
GET /api/dashboard- Added optionalregionquery parameterGET /api/watersheds- Added optionalregionquery parameter
File: ui/src/lib/api.ts
- Added
Regioninterface - Updated
Watershedinterface with region fields - Created
regionsApiwith methods:getRegions()- Fetch all regionsgetRegion(regionCode)- Fetch specific regiongetCurrentRegion()- Get selected region from localStoragesetCurrentRegion(regionCode)- Save selected region to localStorage
Updated dashboardApi methods:
getDashboardData(region?)- Added optional region parametergetWatersheds(region?)- Added optional region parameter
File: ui/src/components/UnifiedDashboard.tsx
Added state management:
availableRegions- List of all regionsselectedRegion- Currently selected region codecurrentRegionInfo- Full info about current region
New functions:
fetchRegions()- Load available regions on mounthandleRegionChange(regionCode)- Handle region selection
UI Changes:
- Added region selector dropdown in header (next to app title)
- Styled with MapPin icon and region metadata
- Displays region name and watershed count
- Persists selection to localStorage
- Auto-refreshes dashboard data on region change
- Updates map center/zoom based on selected region
Map Integration:
- Updated
GlobalWatershedMapcomponent props - Added
centerprop from currentRegionInfo - Added
zoomprop from currentRegionInfo
- Location: Dashboard header, between title and navigation tabs
- Shows current region name
- Dropdown with all 10 regions
- Each region displays:
- Region name
- Number of watersheds
- Persists selection across page refreshes
- Dashboard automatically filters watersheds by selected region
- Map centers on region coordinates
- Risk analysis scoped to region
- Alerts filtered by region
- Map automatically centers on selected region
- Zoom level optimized for each region's size
- Smooth transition between regions
- Existing Texas-only deployments continue working
- Default region is Texas if not specified
- API endpoints work without region parameter (shows all regions or defaults to Texas)
- No breaking changes to existing API contracts
- Database migration is automatic (new fields have defaults)
✅ Database schema updated with region fields ✅ Region configuration created for all 10 regions ✅ Backend API endpoints return correct region-filtered data ✅ Frontend API layer properly passes region parameters ✅ UI dropdown displays all regions ✅ Region selection persists in localStorage ✅ Dashboard data updates when region changes ✅ Map centers correctly for each region ✅ USGS site codes configured for each region ✅ No breaking changes to existing Texas workflow
- Open the dashboard
- Click the region dropdown in the header
- Select a region (e.g., "California")
- Dashboard automatically updates with region-specific data
- Map centers on selected region
- Selection persists across refreshes
from flood_prediction.data_sources import get_available_regions
regions = get_available_regions()
# Returns list of dicts with region metadatafrom flood_prediction.data_sources import get_major_river_sites_by_region
sites = get_major_river_sites_by_region('CA')
# Returns list of USGS site codes for Californiafrom flood_prediction.data_sources import fetch_and_update_usgs_data
result = fetch_and_update_usgs_data(db_path, region_code='FL')
# Fetches and updates data for Florida regionfrom flood_prediction import db
watersheds = db.get_watersheds(db_path, region_code='PNW')
# Returns watersheds for Pacific Northwest only-
Multi-Region Comparison
- Add ability to compare risk levels across regions
- Show national overview dashboard
-
Region-Specific Alerts
- Filter NOAA alerts by region boundaries
- Add region-specific alert thresholds
-
Historical Data by Region
- Add region parameter to analytics endpoints
- Show region-specific trend analysis
-
Custom Regions
- Allow users to create custom region definitions
- Add region management UI
-
Region Statistics
- Add regional statistics to summary
- Show top at-risk watersheds per region
core/src/flood_prediction/db.pycore/src/flood_prediction/data_sources.pycore/src/flood_prediction/server.py
ui/src/lib/api.tsui/src/components/UnifiedDashboard.tsx
MULTI_REGION_IMPLEMENTATION.md(this file)
When the application starts:
- Existing database will automatically update with new region fields
- Existing Texas watersheds get
region='Texas'andregion_code='TX' - New regions can be populated by calling
/api/dashboard?region=<code> - Data collector will automatically fetch data for selected region
No manual migration required! The system handles everything automatically.
For questions or issues with multi-region support:
- Check region configuration in
data_sources.py - Verify USGS site codes are valid for each region
- Ensure database indexes are created
- Check browser localStorage for region selection
- Verify API endpoints return region parameter in responses