DistanceMap
DistanceMap
The DistanceMap is a dictionary containing the distance from a center point to each point in a list of neighbor relative locations.
This exists to avoid repeated recomputation of neighbor distances.
For instance, if a neighborhood included one neighbor that was one unit in the positive x direction, and one that was offset by one unit in both the x and y directions, this map would be summarized by the following:
{ (1, 0): 1, (1, 1): math.sqrt(2) }
Source code in pylattica/core/distance_map.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
__init__(relative_neighbor_locs)
Intializes a DistanceMap.
Parameters
List[Tuple]
The relative neighbor locations to calculate and store distances for.
Source code in pylattica/core/distance_map.py
44 45 46 47 48 49 50 51 52 53 |
|
get_dist(relative_loc)
Given a relative location, returns the stored distance for that location.
Parameters
Tuple[Number]
The location of the neighbor to calculate a distance for.
Returns
float The distance of that neighbor.
Source code in pylattica/core/distance_map.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
EuclideanDistanceMap
Bases: DistanceMap
A distance map for storing Euclidean distances.
Source code in pylattica/core/distance_map.py
92 93 94 95 96 |
|
ManhattanDistanceMap
Bases: DistanceMap
A distance map that calculates and stores Manhattan distances
Source code in pylattica/core/distance_map.py
99 100 101 102 103 |
|
distance(arr1, arr2)
Given two 2D or 3D coordinate tuples, return the Euclidean distance between them. This implementation is simpler than the scipy.distance one, but it is much more efficient for small array.
Parameters
np.array
The first point
np.array
The second point
Returns
float The Euclidean distance between the points.
Source code in pylattica/core/distance_map.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|