Skip to content

Commit

Permalink
write mode share distance distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Jul 26, 2024
1 parent 1086780 commit c81beda
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions matsim/scenariogen/data/run_create_ref_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,32 @@ def summarize_mode_usage(x, trips):
return pd.DataFrame(data={"main_mode": data.keys(), "user": data.values()}).set_index("main_mode")


def mode_share_distance_distribution(trips, dist_groups):
""" Created smoothed distribution of mode share """
from statsmodels.nonparametric.smoothers_lowess import lowess

end = dist_groups[-3] + dist_groups[-2]

x = np.arange(0, end, step=100)

data = {}

for m in set(trips.main_mode):
df = trips[trips.main_mode == m]
hist, bins = np.histogram(df.gis_length * 1000, bins=x)

yout = lowess(hist, x[:-1], frac=0.05, is_sorted=True, return_sorted=False, it=0)
data[m] = np.maximum(0, yout)

data["dist"] = x[:-1]

df = pd.DataFrame(data=data).set_index("dist")
s = df.sum(axis=1)
df = df.apply(lambda d: d / s, axis=0)

return df


def setup(parser: argparse.ArgumentParser):
parser.add_argument("dirs", nargs="+", help="Directories with survey data")

Expand Down Expand Up @@ -183,6 +209,8 @@ def create(survey_dirs, transform_persons, transform_trips,
aggr = summarize_mode_usage(persons, trips)
aggr.to_csv(output_prefix + "mode_users_ref.csv")

mode_share_distance_distribution(trips, dist_groups).to_csv(output_prefix + "mode_share_distance_distribution.csv")

groups = None
if ref_groups:

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# 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", "statsmodels"],
'viz': ["dash", "plotly.express", "dash_cytoscape", "dash_bootstrap_components"]
},
tests_require=["assertpy", "pytest"],
Expand Down

0 comments on commit c81beda

Please sign in to comment.