diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 90feb88..5e006fc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ files: "core\/|notebooks\/" repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.5.6" + rev: "v0.6.9" hooks: - id: ruff - id: ruff-format diff --git a/notebooks/_addartifacts_8989.ipynb b/notebooks/_addartifacts_8989.ipynb index 9857248..a86cdea 100644 --- a/notebooks/_addartifacts_8989.ipynb +++ b/notebooks/_addartifacts_8989.ipynb @@ -37,10 +37,10 @@ "# find predicted artifacts\n", "option = \"circular_compactness_index\"\n", "threshold = results[city][option][\"threshold\"]\n", - "polygons[\"is_artifact\"] = False # set default to False\n", - "polygons.loc[\n", - " polygons[\"circular_compactness_index\"] <= threshold, \"is_artifact\"\n", - "] = True # set to True for polygons where index is below the threshold" + "polygons[\"is_artifact\"] = False # set default to False\n", + "polygons.loc[polygons[\"circular_compactness_index\"] <= threshold, \"is_artifact\"] = (\n", + " True # set to True for polygons where index is below the threshold\n", + ")" ] }, { diff --git a/notebooks/_clip_networks.ipynb b/notebooks/_clip_networks.ipynb index 291f59d..e95e365 100644 --- a/notebooks/_clip_networks.ipynb +++ b/notebooks/_clip_networks.ipynb @@ -331,9 +331,7 @@ "metadata": {}, "outputs": [], "source": [ - "slc = gpd.read_parquet(\"../data/809/original/809.parquet\").query(\n", - " \"highway != 'service'\"\n", - ")" + "slc = gpd.read_parquet(\"../data/809/original/809.parquet\").query(\"highway != 'service'\")" ] }, { diff --git a/notebooks/check_corrected_input_data.ipynb b/notebooks/check_corrected_input_data.ipynb index 4ef0987..815879d 100644 --- a/notebooks/check_corrected_input_data.ipynb +++ b/notebooks/check_corrected_input_data.ipynb @@ -64,24 +64,16 @@ "metadata": {}, "outputs": [], "source": [ - "for fua, city in utils.fua_city.items():\n", - " print(\n", - " \"================================\\n\"\n", - " f\"* {city} *\"\n", - " \"\\n--------------\"\n", - " )\n", + "for _, city in utils.fua_city.items():\n", + " print(\"================================\\n\" f\"* {city} *\" \"\\n--------------\")\n", "\n", " o = utils.read_original(city)\n", " m = utils.read_manual(city, o.crs)\n", "\n", - " print(\n", - " \"Records\\n\"\n", - " f\" Orig: {o.shape[0]:,}\\n\"\n", - " f\" Manu: {m.shape[0]:,}\\n\"\n", - " )\n", + " print(\"Records\\n\" f\" Orig: {o.shape[0]:,}\\n\" f\" Manu: {m.shape[0]:,}\\n\")\n", "\n", - " b = o.plot(figsize=(20,20), ec=\"k\", lw=.5, alpha=.5, zorder=1)\n", - " m.plot(ax=b, ec=\"b\", lw=.2, alpha=1, zorder=2)\n", + " b = o.plot(figsize=(20, 20), ec=\"k\", lw=0.5, alpha=0.5, zorder=1)\n", + " m.plot(ax=b, ec=\"b\", lw=0.2, alpha=1, zorder=2)\n", "\n", " # large plot\n", " matplotlib.pyplot.savefig(f\"{city}_orig_vs_manu.png\", dpi=400)" diff --git a/notebooks/cityseer_overview_gaboardi.ipynb b/notebooks/cityseer_overview_gaboardi.ipynb index e8b9ed9..3bbdaac 100644 --- a/notebooks/cityseer_overview_gaboardi.ipynb +++ b/notebooks/cityseer_overview_gaboardi.ipynb @@ -97,9 +97,10 @@ "\n", "import cityseer # noqa: F401\n", "import momepy\n", - "from core import utils\n", "from cityseer.tools import graphs, io\n", "\n", + "from core import utils\n", + "\n", "%watermark -w\n", "%watermark -iv" ] @@ -2273,8 +2274,8 @@ "outputs": [], "source": [ "mm_nodes_raw, mm_edges_raw = momepy.nx_to_gdf(G_nx_mm)\n", - "#(mm_nodes_raw.to_crs(4326).to_file(fpath / fbase.format(\"mm\", \"nodes\", \"raw\")))\n", - "#(mm_edges_raw.to_crs(4326).to_file(fpath / fbase.format(\"mm\", \"edges\", \"raw\")))" + "# (mm_nodes_raw.to_crs(4326).to_file(fpath / fbase.format(\"mm\", \"nodes\", \"raw\")))\n", + "# (mm_edges_raw.to_crs(4326).to_file(fpath / fbase.format(\"mm\", \"edges\", \"raw\")))" ] }, { @@ -2321,8 +2322,8 @@ ")\n", "G_cs_simp = momepy.gdf_to_nx(cs_road_simp, integer_labels=True)\n", "cs_nodes_simp, cs_edges_simp = momepy.nx_to_gdf(G_cs_simp)\n", - "#(cs_nodes_simp.to_crs(4326).to_file(fpath / fbase.format(\"cs\", \"nodes\", \"simplified\")))\n", - "#(cs_edges_simp.to_crs(4326).to_file(fpath / fbase.format(\"cs\", \"edges\", \"simplified\")))" + "# (cs_nodes_simp.to_crs(4326).to_file(fpath / fbase.format(\"cs\", \"nodes\", \"simplified\")))\n", + "# (cs_edges_simp.to_crs(4326).to_file(fpath / fbase.format(\"cs\", \"edges\", \"simplified\")))" ] }, { @@ -2341,8 +2342,8 @@ "outputs": [], "source": [ "cs_nodes_simp, cs_edges_simp = momepy.nx_to_gdf(G_cs_simp)\n", - "#cs_nodes_simp.to_file(fpath / fbase.format(\"cs\", \"nodes\", \"simplified\"))\n", - "#cs_edges_simp.to_file(fpath / fbase.format(\"cs\", \"edges\", \"simplified\"))" + "# cs_nodes_simp.to_file(fpath / fbase.format(\"cs\", \"nodes\", \"simplified\"))\n", + "# cs_edges_simp.to_file(fpath / fbase.format(\"cs\", \"edges\", \"simplified\"))" ] }, { diff --git a/notebooks/cityseer_parallel_gaboardi.ipynb b/notebooks/cityseer_parallel_gaboardi.ipynb index 80fac3a..3801042 100644 --- a/notebooks/cityseer_parallel_gaboardi.ipynb +++ b/notebooks/cityseer_parallel_gaboardi.ipynb @@ -97,9 +97,10 @@ "import momepy\n", "import networkx\n", "import pyproj\n", - "from core import utils, viz\n", "from cityseer.tools import graphs, io\n", "\n", + "from core import utils, viz\n", + "\n", "%watermark -w\n", "%watermark -iv" ] diff --git a/notebooks/momepy.ipynb b/notebooks/momepy.ipynb index cb93209..bd27016 100644 --- a/notebooks/momepy.ipynb +++ b/notebooks/momepy.ipynb @@ -75,6 +75,7 @@ "source": [ "import momepy as mm # requires main\n", "import networkx as nx\n", + "\n", "from core import utils\n", "\n", "%watermark -w\n", diff --git a/notebooks/osmnx.ipynb b/notebooks/osmnx.ipynb index d54f987..7c80d86 100644 --- a/notebooks/osmnx.ipynb +++ b/notebooks/osmnx.ipynb @@ -82,6 +82,7 @@ "source": [ "import momepy\n", "import osmnx as ox\n", + "\n", "from core import utils, viz\n", "\n", "%watermark -w\n", diff --git a/notebooks/parenx.ipynb b/notebooks/parenx.ipynb index 80b8c55..b59d282 100644 --- a/notebooks/parenx.ipynb +++ b/notebooks/parenx.ipynb @@ -71,24 +71,18 @@ "outputs": [], "source": [ "for subfolder in glob.glob(\"../temp-parenx/*\"):\n", - "\n", - " fua = int(re.findall(r'\\d+', subfolder)[0])\n", + " fua = int(re.findall(r\"\\d+\", subfolder)[0])\n", "\n", " os.makedirs(f\"../data/{fua}/parenx/\", exist_ok=True)\n", "\n", " ske = gpd.read_file(\n", - " filename = subfolder + \"/skeletonize.gpkg\",\n", - " driver = \"fiona\",\n", - " layer = \"line\"\n", + " filename=subfolder + \"/skeletonize.gpkg\", driver=\"fiona\", layer=\"line\"\n", " )\n", "\n", - "\n", " ske.to_parquet(f\"../data/{fua}/parenx/skeletonize.parquet\")\n", "\n", " vor = gpd.read_file(\n", - " filename = subfolder + \"/voronoi.gpkg\",\n", - " driver = \"fiona\",\n", - " layer = \"line\"\n", + " filename=subfolder + \"/voronoi.gpkg\", driver=\"fiona\", layer=\"line\"\n", " )\n", "\n", " vor.to_parquet(f\"../data/{fua}/parenx/voronoi.parquet\")" diff --git a/notebooks/simplification_api.ipynb b/notebooks/simplification_api.ipynb index 88addcb..72b7fbe 100644 --- a/notebooks/simplification_api.ipynb +++ b/notebooks/simplification_api.ipynb @@ -21,7 +21,7 @@ "import folium\n", "import sgeop\n", "\n", - "from core import utils\n" + "from core import utils" ] }, { @@ -134,8 +134,10 @@ "metadata": {}, "outputs": [], "source": [ - "m = roads.explore(max_zoom=52, tiles=\"cartodb positron\", color=\"black\", prefer_canvas=True)\n", - "m = new_roads.explore(\"_status\", m=m, highlight_kwds=dict(color='red'))\n", + "m = roads.explore(\n", + " max_zoom=52, tiles=\"cartodb positron\", color=\"black\", prefer_canvas=True\n", + ")\n", + "m = new_roads.explore(\"_status\", m=m, highlight_kwds=dict(color=\"red\"))\n", "folium.LayerControl().add_to(m)\n", "m" ] diff --git a/notebooks/simplification_api_bug.ipynb b/notebooks/simplification_api_bug.ipynb index 28e5535..8b05a05 100644 --- a/notebooks/simplification_api_bug.ipynb +++ b/notebooks/simplification_api_bug.ipynb @@ -19,10 +19,9 @@ "import warnings\n", "\n", "import folium\n", + "import geopandas as gpd\n", "\n", - "from core import algorithms, utils\n", - "\n", - "import geopandas as gpd\n" + "from core import algorithms, utils" ] }, { diff --git a/notebooks/simplification_pipeline.ipynb b/notebooks/simplification_pipeline.ipynb index ec1bb4e..dc51264 100644 --- a/notebooks/simplification_pipeline.ipynb +++ b/notebooks/simplification_pipeline.ipynb @@ -23,10 +23,10 @@ "import warnings\n", "\n", "import folium\n", - "from libpysal import graph\n", "import sgeop\n", + "from libpysal import graph\n", "\n", - "from core import utils\n" + "from core import utils" ] }, { diff --git a/notebooks/simplification_prg.ipynb b/notebooks/simplification_prg.ipynb index 25404de..4b594a5 100644 --- a/notebooks/simplification_prg.ipynb +++ b/notebooks/simplification_prg.ipynb @@ -73,7 +73,9 @@ "metadata": {}, "outputs": [], "source": [ - "buildings = geopandas.read_parquet(\"/Users/martin/Downloads/buildings_chars_69300.parquet\", columns=[\"geometry\"])" + "buildings = geopandas.read_parquet(\n", + " \"/Users/martin/Downloads/buildings_chars_69300.parquet\", columns=[\"geometry\"]\n", + ")" ] }, { @@ -139,8 +141,14 @@ "metadata": {}, "outputs": [], "source": [ - "m = roads.explore(max_zoom=52, tiles=\"cartodb positron\", color=\"black\", prefer_canvas=True, highlight_kwds=dict(color='red'))\n", - "m = new_roads.explore(\"_status\", m=m, highlight_kwds=dict(color='red'))\n", + "m = roads.explore(\n", + " max_zoom=52,\n", + " tiles=\"cartodb positron\",\n", + " color=\"black\",\n", + " prefer_canvas=True,\n", + " highlight_kwds=dict(color=\"red\"),\n", + ")\n", + "m = new_roads.explore(\"_status\", m=m, highlight_kwds=dict(color=\"red\"))\n", "folium.LayerControl().add_to(m)\n", "m" ] diff --git a/notebooks/typology-doubles.ipynb b/notebooks/typology-doubles.ipynb index 23f0d5a..b5d067a 100644 --- a/notebooks/typology-doubles.ipynb +++ b/notebooks/typology-doubles.ipynb @@ -32,6 +32,8 @@ "source": [ "import logging\n", "\n", + "import folium\n", + "import folium.plugins as plugins\n", "import geopandas as gpd\n", "import matplotlib.pyplot as plt\n", "import momepy\n", @@ -40,16 +42,13 @@ "import shapely\n", "from libpysal import graph\n", "from scipy import sparse, spatial\n", - "import folium\n", - "import folium.plugins as plugins\n", - "import shapely\n", "\n", "from core import algorithms, utils\n", "from core.geometry import (\n", - " voronoi_skeleton,\n", + " is_within,\n", " remove_false_nodes,\n", " snap_to_targets,\n", - " is_within,\n", + " voronoi_skeleton,\n", ")" ] }, diff --git a/notebooks/typology-multiples.ipynb b/notebooks/typology-multiples.ipynb index 9157b1a..5ade609 100644 --- a/notebooks/typology-multiples.ipynb +++ b/notebooks/typology-multiples.ipynb @@ -23,6 +23,8 @@ "metadata": {}, "outputs": [], "source": [ + "import folium\n", + "import folium.plugins as plugins\n", "import geopandas as gpd\n", "import matplotlib.pyplot as plt\n", "import momepy\n", @@ -31,9 +33,6 @@ "import shapely\n", "from libpysal import graph\n", "from scipy import sparse\n", - "import folium\n", - "import folium.plugins as plugins\n", - "import shapely\n", "\n", "from core import algorithms, utils\n", "from core.geometry import voronoi_skeleton" @@ -169,7 +168,7 @@ "\n", " # setting is_artifact to True\n", " polygons.loc[\n", - " (polygons.touching == True)\n", + " (polygons.touching == True) # noqa: E712\n", " & (polygons.face_artifact_index < fas.threshold * prop),\n", " \"is_artifact\",\n", " ] = True\n", @@ -608,21 +607,25 @@ "outputs": [], "source": [ "def nx_gx_cluster(edges, cluster_geom, nodes, to_drop, to_add, eps=0.01):\n", - " '''treat an n-artifact cluster: merge all artifact polygons; drop\n", + " \"\"\"treat an n-artifact cluster: merge all artifact polygons; drop\n", " all lines fully within the merged polygon; skeletonize and keep only\n", - " skeletonized edges and connecting nodes'''\n", + " skeletonized edges and connecting nodes\"\"\"\n", "\n", " # get edges on boundary\n", - " edges_on_boundary = edges.intersection(cluster_geom.boundary.buffer(eps)).explode(ignore_index=True)\n", + " edges_on_boundary = edges.intersection(cluster_geom.boundary.buffer(eps)).explode(\n", + " ignore_index=True\n", + " )\n", " edges_on_boundary = edges_on_boundary[\n", - " (~edges_on_boundary.is_empty) &\n", - " (edges_on_boundary.geom_type.str.contains(\"Line\")) &\n", - " (edges_on_boundary.length > 10*eps)\n", - " ] # keeping only (multi)linestrings of length>>eps\n", + " (~edges_on_boundary.is_empty)\n", + " & (edges_on_boundary.geom_type.str.contains(\"Line\"))\n", + " & (edges_on_boundary.length > 10 * eps)\n", + " ] # keeping only (multi)linestrings of length>>eps\n", " edges_on_boundary = edges_on_boundary.to_frame(\"geometry\")\n", "\n", " # find road segments DELINEATING cluster polygon (to be partially merged, and kept)\n", - " edges_within = edges.iloc[edges.sindex.query(cluster_geom, predicate=\"contains\")].copy()\n", + " # edges_within = edges.iloc[\n", + " # edges.sindex.query(cluster_geom, predicate=\"contains\")\n", + " # ].copy()\n", "\n", " # find nodes ON the cluster polygon boundary (to be partially kept)\n", " nodes_on_boundary = nodes.iloc[\n", @@ -631,19 +634,15 @@ "\n", " # find edges that cross but do not lie within\n", " edges_crossing = edges.iloc[\n", - " edges.sindex.query(\n", - " cluster_geom.buffer(eps),\n", - " predicate = \"crosses\"\n", - " )\n", + " edges.sindex.query(cluster_geom.buffer(eps), predicate=\"crosses\")\n", " ]\n", "\n", " # the nodes to keep are those that intersect with these crossing edges\n", " nodes_to_keep = nodes_on_boundary.iloc[\n", " nodes_on_boundary.sindex.query(\n", - " edges_crossing.union_all(),\n", - " predicate = \"intersects\"\n", - " )].copy()\n", - "\n", + " edges_crossing.union_all(), predicate=\"intersects\"\n", + " )\n", + " ].copy()\n", "\n", " # merging lines between nodes to keep:\n", " buffered_nodes_to_keep = nodes_to_keep.buffer(eps).union_all()\n", @@ -651,7 +650,9 @@ " # make queen contiguity graph on MINUSBUFFERED outline road segments,\n", " # and copy component labels into edges_on_boundary gdf\n", " edges_on_boundary = edges_on_boundary.explode(ignore_index=True)\n", - " queen = graph.Graph.build_fuzzy_contiguity(edges_on_boundary.difference(buffered_nodes_to_keep))\n", + " queen = graph.Graph.build_fuzzy_contiguity(\n", + " edges_on_boundary.difference(buffered_nodes_to_keep)\n", + " )\n", " edges_on_boundary[\"comp\"] = queen.component_labels\n", "\n", " # skeletonize\n", @@ -661,7 +662,9 @@ " snap_to=False,\n", " )\n", "\n", - " lines_to_drop = edges.iloc[edges.sindex.query(cluster_geom.buffer(eps), predicate=\"contains\")].index.to_list()\n", + " lines_to_drop = edges.iloc[\n", + " edges.sindex.query(cluster_geom.buffer(eps), predicate=\"contains\")\n", + " ].index.to_list()\n", " lines_to_add = list(skel)\n", "\n", " to_add.extend(lines_to_add)\n", @@ -670,35 +673,27 @@ " ### RECONNECTING NON-PLANAR INTRUDING EDGES TO SKELETON\n", "\n", " # considering only edges that are kept\n", - " edges_kept = edges.copy().drop(lines_to_drop, axis = 0)\n", + " edges_kept = edges.copy().drop(lines_to_drop, axis=0)\n", "\n", " to_reconnect = []\n", "\n", " skel_merged = shapely.line_merge(skel)\n", " skel_merged = gpd.GeoSeries(skel_merged, crs=edges.crs)\n", "\n", - " skel_nodes = list(\n", - " shapely.get_point(skel_merged, 0))\n", - " skel_nodes.extend(list(\n", - " shapely.get_point(skel_merged, -1))\n", - " )\n", + " skel_nodes = list(shapely.get_point(skel_merged, 0))\n", + " skel_nodes.extend(list(shapely.get_point(skel_merged, -1)))\n", " skel_nodes = gpd.GeoSeries(skel_nodes, crs=edges.crs).union_all()\n", "\n", " # loop through endpoints of kept edges...\n", " for i in [0, -1]:\n", - "\n", " # do the same for \"end\" points\n", " endpoints = gpd.GeoSeries(\n", - " shapely.get_point(edges_kept.geometry, i),\n", - " crs = edges.crs\n", + " shapely.get_point(edges_kept.geometry, i), crs=edges.crs\n", " )\n", "\n", " # which are contained by artifact...\n", " endpoints = endpoints.iloc[\n", - " endpoints.sindex.query(\n", - " cluster_geom,\n", - " predicate=\"contains\"\n", - " )\n", + " endpoints.sindex.query(cluster_geom, predicate=\"contains\")\n", " ]\n", "\n", " # ...but NOT on skeleton\n", @@ -708,10 +703,7 @@ "\n", " # to_reconnect now contains a list of points which need to be connected to the nearest skel node:\n", " # from those nodes, we need to add shapely shortest lines between those edges_kept.endpoints and\n", - " non_planar_connections = shapely.shortest_line(\n", - " skel_nodes,\n", - " to_reconnect\n", - " )\n", + " non_planar_connections = shapely.shortest_line(skel_nodes, to_reconnect)\n", "\n", " ### extend our list \"to_add\" with this artifact clusters' contribution:\n", " to_add.extend(non_planar_connections)" @@ -755,8 +747,7 @@ "# planar = artifacts[~artifacts.non_planar]\n", "\n", "# iterate through CLUSTERS of artifacts\n", - "for _, artifact in artifacts_small.groupby(\"comp\"): # TODO: over entire table\n", - "\n", + "for _, artifact in artifacts_small.groupby(\"comp\"): # TODO: over entire table\n", " # get artifact cluster polygon\n", " cluster_geom = artifact.union_all(method=\"coverage\")\n", " # get edges relevant for an artifact\n", @@ -768,8 +759,8 @@ " nodes=nodes,\n", " to_drop=to_drop,\n", " to_add=to_add,\n", - " eps=my_eps\n", - " )\n" + " eps=my_eps,\n", + " )" ] }, { @@ -779,7 +770,6 @@ "outputs": [], "source": [ "def rebuild_network(roads, to_drop, to_add, distance=2):\n", - "\n", " cleaned_roads = roads.geometry.drop(to_drop)\n", "\n", " # # split lines on new nodes\n", @@ -1569,22 +1559,13 @@ "source": [ "m = roads.iloc[roads.sindex.query(cluster_geom, predicate=\"intersects\")].explore(\n", " tiles=\"CartoDB.Positron\",\n", - " name = \"original roads\",\n", - " color = \"orange\",\n", - " opacity = .4,\n", - " prefer_canvas=True\n", - ")\n", - "new_roads.explore(\n", - " m=m,\n", - " name = \"new roads\",\n", - " color = \"blue\"\n", - ")\n", - "artifacts.explore(\n", - " m=m,\n", - " color = \"yellow\",\n", - " opacity = .1,\n", - " name = \"artifact\"\n", + " name=\"original roads\",\n", + " color=\"orange\",\n", + " opacity=0.4,\n", + " prefer_canvas=True,\n", ")\n", + "new_roads.explore(m=m, name=\"new roads\", color=\"blue\")\n", + "artifacts.explore(m=m, color=\"yellow\", opacity=0.1, name=\"artifact\")\n", "folium.LayerControl().add_to(m)\n", "m" ] @@ -1606,7 +1587,7 @@ ], "metadata": { "kernelspec": { - "display_name": "simplification", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -1620,9 +1601,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.11.10" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/notebooks/typology-rectangles.ipynb b/notebooks/typology-rectangles.ipynb index 7b2d80a..78c2132 100644 --- a/notebooks/typology-rectangles.ipynb +++ b/notebooks/typology-rectangles.ipynb @@ -15,6 +15,8 @@ "metadata": {}, "outputs": [], "source": [ + "from itertools import combinations\n", + "\n", "import folium\n", "import geopandas as gpd\n", "import matplotlib.pyplot as plt\n", @@ -22,13 +24,12 @@ "import numpy as np\n", "import pandas as pd\n", "import shapely\n", - "from core import utils, algorithms, geometry\n", "from folium import plugins\n", - "from itertools import combinations\n", - "\n", "from libpysal import graph\n", "from scipy import sparse, spatial\n", - "from tqdm import tqdm" + "from tqdm import tqdm\n", + "\n", + "from core import algorithms, geometry, utils" ] }, { @@ -1363,9 +1364,7 @@ " else:\n", " mask.append(True)\n", "mains = mains[mask]\n", - "assert (\n", - " mains.intersects(mains[::-1], align=False).all()\n", - ") # two main roads intersect\n", + "assert mains.intersects(mains[::-1], align=False).all() # two main roads intersect\n", "assert mains.coins_group.nunique() == 2" ] }, @@ -1590,9 +1589,7 @@ " else:\n", " mask.append(True)\n", "mains = mains[mask]\n", - "assert (\n", - " mains.intersects(mains[::-1], align=False).all()\n", - ") # two main roads intersect\n", + "assert mains.intersects(mains[::-1], align=False).all() # two main roads intersect\n", "assert mains.coins_group.nunique() == 2" ] }, @@ -1778,9 +1775,7 @@ " else:\n", " mask.append(True)\n", "mains = mains[mask]\n", - "assert (\n", - " mains.intersects(mains[::-1], align=False).all()\n", - ") # two main roads intersect\n", + "assert mains.intersects(mains[::-1], align=False).all() # two main roads intersect\n", "assert mains.coins_group.nunique() == 1\n", "assert len(mains) == 2" ] @@ -2114,9 +2109,7 @@ " else:\n", " mask.append(True)\n", "mains = mains[mask]\n", - "assert (\n", - " mains.intersects(mains[::-1], align=False).all()\n", - ") # two main roads intersect\n", + "assert mains.intersects(mains[::-1], align=False).all() # two main roads intersect\n", "assert mains.coins_group.nunique() == 1\n", "assert len(mains) == 2" ] @@ -2898,7 +2891,9 @@ } ], "source": [ - "roads[roads.intersects(shapely.Point(682619.7584150723, 5612995.734446571).buffer(1))].explore()" + "roads[\n", + " roads.intersects(shapely.Point(682619.7584150723, 5612995.734446571).buffer(1))\n", + "].explore()" ] }, { diff --git a/notebooks/typology-singles.ipynb b/notebooks/typology-singles.ipynb index 2880f2f..a902d0b 100644 --- a/notebooks/typology-singles.ipynb +++ b/notebooks/typology-singles.ipynb @@ -23,7 +23,7 @@ "import momepy\n", "from libpysal import graph\n", "\n", - "from core import algorithms, geometry, utils\n" + "from core import algorithms, geometry, utils" ] }, { diff --git a/notebooks/typology-triangles.ipynb b/notebooks/typology-triangles.ipynb index 88011fa..bec97a2 100644 --- a/notebooks/typology-triangles.ipynb +++ b/notebooks/typology-triangles.ipynb @@ -22,11 +22,12 @@ "import numpy as np\n", "import pandas as pd\n", "import shapely\n", - "from core import utils, algorithms\n", - "from core.geometry import is_within\n", "from folium import plugins\n", "from libpysal import graph\n", - "from scipy import sparse" + "from scipy import sparse\n", + "\n", + "from core import algorithms, utils\n", + "from core.geometry import is_within" ] }, { diff --git a/notebooks/usecases.ipynb b/notebooks/usecases.ipynb index 72ae372..15392ba 100644 --- a/notebooks/usecases.ipynb +++ b/notebooks/usecases.ipynb @@ -204,7 +204,7 @@ "points[_context][\"address\"] = \"Rue du Coq Mosan 7, 4040 Herstal, Belgium\"\n", "points[_context][\"comments\"] = \"collapsed neighborhood - parallel edges\"\n", "\n", - "fpath_base = pathlib.Path(\"..\", \"usecases\", str(core.utils.city_fua[city]))\n", + "fpath_base = pathlib.Path(\"..\", \"usecases\", str(utils.city_fua[city]))\n", "with open(fpath_base / \"points.json\", \"w\") as outfile:\n", " outfile.write(json.dumps(points, indent=6))" ] @@ -240,7 +240,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.11.10" } }, "nbformat": 4, diff --git a/pyproject.toml b/pyproject.toml index 49d5cc3..8daf096 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,6 +96,11 @@ lint.select = ["E", "F", "W", "I", "UP", "N", "B", "A", "C4", "SIM", "ARG"] "F401", # imported but unused "F403", # star import; unable to detect undefined names ] + "*.ipynb" = [ + "C408", # Unnecessary `dict` call + "E501", # Line too long + "F401", # imported but unused +] [tool.coverage.run] source = ["./core"]