Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. lat lng all_distances
  2. 0 39.984198 116.319322 0.000000
  3. 12 39.984611 116.319822 62.663690
  4. 24 39.984252 116.320826 128.601760
  5. 36 39.983916 116.320980 145.036185
  6. 48 39.982688 116.321225 233.518640
  7. 60 39.981441 116.321305 349.856365
  8. 72 39.980291 116.321430 469.693983
  9.  
  10. import pandas as pd
  11. from geopy.distance import distance
  12. print(pd.__version__)
  13.  
  14. data = [[ 39.984198, 116.319322],
  15. [ 39.984611, 116.319822],
  16. [ 39.984252, 116.320826],
  17. [ 39.983916, 116.32098 ],
  18. [ 39.982688, 116.321225],
  19. [ 39.981441, 116.321305],
  20. [ 39.980291, 116.32143 ],
  21. [ 39.979675, 116.321805],
  22. [ 39.979546, 116.322926],
  23. [ 39.979758, 116.324513]]
  24.  
  25. user_gps_log = pd.DataFrame(data, columns=['lat', 'lng'])
  26.  
  27. first_lat = user_gps_log.iloc[0].lat
  28. first_lng = user_gps_log.iloc[0].lng
  29. all_distances = user_gps_log.apply(lambda x: distance((x.lat, x.lng), (first_lat, first_lng)).m, axis=1)
  30.  
  31. user_gps_log['all_distances'] = all_distances
  32.  
  33. p = user_gps_log
  34. i = 0
  35. dist_thres = 2
  36.  
  37. while i < len(p):
  38. j = i+1
  39. while j < len(p):
  40. dist = distance((p.iloc[i].lat, p.iloc[i].lng), (p.iloc[j].lat, p.iloc[j].lng)).m
  41. if dist > dist_thres:
  42. # do stuff
  43. i = j
  44. token = 1
  45. break
  46. j = j+1
  47.  
  48. @njit
  49. def cumsum_distance(lat, lng, limit=200):
  50. running_distance = 0
  51. first = (lat[0], lng[0])
  52. for i in range(lat.shape[0]):
  53. dist = distance(first, (lat[i], lng[i])).m
  54. running_distance += dist
  55. if running_distance > limit:
  56. yield i, running_distance
  57. running_distance = 0
  58.  
  59. runnig_distances = cumsum_distance(user_gps_log.lat.values, user_gps_log.lng.values, 200)
  60.  
  61. TypingError: Failed in nopython mode pipeline (step: nopython frontend)
  62. Untyped global name 'distance': cannot determine Numba type of <class 'type'>
  63.  
  64. File "<ipython-input-194-7214618c7e64>", line 6:
  65. def cumsum_distance(lat, lng, limit=200):
  66. <source elided>
  67. for i in range(lat.shape[0]):
  68. dist = distance(first, (lat[i], lng[i])).m
  69. ^
  70.  
  71. This is not usually a problem with Numba itself but instead often caused by
  72. the use of unsupported features or an issue in resolving types.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement