libpysal icon indicating copy to clipboard operation
libpysal copied to clipboard

ZeroDivisionError and AssertionError thrown from cg.rtree

Open jGaboardi opened this issue 7 years ago • 12 comments

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

jGaboardi avatar Nov 30 '18 23:11 jGaboardi

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

jGaboardi avatar Dec 02 '18 20:12 jGaboardi

pysal/spaghetti#196

jGaboardi avatar Dec 05 '18 16:12 jGaboardi

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 avatar Apr 17 '19 22:04 sdesabbata

@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

jGaboardi avatar Apr 18 '19 02:04 jGaboardi

In legacy, the snapping worked on eberly so I'm not sure what has changed with the swapping from network to spaghetti?

sjsrey avatar Apr 18 '19 02:04 sjsrey

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).

jGaboardi avatar Apr 18 '19 03:04 jGaboardi

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.

sdesabbata avatar Apr 18 '19 18:04 sdesabbata

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...

ljwolf avatar Apr 30 '19 13:04 ljwolf

pysal/spaghetti#259

jGaboardi avatar May 11 '19 18:05 jGaboardi

@sdesabbata This issue (from the standpoint of spaghetti) will be resolved in the master branch of of spaghetti once pysal/spaghetti#259 gets merged.

jGaboardi avatar May 11 '19 21:05 jGaboardi

Stale issue message

github-actions[bot] avatar Mar 05 '20 00:03 github-actions[bot]

Further resolution in pysal/spaghetti#522 and e3ee2c4

jGaboardi avatar Oct 05 '20 13:10 jGaboardi