From 2f454413b27bf1183883d4d94dfdeaf9bc4bab39 Mon Sep 17 00:00:00 2001 From: Sijia Wang Date: Wed, 10 Jul 2024 10:39:17 -0400 Subject: [PATCH] Revert "separate TAZ and MAZ network" This reverts commit eb0785849aa2fe9c9d2d8237c11b59f2c6acfa87. --- tm2py/components/demand/commercial.py | 2 +- tm2py/components/demand/demand.py | 2 +- tm2py/components/demand/prepare_demand.py | 4 +- .../network/create_tod_scenarios.py | 33 +++----- .../network/highway/drive_access_skims.py | 2 +- .../network/highway/highway_assign.py | 78 +------------------ .../components/network/highway/highway_maz.py | 11 +-- .../network/highway/highway_network.py | 2 +- .../network/transit/transit_network.py | 2 +- tm2py/config.py | 6 +- tm2py/emme/manager.py | 24 ++---- 11 files changed, 32 insertions(+), 134 deletions(-) diff --git a/tm2py/components/demand/commercial.py b/tm2py/components/demand/commercial.py index 128ce623..65af8fde 100644 --- a/tm2py/components/demand/commercial.py +++ b/tm2py/components/demand/commercial.py @@ -144,7 +144,7 @@ def emmebank(self): This should really be in the controller? Or part of network.skims? """ - self._emmebank = self.controller.emme_manager.highway_taz_emmebank + self._emmebank = self.controller.emme_manager.highway_emmebank return self._emmebank @property diff --git a/tm2py/components/demand/demand.py b/tm2py/components/demand/demand.py index 86bdad0d..24da7202 100644 --- a/tm2py/components/demand/demand.py +++ b/tm2py/components/demand/demand.py @@ -84,7 +84,7 @@ def __init__(self, controller: RunController): # @LogStartEnd("prepare highway demand") def run(self): """Open combined demand OMX files from demand models and prepare for assignment.""" - self._emmebank_path = self.get_abs_path(self.config.emme.highway_taz_database_path) + self._emmebank_path = self.get_abs_path(self.config.emme.highway_database_path) self._emmebank = self.controller.emme_manager.emmebank(self._emmebank_path) self._create_zero_matrix() for time in self.time_period_names(): diff --git a/tm2py/components/demand/prepare_demand.py b/tm2py/components/demand/prepare_demand.py index c134b3bb..b6d8f66d 100644 --- a/tm2py/components/demand/prepare_demand.py +++ b/tm2py/components/demand/prepare_demand.py @@ -164,7 +164,7 @@ def validate_inputs(self): @property def highway_emmebank(self): if self._highway_emmebank == None: - self._highway_emmebank = self.controller.emme_manager.highway_taz_emmebank + self._highway_emmebank = self.controller.emme_manager.highway_emmebank self._emmebank = self._highway_emmebank return self._highway_emmebank @@ -584,7 +584,7 @@ def num_internal_zones(self): @property def num_total_zones(self): self._emmebank_path = self.controller.get_abs_path( - self.controller.config.emme.highway_taz_database_path + self.controller.config.emme.highway_database_path ) self._emmebank = self.controller.emme_manager.emmebank(self._emmebank_path) time_period = self.controller.config.time_periods[0].name diff --git a/tm2py/components/network/create_tod_scenarios.py b/tm2py/components/network/create_tod_scenarios.py index 4b718f42..7cf5a9c5 100644 --- a/tm2py/components/network/create_tod_scenarios.py +++ b/tm2py/components/network/create_tod_scenarios.py @@ -46,8 +46,7 @@ def run(self): # emme_app = self._emme_manager.project(project_path) # self._emme_manager.init_modeller(emme_app) with self._setup(): - self._create_highway_scenarios(zone_flag="taz") - self._create_highway_scenarios(zone_flag="maz") + self._create_highway_scenarios() self._create_transit_scenarios() @_context @@ -91,32 +90,20 @@ def _project_coordinates(self, ref_scenario): emme_app.project.save() @LogStartEnd("Create highway time of day scenarios.") - def _create_highway_scenarios(self, zone_flag = "taz"): - if zone_flag == "taz": - emmebank = self.controller.emme_manager.highway_taz_emmebank.emmebank - else: - emmebank = self.controller.emme_manager.highway_maz_emmebank.emmebank + def _create_highway_scenarios(self): + emmebank = self.controller.emme_manager.highway_emmebank.emmebank ref_scenario = emmebank.scenario( self.controller.config.emme.all_day_scenario_id ) self._ref_auto_network = ref_scenario.get_network() n_time_periods = len(self.controller.config.time_periods) - if zone_flag == "taz": - self.controller.emme_manager.highway_taz_emmebank.change_dimensions( - { - "scenarios": 1 + n_time_periods, - "full_matrices": 9999, - "extra_attribute_values": 60000000, - } - ) - else: - self.controller.emme_manager.highway_maz_emmebank.change_dimensions( - { - "scenarios": 1 + n_time_periods, - "full_matrices": 9999, - "extra_attribute_values": 60000000, - } - ) + self.controller.emme_manager.highway_emmebank.change_dimensions( + { + "scenarios": 1 + n_time_periods, + "full_matrices": 9999, + "extra_attribute_values": 60000000, + } + ) # create VDFs & set cross-reference function parameters emmebank.extra_function_parameters.el1 = "@free_flow_time" emmebank.extra_function_parameters.el2 = "@capacity" diff --git a/tm2py/components/network/highway/drive_access_skims.py b/tm2py/components/network/highway/drive_access_skims.py index d96bc0f4..59eb82b1 100644 --- a/tm2py/components/network/highway/drive_access_skims.py +++ b/tm2py/components/network/highway/drive_access_skims.py @@ -199,7 +199,7 @@ def process_stops(stops): def _get_drive_costs(self, period: TimePeriodConfig) -> pd.DataFrame: """Load the drive costs from OMX matrix files, return as pandas dataframe.""" - emmebank = self.controller.emme_manager.highway_taz_emmebank.emmebank + emmebank = self.controller.emme_manager.highway_emmebank.emmebank scenario = emmebank.scenario(period.emme_scenario_id) zone_numbers = scenario.zone_numbers network = self.controller.emme_manager.get_network( diff --git a/tm2py/components/network/highway/highway_assign.py b/tm2py/components/network/highway/highway_assign.py index 852175de..16fe772f 100644 --- a/tm2py/components/network/highway/highway_assign.py +++ b/tm2py/components/network/highway/highway_assign.py @@ -103,13 +103,11 @@ def __init__(self, controller: RunController): self._class_config = None self._scenario = None self._highway_emmebank = None - self._highway_maz_scenarios = None - self._highway_maz_emmebank = None @property def highway_emmebank(self): if not self._highway_emmebank: - self._highway_emmebank = self.controller.emme_manager.highway_taz_emmebank + self._highway_emmebank = self.controller.emme_manager.highway_emmebank return self._highway_emmebank @property @@ -124,20 +122,6 @@ def class_config(self): self._class_config = {c.name: c for c in self.config.classes} return self._class_config - - @property - def highway_maz_emmebank(self): - if not self._highway_maz_emmebank: - self._highway_maz_emmebank = self.controller.emme_manager.highway_maz_emmebank - return self._highway_maz_emmebank - - @property - def highway_maz_scenarios(self): - if self._highway_maz_scenarios is None: - self._highway_maz_scenarios = { - tp: self.highway_maz_emmebank.scenario(tp) for tp in self.time_period_names - } - return self._highway_maz_scenarios def validate_inputs(self): """Validate inputs files are correct, raise if an error is found.""" @@ -160,7 +144,7 @@ def run(self): AssignmentClass(c, time, iteration) for c in self.config.classes ] if iteration > 0: - self._copy_maz_flow(scenario, time) + self._copy_maz_flow(scenario) else: self._reset_background_traffic(scenario) self._create_skim_matrices(scenario, assign_classes) @@ -248,72 +232,16 @@ def _setup(self, scenario: EmmeScenario, time_period: str): self._matrix_cache.clear() self._matrix_cache = None self._skim_matrices = [] - - def _get_maz_links( - self, - time_period: str, - ): - """Create dictionary of link ids mapped to maz network. - - Args: - time_period (str): time period abbreviation - """ - _highway_maz_scenario = self.highway_maz_scenarios[time_period] - if not _highway_maz_scenario.has_traffic_results: - return {} - _highway_maz_net = _highway_maz_scenario.get_partial_network( - ["LINK"], include_attributes=False - ) - - highway_attributes = { - "LINK": ["#link_id", "@maz_flow"] - } - self.emme_manager.copy_attribute_values( - _highway_maz_scenario, _highway_maz_net, highway_attributes - ) - - # TODO can we just get the link attributes as a DataFrame and merge them? - maz_link_dict = { - maz_link["#link_id"]: maz_link for maz_link in _highway_maz_net.links() - } - - return maz_link_dict - - def _copy_maz_flow(self, scenario: EmmeScenario, time_period: str): + def _copy_maz_flow(self, scenario: EmmeScenario): """Copy maz_flow from MAZ demand assignment to ul1 for background traffic. Args: scenario: Emme scenario object - time_period (str): time period abbreviation """ - - _highway_net = scenario.get_partial_network( - ["LINK"], include_attributes=False - ) - highway_attributes = { - "LINK": ["#link_id", "@maz_flow"] - } - self.emme_manager.copy_attribute_values( - scenario, _highway_net, highway_attributes - ) - - _maz_link_dict = self._get_maz_links(time_period) - self.logger.log( "Copy @maz_flow to ul1 for background traffic", indent=True, level="DETAIL" ) - for link in _highway_net.links(): - if link["#link_id"] in _maz_link_dict.keys(): - link["@maz_flow"] = _maz_link_dict[link["#link_id"]]["@maz_flow"] - - _update_attributes = { - "LINK": ["@maz_flow"], - } - self.emme_manager.copy_attribute_values( - _highway_net, scenario, _update_attributes - ) - net_calc = NetworkCalculator(self.controller, scenario) net_calc("ul1", "@maz_flow") diff --git a/tm2py/components/network/highway/highway_maz.py b/tm2py/components/network/highway/highway_maz.py index 28180a2c..a43c0c3d 100644 --- a/tm2py/components/network/highway/highway_maz.py +++ b/tm2py/components/network/highway/highway_maz.py @@ -99,7 +99,7 @@ def __init__(self, controller: RunController): @property def highway_emmebank(self): if self._highway_emmebank is None: - self._highway_emmebank = self.controller.emme_manager.highway_maz_emmebank + self._highway_emmebank = self.controller.emme_manager.highway_emmebank return self._highway_emmebank @property @@ -122,11 +122,6 @@ def run(self): county_groups[group.number] = group.counties for time in self.time_period_names: self._scenario = self.highway_emmebank.scenario(time) - if self.controller.iteration == 0: - create_attribute = self.controller.emme_manager.tool( - "inro.emme.data.extra_attribute.create_extra_attribute" - ) - create_attribute("LINK","@maz_flow","Assigned MAZ-to-MAZ flow",overwrite=True,scenario=self._scenario) with self._setup(time): self._prepare_network() for i, names in county_groups.items(): @@ -523,7 +518,7 @@ def _assign_flow_text( ) self.controller.emme_manager.copy_attribute_values( - self._network, self._scenario, {"LINK": ["temp_flow"]}, {"LINK": ["@maz_flow"]} + self._network, self._scenario, {"LINK": ["temp_flow"]}, {"LINK": ["data1"]} ) def _load_text_format_paths( @@ -694,7 +689,7 @@ def __init__(self, controller: RunController): @property def highway_emmebank(self): if self._highway_emmebank is None: - self._highway_emmebank = self.controller.emme_manager.highway_maz_emmebank + self._highway_emmebank = self.controller.emme_manager.highway_emmebank return self._highway_emmebank @property diff --git a/tm2py/components/network/highway/highway_network.py b/tm2py/components/network/highway/highway_network.py index bf292b58..f456b604 100644 --- a/tm2py/components/network/highway/highway_network.py +++ b/tm2py/components/network/highway/highway_network.py @@ -97,7 +97,7 @@ def run(self): @property def highway_emmebank(self): if not self._highway_emmebank: - self._highway_emmebank = self.controller.emme_manager.highway_taz_emmebank + self._highway_emmebank = self.controller.emme_manager.highway_emmebank return self._highway_emmebank @property diff --git a/tm2py/components/network/transit/transit_network.py b/tm2py/components/network/transit/transit_network.py index 49148f45..edee3844 100644 --- a/tm2py/components/network/transit/transit_network.py +++ b/tm2py/components/network/transit/transit_network.py @@ -114,7 +114,7 @@ def transit_emmebank(self): @property def highway_emmebank(self): if not self._highway_emmebank: - self._highway_emmebank = self.controller.emme_manager.highway_taz_emmebank + self._highway_emmebank = self.controller.emme_manager.highway_emmebank return self._highway_emmebank @property diff --git a/tm2py/config.py b/tm2py/config.py index f7e29f99..72ab3387 100644 --- a/tm2py/config.py +++ b/tm2py/config.py @@ -1262,8 +1262,7 @@ class EmmeConfig(ConfigItem): all_day_scenario_id: scenario ID to use for all day (initial imported) scenario with all time period data project_path: relative path from run_dir to Emme desktop project (.emp) - highway_taz_database_path: relative path to TAZ highway Emmebank - highway_maz_database_path: relative path to MAZ highway Emmebank + highway_database_path: relative path to highway Emmebank active_north_database_path: relative paths to active mode Emmebank for north bay active_south_database_path: relative paths to active mode Emmebank for south bay transit_database_path: relative path to transit Emmebank @@ -1275,8 +1274,7 @@ class EmmeConfig(ConfigItem): all_day_scenario_id: int project_path: pathlib.Path - highway_taz_database_path: pathlib.Path - highway_maz_database_path: pathlib.Path + highway_database_path: pathlib.Path active_north_database_path: pathlib.Path active_south_database_path: pathlib.Path transit_database_path: pathlib.Path diff --git a/tm2py/emme/manager.py b/tm2py/emme/manager.py index 0d2ad3a8..dabc65fa 100644 --- a/tm2py/emme/manager.py +++ b/tm2py/emme/manager.py @@ -146,11 +146,8 @@ def __init__(self, controller, emme_config: "EmmeConfig"): self.project_path = self.controller.get_abs_path(self.config.project_path) # see if works without os.path.normcase(os.path.realpath(project_path)) - self.highway_taz_database_path = self.controller.get_abs_path( - self.config.highway_taz_database_path - ) - self.highway_maz_database_path = self.controller.get_abs_path( - self.config.highway_maz_database_path + self.highway_database_path = self.controller.get_abs_path( + self.config.highway_database_path ) self.transit_database_path = self.controller.get_abs_path( self.config.transit_database_path @@ -166,8 +163,7 @@ def __init__(self, controller, emme_config: "EmmeConfig"): self._project = None self._modeller = None - self._highway_taz_emmebank = None - self._highway_maz_emmebank = None + self._highway_emmebank = None self._transit_emmebank = None self._active_north_emmebank = None self._active_south_emmebank = None @@ -225,16 +221,10 @@ def modeller(self) -> EmmeModeller: return self._modeller @property - def highway_taz_emmebank(self) -> EmmeBank: - if self._highway_taz_emmebank is None: - self._highway_taz_emmebank = EmmeBank(self, self.highway_taz_database_path) - return self._highway_taz_emmebank - - @property - def highway_maz_emmebank(self) -> EmmeBank: - if self._highway_maz_emmebank is None: - self._highway_maz_emmebank = EmmeBank(self, self.highway_maz_database_path) - return self._highway_maz_emmebank + def highway_emmebank(self) -> EmmeBank: + if self._highway_emmebank is None: + self._highway_emmebank = EmmeBank(self, self.highway_database_path) + return self._highway_emmebank @property def transit_emmebank(self) -> EmmeBank: