aequilibrae.matrix package

Submodules

aequilibrae.matrix.aequilibrae_data module

class aequilibrae.matrix.aequilibrae_data.AequilibraeData

Bases: object

create_empty(file_path=None, entries=1, field_names=None, data_types=None, memory_mode=False)
Parameters

file_path – Optional. Full path for the output data file. If memory_false is ‘false’ and path is missing,

then the file is created in the temp folder :param entries: Number of records in the dataset. Default is 1 :param field_names: List of field names for this dataset. If no list is provided, the field ‘data’ will be created :param data_types: List of data types for the dataset. Types need to be NumPy data types (e.g. np.int16, np.float64). If no list of types are provided, type will be np.float64 :param memory_mode: If true, dataset will be kept in memory. If false, the dataset will be a memory-mapped numpy array :return: # nothing. Associates a dataset with the AequilibraeData object

export(file_name, table_name='aequilibrae_table')
Parameters
  • file_name – File name with PATH and extension (csv, or sqlite3, sqlite or db)

  • table_name (str) – It only applies if you are saving to an SQLite table. Otherwise ignored

Returns

load(file_path)
Parameters

file_path – Full file path to the AequilibraeData to be loaded

Returns

Loads the dataset into the AequilibraeData instance

static random_name()

aequilibrae.matrix.aequilibrae_matrix module

class aequilibrae.matrix.aequilibrae_matrix.AequilibraeMatrix

Bases: object

Matrix class

close()

Removes matrix from memory and flushes all data to disk, or closes the OMX file if that is the case

columns()

Returns column vector for the matrix in the computational view

Computational view needs to be set to a single matrix core

Example

>>> mat = AequilibraeMatrix()
>>> mat.load('my/path/to/file')
>>> mat.computational_view(mat.cores[0])
>>> mat.columns()
array([0.,...,0.])
computational_view(core_list: List[str] = None)

Creates a memory view for a list of matrices that is compatible with Cython memory buffers

It allows for AequilibraE matrices to be used in all parallelized algorithms within AequilibraE

In case of OMX matrices, the computational view is held only in memory

Example

>>> zones_in_the_model = 3317
>>> names_list = ['Car trips', 'pt trips', 'DRT trips', 'bike trips', 'walk trips']
>>> mat = AequilibraeMatrix()
>>> mat.create_empty(file_name='my/path/to/file', zones=zones_in_the_model, matrix_names= names_list)
>>> mat.computational_view(['bike trips', 'walk trips'])
>>> mat.view_names
['bike trips', 'walk trips']
copy(output_name: str = None, cores: List[str] = None, names: List[str] = None, compress: bool = None)

Copies a list of cores (or all cores) from one matrix file to another one

output_name: Name of the new matrix file

cores: List (str)

List of the matrix cores to be copied

names: List(str), optional

List with the new names for the cores (same list length as cores)

compress: bool

Whether you want to compress the matrix or not. NOT YET IMPLEMENTED

Example

>>> zones_in_the_model = 3317
>>> names_list = ['Car trips', 'pt trips', 'DRT trips', 'bike trips', 'walk trips']
>>> mat = AequilibraeMatrix()
>>> mat.create_empty(file_name='my/path/to/file', zones=zones_in_the_model, matrix_names= names_list)
>>> mat.copy('my/new/path/to/file', cores=['bike trips', 'walk trips'], names=['bicycle', 'walking'])
>>> mat2 = AequilibraeMatrix()
>>> mat2.load('my/new/path/to/file')
>>> mat.cores
['bicycle', 'walking']
create_empty(file_name: str = None, zones: int = None, matrix_names: List[str] = None, data_type: numpy.dtype = <class 'numpy.float64'>, index_names: List[str] = None, compressed: bool = False)

Creates an empty matrix in the AequilibraE format

file_name: string

Local path to the matrix file

zones: integer

Number of zones in the model (Integer). Maximum number of zones in a matrix is 4,294,967,296

matrix_names: list

A regular Python list of names of the matrix. Limit is 50 characters each. Maximum number of cores per matrix is 256

data_type: np.dtype, optional

Data type of the matrix as NUMPY data types (NP.int32, np.int64, np.float32, np.float64). Dafaultis np.float64

index_names: list, optional

A regular Python list of names for indices. Limit is 20 characters each). Maximum number of indices per matrix is 256

compressed: bool, optional

Whether it is a flat matrix or a compressed one(Boolean - Not yet implemented)

Example

