Skip to content

Commit

Permalink
add cli entrypoint for viz tools and piri
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Mar 5, 2024
1 parent 37b3115 commit 28b6ee7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
28 changes: 28 additions & 0 deletions matsim/viz/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from argparse import ArgumentParser


def start_piri(args):
from matsim.viz import piri
piri.app.run(debug=False)

def main():
""" Main entry point. """

parser = ArgumentParser(prog='matsim-viz', description="MATSim viz util")
subparsers = parser.add_subparsers(title="Subcommands")

# Because the dash app can not easily be separated, the command lne parser is duplicated here
s1 = subparsers.add_parser("piri", help="Analyze the evolution of plans of a single agent or compare different agents side by side.")
s1.add_argument("inputfile", help="Full path to the file containing the plan inheritance records, e.g. path/to/matsim/output/planInheritanceRecords.csv.gz")

s1.set_defaults(func=start_piri)

args = parser.parse_args()
args.func(args)


if __name__ == "__main__":
main()
14 changes: 11 additions & 3 deletions matsim/viz/piri.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import dash_bootstrap_components as dbc # column formatting and stuff
import argparse
import io
import sys

# https://dash.plotly.com/cytoscape/layout
# Load extra layouts - time consuming
Expand All @@ -21,15 +22,22 @@

# Process command line arguments
parser = argparse.ArgumentParser(prog="piri", description="Analyze the evolution of plans of a single agent or compare different agents side by side.")

if "piri" in sys.argv:
parser.add_argument("cmd", help="Hidden argument to consume the 'piri' subcommand")

parser.add_argument("inputfile", help="Full path to the file containing the plan inheritance records, e.g. path/to/matsim/output/planInheritanceRecords.csv.gz")
args = parser.parse_args()

# Read and PreProcess data
pir = pd.read_csv(args.inputfile, sep='\t')
pir['mutatedBy'] = pir['mutatedBy'].str.replace('_',' ')
pir['iterationsSelected'] = pir['iterationsSelected'].str.replace('[','').str.replace(']','')
pir['mutatedBy'] = pir['mutatedBy'].str.replace('_', ' ', regex=False)
pir['iterationsSelected'] = pir['iterationsSelected'].str.replace('[', '', regex=False).str.replace(']', '',
regex=False)
defaultagentId = pir['agentId'].unique()[0]
pir['nodeClasses'] = pir.apply(lambda row: "initial" if row['ancestorId'] == "NONE" else "final" if row['iterationRemoved'] == -1 else "regular", axis=1)
pir['nodeClasses'] = pir.apply(
lambda row: "initial" if row['ancestorId'] == "NONE" else "final" if row['iterationRemoved'] == -1 else "regular",
axis=1)

# Initialize the app
app = Dash(__name__,
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
# m2cgen has problems with newer xgb, see this issue
# https://github.com/BayesWitnesses/m2cgen/issues/581
'scenariogen': ["sumolib", "traci", "lxml", "optax", "requests", "tqdm", "scikit-learn", "xgboost==1.7.1", "lightgbm",
"sklearn-contrib-lightning", "numpy", "sympy", "m2cgen", "shapely", "optuna"]
"sklearn-contrib-lightning", "numpy", "sympy", "m2cgen", "shapely", "optuna"],
'viz': ["dash", "plotly.express", "dash_cytoscape", "dash_bootstrap_components"]
},
tests_require=["assertpy", "pytest"],
entry_points={
'console_scripts': [
'matsim-tools=matsim.cli.main:main',
'matsim-scenariogen=matsim.scenariogen:main'
'matsim-scenariogen=matsim.scenariogen:main',
'matsim-viz=matsim.viz:main',
]
},
long_description=README,
Expand Down

0 comments on commit 28b6ee7

Please sign in to comment.