Skip to content

Commit

Permalink
Polish mwe.py and make it more user-friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
mszell committed Apr 18, 2024
1 parent 3eb09d8 commit 2cf5f4d
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions scripts/examples/mwe.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
"""Minimum working example for superblockify."""

from superblockify import ResidentialPartitioner
# While this script is running, figures will be generated on screen.
# Close the figure windows to proceed with the script execution.


from superblockify import ResidentialPartitioner

if __name__ == "__main__":
part = ResidentialPartitioner(
name="Salerno_mwe",
city_name="Salerno",
search_str="Salern, Campania, Italy",
# reload_graph=True
# --- Initialize the partitioner ---
partitioner = ResidentialPartitioner(
name="Scheveningen_test",
city_name="Scheveningen",
search_str="Scheveningen, NL",
unit="time", # "time", "distance", any other edge attribute, or None to count edges
)
# Find search strings via https://nominatim.openstreetmap.org/
# The smaller the place, the quicker the partitioning
# For large places sufficient memory is required
# If you want to select a different city, find the corresponding search string
# (`search_str`) at https://nominatim.openstreetmap.org/.
# The smaller the place, the quicker the partitioning.
# For large places sufficient memory is required.

# Save the preprocessed graph to disk:
# >>> part.save(save_graph_copy=True)
# If loading a previously saved graph, all previous steps are not needed:
# >>> part = ResidentialPartitioner.load("Salerno_mwe")

part.run(
# --- Run the partitioner ---
partitioner.run(
calculate_metrics=True,
make_plots=True,
replace_max_speeds=False,
)

# Save the partitioner to disk, with all attributes, without an extra copy of the
# --- Save the partitioner ---
# Save it to disk, with all attributes, without an extra copy of the
# graph. The original graph has been cached in the data/graphs folder.
part.save()

# or
# >>> import superblockify as sb
# >>> part = sb.ResidentialPartitioner(...)
# >>> part.run(...)
# >>> sb.save_to_gpkg(part)

# If you have the whole GHS POP raster, set the path after importing like so:
# >>> sb.config.Config.FULL_RASTER = ...
partitioner.save()

0 comments on commit 2cf5f4d

Please sign in to comment.