Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: model update 2024 #263

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
18 changes: 9 additions & 9 deletions analysis/marginals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
HOUSEHOLD_SIZE_BOUNDS = [1, 3, np.inf]
HOUSEHOLD_SIZE_LABELS = ["1", "2-3", "4+"]

NUMBER_OF_VEHICLES_BOUNDS = [0, 1, 2, np.inf]
NUMBER_OF_VEHICLES_LABELS = ["0", "1", "2", "3+"]
NUMBER_OF_CARS_BOUNDS = [0, 1, 2, np.inf]
NUMBER_OF_CARS_LABELS = ["0", "1", "2", "3+"]

NUMBER_OF_BIKES_BOUNDS = [0, 1, 2, np.inf]
NUMBER_OF_BIKES_LABELS = ["0", "1", "2", "3+"]
NUMBER_OF_BICYCLES_BOUNDS = [0, 1, 2, np.inf]
NUMBER_OF_BICYCLES_LABELS = ["0", "1", "2", "3+"]

GENERAL_PERSON_MARGINALS = [("age_class",), ("sex",), ("employed",), ("studies",)]
GENERAL_HOUSEHOLD_MARGINALS = [("household_size_class",), ("number_of_vehicles_class",)]
GENERAL_HOUSEHOLD_MARGINALS = [("household_size_class",), ("number_of_cars_class",)]

CENSUS_PERSON_MARGINALS = GENERAL_PERSON_MARGINALS + [("socioprofessional_class",)]
CENSUS_HOUSEHOLD_MARGINALS = GENERAL_HOUSEHOLD_MARGINALS
Expand All @@ -34,11 +34,11 @@ def prepare_classes(df):
if "household_size" in df:
df["household_size_class"] = np.digitize(df["household_size"], HOUSEHOLD_SIZE_BOUNDS, right = True)

if "number_of_vehicles" in df:
df["number_of_vehicles_class"] = np.digitize(df["number_of_vehicles"], NUMBER_OF_VEHICLES_BOUNDS, right = True)
if "number_of_cars" in df:
df["number_of_cars_class"] = np.digitize(df["number_of_cars"], NUMBER_OF_CARS_BOUNDS, right = True)

if "number_of_bikes" in df:
df["number_of_bikes_class"] = np.digitize(df["number_of_bikes"], NUMBER_OF_BIKES_BOUNDS, right = True)
if "number_of_bicycles" in df:
df["number_of_bicycles_class"] = np.digitize(df["number_of_bicycles"], NUMBER_OF_BICYCLES_BOUNDS, right = True)

def cross(*marginals):
result = []
Expand Down
2 changes: 1 addition & 1 deletion analysis/reference/hts/mode_distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def execute(context):

data = dict()

for mode in ["car", "car_passenger", "pt", "bike", "walk"]:
for mode in ["car", "car_passenger", "pt", "bicycle", "walk"]:
f = df["mode"] == mode

if np.count_nonzero(f) > 0:
Expand Down
2 changes: 1 addition & 1 deletion analysis/synthesis/mode_distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def execute(context):
acquisition_sample_size = context.config("acquisition_sample_size")

probabilities = np.linspace(0.0, 1.0, 20)
modes = ["car", "car_passenger", "pt", "bike", "walk"]
modes = ["car", "car_passenger", "pt", "bicycle", "walk"]

quantiles = { mode : [] for mode in modes }

Expand Down
11 changes: 6 additions & 5 deletions data/census/cleaned.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ def execute(context):
# Clean TRANS
df.loc[df["TRANS"] == "1", "commute_mode"] = np.nan
df.loc[df["TRANS"] == "2", "commute_mode"] = "walk"
df.loc[df["TRANS"] == "3", "commute_mode"] = "bike"
df.loc[df["TRANS"] == "3", "commute_mode"] = "bicycle"
df.loc[df["TRANS"] == "4", "commute_mode"] = "car"
df.loc[df["TRANS"] == "5", "commute_mode"] = "pt"
df.loc[df["TRANS"] == "5", "commute_mode"] = "car"
df.loc[df["TRANS"] == "6", "commute_mode"] = "pt"
df.loc[df["TRANS"] == "Z", "commute_mode"] = np.nan
df["commute_mode"] = df["commute_mode"].astype("category")

Expand All @@ -81,11 +82,11 @@ def execute(context):
df["studies"] = df["ETUD"] == "1"

# Number of vehicles
df["number_of_vehicles"] = df["VOIT"].apply(
df["number_of_cars"] = df["VOIT"].apply(
lambda x: str(x).replace("Z", "0").replace("X", "0")
).astype(int)

df["number_of_vehicles"] += df["DEROU"].apply(
df["number_of_cars"] += df["DEROU"].apply(
lambda x: str(x).replace("U", "0").replace("Z", "0").replace("X", "0")
).astype(int)

Expand All @@ -104,7 +105,7 @@ def execute(context):
"iris_id", "commune_id", "departement_id",
"age", "sex", "couple",
"commute_mode", "employed",
"studies", "number_of_vehicles", "household_size",
"studies", "number_of_cars", "household_size",
"consumption_units", "socioprofessional_class"
]]

Expand Down
14 changes: 5 additions & 9 deletions data/hts/edgt_44/cleaned.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def configure(context):
"car": [13, 15, 21, 81],
"car_passenger": [14, 16, 22, 82],
"pt": [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 51, 52, 53, 61, 71, 72, 73, 91, 92, 94, 95],
"bike": [11, 17, 12, 18, 93, 19],
"bicycle": [11, 17, 12, 18, 93, 19],
# "motorbike": [13, 15],
"walk": [1, 2] # Actually, 2 is not really explained, but we assume it is walk
}

Expand Down Expand Up @@ -90,9 +91,9 @@ def execute(context):
df_persons["studies"] = df_persons["P7"].isin(["3", "4", "5"])

# Number of vehicles
df_households["number_of_vehicles"] = df_households["M6"] + df_households["M5"]
df_households["number_of_vehicles"] = df_households["number_of_vehicles"].astype(int)
df_households["number_of_bikes"] = df_households["M7"].astype(int)
df_households["number_of_cars"] = df_households["M6"].astype(int)
df_households["number_of_cars"] += df_households["M5"].astype(int) # motorbikes
df_households["number_of_bicycles"] = df_households["M7"].astype(int)

# License
df_persons["has_license"] = df_persons["P5"] == "1"
Expand Down Expand Up @@ -166,11 +167,6 @@ def execute(context):
# Nonrespondent of travel questionary section (number_of_trips = -1)
df_persons["number_of_trips"] = df_persons["number_of_trips"].fillna(-1).astype(int)

# Passenger attribute
df_persons["is_passenger"] = df_persons["person_id"].isin(
df_trips[df_trips["mode"] == "car_passenger"]["person_id"].unique()
)

# Calculate consumption units
hts.check_household_size(df_households, df_persons)
df_households = pd.merge(df_households, hts.calculate_consumption_units(df_persons), on = "household_id")
Expand Down
14 changes: 5 additions & 9 deletions data/hts/edgt_lyon/cleaned_adisp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def configure(context):
"car": [13, 15, 21, 81],
"car_passenger": [14, 16, 22, 82],
"pt": [31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 51, 52, 53, 61, 71, 91, 92, 94, 95],
"bike": [11, 17, 12, 18, 93],
"bicycle": [11, 17, 12, 18, 93],
# "motorbike": [13, 15],
"walk": [1, 2] # Actually, 2 is not really explained, but we assume it is walk
}

Expand Down Expand Up @@ -106,9 +107,9 @@ def execute(context):
df_persons["studies"] = df_persons["P9"].isin(["3", "4", "5"])

# Number of vehicles
df_households["number_of_vehicles"] = df_households["M6"] + df_households["M14"]
df_households["number_of_vehicles"] = df_households["number_of_vehicles"].astype(int)
df_households["number_of_bikes"] = df_households["M21"].astype(int)
df_households["number_of_cars"] = df_households["M6"].astype(int)
df_households["number_of_cars"] += df_households["M14"].astype(int) # motorbikes
df_households["number_of_bicycles"] = df_households["M21"].astype(int)

# License
df_persons["has_license"] = df_persons["P7"] == "1"
Expand Down Expand Up @@ -179,11 +180,6 @@ def execute(context):
# Nonrespondent of travel questionary section (number_of_trips = -1)
df_persons["number_of_trips"] = df_persons["number_of_trips"].fillna(-1).astype(int)

# Passenger attribute
df_persons["is_passenger"] = df_persons["person_id"].isin(
df_trips[df_trips["mode"] == "car_passenger"]["person_id"].unique()
)

# Calculate consumption units
hts.check_household_size(df_households, df_persons)
df_households = pd.merge(df_households, hts.calculate_consumption_units(df_persons), on = "household_id")
Expand Down
14 changes: 5 additions & 9 deletions data/hts/edgt_lyon/cleaned_cerema.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def configure(context):
"car": [13, 15, 21, 81],
"car_passenger": [14, 16, 22, 82],
"pt": [31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 51, 52, 53, 61, 71, 91, 92, 94, 95],
"bike": [11, 17, 12, 18, 93],
"bicycle": [11, 17, 12, 18, 93],
# "motorbike": [13, 15],
"walk": [1, 2] # Actually, 2 is not really explained, but we assume it is walk
}

Expand Down Expand Up @@ -105,9 +106,9 @@ def execute(context):
df_persons["studies"] = df_persons["P7"].isin(["3", "4", "5"])

# Number of vehicles
df_households["number_of_vehicles"] = df_households["M6"] + df_households["M5"]
df_households["number_of_vehicles"] = df_households["number_of_vehicles"].astype(int)
df_households["number_of_bikes"] = df_households["M7"].astype(int)
df_households["number_of_cars"] = df_households["M6"].astype(int)
df_households["number_of_cars"] += df_households["M5"].astype(int) # motorbikes
df_households["number_of_bicycles"] = df_households["M7"].astype(int)

# License
df_persons["has_license"] = df_persons["P5"] == "1"
Expand Down Expand Up @@ -180,11 +181,6 @@ def execute(context):
# Nonrespondent of travel questionary section (number_of_trips = -1)
df_persons["number_of_trips"] = df_persons["number_of_trips"].fillna(-1).astype(int)

# Passenger attribute
df_persons["is_passenger"] = df_persons["person_id"].isin(
df_trips[df_trips["mode"] == "car_passenger"]["person_id"].unique()
)

# Calculate consumption units
hts.check_household_size(df_households, df_persons)
df_households = pd.merge(df_households, hts.calculate_consumption_units(df_persons), on = "household_id")
Expand Down
2 changes: 1 addition & 1 deletion data/hts/edgt_lyon/raw_adisp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def configure(context):

HOUSEHOLD_COLUMNS = {
"ECH": str, "ZFM": str, # id
"M6": int, "M21": int, "M14": int, # number_of_cars, number_of_bikes, number_of_motorbikes
"M6": int, "M21": int, "M14": int, # number_of_cars, number_of_bicycles, number_of_motorbikes
"COE0": float # weights
}

Expand Down
15 changes: 5 additions & 10 deletions data/hts/egt/cleaned.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def configure(context):
1 : "pt",
2 : "car",
3 : "car_passenger",
4 : "car",
5 : "bike",
4 : "car", # motorbike
5 : "bicycle",
#6 : "pt", # default (other)
7 : "walk"
}
Expand Down Expand Up @@ -99,9 +99,9 @@ def execute(context):
df_persons["studies"] = df_persons["OCCP"].isin([3.0, 4.0, 5.0])

# Number of vehicles
df_households["number_of_vehicles"] = df_households["NB_2RM"] + df_households["NB_VD"]
df_households["number_of_vehicles"] = df_households["number_of_vehicles"].astype(int)
df_households["number_of_bikes"] = df_households["NB_VELO"].astype(int)
df_households["number_of_cars"] = df_households["NB_VD"].astype(int)
df_households["number_of_cars"] += df_households["NB_2RM"].astype(int) # motorbikes
df_households["number_of_bicycles"] = df_households["NB_VELO"].astype(int)

# License
df_persons["has_license"] = (df_persons["PERMVP"] == 1) | (df_persons["PERM2RM"] == 1)
Expand Down Expand Up @@ -172,11 +172,6 @@ def execute(context):
# Chain length
df_persons["number_of_trips"] = df_persons["NBDEPL"].fillna(0).astype(int)

# Passenger attribute
df_persons["is_passenger"] = df_persons["person_id"].isin(
df_trips[df_trips["mode"] == "car_passenger"]["person_id"].unique()
)

# Calculate consumption units
hts.check_household_size(df_households, df_persons)
df_households = pd.merge(df_households, hts.calculate_consumption_units(df_persons), on = "household_id")
Expand Down
18 changes: 6 additions & 12 deletions data/hts/entd/cleaned.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def configure(context):
MODES_MAP = [
("1", "walk"),
("2", "car"), #
("2.20", "bike"), # bike
("2.20", "bicycle"), # bike
("2.23", "car_passenger"), # motorcycle passenger
("2.25", "car_passenger"), # same
("3", "car"),
Expand Down Expand Up @@ -135,13 +135,12 @@ def execute(context):
df_persons.loc[df_persons["age"] < 5, "studies"] = False

# Number of vehicles
df_households["number_of_vehicles"] = 0
df_households["number_of_vehicles"] += df_households["V1_JNBVEH"].fillna(0)
df_households["number_of_vehicles"] += df_households["V1_JNBMOTO"].fillna(0)
df_households["number_of_vehicles"] += df_households["V1_JNBCYCLO"].fillna(0)
df_households["number_of_vehicles"] = df_households["number_of_vehicles"].astype(int)
df_households["number_of_cars"] = df_households["V1_JNBVEH"].fillna(0)
df_households["number_of_cars"] += df_households["V1_JNBMOTO"].fillna(0) # motorbike
df_households["number_of_cars"] += df_households["V1_JNBCYCLO"].fillna(0) # motorbike
df_households["number_of_cars"] = df_households["number_of_cars"].astype(int)

df_households["number_of_bikes"] = df_households["V1_JNBVELOADT"].fillna(0).astype(int)
df_households["number_of_bicycles"] = df_households["V1_JNBVELOADT"].fillna(0).astype(int)

# License
df_persons["has_license"] = (df_persons["V1_GPERMIS"] == 1) | (df_persons["V1_GPERMIS2R"] == 1)
Expand Down Expand Up @@ -236,11 +235,6 @@ def execute(context):
df_persons["number_of_trips"] = df_persons["number_of_trips"].fillna(-1).astype(int)
df_persons.loc[(df_persons["number_of_trips"] == -1) & df_persons["is_kish"], "number_of_trips"] = 0

# Passenger attribute
df_persons["is_passenger"] = df_persons["person_id"].isin(
df_trips[df_trips["mode"] == "car_passenger"]["person_id"].unique()
)

# Calculate consumption units
hts.check_household_size(df_households, df_persons)
df_households = pd.merge(df_households, hts.calculate_consumption_units(df_persons), on = "household_id")
Expand Down
4 changes: 2 additions & 2 deletions data/hts/hts.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def calculate_consumption_units(df_persons):

HOUSEHOLD_COLUMNS = [
"household_id", "household_weight", "household_size",
"number_of_vehicles", "number_of_bikes", "departement_id",
"number_of_cars", "number_of_bicycles", "departement_id",
"consumption_units", # "income_class"
]

Expand All @@ -231,7 +231,7 @@ def calculate_consumption_units(df_persons):
"age", "sex", "employed", "studies",
"has_license", "has_pt_subscription",
"number_of_trips", "departement_id", "trip_weight",
"is_passenger", "socioprofessional_class"
"socioprofessional_class"
]

