diff --git a/.bumpversion.cfg b/.bumpversion.cfg deleted file mode 100644 index f71c65d0..00000000 --- a/.bumpversion.cfg +++ /dev/null @@ -1,10 +0,0 @@ -[bumpversion] -current_version = 2.7.2 -allow_dirty = True -tag_name = version-{new_version} -tag = True -commit = True - -[bumpversion:file:pymove/__init__.py] - -[bumpversion:file:setup.py] diff --git a/.code-style.md b/.code-style.md index ee71c4f0..9099dd13 100644 --- a/.code-style.md +++ b/.code-style.md @@ -22,6 +22,11 @@ We following the [Numpy](https://numpydoc.readthedocs.io/en/latest/format.html) ## flake8 Flake8 is a python linter that helps to keep the code up to PEP standards. + +## mypy + +Mypy is a static type checker for python + To lint the code, run: `make lint` ## Pre-Commit @@ -85,13 +90,14 @@ pymove/core/dataframe.py:970:29: E711 comparison to None should be 'if cond is N - Don't commit to branch: Doesn't allow direct commits to `master` branch. -- seed isort known_third_party: Populates the `.isort.cfg` file. - isort: Sorts the imports. - flake8: Ensures that the code follows `pylint` and `pyflakes` guidelines. It will point the errors in the code. +- mypy: Performs type checking. + It will point the errors in the code. --- ## Codacy diff --git a/.deployment-instructions.md b/.deployment-instructions.md index 74a88808..695bec2c 100644 --- a/.deployment-instructions.md +++ b/.deployment-instructions.md @@ -10,78 +10,66 @@ The link in this tutorial will explain the steps to upload a package to pypi: -#### Get started with Travis CI - -1. Sing up on Travis-ci with GitHub. - -2. Accept the authorization of Travis CI. - -3. Click on your profile picture in the top right of your Travis Dashboard, - click the green Activate button, and select the repositories - you want to use with Travis CI. - -4. Add a .travis.yml file to your repository to tell Travis CI what to do. - -#### Use the .travis.yml file to configure your deploy - -5. Create an API token to authenticate with PyPI: - 1. In your Pypi account settings, go to API tokens section and - select "Add API token" - - 2. Add the token to the Github Actions Secret. - -6. Create a github action with the following content: - ```yaml - name: Publish to PyPI - on: - push: - tags: - - "*" - - jobs: - build-n-publish: - if: github.event.base_ref == 'refs/heads/' && startsWith(github.ref, 'refs/tags') - name: Build and publish package - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.6 - uses: actions/setup-python@v2 - with: - python-version: 3.6 - - name: Install dependencies - run: | - python -m pip install --upgrade "pip<20" - pip install -r requirements-dev.txt - - name: - run: | - flake8 - pytest - - name: Build - run: | - pip install setuptools wheel twine - python setup.py sdist bdist_wheel - - name: Publish - uses: pypa/gh-action-pypi-publish@master - with: - user: __token__ - password: ${{ secrets.pypi_password }} - ``` +#### Use Github Actions to deploy + +1. Create an API token to authenticate with PyPI: + - In your Pypi account settings, go to API tokens section and select "Add API token" + + - Add the token to the Github Actions Secret. + +2. Create a github workflow with the following content: +```yaml +name: Publish to PyPI +on: + push: + tags: + - "*" + +jobs: + build-n-publish: + if: github.event.base_ref == 'refs/heads/' && startsWith(github.ref, 'refs/tags') + name: Build and publish package + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.6 + uses: actions/setup-python@v2 + with: + python-version: 3.6 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + make dev + - name: + run: | + make lint + make test + - name: Build + run: | + pip install setuptools wheel twine + python setup.py sdist bdist_wheel + - name: Publish + uses: pypa/gh-action-pypi-publish@master + with: + user: __token__ + password: ${{ secrets.pypi_password }} +``` #### Configure bump2version For the versioning control we a using the package bump2version. 1. Run `pip install bump2version` in your environment -2. Add the following attributes to the .bumpversion.cfg file: -```yaml - [bumpversion] - current_version = - allow_dirty = True - tag_name = version-{new_version} - tag = True - commit = True - [bumpversion:file:] +2. Add the following attributes to the setup.cfg file: +```conf +[bumpversion] +current_version = +allow_dirty = True +tag_name = version-{new_version} +tag = True +commit = True +[bumpversion:file:] +[bumpversion:file:] ``` ***Note:*** If `NotADirectoryError: [Errno 20] Not a directory`, @@ -89,22 +77,18 @@ For the versioning control we a using the package bump2version. #### For more information see these links -- - - --- -### Deploy the package using Travis CI - -1. Run the command `bumperversion [major|minor|patch]` to increase the - version number. This will create a new tag and commit the changes. +1. Run the command `bumperversion [major|minor|patch]` to increase the version number. + This will create a new tag and commit the changes. 2. Push the changes to the developer branch. 3. Create a pull request onto master. To deploy pymove to Pypi using - you must be in the master branch, Travis was configured to only allow - deployments from tagged commits on the master branch. + you must be in the master branch, pushing a tagged commit. 4. After merging the new version into the master branch, push the new tag created by bump2version. @@ -133,76 +117,76 @@ With the package published to Pypi, we can easily deploy to the 2. Now add some information to the `/meta.yaml` file. ```yaml - {% set name = %} - {% set version = %} - - package: - name: "{{ name|lower }}" - version: "{{ version }}" - - source: - url: "https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gz" - sha256: - - build: - number: 0 - script: "{{ PYTHON }} -m pip install . -vv" - noarch: python - - requirements: - host: - - pip - - python >=3.6 - run: - - - - python >=3.6 - - test: - imports: - - - - about: - home: - license: - license_family: - license_file: - summary: - doc_url: - dev_url: - - extra: - recipe-maintainers: - - - - +{% set name = %} +{% set version = %} + +package: + name: "{{ name|lower }}" + version: "{{ version }}" + +source: + url: "https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gz" + sha256: + +build: + number: 0 + script: "{{ PYTHON }} -m pip install . -vv" + noarch: python + +requirements: + host: + - pip + - python >=3.6 + run: + - + - python >=3.6 + +test: + imports: + - + +about: + home: + license: + license_family: + license_file: + summary: + doc_url: + dev_url: + +extra: + recipe-maintainers: + - + - ``` -1. All package run requirements must be avaiable in the conda-forge channel. +All package run requirements must be available in the conda-forge channel. #### Request the publication to the conda-forge channel -2. Fork the example recipes repository at +1. Fork the example recipes repository at -3. Copy the `/meta.yaml` file created in the step above to +2. Copy the `/meta.yaml` file created in the step above to the forked repo `staged-recipes/recipes/example` directory -4. Push the changes to your forked repository. +3. Push the changes to your forked repository. -5. Make a pull request for your repository to the master branch on +4. Make a pull request for your repository to the master branch on the stage-recipes repository. - `conda-forge:master from :` -6. Now, the pull request will be checked. - - Comlete the checklist for the pull requests. +5. Now, the pull request will be checked. + - Complete the checklist for the pull requests. - The recipe meta.yaml file will be checked by the `conda-forge-linting service`. - The recipe will be built for `linux64`, `macos64` and `windows64` systems. -7. If there are any problems with the PR, a review team member will give +6. If there are any problems with the PR, a review team member will give you feedback, pointing out improvements and answering questions. -8. Once everything is in order, the pull request will be aproved. +7. Once everything is in order, the pull request will be aproved. --- diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index a03776df..00000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -pymove/_version.py export-subst diff --git a/.github/workflows/lint_and_test.yml b/.github/workflows/lint_and_test.yml index e87807ea..ce999458 100644 --- a/.github/workflows/lint_and_test.yml +++ b/.github/workflows/lint_and_test.yml @@ -2,37 +2,26 @@ name: Lint and Test on: [push] jobs: - lint: - name: Code Linting + lint-test: + name: Lint and Test runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.7', '3.8', '3.9'] steps: - - uses: actions/checkout@main - - name: Set up Python 3.7 - uses: actions/setup-python@main - with: - python-version: 3.7 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - make dev - - name: Lint - working-directory: ${{ github.workspace }} - run: | - make lint - test: - name: Code Testing - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@main - - name: Set up Python 3.7 - uses: actions/setup-python@main - with: - python-version: 3.7 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - make dev - - name: Test - working-directory: ${{ github.workspace }} - run: | - make test + - uses: actions/checkout@main + - uses: actions/setup-python@main + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + make dev + - name: Check code style + working-directory: ${{ github.workspace }} + run: | + make lint + - name: Runs unit tests + working-directory: ${{ github.workspace }} + run: | + make test diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7546e5d7..a9b80b57 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,3 +32,7 @@ repos: 'flake8-docstrings==1.6.0', 'pep8-naming==0.11.1' ] +- repo: https://github.com/pre-commit/mirrors-mypy + rev: 'v0.812' + hooks: + - id: mypy diff --git a/Makefile b/Makefile index 5904aeb8..7df795c3 100644 --- a/Makefile +++ b/Makefile @@ -13,20 +13,22 @@ dev: clean: rm -rf `find . -type d -name .pytest_cache` + rm -rf `find . -type d -name .mypy_cache` rm -rf `find . -type d -name __pycache__` rm -rf `find . -type d -name .ipynb_checkpoints` rm -rf docs/_build rm -f .coverage test: clean - pytest + pytest pymove coverage: clean - coverage run -m pytest + coverage run -m pytest pymove coverage report lint: clean - flake8 + flake8 pymove + mypy pymove docs: clean cp docs/examples/notebooks.rst docs diff --git a/README.md b/README.md index dd9dec76..c195cbf7 100644 --- a/README.md +++ b/README.md @@ -4,120 +4,19 @@ ## Information - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Package Status - - Package status - -
License - - Package license - -
Python Version - - Python compatible versions - -
Platforms - - Platforms - -
All Platforms - - conda-forge build status - -
PyPi Downloads - - PyPi downloads - -
PyPi version - - PyPi version - -
Conda Downloads - - Conda downloads - -
Conda version - - Conda version - -
Stars - - Github stars - -
Forks - - Github forks - -
Issues - - Github issues - -
Code Quality - - Code quality - -
Code Coverage - - Code coverage - -
+||| +|--- |--- | +|Package Status|[](https://pypi.org/project/pymove/)| +|License|[](https://github.com/InsightLab/PyMove/blob/master/LICENSE)| +|Python Version|[](https://www.python.org/doc/versions/)| +|Platforms|[](https://anaconda.org/conda-forge/pymove)| +|Build Status|[](https://dev.azure.com/conda-forge/feedstock-builds/_build/latest?definitionId=9753&branchName=master)| +|PyPi version|[](https://pypi.org/project/pymove/#history)| +|PyPi Downloads|[](https://pypi.org/project/pymove/#files)| +|Conda version|[](https://anaconda.org/conda-forge/pymove)| +|Conda Downloads|[](https://anaconda.org/conda-forge/pymove/files)| +|Code Quality|[](https://app.codacy.com/gh/InsightLab/PyMove/dashboard)| +|Code Coverage|[](https://app.codacy.com/gh/InsightLab/PyMove/files)| --- @@ -255,12 +154,16 @@ You can see examples of how to use PyMove [here](https://github.com/InsightLab/P - `by_max_time` - `by_max_speed` -- 7: **Distance of Trajectory** → `pymove.query.query` +- 7: **Distance Measures** → `pymove.distances` + - `medp` + - `medt` + - `euclidean_distance_in_meters` + - `haversine` + +- 8: **Query Historical Trajectories** → `pymove.query.query` - `range_query` - `knn_query` -- 8: **Query Historical Trajectories** - - 9: **Managing Recent Trajectories** - 10: **Privacy Preserving** diff --git a/docs/examples/01_Exploring_MoveDataFrame.rst b/docs/examples/01_Exploring_MoveDataFrame.rst index 1daa1082..716153ae 100644 --- a/docs/examples/01_Exploring_MoveDataFrame.rst +++ b/docs/examples/01_Exploring_MoveDataFrame.rst @@ -786,9 +786,9 @@ c. DataFrames lon_min_x: 113.548843 lat_min_y: 22.147577 - grid_size_lat_y: 262999 - grid_size_lon_x: 105388 - cell_size_by_degree: 7.218478943256657e-05 + grid_size_lat_y: 263013 + grid_size_lon_x: 105394 + cell_size_by_degree: 7.218082747158498e-05 @@ -804,7 +804,7 @@ c. DataFrames .. parsed-literal:: - {'name': 'to_grid', 'time in seconds': 0.004861116409301758, 'memory': '0.0 B'} + {'name': 'to_grid', 'time in seconds': 0.010914802551269531, 'memory': '0.0 B'} diff --git a/docs/examples/03_Exploring_Visualization.rst b/docs/examples/03_Exploring_Visualization.rst index 33c44e35..bd9d9e76 100644 --- a/docs/examples/03_Exploring_Visualization.rst +++ b/docs/examples/03_Exploring_Visualization.rst @@ -21,6 +21,9 @@ data. These views make use of libraries like Matplotlib and Folium! .. code:: ipython3 move_df = pm.read_csv('geolife_sample.csv') + chunk1 = move_df[move_df['id'] == 1].head(5000) + chunk5 = move_df[move_df['id'] == 5].head(5000) + move_df = chunk1.append(chunk5) move_df.head() @@ -112,7 +115,7 @@ have more color options in your visualizations! .. parsed-literal:: - '#0000FF' + '#00FF00' @@ -158,21 +161,8 @@ data is distributed. mpl.show_object_id_by_date(move_df, return_fig=False) -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/pandas/plotting/_matplotlib/tools.py:400: MatplotlibDeprecationWarning: - The is_first_col function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use ax.get_subplotspec().is_first_col() instead. - if ax.is_first_col(): - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/pandas/plotting/_matplotlib/tools.py:400: MatplotlibDeprecationWarning: - The is_first_col function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use ax.get_subplotspec().is_first_col() instead. - if ax.is_first_col(): - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/pandas/plotting/_matplotlib/tools.py:400: MatplotlibDeprecationWarning: - The is_first_col function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use ax.get_subplotspec().is_first_col() instead. - if ax.is_first_col(): - - -.. image:: 03_Exploring_Visualization_files/03_Exploring_Visualization_11_1.png +.. image:: 03_Exploring_Visualization_files/03_Exploring_Visualization_11_0.png .. code:: ipython3 @@ -189,14 +179,14 @@ We can generate a visualization of the trajectory points filtered by: - .. code:: ipython3 - f.plot_trajectory_by_day_week(move_df, 'Sunday') + f.plot_trajectory_by_day_week(move_df, 'Saturday') .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -204,14 +194,14 @@ We can generate a visualization of the trajectory points filtered by: - .. code:: ipython3 - f.plot_trajectory_by_period(move_df, 'Evening') + f.plot_trajectory_by_period(move_df, 'Morning') .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -226,7 +216,7 @@ We can generate a visualization of the trajectory points filtered by: - .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -241,7 +231,7 @@ We can generate a visualization of the trajectory points filtered by: - .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -252,14 +242,14 @@ c. Exploring trajectories .. code:: ipython3 - f.plot_trajectories_with_folium(move_df, n_rows=10000) + f.plot_trajectories(move_df) .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -267,14 +257,14 @@ c. Exploring trajectories .. code:: ipython3 - f.plot_trajectory_by_id_folium(move_df, 1, n_rows=1000, color="orange") + f.plot_trajectory_by_id(move_df, 1, color="orange") .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -282,14 +272,14 @@ c. Exploring trajectories .. code:: ipython3 - f.heatmap(move_df, 10000) + f.heatmap(move_df) .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -297,14 +287,14 @@ c. Exploring trajectories .. code:: ipython3 - f.heatmap_with_time(move_df, 10000) + f.heatmap_with_time(move_df) .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -319,7 +309,7 @@ c. Exploring trajectories .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -327,14 +317,14 @@ c. Exploring trajectories .. code:: ipython3 - f.faster_cluster(move_df, 1000) + f.faster_cluster(move_df) .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -354,7 +344,7 @@ c. Exploring trajectories .. code:: ipython3 - mpl.plot_traj_by_id(move_df, "12008102305", feature="situation", value="stop", return_fig=False) + mpl.plot_trajectory_by_id(move_df, id_="12008102305", label='tid', feature="situation", value="stop", return_fig=False) @@ -370,7 +360,7 @@ c. Exploring trajectories .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -394,4 +384,4 @@ c. Exploring trajectories .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
diff --git a/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_11_0.png b/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_11_0.png new file mode 100644 index 00000000..c77b16fe Binary files /dev/null and b/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_11_0.png differ diff --git a/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_11_1.png b/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_11_1.png deleted file mode 100644 index 69616814..00000000 Binary files a/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_11_1.png and /dev/null differ diff --git a/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_12_0.png b/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_12_0.png index f16976a0..2e4b7e15 100644 Binary files a/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_12_0.png and b/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_12_0.png differ diff --git a/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_35_0.png b/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_35_0.png index 8b9ef50c..f76115db 100644 Binary files a/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_35_0.png and b/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_35_0.png differ diff --git a/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_38_0.png b/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_38_0.png index b24d48a4..f2dbc002 100644 Binary files a/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_38_0.png and b/docs/examples/03_Exploring_Visualization_files/03_Exploring_Visualization_38_0.png differ diff --git a/docs/examples/04_Exploring_Grid.rst b/docs/examples/04_Exploring_Grid.rst index ad3a6c2c..e022d461 100644 --- a/docs/examples/04_Exploring_Grid.rst +++ b/docs/examples/04_Exploring_Grid.rst @@ -175,7 +175,7 @@ Create virtual Grid 'lat_min_y': 39.970511, 'grid_size_lat_y': 341, 'grid_size_lon_x': 266, - 'cell_size_by_degree': 0.0001353464801860623} + 'cell_size_by_degree': 0.00013533905150922183} @@ -189,7 +189,7 @@ Create one polygon to point on grid .. parsed-literal:: - POLYGON ((116.3056033464802 39.97078169296037, 116.3056033464802 39.97091703944056, 116.3057386929604 39.97091703944056, 116.3057386929604 39.97078169296037, 116.3056033464802 39.97078169296037)) + POLYGON ((116.3056033390515 39.97078167810302, 116.3056033390515 39.97091701715453, 116.305738678103 39.97091701715453, 116.305738678103 39.97078167810302, 116.3056033390515 39.97078167810302)) Create or update index grid feature @@ -326,35 +326,35 @@ Create all polygons to all point on grid 1 100 101 - POLYGON ((116.3191379944988 39.98404564801861,... + POLYGON ((116.3191372442024 39.98404490515092,... 1 1 101 102 - POLYGON ((116.319273340979 39.98418099449879, ... + POLYGON ((116.3192725832539 39.98418024420243,... 4 1 101 103 - POLYGON ((116.3194086874592 39.98418099449879,... + POLYGON ((116.3194079223055 39.98418024420243,... 5 1 104 106 - POLYGON ((116.3198147268997 39.98458703393936,... + POLYGON ((116.31981393946 39.98458626135696, 1... 6 1 104 105 - POLYGON ((116.3196793804195 39.98458703393936,... + POLYGON ((116.3196786004085 39.98458626135696,... @@ -428,7 +428,7 @@ Read .pkl to grid 'lat_min_y': 39.970511, 'grid_size_lat_y': 341, 'grid_size_lon_x': 266, - 'cell_size_by_degree': 0.0001353464801860623} + 'cell_size_by_degree': 0.00013533905150922183} @@ -437,8 +437,12 @@ Show a grid polygons .. code:: ipython3 - grid.show_grid_polygons(grid_data, return_fig=False) + from pymove.visualization.matplotlib import plot_grid_polygons + +.. code:: ipython3 + + plot_grid_polygons(grid_data, return_fig=False) -.. image:: 04_Exploring_Grid_files/04_Exploring_Grid_25_0.png +.. image:: 04_Exploring_Grid_files/04_Exploring_Grid_26_0.png diff --git a/docs/examples/04_Exploring_Grid_files/04_Exploring_Grid_25_0.png b/docs/examples/04_Exploring_Grid_files/04_Exploring_Grid_25_0.png deleted file mode 100644 index 8bb041ff..00000000 Binary files a/docs/examples/04_Exploring_Grid_files/04_Exploring_Grid_25_0.png and /dev/null differ diff --git a/docs/examples/04_Exploring_Grid_files/04_Exploring_Grid_26_0.png b/docs/examples/04_Exploring_Grid_files/04_Exploring_Grid_26_0.png new file mode 100644 index 00000000..4915ea90 Binary files /dev/null and b/docs/examples/04_Exploring_Grid_files/04_Exploring_Grid_26_0.png differ diff --git a/docs/examples/05_Exploring_Utils.rst b/docs/examples/05_Exploring_Utils.rst index 4ebcca15..90eed4e5 100644 --- a/docs/examples/05_Exploring_Utils.rst +++ b/docs/examples/05_Exploring_Utils.rst @@ -15,6 +15,7 @@ Imports import pymove.utils as utils import pymove as pm + import datetime Conversions ----------- @@ -1256,29 +1257,12 @@ To get date, in string’s format, from timestamp, you can use -To converts a date in datetime’s format to string’s format, you can use -**to_str**. - -.. code:: ipython3 - - import datetime - utils.datetime.to_str(datetime.datetime(2018, 6, 29, 8, 15, 27)) - - - - -.. parsed-literal:: - - '2018-06-29 08:15:27' - - - To converts a datetime to an int representation in minutes, you can use **to_min**. .. code:: ipython3 - utils.datetime.to_min(datetime.datetime(2018, 6, 29, 8, 15, 27)) + utils.datetime.datetime_to_min(datetime.datetime(2018, 6, 29, 8, 15, 27)) @@ -1360,7 +1344,7 @@ To get datetime of now, you can use **now_str**. .. parsed-literal:: - '2021-04-16 22:35:04' + '2021-07-13 19:56:01' @@ -1456,7 +1440,7 @@ the function is called, you can use **elapsed_time_dt**. .. parsed-literal:: - 3827572504825 + 3835166163375 @@ -1591,7 +1575,7 @@ use **array_stats**. .. parsed-literal:: - (625, 360425, 3) + (625.0, 360425.0, 3) @@ -1760,9 +1744,9 @@ To flatten a dataframe with dict as row values lon datetime id - dict_column_a - dict_column_b dict_column_c + dict_column_b + dict_column_a @@ -1772,9 +1756,9 @@ To flatten a dataframe with dict as row values 116.319236 2008-10-23 05:53:05 1 - 1.0 NaN NaN + 1.0 1 @@ -1792,9 +1776,9 @@ To flatten a dataframe with dict as row values 116.319402 2008-10-23 05:53:11 1 + 3.0 NaN NaN - 3.0 @@ -2367,8 +2351,8 @@ Reduce size of dataframe .. parsed-literal:: Memory usage of dataframe is 6.64 MB - Memory usage after optimization is: 4.15 MB - Decreased by 37.5 % + Memory usage after optimization is: 2.70 MB + Decreased by 59.4 % Create a dataframe with the variables with largest memory footpring @@ -2417,7 +2401,7 @@ Create a dataframe with the variables with largest memory footpring 1 mdf - 4.2 MiB + 2.7 MiB 2 @@ -2446,17 +2430,17 @@ Create a dataframe with the variables with largest memory footpring 7 - utils + matplotlib 72.0 B 8 - pm + sys 72.0 B 9 - datetime + os 72.0 B diff --git a/docs/examples/06_Exploring_Integrations.rst b/docs/examples/06_Exploring_Integrations.rst index 8fd689d1..74962434 100644 --- a/docs/examples/06_Exploring_Integrations.rst +++ b/docs/examples/06_Exploring_Integrations.rst @@ -25,6 +25,11 @@ to be installed import pandas as pd import geopandas +.. code:: ipython3 + + import warnings + warnings.filterwarnings("ignore", category=DeprecationWarning) + 2. Load Data ------------ @@ -123,14 +128,14 @@ Visualization .. code:: ipython3 - folium.plot_trajectories_with_folium(move_df) + folium.plot_trajectories(move_df) .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -147,7 +152,7 @@ Visualization .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -163,12 +168,6 @@ Visualization POIs.head() -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. raw:: html @@ -348,13 +347,6 @@ Removing unrated (null) points of interest POIs = POIs.dropna(subset=["amenity"], inplace=False) - -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - Adapting to the format needed for integration (With labels ‘lat’ and ‘lon’ referring to latitude and longitude, respectively) @@ -364,27 +356,20 @@ Adapting to the format needed for integration (With labels ‘lat’ and POIs['lon'] = POIs['geometry'].x POIs['lat'] = POIs['geometry'].y - -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - Visualization ~~~~~~~~~~~~~ .. code:: ipython3 - m = folium.plot_trajectories_with_folium(move_df) - folium.plot_poi_folium(POIs, slice_tags=['amenity'], base_map=m, poi_point='blue') + m = folium.plot_trajectories(move_df) + folium.plot_poi(POIs, slice_tags=['amenity'], base_map=m, poi_point='blue') .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -394,19 +379,13 @@ Visualization .. code:: ipython3 df_4 = move_df.copy() - it.join_with_pois(df_4, POIs, label_id='osmid', label_poi_name='name') - - -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) + df_4 = it.join_with_pois(df_4, POIs, label_id='osmid', label_poi_name='name') .. parsed-literal:: - VBox(children=(HTML(value=''), IntProgress(value=0, max=5000))) + VBox(children=(HTML(value=''), IntProgress(value=0, max=746))) Result @@ -511,24 +490,18 @@ Point of interest closest to each point of the trajectory df_4['name_poi'].unique() -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. parsed-literal:: array(['太平洋影城(中关村店)', '东亚银行', '南京银行', '星巴克', '小吊梨汤', nan, '鑫蜀源', '必胜客', - '潜渊', '上岛咖啡', '科苑餐厅', '2nd Place', '元绿回转寿司', '中信银行', 'HSBC', '咖啡王', - '招商银行', '中国建设银行', 'Paradiso Coffee', '798 bar', 'Jazz Cafe', - 'Hundred Years Cafe', '安家小厨', '清青快餐', '听涛园', '仰望咖啡', + '潜渊', '上岛咖啡', '科苑餐厅', '2nd Place', '元绿回转寿司', '中信银行', 'HSBC', + '咖啡王(暂时停业)', '招商银行', '中国建设银行', 'Paradiso Coffee', '798 bar', + 'Jazz Cafe', 'Hundred Years Cafe', '安家小厨', '清青快餐', '听涛园', '仰望咖啡', 'China Construction Bank', '同仁堂', '北园餐厅', '北京银行', '交通银行', '宁波银行', '美嘉欢乐影城', '北京101中学', '西苑医院', 'Yu Xiao Mian Noodles', '茶大爷', - "McDonald's", 'Pizza Hut', 'Starbucks', '云海肴', '兰州老妈拉面', - 'Пекинский Ботанический сад (Парковка) 植物园停车场'], dtype=object) + "McDonald's", 'Pizza Hut', 'Starbucks', '云海肴', '兰州老妈拉面'], + dtype=object) @@ -552,8 +525,8 @@ Selecting data .. parsed-literal:: - array(['toilets', 'fast_food', 'massage', 'waste_basket', 'parking', - 'cafe', 'restaurant', 'bank'], dtype=object) + array(['toilets', 'fast_food', 'massage', 'waste_basket', 'cafe', + 'restaurant', 'bank'], dtype=object) @@ -561,7 +534,7 @@ Executing the function .. code:: ipython3 - it.join_with_pois_optimizer(df_5, POIs_5, label_id='osmid', label_poi_name='name', dist_poi=np.array([100,9,1,50,50,10,20])) + df_5 = it.join_with_pois(df_5, POIs_5, label_id='osmid', label_poi_name='name') @@ -570,11 +543,6 @@ Executing the function VBox(children=(HTML(value=''), IntProgress(value=0, max=10))) -.. parsed-literal:: - - <__array_function__ internals>:5: DeprecationWarning: Calling nonzero on 0d arrays is deprecated, as it behaves surprisingly. Use `atleast_1d(cond).nonzero()` if the old behavior was intended. If the context of this warning is of the form `arr[nonzero(cond)]`, just use `arr[cond]`. - - .. code:: ipython3 df_5.head() @@ -618,9 +586,9 @@ Executing the function 116.319236 2008-10-23 05:53:05 1 - 269492188 - 1144.603484 - toilets + 312152376 + 1061.807427 + 永和大王 1 @@ -628,9 +596,9 @@ Executing the function 116.319322 2008-10-23 05:53:06 1 - 269492188 - 1131.338544 - toilets + 312152376 + 1048.334810 + 永和大王 2 @@ -638,9 +606,9 @@ Executing the function 116.319402 2008-10-23 05:53:11 1 - 269492188 - 1124.395459 - toilets + 312152376 + 1041.594793 + 永和大王 3 @@ -648,9 +616,9 @@ Executing the function 116.319389 2008-10-23 05:53:16 1 - 269492188 - 1126.193301 - toilets + 312152376 + 1043.408891 + 永和大王 4 @@ -658,9 +626,9 @@ Executing the function 116.319422 2008-10-23 05:53:21 1 - 269492188 - 1123.692580 - toilets + 312152376 + 1041.019464 + 永和大王 @@ -673,20 +641,306 @@ Executing the function .. code:: ipython3 - df_6 = move_df.copy() - it.join_with_pois_by_category(df_6, POIs_5, label_category='amenity', label_id='id') + POIs_5 -.. parsed-literal:: - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) +.. raw:: html +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
unique_idosmidelement_typeamenityfeegeometrycuisinenamename:enatm...alt_name_1not:nameareawaystypename:janame:kolonlattype_poi
0node/269492188269492188nodetoiletsnoPOINT (116.26750 39.98087)NaNNaNNaNNaN...NaNNaNNaNNaNNaNNaNNaN116.26750439.980869toilets
1node/274942287274942287nodetoiletsNaNPOINT (116.27358 39.99664)NaNNaNNaNNaN...NaNNaNNaNNaNNaNNaNNaN116.27357939.996640toilets
2node/276320137276320137nodefast_foodNaNPOINT (116.33756 39.97541)chinese永和大王NaNNaN...NaNNaNNaNNaNNaNNaNNaN116.33755739.975411fast_food
3node/276320142276320142nodemassageNaNPOINT (116.33751 39.97546)NaNFootmassage 富橋NaNNaN...NaNNaNNaNNaNNaNNaNNaN116.33751039.975463massage
4node/286242547286242547nodetoiletsNaNPOINT (116.19982 40.00670)NaNNaNNaNNaN...NaNNaNNaNNaNNaNNaNNaN116.19982240.006700toilets
5node/286246121286246121nodewaste_basketNaNPOINT (116.20290 39.99787)NaNNaNNaNNaN...NaNNaNNaNNaNNaNNaNNaN116.20290239.997869waste_basket
6node/290600874290600874nodecafeNaNPOINT (116.32900 39.99117)NaN迷你站奶茶专门店Mini Station MilkteaNaN...NaNNaNNaNNaNNaNNaNNaN116.32899739.991167cafe
7node/297407376297407376noderestaurantNaNPOINT (116.33981 39.97537)NaN沸腾渔乡NaNNaN...NaNNaNNaNNaNNaNNaNNaN116.33981039.975369restaurant
8node/297407444297407444nodebankNaNPOINT (116.33826 39.97546)NaN招商银行China Merchants Bankyes...NaNNaNNaNNaNNaNNaNNaN116.33826039.975462bank
9node/312152376312152376noderestaurantNaNPOINT (116.32766 39.99113)NaN永和大王Yonghe KingNaN...NaNNaNNaNNaNNaNNaNNaN116.32766039.991132restaurant
+

10 rows × 121 columns

+
- VBox(children=(HTML(value=''), IntProgress(value=0, max=5000))) + + +.. code:: ipython3 + + df_6 = move_df.copy() + df_6 = it.join_with_pois_by_category(df_6, POIs_5, label_category='amenity', label_id='name') @@ -770,8 +1024,6 @@ Executing the function dist_massage id_waste_basket dist_waste_basket - id_parking - dist_parking id_cafe dist_cafe id_restaurant @@ -787,21 +1039,19 @@ Executing the function 116.319236 2008-10-23 05:53:05 1 - 274942287 + NaN 4132.229067 - 276320137 + 永和大王 1835.502157 - 276320142 + Footmassage 富橋 1829.070918 - 286246121 + NaN 10028.323311 - 286251975 - 9867.997250 - 290600874 + 迷你站奶茶专门店 1144.603484 - 297407376 - 2003.585998 - 297407444 + 永和大王 + 1061.807427 + 招商银行 1883.831094 @@ -810,21 +1060,19 @@ Executing the function 116.319322 2008-10-23 05:53:06 1 - 274942287 + NaN 4135.240296 - 276320137 + 永和大王 1835.403414 - 276320142 + Footmassage 富橋 1828.951254 - 286246121 + NaN 10033.797904 - 286251975 - 9874.072277 - 290600874 + 迷你站奶茶专门店 1131.338544 - 297407376 - 2002.819358 - 297407444 + 永和大王 + 1048.334810 + 招商银行 1883.466601 @@ -833,21 +1081,19 @@ Executing the function 116.319402 2008-10-23 05:53:11 1 - 274942287 + NaN 4140.698090 - 276320137 + 永和大王 1831.182086 - 276320142 + Footmassage 富橋 1824.720741 - 286246121 + NaN 10040.095434 - 286251975 - 9880.550663 - 290600874 + 迷你站奶茶专门店 1124.395459 - 297407376 - 1998.303264 - 297407444 + 永和大王 + 1041.594793 + 招商银行 1879.127020 @@ -856,21 +1102,19 @@ Executing the function 116.319389 2008-10-23 05:53:16 1 - 274942287 + NaN 4140.136625 - 276320137 + 永和大王 1831.345213 - 276320142 + Footmassage 富橋 1824.886604 - 286246121 + NaN 10039.220172 - 286251975 - 9879.599237 - 290600874 + 迷你站奶茶专门店 1126.193301 - 297407376 - 1998.555890 - 297407444 + 永和大王 + 1043.408891 + 招商银行 1879.325712 @@ -879,21 +1123,19 @@ Executing the function 116.319422 2008-10-23 05:53:21 1 - 274942287 + NaN 4142.564150 - 276320137 + 永和大王 1829.326076 - 276320142 + Footmassage 富橋 1822.864349 - 286246121 + NaN 10041.897836 - 286251975 - 9882.326278 - 290600874 + 迷你站奶茶专门店 1123.692580 - 297407376 - 1996.436934 - 297407444 + 永和大王 + 1041.019464 + 招商银行 1877.266370 @@ -902,21 +1144,19 @@ Executing the function 116.319865 2008-10-23 05:53:23 1 - 274942287 + NaN 4160.348133 - 276320137 + 永和大王 1827.992513 - 276320142 + Footmassage 富橋 1821.434719 - 286246121 + NaN 10071.059512 - 286251975 - 9914.343371 - 290600874 + 迷你站奶茶专门店 1058.680139 - 297407376 - 1991.704195 - 297407444 + 永和大王 + 975.127648 + 招商银行 1874.593280 @@ -925,21 +1165,19 @@ Executing the function 116.319810 2008-10-23 05:53:28 1 - 274942287 + NaN 4157.187813 - 276320137 + 永和大王 1829.602658 - 276320142 + Footmassage 富橋 1823.053098 - 286246121 + NaN 10067.008973 - 286251975 - 9910.073317 - 290600874 + 迷你站奶茶专门店 1064.838599 - 297407376 - 1993.624392 - 297407444 + 永和大王 + 981.250366 + 招商银行 1876.325343 @@ -948,21 +1186,19 @@ Executing the function 116.319773 2008-10-23 05:53:33 1 - 274942287 + NaN 4156.022778 - 276320137 + 永和大王 1829.027475 - 276320142 + Footmassage 富橋 1822.486938 - 286246121 + NaN 10064.722571 - 286251975 - 9907.496404 - 290600874 + 迷你站奶茶专门店 1071.002908 - 297407376 - 1993.387313 - 297407444 + 永和大王 + 987.550029 + 招商银行 1875.882508 @@ -971,21 +1207,19 @@ Executing the function 116.319732 2008-10-23 05:53:38 1 - 274942287 + NaN 4153.324576 - 276320137 + 永和大王 1830.866492 - 276320142 + Footmassage 富橋 1824.330899 - 286246121 + NaN 10061.545473 - 286251975 - 9904.207906 - 290600874 + 迷你站奶茶专门店 1074.850689 - 297407376 - 1995.406736 - 297407444 + 永和大王 + 991.312815 + 招商银行 1877.792905 @@ -994,21 +1228,19 @@ Executing the function 116.319728 2008-10-23 05:53:43 1 - 274942287 + NaN 4154.833968 - 276320137 + 永和大王 1827.989263 - 276320142 + Footmassage 富橋 1821.460600 - 286246121 + NaN 10062.044871 - 286251975 - 9904.433434 - 290600874 + 迷你站奶茶专门店 1078.957681 - 297407376 - 1992.786980 - 297407444 + 永和大王 + 995.702764 + 招商银行 1875.015873 @@ -1031,13 +1263,6 @@ to simulate an operation. indexOfPois = np.arange(0, POIs.shape[0], POIs.shape[0]/20, dtype=np.int64) POIs_events = POIs.iloc[indexOfPois].copy() - -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. code:: ipython3 randomIndexOfMoveDf = np.arange(0, move_df.shape[0], move_df.shape[0]/20, dtype=np.int64) @@ -1053,7 +1278,7 @@ to simulate an operation. .. code:: ipython3 - it.join_with_poi_datetime( + df_7 = it.join_with_events( df_7, POIs_events, label_date='datetime', time_window=900, label_event_id='osmid', label_event_type='amenity' @@ -1063,7 +1288,7 @@ to simulate an operation. .. parsed-literal:: - VBox(children=(HTML(value=''), IntProgress(value=0, max=5000))) + VBox(children=(HTML(value=''), IntProgress(value=0, max=20))) .. code:: ipython3 @@ -1159,128 +1384,7 @@ to simulate an operation. -8. Optimized Integrating events (points of interest with timestamp) to the DataSet ----------------------------------------------------------------------------------- - -.. code:: ipython3 - - df_8 = move_df.copy() - POIs_events["event_id"] = POIs_events["osmid"] - POIs_events["event_type"] = POIs_events["amenity"] - it.join_with_poi_datetime_optimizer(df_8, POIs_events) - - -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - - -.. parsed-literal:: - - VBox(children=(HTML(value=''), IntProgress(value=0, max=20))) - - -.. parsed-literal:: - - <__array_function__ internals>:5: DeprecationWarning: Calling nonzero on 0d arrays is deprecated, as it behaves surprisingly. Use `atleast_1d(cond).nonzero()` if the old behavior was intended. If the context of this warning is of the form `arr[nonzero(cond)]`, just use `arr[cond]`. - - -.. code:: ipython3 - - df_8.head() - - - - -.. raw:: html - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
latlondatetimeidevent_iddist_eventevent_type
039.984094116.3192362008-10-23 05:53:051269492188118.990536toilets
139.984198116.3193222008-10-23 05:53:061269492188120.895985toilets
239.984224116.3194022008-10-23 05:53:111269492188118.147609toilets
339.984211116.3193892008-10-23 05:53:161269492188117.863168toilets
439.984217116.3194222008-10-23 05:53:211269492188116.416939toilets
-
- - - -9. Integration with Point of Interest HOME +8. Integration with Point of Interest HOME ------------------------------------------ The Home type contains, in addition to latitude, longitude and id, the @@ -1290,23 +1394,16 @@ Creating a home point .. code:: ipython3 - df_9 = move_df.copy() - home_df = df_9.iloc[300:302].copy() + df_8 = move_df.copy() + home_df = df_8.iloc[300:302].copy() home_df['formatted_address'] = ['Rua1, n02', 'Rua2, n03'] home_df['city'] = ['ChinaTown', 'ChinaTown'] - -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - Using the function .. code:: ipython3 - it.join_with_home_by_id(df_9, home_df, label_id='id') + df_8 = it.join_with_home_by_id(df_8, home_df, label_id='id') @@ -1317,13 +1414,7 @@ Using the function .. code:: ipython3 - df_9.head() - - -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) + df_8.head() @@ -1414,43 +1505,31 @@ Using the function -10. Merge of HOME with DataSet already integrated with POIs ------------------------------------------------------------ +9. Merge of HOME with DataSet already integrated with POIs +---------------------------------------------------------- Integration .. code:: ipython3 - it.join_with_pois(df_9, POIs, label_id='osmid', label_poi_name='name') - - -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) + df_9 = it.join_with_pois(df_8, POIs, label_id='osmid', label_poi_name='name') .. parsed-literal:: - VBox(children=(HTML(value=''), IntProgress(value=0, max=5000))) + VBox(children=(HTML(value=''), IntProgress(value=0, max=746))) .. code:: ipython3 - it.merge_home_with_poi(df_9) + df_9 = it.merge_home_with_poi(df_9) .. code:: ipython3 df_9.head() -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. raw:: html @@ -1570,12 +1649,6 @@ Converts POIs of the types “bank_filials”, “bank_agencies”, banks_pois.head() -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. raw:: html @@ -1655,19 +1728,13 @@ Converts POIs of the types “bank_filials”, “bank_agencies”, .. code:: ipython3 #Join with POIs - it.join_with_pois(df_banks, banks_pois, label_id='id', label_poi_name='type_poi') - - -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) + df_banks = it.join_with_pois(df_banks, banks_pois, label_id='id', label_poi_name='type_poi') .. parsed-literal:: - VBox(children=(HTML(value=''), IntProgress(value=0, max=5000))) + VBox(children=(HTML(value=''), IntProgress(value=0, max=5))) .. code:: ipython3 @@ -1841,16 +1908,10 @@ Converts POIs of the types “bank_filials”, “bank_agencies”, bank: 1238 -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. code:: ipython3 #Finally, the Union - it.union_poi_bank(df_banks, label_poi="name_poi") + df_banks = it.union_poi_bank(df_banks, label_poi="name_poi") #Result df_banks.head() @@ -1950,12 +2011,6 @@ Converts POIs of the types “bank_filials”, “bank_agencies”, df_banks.loc[df_banks['name_poi'] == 'banks'].shape[0] -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. parsed-literal:: @@ -2064,19 +2119,13 @@ Converts “transit_station” and “bus_points” POIs to a single type: .. code:: ipython3 #Integration - it.join_with_pois(df_bus, bus_pois, label_id='id', label_poi_name='name_poi') - - -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) + df_bus = it.join_with_pois(df_bus, bus_pois, label_id='id', label_poi_name='name_poi') .. parsed-literal:: - VBox(children=(HTML(value=''), IntProgress(value=0, max=5000))) + VBox(children=(HTML(value=''), IntProgress(value=0, max=5))) .. code:: ipython3 @@ -2188,16 +2237,10 @@ Converts “transit_station” and “bus_points” POIs to a single type: Number of points close to pontos_de_onibus's: 2154 -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. code:: ipython3 #The union function - it.union_poi_bus_station(df_bus, label_poi="name_poi") + df_bus = it.union_poi_bus_station(df_bus, label_poi="name_poi") df_bus.head() @@ -2297,12 +2340,6 @@ Converts “transit_station” and “bus_points” POIs to a single type: df_bus.loc[df_bus['name_poi'] == 'bus_station'].shape[0] -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. parsed-literal:: @@ -2400,19 +2437,13 @@ Converts “bar” and “restaurant” POIs to a single type: “bar-restaurant .. code:: ipython3 #Integration - it.join_with_pois(df_bar, br_POIs, label_id='id', label_poi_name='name_poi') - - -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) + df_bar = it.join_with_pois(df_bar, br_POIs, label_id='id', label_poi_name='name_poi') .. parsed-literal:: - VBox(children=(HTML(value=''), IntProgress(value=0, max=5000))) + VBox(children=(HTML(value=''), IntProgress(value=0, max=4))) .. code:: ipython3 @@ -2525,16 +2556,10 @@ Converts “bar” and “restaurant” POIs to a single type: “bar-restaurant Closest type points 'restaurant': 2461 -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. code:: ipython3 #Union of the two types of POIs into a single - it.union_poi_bar_restaurant(df_bar, label_poi="name_poi") + df_bar = it.union_poi_bar_restaurant(df_bar, label_poi="name_poi") #Result df_bar.head() @@ -2634,12 +2659,6 @@ Converts “bar” and “restaurant” POIs to a single type: “bar-restaurant df_bar.loc[df_bar['name_poi'] == 'bar-restaurant'].shape[0] -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. parsed-literal:: @@ -2737,22 +2756,16 @@ Converts “pracas_e_parques” and “park” POIs to a single type: “parks .. code:: ipython3 #Integration - it.join_with_pois(df_parks, p_POIs, label_id='id', label_poi_name='name_poi') + df_parks = it.join_with_pois(df_parks, p_POIs, label_id='id', label_poi_name='name_poi') #Result df_parks.head() -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. parsed-literal:: - VBox(children=(HTML(value=''), IntProgress(value=0, max=5000))) + VBox(children=(HTML(value=''), IntProgress(value=0, max=4))) @@ -2859,16 +2872,10 @@ Converts “pracas_e_parques” and “park” POIs to a single type: “parks Number of points closest to park: 2284 -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. code:: ipython3 #Union function - it.union_poi_parks(df_parks, label_poi="name_poi") + df_parks = it.union_poi_parks(df_parks, label_poi="name_poi") df_parks.head() @@ -2967,12 +2974,6 @@ Converts “pracas_e_parques” and “park” POIs to a single type: “parks df_parks.loc[df_parks['name_poi'] == 'parks'].shape[0] -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. parsed-literal:: @@ -3068,21 +3069,15 @@ Union of police points .. code:: ipython3 #Integration - it.join_with_pois(df_police, pol_POIs, label_id='id', label_poi_name='name_poi') + df_police = it.join_with_pois(df_police, pol_POIs, label_id='id', label_poi_name='name_poi') df_police.head() -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. parsed-literal:: - VBox(children=(HTML(value=''), IntProgress(value=0, max=5000))) + VBox(children=(HTML(value=''), IntProgress(value=0, max=4))) @@ -3186,16 +3181,10 @@ Union of police points Number of points closest to distritos_policiais: 3420 -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. code:: ipython3 #Union funcion - it.union_poi_police(df_police, label_poi="name_poi") + df_police = it.union_poi_police(df_police, label_poi="name_poi") .. code:: ipython3 @@ -3297,12 +3286,6 @@ Union of police points df_police.loc[df_police['name_poi'] == 'police'].shape[0] -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. parsed-literal:: @@ -3406,12 +3389,6 @@ Union of police points area_c -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - .. raw:: html @@ -3483,13 +3460,7 @@ Union of police points .. code:: ipython3 #Integration - it.join_collective_areas(gdf, area_c) - - -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) + gdf = it.join_collective_areas(gdf, area_c) @@ -3582,48 +3553,3 @@ Union of police points - - - -Viewing points on the map -~~~~~~~~~~~~~~~~~~~~~~~~~ - -Collective Area points - -.. code:: ipython3 - - folium.plot_markers(area_c) - - -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - - - -.. raw:: html - -
Make this Notebook Trusted to load map: File -> Trust Notebook
- - - -Corresponding points - -.. code:: ipython3 - - folium.plot_markers(gdf.loc[gdf['violating'] == True]) - - -.. parsed-literal:: - - /home/flycher/anaconda3/envs/pmv/lib/python3.8/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above. - and should_run_async(code) - - - - -.. raw:: html - -
Make this Notebook Trusted to load map: File -> Trust Notebook
diff --git a/docs/examples/07_Exploring_Query.rst b/docs/examples/07_Exploring_Query.rst index 902007b3..c6dfeacf 100644 --- a/docs/examples/07_Exploring_Query.rst +++ b/docs/examples/07_Exploring_Query.rst @@ -15,7 +15,7 @@ ------------ DataSet - `Hurricanes and -Typhoons `__:he NHC +Typhoons `__: The NHC publishes the tropical cyclone historical database in a format known as HURDAT, short for HURricane DATabase @@ -729,14 +729,14 @@ Visualization .. code:: ipython3 - folium.plot_trajectories_with_folium(hurricanes_2012, zoom_start=2) + folium.plot_trajectories(hurricanes_2012, zoom_start=2) .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -758,11 +758,21 @@ Visualization .. code:: ipython3 #Selecting a hurricane for demonstration - gonzalo = hurricanes_2012.loc[hurricanes_2012['id'] == ' GONZALO'] + gonzalo = hurricanes_2012.loc[hurricanes_2012['id'].str.strip() == 'GONZALO'] + gonzalo.shape + + + + +.. parsed-literal:: + + (39, 23) + + .. code:: ipython3 - folium.plot_trajectories_with_folium( + folium.plot_trajectories( gonzalo, lat_origin=gonzalo['lat'].median(), lon_origin=gonzalo['lon'].median(), zoom_start=2 ) @@ -771,7 +781,7 @@ Visualization .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -794,14 +804,14 @@ Using distance MEDP (Mean Euclidean Distance Predictive) .. code:: ipython3 - folium.plot_trajectories_with_folium(prox_Gonzalo, zoom_start=3) + folium.plot_trajectories(prox_Gonzalo, zoom_start=3) .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -821,14 +831,14 @@ Using Distance MEDT (Mean Euclidean Distance Trajectory) .. code:: ipython3 - folium.plot_trajectories_with_folium(prox_Gonzalo, zoom_start=3) + folium.plot_trajectories(prox_Gonzalo, zoom_start=3) .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -851,14 +861,14 @@ Using distance MEDP (Mean Euclidean Distance Predictive) .. code:: ipython3 - folium.plot_trajectories_with_folium(prox_Gonzalo, zoom_start=3) + folium.plot_trajectories(prox_Gonzalo, zoom_start=3) .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
@@ -878,11 +888,11 @@ Using Distance MEDT (Mean Euclidean Distance Trajectory) .. code:: ipython3 - folium.plot_trajectories_with_folium(prox_Gonzalo, zoom_start=3) + folium.plot_trajectories(prox_Gonzalo, zoom_start=3) .. raw:: html -
Make this Notebook Trusted to load map: File -> Trust Notebook
+
Make this Notebook Trusted to load map: File -> Trust Notebook
diff --git a/notebooks/01_Exploring_MoveDataFrame.ipynb b/notebooks/01_Exploring_MoveDataFrame.ipynb index 9340cd34..48b5bb55 100644 --- a/notebooks/01_Exploring_MoveDataFrame.ipynb +++ b/notebooks/01_Exploring_MoveDataFrame.ipynb @@ -2,7 +2,6 @@ "cells": [ { "cell_type": "markdown", - "metadata": {}, "source": [ "# 01 - Exploring MoveDataFrame\n", "\n", @@ -34,32 +33,53 @@ "## Creating a MoveDataFrame\n", "\n", "A MoveDataFrame can be created by passing a Pandas DataFrame, a list, dict or even reading a file. Look:" - ] + ], + "metadata": {} }, { "cell_type": "code", "execution_count": 1, - "metadata": {}, - "outputs": [], "source": [ "import pymove as pm\n", "from pymove import MoveDataFrame" - ] + ], + "outputs": [], + "metadata": {} }, { "cell_type": "markdown", - "metadata": {}, "source": [ "### From a list" - ] + ], + "metadata": {} }, { "cell_type": "code", "execution_count": 2, - "metadata": {}, + "source": [ + "list_data = [\n", + " [39.984094, 116.319236, '2008-10-23 05:53:05', 1],\n", + " [39.984198, 116.319322, '2008-10-23 05:53:06', 1],\n", + " [39.984224, 116.319402, '2008-10-23 05:53:11', 1],\n", + " [39.984224, 116.319402, '2008-10-23 05:53:11', 1],\n", + " [39.984224, 116.319402, '2008-10-23 05:53:11', 1],\n", + " [39.984224, 116.319402, '2008-10-23 05:53:11', 1]\n", + "]\n", + "move_df = MoveDataFrame(data=list_data, latitude=\"lat\", longitude=\"lon\", datetime=\"datetime\", traj_id=\"id\")\n", + "move_df.head()" + ], "outputs": [ { + "output_type": "execute_result", "data": { + "text/plain": [ + " lat lon datetime id\n", + "0 39.984094 116.319236 2008-10-23 05:53:05 1\n", + "1 39.984198 116.319322 2008-10-23 05:53:06 1\n", + "2 39.984224 116.319402 2008-10-23 05:53:11 1\n", + "3 39.984224 116.319402 2008-10-23 05:53:11 1\n", + "4 39.984224 116.319402 2008-10-23 05:53:11 1" + ], "text/html": [ "
\n", "