Skip to content

Commit

Permalink
linting & formatting for benchmarks/* and docs/* (#578)
Browse files Browse the repository at this point in the history
* update pre-commit ruff

* update pre-commit & pyproject

* update pyproject

* lint & format benchmarks/* and docs/*

* update pre-commit config

* add ruff.toml to docs

* test commit

* test commit [2]

* test commit [3]

* fine-tuned ruff
  • Loading branch information
jGaboardi committed May 13, 2024
1 parent 36b13f8 commit 7c1d30a
Show file tree
Hide file tree
Showing 25 changed files with 4,397 additions and 3,880 deletions.
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
files: 'momepy\/'
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.3.5"
rev: "v0.4.4"
hooks:
- id: ruff
- id: ruff-format
Expand Down
17 changes: 12 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# -- Project information -----------------------------------------------------

project = "momepy"
copyright = "2018-, Martin Fleischmann and PySAL Developers"
copyright = "2018-, Martin Fleischmann and PySAL Developers" # noqa: A001
author = "Martin Fleischmann"

# The short X.Y version
Expand Down Expand Up @@ -186,7 +186,13 @@ def setup(app):
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, "momepy.tex", "momepy Documentation", "Martin Fleischmann", "manual")
(
master_doc,
"momepy.tex",
"momepy Documentation",
"Martin Fleischmann",
"manual",
)
]


Expand Down Expand Up @@ -232,10 +238,11 @@ def setup(app):
# A list of files that should not be packed into the epub file.
epub_exclude_files = ["search.html"]

# Add redirect for previously existing pages, each item is like `(from_old, to_new)`
# Add redirect for previously existing pages,
# each item is like `(from_old, to_new)`

rediraffe_redirects = {
"user_guide/elements/preprocessing.ipynb": "user_guide/preprocessing/simple_preprocessing.ipynb", # noqa
"user_guide/elements/preprocessing.ipynb": "user_guide/preprocessing/simple_preprocessing.ipynb", # noqa: E501
}

# -- Extension configuration -------------------------------------------------
Expand All @@ -261,7 +268,7 @@ def setup(app):
| Interactive online version: :raw-html:`<a href="https://mybinder.org/v2/gh/pysal/momepy/master?urlpath=lab/tree/docs/{{ docname }}"><img alt="Binder badge" src="https://mybinder.org/badge_logo.svg" style="vertical-align:text-bottom"></a>`
__ https://github.com/pysal/momepy/blob/master/docs/{{ docname }}
"""
""" # noqa: E501


def linkcode_resolve(domain, info):
Expand Down
6,158 changes: 3,109 additions & 3,049 deletions docs/examples/clustering.ipynb

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
line-length = 80
lint.select = ["E", "F", "W", "I", "UP", "N", "B", "A", "C4", "SIM", "ARG"]
lint.ignore = ["B006", "SIM108"]
include = ["*.py", "*.ipynb"]
139 changes: 79 additions & 60 deletions docs/user_guide/combined/distribution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
"metadata": {},
"outputs": [],
"source": [
"import momepy\n",
"import geopandas as gpd\n",
"import matplotlib.pyplot as plt"
"import matplotlib.pyplot as plt\n",
"import momepy"
]
},
{
Expand Down Expand Up @@ -52,12 +51,16 @@
"source": [
"import osmnx as ox\n",
"\n",
"gdf = ox.geometries.geometries_from_place('Kahla, Germany', tags={'building': True})\n",
"gdf = ox.geometries.geometries_from_place(\n",
" \"Kahla, Germany\", tags={\"building\": True}\n",
")\n",
"buildings = ox.projection.project_gdf(gdf)\n",
"\n",
"buildings['uID'] = momepy.unique_id(buildings)\n",
"buildings[\"uID\"] = momepy.unique_id(buildings)\n",
"limit = momepy.buffered_limit(buildings)\n",
"tessellation = momepy.Tessellation(buildings, unique_id='uID', limit=limit).tessellation"
"tessellation = momepy.Tessellation(\n",
" buildings, unique_id=\"uID\", limit=limit\n",
").tessellation"
]
},
{
Expand All @@ -66,10 +69,15 @@
"metadata": {},
"outputs": [],
"source": [
"streets_graph = ox.graph_from_place('Kahla, Germany', network_type='drive')\n",
"streets_graph = ox.graph_from_place(\"Kahla, Germany\", network_type=\"drive\")\n",
"streets_graph = ox.projection.project_graph(streets_graph)\n",
"edges = ox.graph_to_gdfs(streets_graph, nodes=False, edges=True,\n",
" node_geometry=False, fill_edge_geometry=True)"
"edges = ox.graph_to_gdfs(\n",
" streets_graph,\n",
" nodes=False,\n",
" edges=True,\n",
" node_geometry=False,\n",
" fill_edge_geometry=True,\n",
")"
]
},
{
Expand Down Expand Up @@ -123,8 +131,8 @@
}
],
"source": [
"buildings['orientation'] = momepy.Orientation(buildings).series\n",
"tessellation['orientation'] = momepy.Orientation(tessellation).series"
"buildings[\"orientation\"] = momepy.Orientation(buildings).series\n",
"tessellation[\"orientation\"] = momepy.Orientation(tessellation).series"
]
},
{
Expand All @@ -150,8 +158,9 @@
}
],
"source": [
"buildings.plot(column='orientation', legend=True, cmap='Spectral',\n",
" figsize=(10, 10)).set_axis_off()"
"buildings.plot(\n",
" column=\"orientation\", legend=True, cmap=\"Spectral\", figsize=(10, 10)\n",
").set_axis_off()"
]
},
{
Expand All @@ -167,10 +176,10 @@
"metadata": {},
"outputs": [],
"source": [
"blg_cell_align = momepy.CellAlignment(buildings, tessellation,\n",
" 'orientation', 'orientation',\n",
" 'uID', 'uID')\n",
"buildings['cell_align'] = blg_cell_align.series"
"blg_cell_align = momepy.CellAlignment(\n",
" buildings, tessellation, \"orientation\", \"orientation\", \"uID\", \"uID\"\n",
")\n",
"buildings[\"cell_align\"] = blg_cell_align.series"
]
},
{
Expand All @@ -196,8 +205,9 @@
}
],
"source": [
"buildings.plot(column='cell_align', legend=True, cmap='Reds',\n",
" figsize=(10, 10)).set_axis_off()"
"buildings.plot(\n",
" column=\"cell_align\", legend=True, cmap=\"Reds\", figsize=(10, 10)\n",
").set_axis_off()"
]
},
{
Expand Down Expand Up @@ -244,9 +254,10 @@
}
],
"source": [
"edges['networkID'] = momepy.unique_id(edges)\n",
"buildings['networkID'] = momepy.get_network_id(buildings, edges,\n",
" 'networkID').values"
"edges[\"networkID\"] = momepy.unique_id(edges)\n",
"buildings[\"networkID\"] = momepy.get_network_id(\n",
" buildings, edges, \"networkID\"\n",
").values"
]
},
{
Expand Down Expand Up @@ -332,10 +343,10 @@
}
],
"source": [
"str_align = momepy.StreetAlignment(buildings_net, edges,\n",
" 'orientation', 'networkID',\n",
" 'networkID')\n",
"buildings_net['str_align'] = str_align.series"
"str_align = momepy.StreetAlignment(\n",
" buildings_net, edges, \"orientation\", \"networkID\", \"networkID\"\n",
")\n",
"buildings_net[\"str_align\"] = str_align.series"
]
},
{
Expand All @@ -361,8 +372,8 @@
}
],
"source": [
"ax = edges.plot(color='grey', linewidth=0.5, figsize=(10, 10))\n",
"buildings_net.plot(ax=ax, column='str_align', legend=True)\n",
"ax = edges.plot(color=\"grey\", linewidth=0.5, figsize=(10, 10))\n",
"buildings_net.plot(ax=ax, column=\"str_align\", legend=True)\n",
"ax.set_axis_off()"
]
},
Expand All @@ -383,9 +394,11 @@
"source": [
"point = (40.731603, -73.977857)\n",
"dist = 1000\n",
"gdf = ox.geometries.geometries_from_point(point, dist=dist, tags={'building':True})\n",
"gdf = ox.geometries.geometries_from_point(\n",
" point, dist=dist, tags={\"building\": True}\n",
")\n",
"buildings = ox.projection.project_gdf(gdf)\n",
"buildings = buildings[buildings.geom_type.isin(['Polygon', 'MultiPolygon'])]"
"buildings = buildings[buildings.geom_type.isin([\"Polygon\", \"MultiPolygon\"])]"
]
},
{
Expand All @@ -400,7 +413,8 @@
" except ValueError:\n",
" return 0\n",
"\n",
"buildings['height'] = buildings['height'].fillna(0).apply(clean_heights)\n",
"\n",
"buildings[\"height\"] = buildings[\"height\"].fillna(0).apply(clean_heights)\n",
"buildings = buildings.reset_index().explode()\n",
"buildings.reset_index(inplace=True, drop=True)"
]
Expand All @@ -411,10 +425,15 @@
"metadata": {},
"outputs": [],
"source": [
"streets_graph = ox.graph_from_point(point, dist, network_type='drive')\n",
"streets_graph = ox.graph_from_point(point, dist, network_type=\"drive\")\n",
"streets_graph = ox.projection.project_graph(streets_graph)\n",
"edges = ox.graph_to_gdfs(streets_graph, nodes=False, edges=True,\n",
" node_geometry=False, fill_edge_geometry=True)"
"edges = ox.graph_to_gdfs(\n",
" streets_graph,\n",
" nodes=False,\n",
" edges=True,\n",
" node_geometry=False,\n",
" fill_edge_geometry=True,\n",
")"
]
},
{
Expand All @@ -440,7 +459,7 @@
}
],
"source": [
"ax = buildings.plot(figsize=(10, 10), color='lightgrey')\n",
"ax = buildings.plot(figsize=(10, 10), color=\"lightgrey\")\n",
"edges.plot(ax=ax)\n",
"ax.set_axis_off()"
]
Expand All @@ -462,7 +481,7 @@
}
],
"source": [
"profile = momepy.StreetProfile(edges, buildings, heights='height')"
"profile = momepy.StreetProfile(edges, buildings, heights=\"height\")"
]
},
{
Expand All @@ -478,12 +497,12 @@
"metadata": {},
"outputs": [],
"source": [
"edges['widths'] = profile.w\n",
"edges['width_deviations'] = profile.wd\n",
"edges['openness'] = profile.o\n",
"edges['heights'] = profile.h\n",
"edges['heights_deviations'] = profile.hd\n",
"edges['profile'] = profile.p"
"edges[\"widths\"] = profile.w\n",
"edges[\"width_deviations\"] = profile.wd\n",
"edges[\"openness\"] = profile.o\n",
"edges[\"heights\"] = profile.h\n",
"edges[\"heights_deviations\"] = profile.hd\n",
"edges[\"profile\"] = profile.p"
]
},
{
Expand All @@ -510,30 +529,30 @@
],
"source": [
"f, axes = plt.subplots(figsize=(15, 25), ncols=2, nrows=3)\n",
"edges.plot(ax=axes[0][0], column='widths', legend=True, cmap='Blues_r')\n",
"buildings.plot(ax=axes[0][0], color='lightgrey')\n",
"edges.plot(ax=axes[0][1], column='width_deviations', legend=True)\n",
"buildings.plot(ax=axes[0][1], color='lightgrey')\n",
"edges.plot(ax=axes[0][0], column=\"widths\", legend=True, cmap=\"Blues_r\")\n",
"buildings.plot(ax=axes[0][0], color=\"lightgrey\")\n",
"edges.plot(ax=axes[0][1], column=\"width_deviations\", legend=True)\n",
"buildings.plot(ax=axes[0][1], color=\"lightgrey\")\n",
"axes[0][0].set_axis_off()\n",
"axes[0][0].set_title('widths')\n",
"axes[0][0].set_title(\"widths\")\n",
"axes[0][1].set_axis_off()\n",
"axes[0][1].set_title('width_deviations')\n",
"edges.plot(ax=axes[1][0], column='profile', legend=True, cmap='Spectral')\n",
"buildings.plot(ax=axes[1][0], color='lightgrey')\n",
"edges.plot(ax=axes[1][1], column='openness', legend=True, cmap='Greens')\n",
"buildings.plot(ax=axes[1][1], color='lightgrey')\n",
"axes[0][1].set_title(\"width_deviations\")\n",
"edges.plot(ax=axes[1][0], column=\"profile\", legend=True, cmap=\"Spectral\")\n",
"buildings.plot(ax=axes[1][0], color=\"lightgrey\")\n",
"edges.plot(ax=axes[1][1], column=\"openness\", legend=True, cmap=\"Greens\")\n",
"buildings.plot(ax=axes[1][1], color=\"lightgrey\")\n",
"axes[1][0].set_axis_off()\n",
"axes[1][0].set_title('profile')\n",
"axes[1][0].set_title(\"profile\")\n",
"axes[1][1].set_axis_off()\n",
"axes[1][1].set_title('openness')\n",
"edges.plot(ax=axes[2][0], column='heights', legend=True, cmap='Reds')\n",
"buildings.plot(ax=axes[2][0], color='lightgrey')\n",
"edges.plot(ax=axes[2][1], column='heights_deviations', legend=True)\n",
"buildings.plot(ax=axes[2][1], color='lightgrey')\n",
"axes[1][1].set_title(\"openness\")\n",
"edges.plot(ax=axes[2][0], column=\"heights\", legend=True, cmap=\"Reds\")\n",
"buildings.plot(ax=axes[2][0], color=\"lightgrey\")\n",
"edges.plot(ax=axes[2][1], column=\"heights_deviations\", legend=True)\n",
"buildings.plot(ax=axes[2][1], color=\"lightgrey\")\n",
"axes[2][0].set_axis_off()\n",
"axes[2][0].set_title('heights')\n",
"axes[2][0].set_title(\"heights\")\n",
"axes[2][1].set_axis_off()\n",
"axes[2][1].set_title('heights_deviations')\n",
"axes[2][1].set_title(\"heights_deviations\")\n",
"plt.show()"
]
}
Expand Down
Loading

0 comments on commit 7c1d30a

Please sign in to comment.