Skip to content

Comments

Fix critical unit conversion bug in water access calculations#9

Merged
k-r-a-s-s merged 2 commits intomainfrom
unit-conversion-fix
Aug 12, 2025
Merged

Fix critical unit conversion bug in water access calculations#9
k-r-a-s-s merged 2 commits intomainfrom
unit-conversion-fix

Conversation

@k-r-a-s-s
Copy link
Collaborator

Summary

  • Fixes critical unit conversion bug that caused water access distances to be underestimated by 3.6x
  • Updates sensitivity analysis MET value for more accurate results
  • Adds improved error handling

The Bug

The velocity data from the mobility models is in meters per second (m/s) but the distance calculation formula was treating it as kilometers per hour (km/h). This missing unit conversion caused all water access distances to be 3.6x smaller than they should be.

Evidence

  • Walking velocity data shows ~1.3 m/s (4.7 km/h) which is typical walking speed
  • The formula calculated 3.7 km instead of 13.3 km for 5.5 hours of walking
  • The sensitivity analysis correctly used the conversion factor and showed the discrepancy

The Fix

Added the proper unit conversion factor * 3600 / 1000 to convert m/s velocities to km distances:

# Before (incorrect)
df_zones["max distance walking"] = df_zones["average_velocity_walk"] * time_gathering_water / 2

# After (correct)
df_zones["max distance walking"] = df_zones["average_velocity_walk"] * time_gathering_water * 3600 / 2 / 1000

Changes

  1. src/gis_global_module.py: Fixed unit conversion in lines 840-844
  2. scripts/sensitivity_analysis_refactored.py: Updated MET value from 3.5 to 4.5 and improved error handling

Impact

This fix corrects a fundamental calculation error that affected all water access distance estimates in the global model.

🤖 Generated with Claude Code

Your Name and others added 2 commits August 13, 2025 09:50
- Fix critical unit conversion bug in gis_global_module.py
  * Velocity data is in m/s but was treated as km/h
  * Added proper conversion factor (3600/1000) to distance calculations
  * This fixes the 3.6x underestimation of water access distances

- Update sensitivity analysis MET value from 3.5 to 4.5
- Add better error handling for mobility model results

Co-Authored-By: Claude <noreply@anthropic.com>
@k-r-a-s-s k-r-a-s-s merged commit 04517db into main Aug 12, 2025
1 of 2 checks passed
@k-r-a-s-s k-r-a-s-s deleted the unit-conversion-fix branch August 12, 2025 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants