Skip to content

Commit

Permalink
Update swmmanywhere.py
Browse files Browse the repository at this point in the history
enable argprase for main function
  • Loading branch information
Dobson committed May 9, 2024
1 parent 09a9830 commit e85292b
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions swmmanywhere/swmmanywhere.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""The main SWMManywhere module to generate and run a synthetic network."""
from __future__ import annotations

import argparse
import os
from pathlib import Path

Expand All @@ -12,8 +13,8 @@

import swmmanywhere.geospatial_utilities as go
from swmmanywhere import parameters, preprocessing
from swmmanywhere.custom_logging import logger
from swmmanywhere.graph_utilities import iterate_graphfcns, load_graph, save_graph
from swmmanywhere.logging import logger
from swmmanywhere.metric_utilities import iterate_metrics
from swmmanywhere.post_processing import synthetic_write

Expand Down Expand Up @@ -64,7 +65,7 @@ def swmmanywhere(config: dict) -> tuple[Path, dict | None]:

# Identify the starting graph
logger.info("Iterating graphs.")
if config['starting_graph']:
if config.get('starting_graph', None):
G = load_graph(config['starting_graph'])
else:
G = preprocessing.create_starting_graph(addresses)
Expand Down Expand Up @@ -384,4 +385,33 @@ def run(model: Path,
storevar['id'])})

logger.info("Model run complete.")
return pd.DataFrame(results)
return pd.DataFrame(results)

def parse_arguments():
"""Parse the command line arguments.
Returns:
Path: The path to the configuration file.
"""
parser = argparse.ArgumentParser(description='Process command line arguments.')
parser.add_argument('--config_path',
type=Path,
default=Path(__file__).parent.parent.parent / 'tests' /\
'test_data' / 'demo_config.yml',
help='Configuration file path')
parser.add_argument('--verbose',
type=bool,
default=False,
help='Configuration verbosity')
args = parser.parse_args()
return args.config_path, args.verbose

if __name__ == '__main__':
# Parse the arguments
config_path, verbose = parse_arguments()
os.environ["SWMMANYWHERE_VERBOSE"] = str(verbose).lower()

config = load_config(config_path)

# Run the model
inp, metrics = swmmanywhere(config)

0 comments on commit e85292b

Please sign in to comment.