Skip to content

Commit cb16403

Browse files
authored
Merge pull request #189 from InsightLab/examples
Putting examples on distances module
2 parents 27d3203 + 81c869c commit cb16403

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

pymove/utils/distances.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ def haversine(
5555
float or ndarray
5656
Represents distance between points in meters
5757
58+
Example
59+
-------
60+
>>> from pymove.utils.distances import haversine
61+
>>> lat_fortaleza, lon_fortaleza = [-3.71839 ,-38.5434]
62+
>>> lat_quixada, lon_quixada = [-4.979224744401671, -39.056434302570665]
63+
>>> haversine(lat_fortaleza, lon_fortaleza, lat_quixada, lon_quixada)
64+
151298.02548428564
65+
5866
References
5967
----------
6068
Vectorized haversine function:
@@ -98,6 +106,16 @@ def euclidean_distance_in_meters(
98106
-------
99107
float or ndarray
100108
euclidean distance in meters between the two points.
109+
110+
Example
111+
-------
112+
>>> from pymove.utils.distances import euclidean_distance_in_meters
113+
>>> lat_fortaleza, lon_fortaleza = [-3.71839 ,-38.5434]
114+
>>> lat_quixada, lon_quixada = [-4.979224744401671, -39.056434302570665]
115+
>>> euclidean_distance_in_meters(
116+
>>> lat_fortaleza, lon_fortaleza, lat_quixada, lon_quixada
117+
>>> )
118+
151907.9670136588
101119
"""
102120
y1 = utils.conversions.lat_to_y_spherical(lat=lat1)
103121
y2 = utils.conversions.lat_to_y_spherical(lat=lat2)
@@ -136,6 +154,21 @@ def nearest_points(
136154
DataFrame
137155
dataframe with closest points
138156
157+
Example
158+
-------
159+
>>> from pymove.utils.distances import nearest_points
160+
>>> df_a
161+
lat lon datetime id
162+
0 39.984198 116.319322 2008-10-23 05:53:06 1
163+
1 39.984224 116.319402 2008-10-23 05:53:11 1
164+
>>> df_b
165+
lat lon datetime id
166+
0 39.984211 116.319389 2008-10-23 05:53:16 1
167+
1 39.984217 116.319422 2008-10-23 05:53:21 1
168+
>>> nearest_points(df_a,df_b)
169+
lat lon datetime id
170+
0 39.984211 116.319389 2008-10-23 05:53:16 1
171+
1 39.984211 116.319389 2008-10-23 05:53:16 1
139172
"""
140173
result = pd.DataFrame(columns=traj1.columns)
141174

@@ -164,8 +197,7 @@ def medp(
164197
"""
165198
Returns the Mean Euclidian Distance Predictive between two trajectories.
166199
167-
Considers only the spatial
168-
dimension for the similarity measure.
200+
Considers only the spatial dimension for the similarity measure.
169201
170202
Parameters
171203
----------
@@ -184,6 +216,18 @@ def medp(
184216
-------
185217
float
186218
total distance
219+
220+
Example
221+
-------
222+
>>> from pymove.utils.distances import medp
223+
>>> traj_1
224+
lat lon datetime id
225+
0 39.98471 116.319865 2008-10-23 05:53:23 1
226+
>>> traj_2
227+
lat lon datetime id
228+
0 39.984674 116.31981 2008-10-23 05:53:28 1
229+
>>> medp(traj_1, traj_2)
230+
6.573431370981577e-05
187231
"""
188232
soma = 0
189233
traj2 = nearest_points(traj1, traj2, latitude, longitude)
@@ -230,6 +274,17 @@ def medt(
230274
float
231275
total distance
232276
277+
Example
278+
-------
279+
>>> from pymove.utils.distances import medt
280+
>>> traj_1
281+
lat lon datetime id
282+
0 39.98471 116.319865 2008-10-23 05:53:23 1
283+
>>> traj_2
284+
lat lon datetime id
285+
0 39.984674 116.31981 2008-10-23 05:53:28 1
286+
>>> medt(traj_1, traj_2)
287+
6.592419887747872e-05
233288
"""
234289
soma = 0
235290
proportion = 1000000000

0 commit comments

Comments
 (0)