AIFDR / riab

Risk in a Box - main project
Other
17 stars 6 forks source link

New interpolation has index out of range in some cases. #155

Closed uniomni closed 13 years ago

uniomni commented 13 years ago

E.g. running the earthquake ground shaking on OSM building test data gives the error below. This is reproduced by the unit test: https://github.com/AIFDR/riab/commit/2d2c34f9f9a7a0c80ec95354f09d0c7598f49738

ERROR: test_earthquake_impact_OSM_data (main.Test_Engine)

Earthquake impact on OSM building data works

Traceback (most recent call last): File "test_engine.py", line 427, in test_earthquake_impact_OSM_data impact_fcn=IF) File "/home/nielso/dev/riab/impact/engine/core.py", line 50, in calculate_impact F = impact_function.run(layers) File "/home/nielso/dev/riab/impact/plugins/earthquake/BNPB_earthquake_guidelines.py", line 61, in run H = H.interpolate(E) File "/home/nielso/dev/riab/impact/storage/raster.py", line 274, in interpolate return interpolate_raster_vector(self, X, name) File "/home/nielso/dev/riab/impact/engine/interpolation.py", line 168, in interpolate_raster_vector return interpolate_raster_vector_points(R, P, name=name) File "/home/nielso/dev/riab/impact/engine/interpolation.py", line 132, in interpolate_raster_vector_points values = interpolate_raster(longitudes, latitudes, A, coordinates, mode='linear') File "/home/nielso/dev/riab/impact/engine/interpolation2d.py", line 165, in interpolate_raster res = interpolate2d(x, y, A, points, mode=mode, bounds_error=bounds_error) File "/home/nielso/dev/riab/impact/engine/interpolation2d.py", line 117, in interpolate2d x1 = x[idx] IndexError: index 922 out of bounds 0<=index<922

uniomni commented 13 years ago

Dedicated test for this is here: https://github.com/AIFDR/riab/commit/ce617d87e42eb19821edeece635e7dac47725b20#L1L75

uniomni commented 13 years ago

The problem arises when interpolation points have NaN values. The solution is to treat them the same way as interpolation points outside domain: https://github.com/AIFDR/riab/commit/ce617d87e42eb19821edeece635e7dac47725b20#L0L59