riskaware-ltd / open-eaggr

The OpenEAGGR software library is an implementation of a Discrete Global Grid System (DGGS) which models the Earth's surface as a network of equal area cells.
GNU Lesser General Public License v3.0
35 stars 14 forks source link

IndexError: invalid index #1

Open HeikkiVesanto opened 6 years ago

HeikkiVesanto commented 6 years ago

Working with python2.7 I am getting an index error with get_dggs_cell_siblings()

Results in: Process finished with exit code -1073741819 (0xC0000005)

Looks like it is Cell ID 02081,-3 that fails.

Full script that reproduces the error:

from eaggr.eaggr import Eaggr
from eaggr.shapes.lat_long_point import LatLongPoint
from eaggr.enums.model import Model

eaggr_mod = Eaggr(Model.ISEA3H)
print(eaggr_mod.get_version())

# Test:
lat_long_point = LatLongPoint(53.477569, -5.247472, 10000000000)
cell = eaggr_mod.convert_point_to_dggs_cell(lat_long_point)
print(cell.get_cell_id())
sibs = eaggr_mod.get_dggs_cell_siblings(cell)
for s in sibs:
    print(s.get_cell_id())
    eaggr_mod.get_dggs_cell_siblings(s)

Results in:

C:\OSGeo4W64\bin\python.exe C:/0VesaHe/point_to_grid.py
v2.0
02081,-4
02082,-3
02081,-3
Traceback (most recent call last):
  File "C:/0VesaHe/point_to_grid.py", line 16, in <module>
    eaggr_mod.get_dggs_cell_siblings(s)
  File "C:\OSGEO4~1\apps\Python27\lib\site-packages\eaggr\eaggr.py", line 388, in get_dggs_cell_siblings
    siblings_cells.append(output_cells[cell_index].to_dggs_cell())
IndexError: invalid index

Process finished with exit code -1073741819 (0xC0000005)
ian-bush-riskaware commented 6 years ago

Thanks for reporting this bug. I have managed to reproduce your issue. It appears that there is a bug in the parent/child relationships for some cells in the hexagonal gridding system. This has the knock-on effect of generating more sibling cells than there should be and there is an invalid index when referencing the array of siblings. This problem is specific to the hexagonal gridding system of ISEA3H. For now you could use ISEA4T if that suits your purposes. We will aim to include a fix for this bug in the next round of development.

HeikkiVesanto commented 6 years ago

Thanks for the response and the library, very useful.

No rush on the fix, I can work around it by using children from a higher level instead of siblings from the same.

ian-bush-riskaware commented 6 years ago

Glad you like the library. Just be aware that this bug is caused by a problem getting child cells of a parent in ISEA3H. It only affects some cells but as you can see in the attached image, getting the child cells for cell 02070,-1 is producing incorrect children. As I said, this is specific to the hexagonal gridding - the triangular gridding of ISEA4T should work fine. openeaggr_issue1

HeikkiVesanto commented 6 years ago

Good to know. That does explain some of the results I have experienced. Thanks.