Skip to content

Commit 8dacf7b

Browse files
committed
examples
2 parents 000a8b0 + a1c6f09 commit 8dacf7b

File tree

6 files changed

+50
-57
lines changed

6 files changed

+50
-57
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,13 @@ You can see examples of how to use PyMove [here](https://github.com/InsightLab/P
231231
- 1: **Spatial Trajectories** → `pymove.core`
232232
- `MoveDataFrame`
233233
- `DiscreteMoveDataFrame`
234+
234235
- 2: **Stay Point Detection** → `pymove.preprocessing.stay_point_detection`
235236
- `create_or_update_move_stop_by_dist_time`
236237
- `create_or_update_move_and_stop_by_radius`
238+
237239
- 3: **Map-Matching** → `pymove-osmnx`
240+
238241
- 4: **Noise Filtering** → `pymove.preprocessing.filters`
239242
- `by_bbox`
240243
- `by_datetime`
@@ -249,29 +252,42 @@ You can see examples of how to use PyMove [here](https://github.com/InsightLab/P
249252
- `clean_trajectories_with_few_points`
250253
- `clean_trajectories_short_and_few_points`
251254
- `clean_id_by_time_max`
255+
252256
- 5: **Compression** → `pymove.preprocessing.compression`
253257
- `compress_segment_stop_to_point`
258+
254259
- 6: **Segmentation** → `pymove.preprocessing.segmentation`
255260
- `bbox_split`
256261
- `by_dist_time_speed`
257262
- `by_max_dist`
258263
- `by_max_time`
259264
- `by_max_speed`
265+
260266
- 7: **Distance of Trajectory** → `pymove.query.query`
261267
- `range_query`
262268
- `knn_query`
269+
263270
- 8: **Query Historical Trajectories**
271+
264272
- 9: **Managing Recent Trajectories**
273+
265274
- 10: **Privacy Preserving**
275+
266276
- 11: **Reducing Uncertainty**
277+
267278
- 12: **Moving Together Patterns**
279+
268280
- 13: **Clustering** → `pymove.models.pattern_mining.clustering`
269281
- `elbow_method`
270282
- `gap_statistics`
271283
- `dbscan_clustering`
284+
272285
- 14: **Freq. Seq. Patterns**
286+
273287
- 15: **Periodic Patterns**
288+
274289
- 16: **Trajectory Classification**
290+
275291
- 17: **Trajectory Outlier / Anomaly Detection** → `pymove.semantic.semantic`
276292
- `outliers`
277293
- `create_or_update_out_of_the_bbox`

pymove/core/grid.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ def __init__(
5151
Represents grid cell size, by default None
5252
meters_by_degree : float, optional
5353
Represents the corresponding meters of lat by degree,
54-
by default lat_meters(-3.8162973555)
54+
by default lat_meters(-3.71839)
5555
"""
5656
self.last_operation = None
5757
if meters_by_degree is None:
58-
meters_by_degree = lat_meters(-3.8162973555)
58+
meters_by_degree = lat_meters(-3.71839)
5959
if isinstance(data, dict):
6060
self._grid_from_dict(data)
6161
else:
@@ -126,7 +126,6 @@ def _create_virtual_grid(
126126
bbox = data.get_bbox()
127127
logger.debug('\nCreating a virtual grid without polygons')
128128

129-
# Latitude in Fortaleza: -3.8162973555
130129
cell_size_by_degree = cell_size / meters_by_degree
131130
logger.debug('...cell size by degree: %s' % cell_size_by_degree)
132131

pymove/core/pandas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def to_grid(
375375
376376
meters_by_degree : float, optional
377377
Represents the corresponding meters of lat by degree,
378-
by default lat_meters(-3.8162973555)
378+
by default lat_meters(-3.71839)
379379
380380
Returns
381381
-------
@@ -385,7 +385,7 @@ def to_grid(
385385
"""
386386
operation = begin_operation('to_grid')
387387
if meters_by_degree is None:
388-
meters_by_degree = lat_meters(-3.8162973555)
388+
meters_by_degree = lat_meters(-3.71839)
389389
grid_ = Grid(
390390
data=self, cell_size=cell_size, meters_by_degree=meters_by_degree
391391
)

pymove/tests/test_core_grid.py

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import joblib
44
from numpy import array
5-
from numpy.testing import assert_array_equal, assert_equal
5+
from numpy.testing import assert_array_almost_equal, assert_equal
66
from pandas import DataFrame, Timestamp
77
from pandas.testing import assert_frame_equal
88
from shapely.geometry import Polygon
@@ -64,7 +64,7 @@ def test_get_grid():
6464
'lat_min_y': 39.984094,
6565
'grid_size_lat_y': 5,
6666
'grid_size_lon_x': 5,
67-
'cell_size_by_degree': 0.0001353464801860623
67+
'cell_size_by_degree': 0.00013533905150922183
6868
}
6969
assert_equal(grid, expected)
7070

@@ -205,11 +205,11 @@ def test_convert_one_index_grid_to_two():
205205

206206
def test_create_one_polygon_to_point_on_grid():
207207
expected = [
208-
[116.3193713464802, 39.984094],
209-
[116.3193713464802, 39.984229346480184],
210-
[116.31950669296039, 39.984229346480184],
211-
[116.31950669296039, 39.984094],
212-
[116.3193713464802, 39.984094]
208+
[116.31937134, 39.984094],
209+
[116.31937134, 39.98422934],
210+
[116.31950668, 39.98422934],
211+
[116.31950668, 39.984094],
212+
[116.31937134, 39.984094],
213213
]
214214

215215
grid = _default_grid()
@@ -218,7 +218,7 @@ def test_create_one_polygon_to_point_on_grid():
218218

219219
polygon_coordinates = array(polygon.exterior.coords)
220220

221-
assert_array_equal(polygon_coordinates, expected)
221+
assert_array_almost_equal(polygon_coordinates, expected)
222222

223223

224224
def test_create_all_polygons_to_all_point_on_grid():
@@ -227,48 +227,25 @@ def test_create_all_polygons_to_all_point_on_grid():
227227
[
228228
1, 0, 0, Polygon((
229229
(116.319236, 39.984094),
230-
(116.319236, 39.984229346480184),
231-
(116.3193713464802, 39.984229346480184),
232-
(116.3193713464802, 39.984094),
230+
(116.319236, 39.98422933905151),
231+
(116.3193713390515, 39.98422933905151),
232+
(116.3193713390515, 39.984094),
233233
(116.319236, 39.984094)
234234
))
235-
],
236-
[
237-
1, 0, 1, Polygon((
238-
(116.3193713464802, 39.984094),
239-
(116.3193713464802, 39.984229346480184),
240-
(116.31950669296039, 39.984229346480184),
241-
(116.31950669296039, 39.984094),
242-
(116.3193713464802, 39.984094)
243-
))
244-
],
245-
[
246-
1, 4, 4, Polygon((
247-
(116.31977738592074, 39.98463538592074),
248-
(116.31977738592074, 39.984770732400925),
249-
(116.31991273240094, 39.984770732400925),
250-
(116.31991273240094, 39.98463538592074),
251-
(116.31977738592074, 39.98463538592074)
252-
))
253-
],
254-
[
255-
1, 3, 3, Polygon((
256-
(116.31964203944057, 39.984500039440555),
257-
(116.31964203944057, 39.98463538592074),
258-
(116.31977738592076, 39.98463538592074),
259-
(116.31977738592076, 39.984500039440555),
260-
(116.31964203944057, 39.984500039440555)
261-
))
262-
],
235+
]
263236
],
264237
columns=['id', 'index_grid_lat', 'index_grid_lon', 'polygon'],
265-
index=[0, 2, 5, 7],
238+
index=[0],
266239
)
267240
move_df = _default_move_df()
241+
move_df = move_df[move_df.index == 0]
268242
grid = Grid(move_df, 15)
269243

