From fd3e3e3ef116418c6533eb0ebc2e4ace03a7ae2d Mon Sep 17 00:00:00 2001 From: Thedore-Chatziioannou Date: Tue, 14 May 2024 11:23:23 +0000 Subject: [PATCH] linting --- src/pam/cli.py | 5 ++--- src/pam/operations/snap.py | 17 ++++++++--------- tests/test_29_snap.py | 13 +++++++------ 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/pam/cli.py b/src/pam/cli.py index 823b411e..1e270c5d 100644 --- a/src/pam/cli.py +++ b/src/pam/cli.py @@ -670,7 +670,6 @@ def plan_filter(plan): logger.info(f"Output saved at {path_population_output}") - @cli.command() @click.argument("path_population_in", type=click.Path(exists=True)) @click.argument("path_population_out", type=click.Path(exists=False, writable=True)) @@ -693,5 +692,5 @@ def snap_facilities( path_population_in=path_population_in, path_population_out=path_population_out, path_network_geometry=path_network_geometry, - link_id_field=link_id_field - ) \ No newline at end of file + link_id_field=link_id_field, + ) diff --git a/src/pam/operations/snap.py b/src/pam/operations/snap.py index cabc694b..439ab378 100644 --- a/src/pam/operations/snap.py +++ b/src/pam/operations/snap.py @@ -8,9 +8,7 @@ def snap_facilities_to_network( - population: Population, - network: gp.GeoDataFrame, - link_id_field: str = "id" + population: Population, network: gp.GeoDataFrame, link_id_field: str = "id" ) -> None: """Snaps activity facilities to a network geometry (in-place). @@ -25,12 +23,13 @@ def snap_facilities_to_network( link_id = link_ids[network.distance(act.location.loc).argmin()] act.location.link = link_id + def run_facility_link_snapping( - path_population_in: str, - path_population_out: str, - path_network_geometry: str, - link_id_field: str = "id" -)->None: + path_population_in: str, + path_population_out: str, + path_network_geometry: str, + link_id_field: str = "id", +) -> None: """Reads a population, snaps activity facilities to a network geometry, and saves the results. Args: @@ -45,4 +44,4 @@ def run_facility_link_snapping( else: network = gp.read_file(path_network_geometry) snap_facilities_to_network(population=population, network=network, link_id_field=link_id_field) - write_matsim(population=population, plans_path=path_population_out) \ No newline at end of file + write_matsim(population=population, plans_path=path_population_out) diff --git a/tests/test_29_snap.py b/tests/test_29_snap.py index ff144c58..72976d1e 100644 --- a/tests/test_29_snap.py +++ b/tests/test_29_snap.py @@ -9,7 +9,7 @@ def test_add_snapping_adds_link_attribute(population_heh): - network=gp.read_file(os.path.join(TEST_DATA_DIR, "test_link_geometry.geojson")) + network = gp.read_file(os.path.join(TEST_DATA_DIR, "test_link_geometry.geojson")) for _, _, person in population_heh.people(): for act in person.activities: assert act.location.link is None @@ -19,15 +19,16 @@ def test_add_snapping_adds_link_attribute(population_heh): for act in person.activities: assert act.location.link is not None + def test_links_resnapped(tmpdir): - path_out=os.path.join(tmpdir, "pop_snapped.xml") + path_out = os.path.join(tmpdir, "pop_snapped.xml") run_facility_link_snapping( - path_population_in=os.path.join(TEST_DATA_DIR, "1.plans.xml"), - path_population_out=path_out, - path_network_geometry=os.path.join(TEST_DATA_DIR, "test_link_geometry.geojson") + path_population_in=os.path.join(TEST_DATA_DIR, "1.plans.xml"), + path_population_out=path_out, + path_network_geometry=os.path.join(TEST_DATA_DIR, "test_link_geometry.geojson"), ) assert os.path.exists(path_out) pop_snapped = read_matsim(path_out) for _, _, person in pop_snapped.people(): for act in person.activities: - assert "link-" in act.location.link \ No newline at end of file + assert "link-" in act.location.link