TRIP_COLUMNS = [
Expand Down
4 changes: 2 additions & 2 deletions data/od/cleaned.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def execute(context):
df_work["commute_mode"] = np.nan
df_work.loc[df_work["TRANS"] == 1, "commute_mode"] = "no transport"
df_work.loc[df_work["TRANS"] == 2, "commute_mode"] = "walk"
df_work.loc[df_work["TRANS"] == 3, "commute_mode"] = "bike"
df_work.loc[df_work["TRANS"] == 4, "commute_mode"] = "car"
df_work.loc[df_work["TRANS"] == 3, "commute_mode"] = "bicycle"
df_work.loc[df_work["TRANS"] == 4, "commute_mode"] = "car" # motorbike
df_work.loc[df_work["TRANS"] == 5, "commute_mode"] = "car"
df_work.loc[df_work["TRANS"] == 6, "commute_mode"] = "pt"
df_work["commute_mode"] = df_work["commute_mode"].astype("category")
Expand Down
5 changes: 2 additions & 3 deletions documentation/plots/secondary_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def execute(context):
plt.figure()

modes = list(context.stage("analysis.reference.hts.mode_distances").keys())
#modes = ["car", "car_passenger", "pt", "bike", "walk"]

for index, mode in enumerate(modes):
mode_distribution = distributions[mode]
Expand Down Expand Up @@ -71,10 +70,10 @@ def execute(context):

limits = dict(
car = 20 * 1e3, car_passenger = 20 * 1e3, pt = 20 * 1e3,
bike = 6 * 1e3, walk = 1 * 1e3
bicycle = 6 * 1e3, walk = 1 * 1e3
)

modes = ["car", "bike" if "bike" in modes else "walk" ]
modes = ["car", "bicycle" if "bicycle" in modes else "walk" ]

for index, mode in enumerate(modes):
plt.subplot(1, 2, index + 1)
Expand Down
10 changes: 5 additions & 5 deletions documentation/plots/sociodemographics/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ def label(row):
elif row["attribute"] == "household_size_class":
return "Household size %s" % analysis.marginals.HOUSEHOLD_SIZE_LABELS[row["value"]]

elif row["attribute"] == "number_of_vehicles_class":
return "No. vehicles %s" % analysis.marginals.NUMBER_OF_VEHICLES_LABELS[row["value"]]
elif row["attribute"] == "number_of_cars_class":
return "No. vehicles %s" % analysis.marginals.NUMBER_OF_CARS_LABELS[row["value"]]

elif row["attribute"] == "number_of_bikes_class":
return "No. bicycles %s" % analysis.marginals.NUMBER_OF_BIKES_LABELS[row["value"]]
elif row["attribute"] == "number_of_bicycles_class":
return "No. bicycles %s" % analysis.marginals.NUMBER_OF_BICYCLES_LABELS[row["value"]]

def add_labels(df_figure):
df_figure["label"] = df_figure.apply(label, axis = 1, raw = False)
Expand Down Expand Up @@ -115,7 +115,7 @@ def execute(context):
),
dict(
level = "household", label = "Number of households", size = plotting.WIDE_FIGSIZE,
marginals = ["household_size_class", "number_of_vehicles_class", "number_of_bikes_class"]
marginals = ["household_size_class", "number_of_cars_class", "number_of_bikes_class"]
)
]

Expand Down
2 changes: 1 addition & 1 deletion documentation/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
car = "Car driver",
car_passenger = "Car passenger",
pt = "Public transport",
bike = "Bicycle",
bicycle = "Bicycle",
walk = "Walking"
)

Expand Down
4 changes: 2 additions & 2 deletions matsim/runtime/eqasim.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import matsim.runtime.maven as maven

DEFAULT_EQASIM_VERSION = "1.5.0"
DEFAULT_EQASIM_BRANCH = "develop"
DEFAULT_EQASIM_COMMIT = "ece4932"
DEFAULT_EQASIM_BRANCH = "feat/model-2024"
DEFAULT_EQASIM_COMMIT = "c0645372"

def configure(context):
context.stage("matsim.runtime.git")
Expand Down
4 changes: 2 additions & 2 deletions matsim/scenario/households.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
def configure(context):
context.stage("synthesis.population.enriched")

FIELDS = ["household_id", "person_id", "household_income", "car_availability", "bike_availability", "census_household_id"]
FIELDS = ["household_id", "person_id", "household_income", "car_availability", "bicycle_availability", "census_household_id"]

def add_household(writer, household, member_ids):
writer.start_household(household[FIELDS.index("household_id")])
writer.add_members(member_ids)

writer.start_attributes()
writer.add_attribute("carAvailability", "java.lang.String", household[FIELDS.index("car_availability")])
writer.add_attribute("bikeAvailability", "java.lang.String", household[FIELDS.index("bike_availability")])
writer.add_attribute("bicycleAvailability", "java.lang.String", household[FIELDS.index("bicycle_availability")])
writer.add_attribute("household_income", "java.lang.Double", household[FIELDS.index("household_income")])
writer.add_attribute("censusId", "java.lang.Long", household[FIELDS.index("census_household_id")])
writer.end_attributes()
Expand Down
Loading
Loading