aequilibrae.distribution.GravityCalibration#

class aequilibrae.distribution.GravityCalibration(project=None, **kwargs)[source]#

Calibrate a traditional gravity model

Available deterrence function forms are: ‘EXPO’ or ‘POWER’. ‘GAMMA’

>>> from aequilibrae import Project
>>> from aequilibrae.matrix import AequilibraeMatrix
>>> from aequilibrae.distribution import GravityCalibration

>>> project = Project.from_path("/tmp/test_project_gc")

# We load the impedance matrix
>>> matrix = AequilibraeMatrix()
>>> matrix.load('/tmp/test_project_gc/matrices/demand.omx')
>>> matrix.computational_view(['matrix'])

# We load the impedance matrix
>>> impedmatrix = AequilibraeMatrix()
>>> impedmatrix.load('/tmp/test_project_gc/matrices/skims.omx')
>>> impedmatrix.computational_view(['time_final'])

# Creates the problem
>>> args = {"matrix": matrix,
...         "impedance": impedmatrix,
...         "row_field": "productions",
...         "function": 'expo',
...         "nan_as_zero": True}
>>> gravity = GravityCalibration(**args)

# Solve and save outputs
>>> gravity.calibrate()
>>> gravity.model.save('/tmp/test_project_gc/dist_expo_model.mod')

# To save the model report in a file
# with open('/tmp/test_project_gc/report.txt', 'w') as f:
#     for line in gravity.report:
#         f.write(f'{line}\n')
__init__(project=None, **kwargs)[source]#

Instantiates the Gravity calibration problem

Arguments:

matrix (AequilibraeMatrix): Seed/base trip matrix

impedance (AequilibraeMatrix): Impedance matrix to be used

function (str): Function name to be calibrated. “EXPO” or “POWER”

project (Project, optional): The Project to connect to. By default, uses the currently active project

parameters (str, optional): Convergence parameters. Defaults to those in the parameter file

nan_as_zero (bool, optional): If Nan values should be treated as zero. Defaults to True

Results:

model (SyntheticGravityModel): Calibrated model

report (list): Iteration and convergence report

error (str): Error description

Methods

__init__([project])

Instantiates the Gravity calibration problem

calibrate()

Calibrate the model