libpysal
libpysal copied to clipboard
ZeroDivisionError and AssertionError thrown from cg.rtree
When attempting to snap point to a network using spaghetti, I have encountered two errors thrown from within libpysal.cg.rtree. Here is a gist showing the code and full error messages. These errors may originate in the snapping procedure implemented in spaghetti.util, though I am still unclear about it.
-
Platform information: posix darwin posix.uname_result(sysname='Darwin', nodename='wg-dhcp174d177d101.secure.wireless.fsu.edu', release='18.2.0', version='Darwin Kernel Version 18.2.0: Fri Oct 5 19:41:49 PDT 2018; root:xnu-4903.221.2~2/RELEASE_X86_64', machine='x86_64')
-
Python version: 3.6.6 | packaged by conda-forge | (default, Jul 26 2018, 09:55:02) [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]
-
SciPy version: 1.1.0
-
NumPy version: 1.15.4
Also, both libpysal and spaghetti are the most current development versions installed by:
$ pip install git+https://github.com/pysal/libpysal
$ pip install git+https://github.com/pysal/spaghetti
pysal/spaghetti#196
Hi @jGaboardi I am having the exact same errors. I think the ZeroDivisionError might be due to disconnected components in the network, as it disappears when I delete them in my own dataset. However, I am still unable to figure out the reason behind the AssertionError. Did you make any progress?
@sdesabbata I have not had any time to look into this, but now that others are having the issue it might be time to see about a fix.
@ljwolf @sjsrey
In legacy, the snapping worked on eberly so I'm not sure what has changed with the swapping from network to spaghetti?
The only substantive thing that I found that I changed was using a relatively small epsilon to using the smallest possible epsilon to grow a bounding box. Everything else that I have changed is only naming conventions (though I may very well be overlooking something).
I worked a bit on a copy of the code and the problem seems to be the creation of the rtree object. Commenting out lines 423 to 463 in spaghetti/util.py and replacing the nearest neighbor on 469 (and related) with the first edge of the network it seems to work fine and the output on the test dataset is the same. It obviously loses the advantage of working with an rtree.
I've looked at this myself today, and I'm not immediately clear on why this errs at first glance.
The only thing I can think of is that there should be some default value for the computation of a center of gravity for a collection of NullRects that would solve this problem, and I think that ought be (0,0). However, I'm not sure how this code works, and honestly haven't ever written/worked with the mechanics of balancing an Rtree myself.
That said, I'm sure the refrain familiar to my fellow collaborators would be to consider swapping our Rtree to the one based on libspatialite to reduce our maintenance surface...
pysal/spaghetti#259
@sdesabbata This issue (from the standpoint of spaghetti) will be resolved in the master branch of of spaghetti once pysal/spaghetti#259 gets merged.
Stale issue message
Further resolution in pysal/spaghetti#522 and e3ee2c4