270244
all_polygon = grid.create_all_polygons_to_all_point_on_grid(move_df)
271-
assert_frame_equal(all_polygon, expected)
245+
246+
a = all_polygon.iloc[0]['polygon'].exterior.xy
247+
b = expected.iloc[0]['polygon'].exterior.xy
248+
assert_array_almost_equal(a, b)
272249

273250

274251
def test_point_to_index_grid():
@@ -288,7 +265,7 @@ def test_save_grid_pkl(tmpdir):
288265
'lat_min_y': 39.984094,
289266
'grid_size_lat_y': 5,
290267
'grid_size_lon_x': 5,
291-
'cell_size_by_degree': 0.0001353464801860623
268+
'cell_size_by_degree': 0.00013533905150922183
292269
}
293270
d = tmpdir.mkdir('core')
294271

pymove/utils/datetime.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ def working_day(
246246
Examples
247247
--------
248248
>>> from pymove.utils.datetime import str_to_datetime
249-
>>> independence_day = str_to_datetime('2021-09-7 12:00:01') # In Brazil this day is a holiday
250-
>>> next_day = str_to_datetime('2021-09-8 12:00:01') # In Brazil this day is a Wednesday and isn't a holiday
249+
>>> independence_day = str_to_datetime('2021-09-7 12:00:01') # Holiday in Brazil
250+
>>> next_day = str_to_datetime('2021-09-8 12:00:01') # Not a Holiday in Brazil
251251
>>> print(working_day(independence_day, 'BR'))
252252
False
253253
>>> print(type(working_day(independence_day, 'BR')))
@@ -535,7 +535,6 @@ def create_time_slot_in_minute(
535535
1 39.984198 116.319322 2008-10-23 05:56:06 1 23
536536
2 39.984224 116.319402 2008-10-23 05:56:11 1 23
537537
3 39.984224 116.319402 2008-10-23 06:10:15 1 24
538-
539538
"""
540539
if data.dtypes[label_datetime] != 'datetime64[ns]':
541540
raise ValueError('{} colum must be of type datetime'.format(label_datetime))
@@ -665,7 +664,6 @@ def threshold_time_statistics(
665664
Example
666665
-------
667666
>>> from pymove.utils.datetime import generate_time_statistics
668-
669667
>>> df
670668
local_label prev_local time_to_prev id
671669
0 house NaN NaN 1
@@ -680,11 +678,14 @@ def threshold_time_statistics(
680678
1 market house 720.0 0.000000 720.0 720.0 720.0 1
681679
2 market market 3.0 2.828427 1.0 5.0 6.0 2
682680
>>> threshold_time_statistics(statistics)
683-
local_label prev_local mean std min max sum count threshold
684-
0 house market 844.0 0.000000 844.0 844.0 844.0 1 844.0
685-
1 market house 720.0 0.000000 720.0 720.0 720.0 1 720.0
686-
2 market market 3.0 2.828427 1.0 5.0 6.0 2 5.8
687-
681+
local_label prev_local mean std min max sum count
682+
0 house market 844.0 0.000000 844.0 844.0 844.0 1
683+
1 market house 720.0 0.000000 720.0 720.0 720.0 1
684+
2 market market 3.0 2.828427 1.0 5.0 6.0 2
685+
threshold
686+
0 844.0
687+
1 720.0
688+
2 5.8
688689
"""
689690
if not inplace:
690691
df_statistics = df_statistics.copy()

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[flake8]
22
ignore = E203, E266, W402, W503, F401, F841, D401
3-
max-line-length = 120
3+
max-line-length = 90
44
max-complexity = 15
55
select = B,C,E,D,N,F,W
66
exclude = pymove/core/interface.py, pymove/tests/*

0 commit comments

Comments
 (0)