>>> zones_in_the_model = 3317
>>> names_list = ['Car trips', 'pt trips', 'DRT trips', 'bike trips', 'walk trips']
>>> mat = AequilibraeMatrix()
>>> mat.create_empty(file_name='my/path/to/file', zones=zones_in_the_model, matrix_names= names_list)
>>> mat.num_indices
1
>>> mat.zones
3317
>>> np.sum(mat[trips])
0.0
create_from_omx(file_path: str, omx_path: str, cores: List[str] = None, mappings: List[str] = None, robust: bool = True, compressed: bool = False)
Parameters
  • file_path (str) – Path for the output AequilibraEMatrix

  • omx_path (str) – Path to the OMX file one wants to import

  • cores – List of matrix cores to be imported

  • mappings – List of the matrix mappings (i.e. indices, centroid numbers) to be imoprted

Param

robust: Boolean for whether AequilibraE should try to adjust the names for cores and indices in case they are too long

Param

compressed

Returns

define_data_class()
export(output_name: str, cores: List[str] = None)

Exports the matrix to other formats. Formats currently supported: CSV, OMX

When exporting to AEM or OMX, the user can chose to export only a set of cores, but all indices are exported

When exporting to CSV, the active index will be used, and all cores will be exported as separate columns in the output file

output_name: Name of the output file

cores: Names of the cores to be exported.

Example

>>> zones_in_the_model = 3317
>>> names_list = ['Car trips', 'pt trips', 'DRT trips', 'bike trips', 'walk trips']
>>> mat = AequilibraeMatrix()
>>> mat.create_empty(file_name='my/path/to/file', zones=zones_in_the_model, matrix_names= names_list)
>>> mat.cores
['Car trips', 'pt trips', 'DRT trips', 'bike trips', 'walk trips']
>>> mat.export('my_new_path', ['Car trips', 'bike trips'])
>>> mat2 = AequilibraeMatrix()
>>> mat2.load('my_new_path')
>>> mat2.cores
['Car trips', 'bike trips']
load(file_path: str)

Loads matrix from disk. All cores and indices are load. First index is default

Example

>>> zones_in_the_model = 3317
>>> names_list = ['Car trips', 'pt trips', 'DRT trips', 'bike trips', 'walk trips']
>>> mat = AequilibraeMatrix()
>>> mat.create_empty(file_name='my/path/to/file', zones=zones_in_the_model, matrix_names= names_list)
>>> mat.close()
>>> mat2 = AequilibraeMatrix()
>>> mat2.load('my/path/to/file')
>>> mat2.zones
3317
nan_to_num()

Converts all NaN values in all cores in the computational view to zeros

Example

>>> mat = AequilibraeMatrix()
>>> mat.load('my/path/to/file')
>>> mat.computational_view(mat.cores[0])
>>> mat.nan_to_num()
static random_name() → str

Returns a random name for a matrix with root in the temp directory of the user

Example

>>> name = AequilibraeMatrix().random_name()
'/tmp/Aequilibrae_matrix_54625f36-bf41-4c85-80fb-7fc2e3f3d76e.aem'
rows()

Returns row vector for the matrix in the computational view

Computational view needs to be set to a single matrix core

Example

>>> mat = AequilibraeMatrix()
>>> mat.load('my/path/to/file')
>>> mat.computational_view(mat.cores[0])
>>> mat.rows()
array([0.,...,0.])
setDescription(matrix_description: str)

Sets description for the matrix

matrix_name: str

Text with matrix description . Maximum length is 144 characters

Example

>>> mat = AequilibraeMatrix()
>>> mat.load('my/path/to/file')
>>> mat.setDescription('This is some text about this matrix of mine')
>>> mat.description
'This is some text about this matrix of mine'
setName(matrix_name: str)

Sets the name for the matrix itself

matrix_name: str

matrix name. Maximum length is 50 characters

Example

>>> mat = AequilibraeMatrix()
>>> mat.load('my/path/to/file')
>>> mat.setName('This is my example')
>>> mat.name
'This is my example'
set_index(index_to_set: str) → None

Sets the standard index to be the one the user wants to have be the one being used in all operations during run time. The first index is ALWAYS the default one every time the matrix is instantiated

index_to_set: string

Name of the index to be used. The default index name is ‘main_index’

Example

>>> zones_in_the_model = 3317
>>> names_list = ['Car trips', 'pt trips', 'DRT trips', 'bike trips', 'walk trips']
>>> index_list = ['tazs',  'census']
>>> mat = AequilibraeMatrix()
>>> mat.create_empty(file_name='my/path/to/file', zones=zones_in_the_model, matrix_names=names_list, index_names =index_list )
>>> mat.num_indices
2
>>> mat.current_index
'tazs'
>>> mat.set_index('census')
>>> mat.current_index
'census'

Module contents