Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start basic tests for common.continuity() #80

Merged
merged 22 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
files: "core\/"
files: "core\/|notebooks\/"
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.5.4"
Expand Down
15 changes: 9 additions & 6 deletions core/algorithms/common.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import geopandas
import momepy
from libpysal import graph


def continuity(roads):
"""Assign COINS-based information to roads
def continuity(roads: geopandas.GeoDataFrame) -> geopandas.GeoDataFrame:
"""Assign COINS-based information to roads.

Parameters
----------
roads : GeoDataFrame
Road network
roads : geopandas.GeoDataFrame
Road network.

Returns
-------
GeoDataFrame
original roads with additional columns
geopandas.GeoDataFrame
The input ``roads`` with additional columns where the original
index may be reset (see ``dedup`` keyword argument).
"""
roads = roads.copy()

# Measure continuity of street network
coins = momepy.COINS(roads)

Expand Down
34 changes: 34 additions & 0 deletions core/tests/test_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import geopandas
import pandas

import core


class TestContinuity:
def setup_method(self):
self.city = "Liège"
self.roads = core.utils.read_no_degree_2(self.city)

def test_basic(self):
roads = core.algorithms.common.continuity(self.roads)

assert isinstance(roads, geopandas.GeoDataFrame)
assert roads.geom_type.unique()[0] == "LineString"
jGaboardi marked this conversation as resolved.
Show resolved Hide resolved

assert roads.columns.tolist() == [
"geometry",
"coins_group",
"coins_len",
"coins_count",
"coins_end",
]

known_counts_coins_end = pandas.DataFrame(
{"coins_end": [True, False], "count": [15205, 13392]}
)
observed_counts_coins_end = (
roads["coins_end"].value_counts().to_frame().reset_index()
)
pandas.testing.assert_frame_equal(
known_counts_coins_end, observed_counts_coins_end
)
2 changes: 1 addition & 1 deletion core/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_read_sample_data():

cities = list(core.utils.city_fua.keys())
osm_records = [86_101, 109_976, 110_074, 88_746, 105_174, 110_211, 107_551]
xnd2_records = [46_952, 41_566, 25_761, 32_903, 30_025, 47_859, 37_129]
xnd2_records = [46_179, 40_177, 23_127, 32_020, 28_597, 46_362, 35_869]
man_records = [41_481, 35_650, 20_347, 30_647, 25_133, 43_955, numpy.nan]


Expand Down
4 changes: 3 additions & 1 deletion core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,6 @@ def make_grid(

def remove_degree_2_nodes(fua: int | str) -> geopandas.GeoDataFrame:
"""Remove [interstitial / non-articulation / degree 2] nodes from road network."""
return momepy.remove_false_nodes(read_original(fua))
df = momepy.remove_false_nodes(read_original(fua))
df = df[~df.geometry.duplicated()].reset_index(drop=True)
return momepy.remove_false_nodes(df)
Binary file modified data/1133/no_degree_2/1133.parquet
Binary file not shown.
Binary file modified data/1656/no_degree_2/1656.parquet
Binary file not shown.
Binary file modified data/4617/no_degree_2/4617.parquet
Binary file not shown.
Binary file modified data/4881/no_degree_2/4881.parquet
Binary file not shown.
Binary file modified data/809/no_degree_2/809.parquet
Binary file not shown.
Binary file modified data/869/no_degree_2/869.parquet
Binary file not shown.
Binary file modified data/8989/no_degree_2/8989.parquet
Binary file not shown.
79 changes: 41 additions & 38 deletions notebooks/remove_degree_2_nodes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
"id": "c785905e-e1de-4940-9a40-d50a1769062a",
"metadata": {
"execution": {
"iopub.execute_input": "2024-06-28T14:18:08.547293Z",
"iopub.status.busy": "2024-06-28T14:18:08.547142Z",
"iopub.status.idle": "2024-06-28T14:18:08.569439Z",
"shell.execute_reply": "2024-06-28T14:18:08.569068Z",
"shell.execute_reply.started": "2024-06-28T14:18:08.547278Z"
"iopub.execute_input": "2024-07-24T15:12:05.985101Z",
"iopub.status.busy": "2024-07-24T15:12:05.984605Z",
"iopub.status.idle": "2024-07-24T15:12:06.006511Z",
"shell.execute_reply": "2024-07-24T15:12:06.006160Z",
"shell.execute_reply.started": "2024-07-24T15:12:05.985073Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Last updated: 2024-06-28T10:18:08.562263-04:00\n",
"Last updated: 2024-07-24T11:12:05.999509-04:00\n",
"\n",
"Python implementation: CPython\n",
"Python version : 3.11.9\n",
"IPython version : 8.25.0\n",
"IPython version : 8.26.0\n",
"\n",
"Compiler : Clang 16.0.6 \n",
"OS : Darwin\n",
Expand All @@ -54,17 +54,19 @@
"id": "b4891b2f-c26f-450e-8afb-ce147455d649",
"metadata": {
"execution": {
"iopub.execute_input": "2024-06-28T14:18:08.570626Z",
"iopub.status.busy": "2024-06-28T14:18:08.570378Z",
"iopub.status.idle": "2024-06-28T14:18:09.709930Z",
"shell.execute_reply": "2024-06-28T14:18:09.709559Z",
"shell.execute_reply.started": "2024-06-28T14:18:08.570607Z"
"iopub.execute_input": "2024-07-24T15:12:06.007420Z",
"iopub.status.busy": "2024-07-24T15:12:06.007280Z",
"iopub.status.idle": "2024-07-24T15:12:07.097670Z",
"shell.execute_reply": "2024-07-24T15:12:07.097323Z",
"shell.execute_reply.started": "2024-07-24T15:12:06.007406Z"
}
},
"outputs": [],
"source": [
"import pathlib\n",
"\n",
"import momepy # noqa: F401\n",
"\n",
"import core # noqa: F401\n",
"from core import utils"
]
Expand All @@ -75,11 +77,11 @@
"id": "a124677d-de91-4164-9f9b-fa07afe1904d",
"metadata": {
"execution": {
"iopub.execute_input": "2024-06-28T14:18:09.710465Z",
"iopub.status.busy": "2024-06-28T14:18:09.710327Z",
"iopub.status.idle": "2024-06-28T14:18:09.713083Z",
"shell.execute_reply": "2024-06-28T14:18:09.712882Z",
"shell.execute_reply.started": "2024-06-28T14:18:09.710458Z"
"iopub.execute_input": "2024-07-24T15:12:07.098264Z",
"iopub.status.busy": "2024-07-24T15:12:07.098108Z",
"iopub.status.idle": "2024-07-24T15:12:07.101011Z",
"shell.execute_reply": "2024-07-24T15:12:07.100851Z",
"shell.execute_reply.started": "2024-07-24T15:12:07.098257Z"
}
},
"outputs": [
Expand All @@ -89,7 +91,8 @@
"text": [
"Watermark: 2.4.3\n",
"\n",
"core: 0.1.dev103+gc27d2d8\n",
"core : 0.1.dev103+gc27d2d8\n",
"momepy: 0.8.0a3.dev35+g4e45e54\n",
"\n"
]
}
Expand All @@ -105,11 +108,11 @@
"id": "5ec07872-0a18-400b-98cf-2c2a05c59727",
"metadata": {
"execution": {
"iopub.execute_input": "2024-06-28T14:18:09.713509Z",
"iopub.status.busy": "2024-06-28T14:18:09.713446Z",
"iopub.status.idle": "2024-06-28T14:18:09.716027Z",
"shell.execute_reply": "2024-06-28T14:18:09.715834Z",
"shell.execute_reply.started": "2024-06-28T14:18:09.713502Z"
"iopub.execute_input": "2024-07-24T15:12:07.101445Z",
"iopub.status.busy": "2024-07-24T15:12:07.101368Z",
"iopub.status.idle": "2024-07-24T15:12:07.103916Z",
"shell.execute_reply": "2024-07-24T15:12:07.103742Z",
"shell.execute_reply.started": "2024-07-24T15:12:07.101438Z"
}
},
"outputs": [
Expand Down Expand Up @@ -140,11 +143,11 @@
"id": "a1731d0f-65ac-483c-8dde-6a410747ea71",
"metadata": {
"execution": {
"iopub.execute_input": "2024-06-28T14:18:09.716442Z",
"iopub.status.busy": "2024-06-28T14:18:09.716370Z",
"iopub.status.idle": "2024-06-28T14:18:09.718138Z",
"shell.execute_reply": "2024-06-28T14:18:09.717954Z",
"shell.execute_reply.started": "2024-06-28T14:18:09.716436Z"
"iopub.execute_input": "2024-07-24T15:12:07.104378Z",
"iopub.status.busy": "2024-07-24T15:12:07.104293Z",
"iopub.status.idle": "2024-07-24T15:12:07.106006Z",
"shell.execute_reply": "2024-07-24T15:12:07.105838Z",
"shell.execute_reply.started": "2024-07-24T15:12:07.104371Z"
}
},
"outputs": [
Expand All @@ -170,11 +173,11 @@
"id": "1489f17a-18c7-4192-9bc8-881eabc13866",
"metadata": {
"execution": {
"iopub.execute_input": "2024-06-28T14:18:09.719263Z",
"iopub.status.busy": "2024-06-28T14:18:09.719190Z",
"iopub.status.idle": "2024-06-28T14:18:09.720537Z",
"shell.execute_reply": "2024-06-28T14:18:09.720366Z",
"shell.execute_reply.started": "2024-06-28T14:18:09.719257Z"
"iopub.execute_input": "2024-07-24T15:12:07.107373Z",
"iopub.status.busy": "2024-07-24T15:12:07.107289Z",
"iopub.status.idle": "2024-07-24T15:12:07.108699Z",
"shell.execute_reply": "2024-07-24T15:12:07.108516Z",
"shell.execute_reply.started": "2024-07-24T15:12:07.107366Z"
}
},
"outputs": [],
Expand All @@ -189,11 +192,11 @@
"id": "a4c550d8-28ef-4971-b4cf-ddbbeda80a2e",
"metadata": {
"execution": {
"iopub.execute_input": "2024-06-28T14:18:09.720839Z",
"iopub.status.busy": "2024-06-28T14:18:09.720783Z",
"iopub.status.idle": "2024-06-28T14:20:40.284664Z",
"shell.execute_reply": "2024-06-28T14:20:40.284426Z",
"shell.execute_reply.started": "2024-06-28T14:18:09.720833Z"
"iopub.execute_input": "2024-07-24T15:12:07.109083Z",
"iopub.status.busy": "2024-07-24T15:12:07.108971Z",
"iopub.status.idle": "2024-07-24T15:12:29.612541Z",
"shell.execute_reply": "2024-07-24T15:12:29.612326Z",
"shell.execute_reply.started": "2024-07-24T15:12:07.109059Z"
}
},
"outputs": [
Expand Down
Loading