From a341ccbe2d730ccd4021267841db21e355060370 Mon Sep 17 00:00:00 2001 From: Nicholas Reinicke Date: Thu, 7 Nov 2024 17:24:54 -0700 Subject: [PATCH 1/4] add methods to convert results to geodataframe --- .github/workflows/lint_test.yml | 40 +++++++++++++-------------- .pre-commit-config.yaml | 6 ---- mappymatch/matchers/match_result.py | 43 +++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 26 deletions(-) diff --git a/.github/workflows/lint_test.yml b/.github/workflows/lint_test.yml index cd10eed..8ccf217 100644 --- a/.github/workflows/lint_test.yml +++ b/.github/workflows/lint_test.yml @@ -1,8 +1,8 @@ -name: Lint & Test +name: Lint & Test on: push: - branches: [ main ] + branches: [main] pull_request: jobs: @@ -11,22 +11,22 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install .[tests] - - name: Run black - run: black . --check - - name: Run ruff - run: ruff check . - - name: Run mypy - run: mypy . - - name: Run Tests - run: pytest tests \ No newline at end of file + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install .[tests] + - name: Run black + run: black . --check + - name: Run ruff + run: ruff check . + - name: Run mypy + run: mypy . + - name: Run Tests + run: pytest tests diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3300d46..1019a83 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,12 +4,6 @@ repos: hooks: - id: black args: [--config, pyproject.toml] -- repo: https://github.com/econchick/interrogate - rev: 1.5.0 - hooks: - - id: interrogate - args: [-c, pyproject.toml] - pass_filenames: false - repo: https://github.com/charliermarsh/ruff-pre-commit rev: v0.0.188 hooks: diff --git a/mappymatch/matchers/match_result.py b/mappymatch/matchers/match_result.py index 5eb89bd..dfb4954 100644 --- a/mappymatch/matchers/match_result.py +++ b/mappymatch/matchers/match_result.py @@ -1,6 +1,7 @@ from dataclasses import dataclass from typing import List, Optional +import geopandas as gpd import numpy as np import pandas as pd @@ -13,6 +14,30 @@ class MatchResult: matches: List[Match] path: Optional[List[Road]] = None + @property + def crs(self): + first_crs = self.matches[0].coordinate.crs + if not all([first_crs.equals(m.coordinate.crs) for m in self.matches]): + raise ValueError( + "Found that there were different CRS within the matches. " + "These must all be equal to use this function" + ) + return first_crs + + def matches_to_geodataframe(self) -> gpd.GeoDataFrame: + """ + Returns a geodataframe with all the coordinates and their resulting match (or NA if no match) in each row + """ + df = self.matches_to_dataframe() + gdf = gpd.GeoDataFrame(df, geometry="geom") + + if len(self.matches) == 0: + return gdf + + gdf = gdf.set_crs(self.crs) + + return gdf + def matches_to_dataframe(self) -> pd.DataFrame: """ Returns a dataframe with all the coordinates and their resulting match (or NA if no match) in each row. @@ -40,3 +65,21 @@ def path_to_dataframe(self) -> pd.DataFrame: df = df.fillna(np.nan) return df + + def path_to_geodataframe(self) -> gpd.GeoDataFrame: + """ + Returns a geodataframe with the resulting estimated trace path through the road network. + The geodataframe is empty if there was no path. + + Returns: + A geopandas geodataframe + """ + if self.path is None: + return gpd.GeoDataFrame() + + df = self.path_to_dataframe() + gdf = gpd.GeoDataFrame(df, geometry="geom") + + gdf = gdf.set_crs(self.crs) + + return gdf From 3096fc28ed67ebddac51fe9ea858dc682982c54c Mon Sep 17 00:00:00 2001 From: Nicholas Reinicke Date: Thu, 7 Nov 2024 17:29:42 -0700 Subject: [PATCH 2/4] drop python 3.8 --- .github/workflows/lint_test.yml | 2 +- .github/workflows/release.yaml | 2 +- pyproject.toml | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint_test.yml b/.github/workflows/lint_test.yml index 8ccf217..fcb2ccd 100644 --- a/.github/workflows/lint_test.yml +++ b/.github/workflows/lint_test.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4adddd6..6aa0e4d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -17,7 +17,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.8' + python-version: '3.9' - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/pyproject.toml b/pyproject.toml index 906ca29..12d19a4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ classifiers = [ "License :: Other/Proprietary License", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.12", "Topic :: Scientific/Engineering", ] keywords = ["GPS", "map", "match"] @@ -34,7 +34,7 @@ dependencies = [ "requests", "polyline", ] -requires-python = ">=3.8" +requires-python = ">=3.9" [project.optional-dependencies] # Used to run CI. @@ -77,7 +77,7 @@ exclude = ''' ''' include = '\.pyi?$' line-length = 79 -target-version = ['py38'] +target-version = ['py39'] [tool.ruff] line-length = 79 From f33b3de1882dbdcf8a31ba7134026ad83d6ccd9c Mon Sep 17 00:00:00 2001 From: Nicholas Reinicke Date: Fri, 8 Nov 2024 09:30:55 -0700 Subject: [PATCH 3/4] update read the docs to python 3.12 and ubuntu 22 --- .readthedocs.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 472dc95..989d3c5 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,9 +1,9 @@ version: 2 build: - os: ubuntu-20.04 + os: ubuntu-22.04 tools: - python: "3.8" + python: "3.12" python: install: From 618d0094df804cb3fb5344e03a1dedd0af0ff658 Mon Sep 17 00:00:00 2001 From: Nicholas Reinicke Date: Fri, 8 Nov 2024 09:48:03 -0700 Subject: [PATCH 4/4] update sphinx --- docs/source/conf.py | 3 +-- docs/source/general/install.rst | 16 +++++++++------- docs/source/reference/maps.rst | 5 ----- environment.yml | 2 +- pyproject.toml | 2 +- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 5490d57..1f8edd6 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -21,7 +21,7 @@ author = "National Renewable Energy Laboratory" # Initial releases at 0.x.x # First stable release at 1.x.x -full_version = "0.4.1" +full_version = "0.4.5" version = full_version # Full version for display in various places. release = full_version @@ -56,7 +56,6 @@ # html_theme = "sphinx_rtd_theme" html_theme_options = { - "display_version": True, "style_external_links": True, "style_nav_header_background": "#9B59B6", } diff --git a/docs/source/general/install.rst b/docs/source/general/install.rst index 7f5bcbf..056606a 100644 --- a/docs/source/general/install.rst +++ b/docs/source/general/install.rst @@ -1,8 +1,16 @@ Install ================== -From Source (recommended) +From PyPI (recommended) +--------- + +.. code-block:: + + pip install mappymatch + +From Source ------------------------- + Clone the repo:: git clone https://github.com/NREL/mappymatch.git && cd mappymatch @@ -15,12 +23,6 @@ To activate the mappymatch environment:: conda activate mappymatch -From PyPI ---------- - -.. code-block:: - - pip install mappymatch .. warning:: diff --git a/docs/source/reference/maps.rst b/docs/source/reference/maps.rst index eb35f03..e74aa22 100644 --- a/docs/source/reference/maps.rst +++ b/docs/source/reference/maps.rst @@ -16,11 +16,6 @@ NxMap .. autoclass:: mappymatch.maps.nx.nx_map.NxMap :members: -Utility Functions ----------------------- -.. autofunction:: mappymatch.maps.nx.nx_map.parse_osmnx_graph -.. autofunction:: mappymatch.maps.nx.nx_map.compress - Map interface ------------------- diff --git a/environment.yml b/environment.yml index d517690..be2495e 100644 --- a/environment.yml +++ b/environment.yml @@ -4,7 +4,7 @@ channels: - conda-forge - defaults dependencies: - - python=3.10 + - python=3.12 - folium - geopandas - matplotlib diff --git a/pyproject.toml b/pyproject.toml index 12d19a4..4f1972f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ requires-python = ">=3.9" # Used to run CI. tests = ["black", "ruff", "mypy>=0.981", "types-requests", "pytest"] # Used to build the docs. -docs = ["sphinx==4.5.0", "sphinx_rtd_theme==1.0.0", "sphinxemoji==0.2.0"] +docs = ["sphinx>=8.1", "sphinx_rtd_theme>=3.0", "sphinxemoji>=0.3.1"] # Tests + docs + other. dev = [ "mappymatch[tests]",