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

Avoided RuntimeWarning: divide by zero encountered in buffer #10085

Merged
merged 8 commits into from
Oct 24, 2024
Merged

Conversation

micheles
Copy link
Contributor

@micheles micheles commented Oct 24, 2024

Part of #10009.
For unknown reasons in many calculations (for instance the preclassical part of the Alaska model) the engine produces warnings such as

shapely/constructive.py:180: RuntimeWarning: divide by zero encountered in buffer

The change here is fixing the ALS model, not sure what will happen with other models. The way to see if the fix
works is to run

$ python -W error::RuntimeWarning -m openquake.commands run job.ini -p calculation_mode=preclassical

Here is a script producing the warning:

import numpy as np
from shapely import lib, wkt

geometry = wkt.loads('LINESTRING (104.20272072347558 -102.78153934821849, 97.47473519061595 -95.37910327186535, 93.65477746522551 -92.14932392491421, 89.99072683638946 -88.74425030520096, 86.87587494591658 -84.83173309217692, 84.11859105507783 -80.66009456126854, 81.91879274807779 -76.17002923159556, 79.6804372741759 -71.6990277209707, 77.30878963120625 -67.29716823927967, 74.76104218126518 -62.99467689076357, 71.79348924023687 -58.96975190368317, 68.88958010016543 -54.898786652062725, 66.05533205705616 -50.77913131314857, 62.765317800054326 -47.01283995544493, 55.41255826892601 -40.231131023102755, 47.93286745464175 -33.58975351967588, 41.14662393273625 -26.242722336516774, 37.59000955300192 -22.727102707485002, 34.01608649261132 -19.22912690717666, 30.353915236422658 -15.823584470676076, 26.616446761485566 -12.500808259648077, 23.25375387535472 -8.799786076282833, 20.052256150620245 -4.9586827692792115, 16.149896012011418 -1.8311968713731341, 12.312892675232398 1.3759166181769253, 8.785516485170215 4.920253984763066, 5.002554348275526 8.1906598114418, 1.325277026779542 11.579237402345274, -5.5676176758887586 18.82477516603797, -9.055825409455341 22.407283834916957, -12.556508443695519 25.977543115236138, -16.16325532440072 29.440626113585687, -27.82859838201426 38.871351651297836, -31.606570407710397 42.14657296509427, -35.09004761315348 45.73320293587195, -38.74556529537771 49.144310858010655, -42.3542883492067 52.60478818844773, -45.86261627835951 56.166911688065916, -49.57777913183215 59.512724851285604, -53.168834941480384 62.991296086685225, -56.7392405800298 66.49098173654262, -60.41185360773449 69.88318012710155, -64.22074200268031 73.12154389217457, -67.90692270380146 76.49882437931568, -71.57100637314473 79.89998293112593, -75.4595287853243 83.04198197739868, -79.57414244123275 85.88141645596902, -83.63434950169344 88.7979670064855, -87.3862538359715 92.10162379160434, -91.22194284867804 95.30750160530553, -95.67786564739313 97.57362437868531, -100.044063548525 100.00784745717648, -104.2027207234744 102.78153934821849, -100.044063548525 100.00784745717648, -95.67786564739313 97.57362437868531, -91.22194284867804 95.30750160530553, -87.3862538359715 92.10162379160434, -83.63434950169344 88.7979670064855, -79.57414244123275 85.88141645596902, -75.4595287853243 83.04198197739868, -71.57100637314473 79.89998293112593, -67.90692270380148 76.49882437931426, -64.22074200268031 73.12154389217457, -60.41185360773453 69.88318012710015, -56.7392405800298 66.49098173654262, -53.168834941480384 62.991296086685225, -49.57777913183215 59.512724851285604, -45.86261627835951 56.166911688065916, -42.3542883492067 52.60478818844773, -38.74556529537771 49.144310858010655, -35.09004761315349 45.73320293587054, -31.606570407710397 42.14657296509427, -27.82859838201426 38.871351651297836, -16.16325532440072 29.440626113585687, -12.556508443695519 25.977543115236138, -9.055825409455341 22.407283834916957, -5.56761767588876 18.824775166036556, 1.325277026779542 11.579237402345274, 5.002554348275526 8.1906598114418, 8.785516485170218 4.9202539847616515, 12.312892675232398 1.3759166181769253, 16.149896012011418 -1.8311968713731341, 20.052256150620245 -4.9586827692792115, 23.25375387535472 -8.799786076282833, 26.616446761485566 -12.500808259648077, 30.353915236422658 -15.823584470676076, 34.01608649261132 -19.22912690717666, 37.59000955300192 -22.727102707485002, 41.14662393273625 -26.242722336516774, 47.93286745464175 -33.58975351967588, 55.41255826892601 -40.231131023102755, 62.765317800054326 -47.01283995544493, 66.05533205705616 -50.77913131314857, 68.88958010016543 -54.898786652062725, 71.79348924023687 -58.96975190368317, 74.76104218126518 -62.99467689076357, 77.30878963120625 -67.29716823927967, 79.6804372741759 -71.6990277209707, 81.91879274807779 -76.17002923159556, 84.11859105507783 -80.66009456126854, 86.87587494591658 -84.83173309217692, 89.99072683638946 -88.74425030520096, 93.65477746522551 -92.14932392491421, 97.47473519061599 -95.37910327186677, 104.20272072347558 -102.78153934821849)')

poly = lib.buffer(geometry, .005, np.intc(2), np.intc(1), np.intc(1), 5., np.bool_(False))
print(poly)

@micheles micheles added this to the Engine 3.22.0 milestone Oct 24, 2024
@micheles micheles requested a review from ptormene October 24, 2024 04:34
@micheles micheles merged commit 51cb5af into master Oct 24, 2024
7 checks passed
@micheles micheles deleted the zerodiv branch October 24, 2024 07:21
@micheles
Copy link
Contributor Author

NB: the AELO tests are green :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant