Skip to content

Commit

Permalink
Fix scripts (#80)
Browse files Browse the repository at this point in the history
* updare standard outputs script

* update google dir api inspect script

* update osm read script

* update reproj script

* update goog dir api send script

* update validate script

* update defaults for vehicles and schedule
  • Loading branch information
KasiaKoz authored May 6, 2021
1 parent ed78846 commit d5c29ed
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 38 deletions.
21 changes: 11 additions & 10 deletions scripts/generate_standard_outputs.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import argparse
import genet as gn
import logging
import time
import os
import json
from genet.utils.persistence import ensure_dir

from genet import read_matsim
from genet.utils.persistence import ensure_dir

if __name__ == '__main__':
arg_parser = argparse.ArgumentParser(description='Reproject a MATSim network')
arg_parser = argparse.ArgumentParser(description='Generate Standard outputs for a MATSim network')

arg_parser.add_argument('-n',
'--network',
Expand All @@ -19,13 +17,13 @@
'--schedule',
help='Location of the schedule.xml file',
required=False,
default='')
default=None)

arg_parser.add_argument('-v',
'--vehicles',
help='Location of the vehicles.xml file',
required=False,
default='')
default=None)

arg_parser.add_argument('-p',
'--projection',
Expand All @@ -47,16 +45,19 @@

logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.WARNING)

n = gn.Network(projection)
logging.info('Reading in network at {}'.format(network))
n.read_matsim_network(network)
if schedule:
logging.info(f'Reading in schedule at {schedule}')
if vehicles:
logging.info(f'Reading in vehicles at {vehicles}')
else:
logging.info('No vehicles file given with the Schedule, vehicle types will be based on the default.')
n.read_matsim_schedule(schedule, vehicles)
n = read_matsim(
path_to_network=network,
epsg=projection,
path_to_schedule=schedule,
path_to_vehicles=vehicles
)

logging.info('Generating standard outputs')
n.generate_standard_outputs(os.path.join(output_dir))
9 changes: 5 additions & 4 deletions scripts/inspect_google_directions_requests_for_network.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import argparse
import genet as gn
import logging
import json
import os


Expand Down Expand Up @@ -43,9 +42,11 @@

logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.WARNING)

n = gn.Network(projection)
logging.info(f'Reading in network at {network}')
n.read_matsim_network(network)
logging.info('Reading in network at {}'.format(network))
n = gn.read_matsim(
path_to_network=network,
epsg=projection
)

logging.info('Generating requests for the network')
api_requests = gn.google_directions.generate_requests(n=n)
Expand Down
5 changes: 2 additions & 3 deletions scripts/make_road_only_network.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import argparse
import genet as gn
from genet import read_osm
import logging


Expand Down Expand Up @@ -47,9 +47,8 @@

logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.WARNING)

n = gn.Network(projection)
logging.info('Reading in network at {}'.format(osm))
n.read_osm(osm, config, num_processes=processes)
n = read_osm(osm_file_path=osm, osm_read_config=config, num_processes=processes, epsg=projection)
# TODO uncomment when this functionality makes it to master
# for mode in ['walk', 'car', 'bike']:
# n.retain_n_connected_subgraphs(n=connected_components, mode=mode)
Expand Down
16 changes: 10 additions & 6 deletions scripts/reproject_network.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import argparse
import genet as gn
import logging
import time

from genet import read_matsim

if __name__ == '__main__':
arg_parser = argparse.ArgumentParser(description='Reproject a MATSim network')
Expand All @@ -16,13 +16,13 @@
'--schedule',
help='Location of the schedule.xml file',
required=False,
default='')
default=None)

arg_parser.add_argument('-v',
'--vehicles',
help='Location of the vehicles.xml file',
required=False,
default='')
default=None)

arg_parser.add_argument('-cp',
'--current_projection',
Expand Down Expand Up @@ -57,19 +57,23 @@

logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.WARNING)

n = gn.Network(current_projection)
logging.info('Reading in network at {}'.format(network))
n.read_matsim_network(network)
if schedule:
logging.info(f'Reading in schedule at {schedule}')
if vehicles:
logging.info(f'Reading in vehicles at {vehicles}')
else:
logging.info('No vehicles file given with the Schedule, vehicle types will be based on the default.')
n.read_matsim_schedule(schedule, vehicles)
else:
logging.info('You have not passed the schedule.xml file. If your network is road only, that is fine, otherwise'
'if you mix and match them, you will have a bad time.')
n = read_matsim(
path_to_network=network,
epsg=current_projection,
path_to_schedule=schedule,
path_to_vehicles=vehicles
)

logging.info('Reprojecting the network.')

start = time.time()
Expand Down
6 changes: 4 additions & 2 deletions scripts/send_google_directions_requests_for_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@

logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.WARNING)

n = gn.Network(projection)
logging.info('Reading in network at {}'.format(network))
n.read_matsim_network(network)
n = gn.read_matsim(
path_to_network=network,
epsg=projection
)

if subset_conditions is not None:
logging.info(f"Considering subset of the network satisfying attributes-osm:way:highway-{subset_conditions}")
Expand Down
4 changes: 2 additions & 2 deletions scripts/simplify_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
'--schedule',
help='Location of the schedule.xml file',
required=False,
default='')
default=None)

arg_parser.add_argument('-v',
'--vehicles',
help='Location of the vehicles.xml file',
required=False,
default='')
default=None)

arg_parser.add_argument('-p',
'--projection',
Expand Down
23 changes: 12 additions & 11 deletions scripts/validate_network.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import argparse
import genet as gn
import json
import logging
import time
import os
import json
from genet.utils.persistence import ensure_dir

from genet import read_matsim
from genet.utils.persistence import ensure_dir

if __name__ == '__main__':
arg_parser = argparse.ArgumentParser(description='Simplify a MATSim network by removing '
'intermediate links from paths')
arg_parser = argparse.ArgumentParser(description='Run MATSim specific validation methods on a MATSim network')

arg_parser.add_argument('-n',
'--network',
Expand All @@ -20,13 +18,13 @@
'--schedule',
help='Location of the schedule.xml file',
required=False,
default='')
default=None)

arg_parser.add_argument('-v',
'--vehicles',
help='Location of the vehicles.xml file',
required=False,
default='')
default=None)

arg_parser.add_argument('-p',
'--projection',
Expand All @@ -48,16 +46,19 @@

logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.WARNING)

n = gn.Network(projection)
logging.info('Reading in network at {}'.format(network))
n.read_matsim_network(network)
if schedule:
logging.info(f'Reading in schedule at {schedule}')
if vehicles:
logging.info(f'Reading in vehicles at {vehicles}')
else:
logging.info('No vehicles file given with the Schedule, vehicle types will be based on the default.')
n.read_matsim_schedule(schedule, vehicles)
n = read_matsim(
path_to_network=network,
epsg=projection,
path_to_schedule=schedule,
path_to_vehicles=vehicles
)

logging.info('Generating validation report')
report = n.generate_validation_report()
Expand Down

0 comments on commit d5c29ed

Please sign in to comment.