Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:
description: Manual Doc Build
default: run-doc-build
required: false

jobs:
docs:
name: CI (${{ matrix.os }}-${{ matrix.environment-file }})
Expand Down
2 changes: 1 addition & 1 deletion access/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
from .datasets import Datasets

with contextlib.suppress(PackageNotFoundError):
__version__ = version("access")
__version__ = version("access")
63 changes: 46 additions & 17 deletions access/tests/test_euclidean.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,19 @@ def setUp(self):
demand_grid = gpd.GeoDataFrame(
demand_data, geometry=gpd.points_from_xy(demand_data.x, demand_data.y)
)
demand_grid["geometry"] = demand_grid.buffer(0.5)
demand_grid["geometry"] = demand_grid.buffer(0.25)

supply_data = pd.DataFrame({"id": [1], "x": [0], "y": [1], "value": [1]})
supply_grid = gpd.GeoDataFrame(
supply_data, geometry=gpd.points_from_xy(supply_data.x, supply_data.y)
)

cost_matrix = pd.DataFrame(
{"origin": [0, 0, 1, 1], "dest": [1, 0, 0, 1], "cost": [1, 0, 1, 0]}
point_cost_matrix = pd.DataFrame(
{
"origin": [0, 0, 1, 1],
"dest": [1, 0, 0, 1],
"ctr_expectation": [1, 0, 1, 0],
}
)

self.model = Access(
Expand All @@ -112,33 +116,58 @@ def setUp(self):
supply_df=supply_grid,
supply_index="id",
supply_value="value",
cost_df=cost_matrix,
cost_df=point_cost_matrix,
cost_origin="origin",
cost_dest="dest",
cost_name="cost",
neighbor_cost_df=cost_matrix,
cost_name="ctr_expectation",
neighbor_cost_df=point_cost_matrix,
neighbor_cost_origin="origin",
neighbor_cost_dest="dest",
neighbor_cost_name="cost",
neighbor_cost_name="ctr_expectation",
)

# The geometries are buffered by 0.25, so the circles are 0.5 apart.
# Add these as a second set of costs
buff_cost_matrix = pd.DataFrame(
{
"origin": [0, 0, 1, 1],
"dest": [1, 0, 0, 1],
"buf_expectation": [0.5, 0, 0.5, 0],
}
)

self.model.append_user_cost_neighbors(
buff_cost_matrix, "origin", "dest", "buf_expectation"
)

def test_euclidean_neighbors_centroids(self):
self.model.create_euclidean_distance_neighbors(
name="euclidian", threshold=2, centroid=True
name="euclidean", threshold=2, centroid=True
)
self.assertAlmostEqual(
(
self.model.neighbor_cost_df.euclidean
- self.model.neighbor_cost_df.ctr_expectation
)
.abs()
.max(),
0,
)
actual1 = self.model.neighbor_cost_df["euclidian"][0]
actual2 = self.model.neighbor_cost_df["euclidian"][2]
self.assertAlmostEqual(actual1, 1)
self.assertAlmostEqual(actual2, 1)

def test_euclidean_neighbors_poly(self):
self.model.create_euclidean_distance_neighbors(
name="euclidian", threshold=2, centroid=False
name="euclidean", threshold=2, centroid=False
)

self.assertAlmostEqual(
(
self.model.neighbor_cost_df.euclidean
- self.model.neighbor_cost_df.buf_expectation
)
.abs()
.max(),
0,
)
actual1 = self.model.neighbor_cost_df["euclidian"][0]
actual2 = self.model.neighbor_cost_df["euclidian"][2]
self.assertAlmostEqual(actual1, 0)
self.assertAlmostEqual(actual2, 0)

def test_euclidean_neighbors_without_geopandas_demand_dataframe_raises_TypeError(
self,
Expand Down