sukri12 / pysal

Automatically exported from code.google.com/p/pysal
Other
0 stars 0 forks source link

using pysal.cg.KDTree.query with distance_upper_bound raises exception if neighbours are not found #208

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

from pysal.cg import KDTree
from pysal.cg import sphere
x=[(115,35), (112, 30)]
tree = KDTree(x, radius=sphere.RADIUS_EARTH_KM, distance_metric = "Arc")
tree.query((90,30), k=2, distance_upper_bound = 10) 

What is the expected output? What do you see instead?
Expected: (inf, inf) (missing neighbors are indicated with inf)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/z3424894/climddir-prototype/tools/myenv/lib/python2.7/site-packages/pysal/cg/kdtree.py", line 109, in query
    d = [sphere.linear2arcdist(x,r) for x in d]
  File "/home/z3424894/climddir-prototype/tools/myenv/lib/python2.7/site-packages/pysal/cg/sphere.py", line 65, in linear2arcdist
    raise ValueError, "linear_dist, must not exceed the diameter of the unit sphere, 2.0"

What version of the product are you using? On what operating system?
pysal==1.3.0
ScientificPython==2.8
numpy==1.6.1

Please provide any additional information below.
I believe the problem are the lines:

      if dims == 0:
            return sphere.linear2arcdist(d,r),i
        if dims == 1:
            #TODO: implement linear2arcdist on numpy arrays
            d = [sphere.linear2arcdist(x,r) for x in d]
        elif dims == 2:
            d = [[sphere.linear2arcdist(x,r) for x in row] for row in d]

This should either read like
d = [sphere.linear2arcdist(x,r) if x != inf else inf for x in d]
or
sphere.linear2arcdist should handle inf as an input (and perhaps return inf).

Regards,
Adam

Original issue reported on code.google.com by adam.h...@gmail.com on 19 Apr 2012 at 1:40

GoogleCodeExporter commented 8 years ago

Original comment by schmi...@gmail.com on 1 May 2012 at 9:52

GoogleCodeExporter commented 8 years ago
Fixed in r1281.

Adam, Thank for for submitting this bug and the suggested fix! This will be 
pushed out in 1.4.

Original comment by schmi...@gmail.com on 24 Jul 2012 at 4:34