Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential for division by zero error summarising destinations for very low population study region #349

Closed
carlhiggs opened this issue Jul 24, 2023 · 0 comments

Comments

@carlhiggs
Copy link
Collaborator

Describe the bug
The GHSCI software is designed to be used for metropolitan areas of cities, however users could apply it for a single neighbourhood, or even a single street block.

If they did, and the population was very low, they might run into a division by zero error when a particular step in the process summarises destinations and population within grid cells.

The problematic SQL query line where this occurs is here:

https://github.com/global-healthy-liveable-cities/global-indicators/blob/2ba788e601ebecbf374025986c69f9ac0ad9ea0e/process/subprocesses/_08_destination_summary.py#L45

This is a problem because 10,000 is treated as an integer, not a float with the result that it gets rounded to zero because the denominator is so small. The fix is simple, to amend to the following with 10000.0 instead, which evaluates the denominator as a float not an integer

t.count/a.area_sqkm/(pop_est/10000.0) AS dest_per_sqkm_per_10kpop

That should mean that regardless how low a population a study region has, as long as its greater than zero, this step will pass.

carlhiggs added a commit that referenced this issue Jul 24, 2023
…346) by creating a raster_to_db function that is now used when importing raster population grids. Also added function to drop a single table (#347), and addressed a potential division by zero error for study regions with population < 10000 (#349)
@carlhiggs carlhiggs mentioned this issue Jul 24, 2023
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

No branches or pull requests

1 participant