Skip to content

Commit b0f18d7

Browse files
authored
Merge pull request #185 from InsightLab/examples
Putting examples
2 parents eed6b96 + e2aaaac commit b0f18d7

File tree

11 files changed

+495
-146
lines changed

11 files changed

+495
-146
lines changed

.github/workflows/code_coverage.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ jobs:
1717
python-version: 3.7
1818
- name: Install dependencies
1919
run: |
20-
python -m pip install --upgrade pip
21-
pip install pytest coverage geopandas .
20+
make ci
2221
- name: Coverage
2322
run: |
24-
coverage run -m pytest
23+
make coverage
2524
coverage xml -o "coverage.xml"
2625
- name: Codacy Coverage Reporter
2726
uses: codacy/codacy-coverage-reporter-action@master

.github/workflows/lint_and_test.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ jobs:
1313
python-version: 3.7
1414
- name: Install dependencies
1515
run: |
16-
python -m pip install --upgrade pip
17-
pip install flake8 pep8-naming .
16+
make ci
1817
- name: Lint
1918
working-directory: ${{ github.workspace }}
2019
run: |
21-
flake8
20+
make lint
2221
test:
2322
name: Code Testing
2423
runs-on: ubuntu-latest
@@ -35,4 +34,4 @@ jobs:
3534
- name: Test
3635
working-directory: ${{ github.workspace }}
3736
run: |
38-
pytest --verbose
37+
make test

.github/workflows/publish.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ jobs:
1717
python-version: 3.7
1818
- name: Install dependencies
1919
run: |
20-
python -m pip install --upgrade pip
21-
pip install flake8 pep8-naming pytest geopandas .
20+
make ci
2221
- name: Lint and Test
2322
run: |
24-
flake8
25-
pytest
23+
make lint
24+
make test
2625
- name: Build
2726
run: |
2827
pip install setuptools wheel twine

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ dev:
1010
pip install -r requirements-dev.txt
1111
pre-commit install
1212

13+
ci:
14+
python -m pip install --upgrade pip
15+
pip install flake8 pep8-naming flake8-bugbear flake8-docstrings pytest coverage geopandas
16+
pip install .
17+
1318
clean:
1419
rm -rf `find . -type d -name .pytest_cache`
1520
rm -rf `find . -type d -name __pycache__`
@@ -18,6 +23,9 @@ clean:
1823
rm -f .coverage
1924

2025
test: clean
26+
pytest
27+
28+
coverage: clean
2129
coverage run -m pytest
2230
coverage report
2331

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

0 commit comments

Comments
 (0)