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

MAL 2023 Car ownership #434

Draft
wants to merge 16 commits into
base: olusanya
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Scripts/assignment/emme_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def aggregate_results(self, resultdata):
linktypes.add(param.roadtypes[linktype])
linklengths = pandas.Series(0.0, linktypes)
soft_modes = param.transit_classes + ("bike",)
attr_names = self.day_scenario.attributes("LINK")
resultdata.print_line("Link\t" + "\t".join(attr_names), "links")
network = self.day_scenario.get_network()
for link in network.links():
linktype = link.type % 100
Expand All @@ -197,6 +199,10 @@ def aggregate_results(self, resultdata):
linklengths[param.railtypes[linktype]] += link.length
else:
linklengths[param.roadtypes[vdf]] += link.length / 2
wkt = "LINESTRING ({} {}, {} {})".format(
link.i_node.x, link.i_node.y, link.j_node.x, link.j_node.y)
attrs = "\t".join([str(link[attr]) for attr in attr_names])
resultdata.print_line(wkt + "\t" + attrs, "links")
if faulty_kela_code_nodes:
s = "Municipality KELA code not found for nodes: " + ", ".join(
faulty_kela_code_nodes)
Expand Down
5 changes: 5 additions & 0 deletions Scripts/assignment/emme_bindings/mock_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ def __init__(self, idx):
def zone_numbers(self):
return sorted(self._network._centroids)

def attributes(self, attr_type):
network = self.get_network()
# TODO Return other attributes except extra attributes
return list(network._extra_attr[attr_type])

def extra_attribute(self, idx):
network = self.get_network()
for attr_type in network._extra_attr:
Expand Down
14 changes: 14 additions & 0 deletions Scripts/helmet.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def main(args):
results_path, ass_model, args.scenario_name)
log_extra["status"]["results"] = model.mode_share

model.cdm.set_car_growth(constant=args.car_growth_constant,
factor=args.car_growth_factor)

# Run traffic assignment simulation for N iterations,
# on last iteration model-system will save the results
log_extra["status"]["state"] = "preparing"
Expand Down Expand Up @@ -247,6 +250,17 @@ def main(args):
action="store_true",
default=config.USE_FIXED_TRANSIT_COST,
help="Using this flag activates use of pre-calculated (fixed) transit costs."),
# MAL 2023 input data
parser.add_argument(
"--car-growth-constant",
type=float,
default=0.0,
help="Car ownership growth constant. To increase, try 0.1."),
parser.add_argument(
"--car-growth-factor",
type=float,
default=1.0,
help="Car ownership growth factor. To decrease, try 0.8."),
args = parser.parse_args()

log.initialize(args)
Expand Down
20 changes: 18 additions & 2 deletions Scripts/models/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,24 @@ def __init__(self, zone_data_base, zone_data_forecast, bounds, resultdata):
out=numpy.array(forecast_sh_detached), where=pop_growth!=0)
self.zone_data._values["share_detached_houses_new"] = pandas.Series(
share_detached_new, self.zone_data.zone_numbers[self.bounds])

self.set_car_growth()

def set_car_growth(self, constant=0.0, factor=1.0):
"""Set extra car ownership growth for sensitivity analyses.

Parameters
----------
constant : float (optional)
Constant to add to prediction
factor : float (optional)
Factor to multiply prediction by
"""
self._growth_constant = constant
self._growth_factor = factor

def predict(self):
"""Get car ownership prediction for zones.

Return
------
pandas.Series
Expand All @@ -108,6 +122,8 @@ def predict(self):
.clip(upper=1.0))
prediction = (self.pop_growth_share * prediction
+ (1-self.pop_growth_share) * base_car_density)
prediction += self._growth_constant
prediction *= self._growth_factor
self.print_results(prediction)
return prediction

Expand Down