Skip to content

Commit

Permalink
methods for create ref data and some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Oct 9, 2023
1 parent 902ab88 commit 461c9a2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
5 changes: 2 additions & 3 deletions matsim/scenariogen/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ def read_all(dirs: Union[str, List[str]], regio=None) -> Tuple[pd.DataFrame]:

for d in dirs:

files = []

for format in (srv, mid):

files = []

# Collect all files for each format
for f in os.scandir(d):
fp = f.name
if not f.is_file():
continue
if format.is_format(f):
Expand Down
3 changes: 3 additions & 0 deletions matsim/scenariogen/data/formats/srv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import os

import pandas as pd
import numpy as np

from .. import *

# Has households, persons and trips
Expand Down
26 changes: 16 additions & 10 deletions matsim/scenariogen/data/run_create_ref_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@ def summarize_mode_usage(x, trips):
def setup(parser: argparse.ArgumentParser):
parser.add_argument("dirs", nargs="+", help="Directories with survey data")

def create(hh, persons, trips):
pass
# TODO

def default_person_filter(df):
""" Default person filter for reference data. """
return df[df.present_on_day & (df.reporting_day <= 4)]

def main(args):
all_hh, all_persons, all_trips = read_all(args.dirs)

def create(survey_dirs, transform_persons):
""" Create reference data from survey data. """

all_hh, all_persons, all_trips = read_all(survey_dirs)

# Filter person ad trips for area
df = all_persons.join(all_hh, on="hh_id")

# TODO: configurable filter
persons = df[df.present_on_day &
(df.reporting_day <= 4) &
(df.region_type == 1)]
persons = transform_persons(df) if transform_persons is not None else df

# TODO: configurable attributes
persons["age_group"] = pd.cut(persons.age, [0, 18, 66, np.inf], labels=["0 - 17", "18 - 65", "65+"], right=False)
Expand All @@ -103,7 +103,8 @@ def main(args):
aggr["share"] = aggr.n / aggr.n.sum()
aggr["share"].fillna(0, inplace=True)

aggr = aggr.drop(columns=["n"])
share = aggr.drop(columns=["n"])
aggr = share.copy()

# TODO: configurable output

Expand All @@ -124,3 +125,8 @@ def main(args):
aggr.to_csv("mode_users_ref.csv")

# TODO: ref data per attribute ?
return persons, trips, share.groupby("main_mode").sum().drop(columns=["mean_dist"])


def main(args):
create(args.dirs, default_person_filter)

0 comments on commit 461c9a2

Please sign in to comment.