Mercurial > hg > GlobalNeighbors
comparison globalneighbors/distance.py @ 3:49aae0c0293b
improved test coverage
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sat, 24 Jun 2017 14:48:31 -0700 |
parents | 1b94f3bf97e5 |
children | 7e27e874655b |
comparison
equal
deleted
inserted
replaced
2:50ee13cddf58 | 3:49aae0c0293b |
---|---|
55 | 55 |
56 def calculate_neighbors(locations, | 56 def calculate_neighbors(locations, |
57 k=10, | 57 k=10, |
58 lat_tol=1., | 58 lat_tol=1., |
59 lon_tol=1., | 59 lon_tol=1., |
60 output=1000, | 60 output=None, |
61 neighbors=None): | 61 neighbors=None): |
62 """ | 62 """ |
63 calculate `k` nearest neighbors for each location | 63 calculate `k` nearest neighbors for each location |
64 | |
65 locations -- dict of `geoid: (lat, lon)` | |
64 """ | 66 """ |
65 neighbors = neighbors or {} | 67 neighbors = neighbors or {} |
66 items = locations.items() | 68 items = locations.items() # copy |
67 index = 0 | 69 index = 0 |
68 n_items = len(items) | 70 n_items = len(items) |
69 start = int(time.time()) | 71 start = int(time.time()) |
70 while items: | 72 while items: |
71 index += 1 | 73 index += 1 |
72 if not index % output: | 74 if output and not index % output: |
73 # output status counter | 75 # output status counter |
74 now = int(time.time()) | 76 now = int(time.time()) |
75 duration = now - start | 77 duration = now - start |
76 start = now | 78 start = now |
77 print ('{},{},{},{}'.format(index, | 79 print ('{},{},{},{}'.format(index, |