def __init__(self, parent_thread, layer, index_field, fields, file_name): WorkerThread.__init__(self, parent_thread) self.layer = layer self.index_field = index_field self.fields = fields self.error = None self.python_version = (8 * struct.calcsize("P")) self.output = AequilibraEData() self.output_name = file_name
def load_from_aequilibrae_format(self): out_name, _ = GetOutputFileName(self, 'AequilibraE dataset', ["Aequilibrae dataset(*.aed)"], '.aed', self.path) try: self.dataset = AequilibraEData() self.dataset.load(out_name) except: self.error = 'Could not load file. It might be corrupted or might not be a valid AequilibraE file' self.exit_procedure()
def test___init__(self): # Generates the dataset dataset = AequilibraEData() dataset.create_empty(**args) dataset.index[:] = np.arange(dataset.entries) + 100 dataset.d[:] = dataset.index[:]**2 if dataset.index[70] != 170: self.fail() if int(dataset.d[70]) != 28900: self.fail() # removes the dataset del(dataset)
def test_load(self): # re-imports the dataset self.ad = AequilibraEData() self.ad.load(file_path) # checks if the values were properly saved if self.ad.index[70] != 170: self.fail("Value for data index test was not as expected") if int(self.ad.d[70]) != 28900: self.fail("Value for data field test was not as expected") for f in self.ad.fields: if f not in args["field_names"]: self.fail("Could not retrieve all fields")
from aequilibrae.distribution import SyntheticGravityModel, GravityApplication import numpy as np import tempfile import os zones = 10 # row vector args = { "entries": zones, "field_names": [u"rows"], "data_types": [np.float64], "memory_mode": True, } row_vector = AequilibraEData() row_vector.create_empty(**args) row_vector.index[:] = np.arange(row_vector.entries) + 100 row_vector.rows[:] = row_vector.index[:] + np.random.rand(zones)[:] # column vector args["field_names"] = ["columns"] column_vector = AequilibraEData() column_vector.create_empty(**args) column_vector.index[:] = np.arange(column_vector.entries) + 100 column_vector.columns[:] = column_vector.index[:] + np.random.rand(zones)[:] # balance vectors column_vector.columns[:] = column_vector.columns[:] * ( row_vector.rows.sum() / column_vector.columns.sum() )
def __init__(self, iface): QtWidgets.QDialog.__init__(self) self.iface = iface self.setupUi(self) self.error = None self.error = None self.data_path, self.data_type = GetOutputFileName( self, 'AequilibraE custom formats', ["Aequilibrae dataset(*.aed)", "Aequilibrae matrix(*.aem)"], '.aed', standard_path()) if self.data_type is None: self.error = 'Path provided is not a valid dataset' self.exit_with_error() self.data_type = self.data_type.upper() if self.data_type == 'AED': self.data_to_show = AequilibraEData() elif self.data_type == 'AEM': self.data_to_show = AequilibraeMatrix() try: self.data_to_show.load(self.data_path) except: self.error = 'Could not load dataset' self.exit_with_error() # Elements that will be used during the displaying self._layout = QVBoxLayout() self.table = QTableView() self._layout.addWidget(self.table) # Settings for displaying self.show_layout = QHBoxLayout() # Thousand separator self.thousand_separator = QCheckBox() self.thousand_separator.setChecked(True) self.thousand_separator.setText('Thousands separator') self.thousand_separator.toggled.connect(self.format_showing) self.show_layout.addWidget(self.thousand_separator) self.spacer = QSpacerItem(5, 0, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.show_layout.addItem(self.spacer) # Decimals txt = QLabel() txt.setText('Decimal places') self.show_layout.addWidget(txt) self.decimals = QSpinBox() self.decimals.valueChanged.connect(self.format_showing) self.decimals.setMinimum(0) self.decimals.setValue(4) self.decimals.setMaximum(10) self.show_layout.addWidget(self.decimals) self._layout.addItem(self.show_layout) # differentiates between matrix and dataset if self.data_type == 'AEM': self.data_to_show.computational_view([self.data_to_show.names[0]]) # Matrices need cores and indices to be set as well self.mat_layout = QHBoxLayout() self.mat_list = QComboBox() for n in self.data_to_show.names: self.mat_list.addItem(n) self.mat_list.currentIndexChanged.connect(self.change_matrix_cores) self.mat_layout.addWidget(self.mat_list) self.idx_list = QComboBox() for i in self.data_to_show.index_names: self.idx_list.addItem(i) self.idx_list.currentIndexChanged.connect(self.change_matrix_cores) self.mat_layout.addWidget(self.idx_list) self._layout.addItem(self.mat_layout) self.change_matrix_cores() self.but_export = QPushButton() self.but_export.setText('Export') self.but_export.clicked.connect(self.export) self.but_close = QPushButton() self.but_close.clicked.connect(self.exit_procedure) self.but_close.setText('Close') self.but_layout = QHBoxLayout() self.but_layout.addWidget(self.but_export) self.but_layout.addWidget(self.but_close) self._layout.addItem(self.but_layout) # We chose to use QTableView. However, if we want to allow the user to edit the dataset # The we need to allow them to switch to the slower QTableWidget # Code below # self.table = QTableWidget(self.data_to_show.entries, self.data_to_show.num_fields) # self.table.setHorizontalHeaderLabels(self.data_to_show.fields) # self.table.setObjectName('data_viewer') # # self.table.setVerticalHeaderLabels([str(x) for x in self.data_to_show.index[:]]) # self.table.clearContents() # # for i in range(self.data_to_show.entries): # for j, f in enumerate(self.data_to_show.fields): # item1 = QTableWidgetItem(str(self.data_to_show.data[f][i])) # item1.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) # self.table.setItem(i, j, item1) self.resize(700, 500) self.setLayout(self._layout) self.format_showing()
import os import tempfile import uuid from unittest import TestCase import tempfile import numpy as np from aequilibrae.matrix import AequilibraEData file_path = AequilibraEData().random_name() args = {'file_path': file_path, 'entries': 100, 'field_names': ['d', 'data2', 'data3'], 'data_types': [np.float64, np.float32, np.int8]} class TestAequilibraEData(TestCase): def test___init__(self): # Generates the dataset dataset = AequilibraEData() dataset.create_empty(**args) dataset.index[:] = np.arange(dataset.entries) + 100 dataset.d[:] = dataset.index[:]**2 if dataset.index[70] != 170: self.fail() if int(dataset.d[70]) != 28900: self.fail() # removes the dataset del(dataset)