Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
simei94 committed Feb 20, 2024
1 parent f7df9e9 commit a5754ff
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions matsim/calibration/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@ def read_trips_and_persons(run, transform_persons=None, transform_trips=None) ->
trips = glob.glob(run.rstrip("/") + "/*.output_trips.csv.gz")[0]
persons = glob.glob(run.rstrip("/") + "/*.output_persons.csv.gz")[0]

df = pd.read_csv(trips, sep=";", dtype={"person": "str"})
dfp = pd.read_csv(persons, sep=";", dtype={"person": "str"})

df = get_correct_delimiter(df, trips, persons)
dfp = get_correct_delimiter(dfp, trips, persons)
df = pd.read_csv(trips, dtype={"person": "str"})
dfp = pd.read_csv(persons, dtype={"person": "str"})

gdf = geopandas.GeoDataFrame(dfp,
geometry=geopandas.points_from_xy(dfp.first_act_x, dfp.first_act_y)
Expand All @@ -96,26 +93,6 @@ def read_trips_and_persons(run, transform_persons=None, transform_trips=None) ->

return df, gdf

def get_correct_delimiter(df : pd.DataFrame, trips : str, persons : str):
""" Determine correct delimiter """

delimiter = ""

if len(df.columns) == 1:
if str(df.columns).find(",") != -1:
delimiter = ","

if str(df.columns).find("\t") != -1:
delimiter = "\t"

if str(df.columns).find("trip") != -1:
df = pd.read_csv(trips, sep=delimiter, dtype={"person": "str"})
else:
df = pd.read_csv(persons, sep=delimiter, dtype={"person": "str"})

return df


def read_leg_stats(run : str, transform_persons=None, transform_legs=None):
""" Reads leg statistic from run directory """

Expand Down

0 comments on commit a5754ff

Please sign in to comment.