-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2009126
commit 0a17bad
Showing
6 changed files
with
111 additions
and
47 deletions.
There are no files selected for viewing
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"""Testing graph generator behavior""" | ||
|
||
import os | ||
import pytest | ||
import geopandas as gpd | ||
import osmnx as ox | ||
from blocksnet import GraphGenerator, AdjacencyCalculator | ||
|
||
data_path = "./tests/data" | ||
|
||
|
||
@pytest.fixture | ||
def blocks(): | ||
return gpd.read_parquet(os.path.join(data_path, "_blocks.parquet")) | ||
|
||
|
||
@pytest.fixture | ||
def graph_generator(blocks): | ||
return GraphGenerator(blocks) | ||
|
||
|
||
@pytest.fixture | ||
def graph(graph_generator): | ||
return graph_generator.run("intermodal") | ||
|
||
|
||
@pytest.fixture | ||
def adjacency_calculator(blocks, graph): | ||
return AdjacencyCalculator(blocks, graph) | ||
|
||
|
||
@pytest.fixture | ||
def adjacency_matrix(adjacency_calculator): | ||
return adjacency_calculator.run() | ||
|
||
|
||
def test_within(graph, graph_generator): | ||
"""Check if graph nodes are within the initial geometry""" | ||
nodes, _ = ox.graph_to_gdfs(graph) | ||
assert all(nodes.within(graph_generator.territory.unary_union)) | ||
|
||
|
||
def test_index(blocks, adjacency_matrix): | ||
"""Check if blocks index matches matrix index and columns""" | ||
assert (blocks.index == adjacency_matrix.index).all() | ||
assert (blocks.index == adjacency_matrix.columns).all() | ||
|
||
|
||
def test_values(adjacency_matrix): | ||
"""Check if adjacency matrix values are positive""" | ||
values = adjacency_matrix.values.ravel() | ||
assert all(v >= 0 for v in values) | ||
|
||
|
||
def test_output(adjacency_matrix): | ||
adjacency_matrix.to_pickle(os.path.join(data_path, "_adj_mx.pickle")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Testing city model behavior""" | ||
|
||
import os | ||
import pytest | ||
import geopandas as gpd | ||
import pandas as pd | ||
import statistics | ||
from blocksnet import City | ||
|
||
data_path = "./tests/data" | ||
|
||
|
||
@pytest.fixture | ||
def blocks(): | ||
return gpd.read_parquet(os.path.join(data_path, "_blocks.parquet")) | ||
|
||
|
||
@pytest.fixture | ||
def adjacency_matrix(): | ||
return pd.read_pickle(os.path.join(data_path, "_adj_mx.pickle")) | ||
|
||
|
||
@pytest.fixture | ||
def local_crs(blocks): | ||
return blocks.crs | ||
|
||
|
||
@pytest.fixture | ||
def buildings(local_crs): | ||
return gpd.read_parquet(os.path.join(data_path, "buildings.parquet")).to_crs(local_crs) | ||
|
||
|
||
@pytest.fixture | ||
def city(blocks, adjacency_matrix, buildings): | ||
city = City(blocks, adjacency_matrix) | ||
city.update_buildings(buildings) | ||
return city | ||
|
||
|
||
def test_coherence(city, blocks, adjacency_matrix): | ||
blocks_gdf = city.get_blocks_gdf(True) | ||
assert all(blocks.index == blocks_gdf.index) | ||
assert all(adjacency_matrix.index == city.adjacency_matrix.index) | ||
assert all(adjacency_matrix.columns == city.adjacency_matrix.columns) | ||
assert all(blocks_gdf.index == city.adjacency_matrix.index) | ||
assert all(city.adjacency_matrix.index == city.adjacency_matrix.columns) | ||
|
||
|
||
def test_output(city): | ||
city.to_pickle(os.path.join(data_path, "_city.pickle")) |
This file was deleted.
Oops, something went wrong.