generated from matsim-scenarios/matsim-scenario-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added script to extract population data
- Loading branch information
Showing
4 changed files
with
126 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
26101001001 | ||
1 | ||
135.73306751966228 34.87073344970929 | ||
135.73136033233789 34.87075299638351 | ||
135.72974358990282 34.87120532106917 | ||
135.59762830922838 34.923964796171695 | ||
135.59625597408223 34.924804541820436 | ||
135.59511567458847 34.92575628050391 | ||
135.59436440996362 34.926941605825384 | ||
135.5940682681097 34.92825627406589 | ||
135.55374249771842 35.1360553509106 | ||
135.5537017047248 35.137798206491034 | ||
135.55507396099628 35.154786309421894 | ||
135.5551811918037 35.15600937780549 | ||
135.55568575318512 35.157163475622625 | ||
135.584450355535 35.220492859394284 | ||
135.58508235914425 35.221573285574834 | ||
135.5854822787441 35.222073257668065 | ||
135.58689642543368 35.22327641771856 | ||
135.63373787093332 35.25976016576515 | ||
135.63428707280005 35.260154583120915 | ||
135.63629113691238 35.26157299086489 | ||
135.63661612131972 35.26174798609984 | ||
135.79227684372395 35.32516809539943 | ||
135.79373704613968 35.32566494849434 | ||
135.79530938467258 35.32580087577925 | ||
135.79686394802118 35.32556464681516 | ||
135.7988485911786 35.32501195332199 | ||
135.8105242695204 35.321299774608505 | ||
135.81189106881797 35.32070288935732 | ||
135.86079475870204 35.293247205920665 | ||
135.8621412834626 35.292452461528406 | ||
135.86313733948296 35.29136458518591 | ||
135.86504228537342 35.28738939817372 | ||
135.86615870500023 35.28404059023343 | ||
135.86629592495538 35.282670565935724 | ||
135.8841505317859 34.94744801911249 | ||
135.8841462130628 34.94734667094723 | ||
135.8838632494947 34.94606591651803 | ||
135.88314767698824 34.944905119127014 | ||
135.8830855117753 34.94483258961723 | ||
135.881914550447 34.94383615747787 | ||
135.84888627371598 34.92639040728104 | ||
135.84754883545472 34.92569676588468 | ||
135.73469888281187 34.871148584446594 | ||
135.73306751966228 34.87073344970929 | ||
END | ||
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import argparse | ||
import os | ||
|
||
import numpy as np | ||
from matsim.scenariogen.data import TripMode, preparation, run_create_ref_data | ||
from matsim.scenariogen.data.preparation import join_person_with_household, remove_persons_with_invalid_trips, \ | ||
create_activities | ||
|
||
|
||
def transform_persons(df): | ||
|
||
# Filter on the shape file for kyoto | ||
# "PREF" = 26 AND "CITY" IN (101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111) | ||
|
||
df = df[df.location.isin(("26101", "26102", "26103", "26104", "26105", "26106", "26107", "26108", "26109", "26110", "26111"))] | ||
|
||
df.loc[:, "age"] = preparation.cut(df.age, [0, 12, 18, 25, 35, 66, np.inf]) | ||
|
||
return df | ||
|
||
|
||
def trip_filter(df): | ||
# Motorcycles are counted as cars | ||
df.loc[df.main_mode == TripMode.MOTORCYCLE, "main_mode"] = TripMode.CAR | ||
|
||
# Other mode are ignored in the total share | ||
df = df[df.main_mode != TripMode.OTHER] | ||
|
||
return df | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Converter for survey data") | ||
|
||
parser.add_argument("-d", "--directory", | ||
help="Directory with the kyoto survey data", | ||
default=os.path.expanduser( | ||
"~/Development/matsim-scenarios/shared-svn/projects/matsim-kyoto/data/survey_2010")) | ||
|
||
parser.add_argument("--output", default="table", help="Output prefix") | ||
|
||
args = parser.parse_args() | ||
|
||
result = run_create_ref_data.create( | ||
args.directory, transform_persons, trip_filter, | ||
invalid_trip_handling=run_create_ref_data.InvalidHandling.REMOVE_TRIPS, | ||
ref_groups=["age"] | ||
) | ||
|
||
print(result.share) | ||
|
||
hh, persons, trips = (result.all_hh, result.all_persons, result.all_trips) | ||
|
||
# Motorcycles are counted as cars | ||
trips.loc[trips.main_mode == TripMode.MOTORCYCLE, "main_mode"] = TripMode.CAR | ||
|
||
hh.to_csv(args.output + "-households.csv") | ||
trips.to_csv(args.output + "-trips.csv") | ||
|
||
df = join_person_with_household(persons, hh) | ||
df = remove_persons_with_invalid_trips(df, trips) | ||
|
||
df.to_csv(args.output + "-persons.csv") | ||
|
||
print("Written survey csvs with %d persons" % len(df)) | ||
|
||
activities = create_activities(df, trips, include_person_context=False, cut_groups=False) | ||
activities.to_csv(args.output + "-activities.csv", index=False) |