Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Thedore-Chatziioannou authored and Thedore-Chatziioannou committed May 14, 2024
1 parent 172d8e6 commit fd3e3e3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/pam/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
)
link_id_field=link_id_field,
)
17 changes: 8 additions & 9 deletions src/pam/operations/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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:
Expand All @@ -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)
write_matsim(population=population, plans_path=path_population_out)
13 changes: 7 additions & 6 deletions tests/test_29_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
assert "link-" in act.location.link

0 comments on commit fd3e3e3

Please sign in to comment.