Ejemplo n.º 1
0
def setup_emme_bank_folders():
    tod_dict = text_to_dictionary('time_of_day')
    emmebank_dimensions_dict = json_to_dictionary('emme_bank_dimensions')

    if not os.path.exists('Banks'):
        os.makedirs('Banks')
    else:
        # remove it
        print 'deleting Banks folder'
        shutil.rmtree('Banks')

    #gets time periods from the projects folder, so setup_emme_project_folder must be run first!
    time_periods = list(set(tod_dict.values()))
    time_periods.append('TruckModel')
    time_periods.append('Supplementals')
    for period in time_periods:
        print period
        print "creating bank for time period %s" % period
        os.makedirs(os.path.join('Banks', period))
        path = os.path.join('Banks', period, 'emmebank')
        emmebank = _eb.create(path, emmebank_dimensions_dict)
        emmebank.title = period
        emmebank.unit_of_length = unit_of_length
        emmebank.coord_unit_length = coord_unit_length
        scenario = emmebank.create_scenario(1002)
        network = scenario.get_network()
        #need to have at least one mode defined in scenario. Real modes are imported in network_importer.py
        network.create_mode('AUTO', 'a')
        scenario.publish_network(network)
        emmebank.dispose()
Ejemplo n.º 2
0
def setup_emme_bank_folders():
    tod_dict = text_to_dictionary('time_of_day')
    emmebank_dimensions_dict = json_to_dictionary('emme_bank_dimensions')
    
    if not os.path.exists('Banks'):
        os.makedirs('Banks')
    else:
        # remove it
        print 'deleting Banks folder'
        shutil.rmtree('Banks')

    #gets time periods from the projects folder, so setup_emme_project_folder must be run first!
    time_periods = list(set(tod_dict.values()))
    time_periods.append('TruckModel')
    time_periods.append('Supplementals')
    for period in time_periods:
        print period
        print "creating bank for time period %s" % period
        os.makedirs(os.path.join('Banks', period))
        path = os.path.join('Banks', period, 'emmebank')
        emmebank = _eb.create(path, emmebank_dimensions_dict)
        emmebank.title = period
        emmebank.unit_of_length = unit_of_length
        emmebank.coord_unit_length = coord_unit_length  
        scenario = emmebank.create_scenario(1002)
        network = scenario.get_network()
        #need to have at least one mode defined in scenario. Real modes are imported in network_importer.py
        network.create_mode('AUTO', 'a')
        scenario.publish_network(network)
        emmebank.dispose()
Ejemplo n.º 3
0
def create_emmebank(dir_name):
    
    #tod_dict = text_to_dictionary('time_of_day')
    emmebank_dimensions_dict = json_to_dictionary('emme_bank_dimensions')
    
    path = os.path.join('Banks', dir_name)
    if os.path.exists(path):
        shutil.rmtree(path)
    
    os.makedirs(path)
    path = os.path.join(path, 'emmebank')
    emmebank = _emmebank.create(path, emmebank_dimensions_dict)
    emmebank.title = dir_name
    scenario = emmebank.create_scenario(1002)
    network = scenario.get_network()
    #need to have at least one mode defined in scenario. Real modes are imported in network_importer.py
    network.create_mode('AUTO', 'a')
    scenario.publish_network(network)
    emmebank.dispose()
Ejemplo n.º 4
0
def create_emmebank(dir_name):

    #tod_dict = text_to_dictionary('time_of_day')
    emmebank_dimensions_dict = json_to_dictionary('emme_bank_dimensions')

    path = os.path.join('Banks', dir_name)
    if os.path.exists(path):
        shutil.rmtree(path)

    os.makedirs(path)
    path = os.path.join(path, 'emmebank')
    emmebank = _emmebank.create(path, emmebank_dimensions_dict)
    emmebank.title = dir_name
    scenario = emmebank.create_scenario(1002)
    network = scenario.get_network()
    #need to have at least one mode defined in scenario. Real modes are imported in network_importer.py
    network.create_mode('AUTO', 'a')
    scenario.publish_network(network)
    emmebank.dispose()
Ejemplo n.º 5
0
    #scenario_junctions['hdwfr'] = np.where(scenario_junctions.ScenarioNodeID.isin(special_stops), .1,.5)
    #scenario_junctions['wait'] = np.where(scenario_junctions.ScenarioNodeID.isin(special_stops), 1,2)
    #scenario_junctions['invt'] = np.where(scenario_junctions.ScenarioNodeID.isin(special_stops), .7,1)

    if config['create_emme_network']:
        logger.info("creating emme bank")
        emme_folder = os.path.join(config['output_dir'],
                                   config['emme_folder_name'])
        emmebank_dimensions_dict = json.load(
            open(os.path.join(config['data_path'],
                              'emme_bank_dimensions.json')))
        if os.path.exists(emme_folder):
            shutil.rmtree(emme_folder)
        os.makedirs(emme_folder)
        bank_path = os.path.join(emme_folder, 'emmebank')
        emmebank = _eb.create(bank_path, emmebank_dimensions_dict)
        emmebank.title = config['emmebank_title']
        emmebank.unit_of_length = 'mi'
        emmebank.coord_unit_length = 0.0001894
        scenario = emmebank.create_scenario(999)
        # project
        project = app.create_project(emme_folder, 'emme_networks')
        desktop = app.start_dedicated(False, "SEC", project)
        data_explorer = desktop.data_explorer()
        database = data_explorer.add_database(bank_path)
        #open the database added so that there is an active one
        database.open()
        desktop.project.save()
        desktop.close()
        emme_toolbox_path = os.path.join(os.environ['EMMEPATH'], 'toolboxes')
        shcopy(emme_toolbox_path + '/standard.mtbx',
Ejemplo n.º 6
0
    def setup_remote_database(self, src_scenarios, periods, remote_num,
                              msa_iteration):
        with _m.logbook_trace("Set up remote database #%s for %s" %
                              (remote_num, ", ".join(periods))):
            init_matrices = _m.Modeller().tool(
                "sandag.initialize.initialize_matrices")
            create_function = _m.Modeller().tool(
                "inro.emme.data.function.create_function")
            src_emmebank = src_scenarios[0].emmebank
            remote_db_dir = _join(self._path, "emme_project",
                                  "Database_remote" + str(remote_num))
            if msa_iteration == 1:
                # Create and initialize database at first iteration, overwrite existing
                if os.path.exists(remote_db_dir):
                    _shutil.rmtree(remote_db_dir)
                    _time.sleep(1)
                os.mkdir(remote_db_dir)
                dimensions = src_emmebank.dimensions
                dimensions["scenarios"] = len(src_scenarios)
                remote_emmebank = _eb.create(_join(remote_db_dir, "emmebank"),
                                             dimensions)
                try:
                    remote_emmebank.title = src_emmebank.title
                    remote_emmebank.coord_unit_length = src_emmebank.coord_unit_length
                    remote_emmebank.unit_of_length = src_emmebank.unit_of_length
                    remote_emmebank.unit_of_cost = src_emmebank.unit_of_cost
                    remote_emmebank.unit_of_energy = src_emmebank.unit_of_energy
                    remote_emmebank.use_engineering_notation = src_emmebank.use_engineering_notation
                    remote_emmebank.node_number_digits = src_emmebank.node_number_digits

                    for src_scen in src_scenarios:
                        remote_scen = remote_emmebank.create_scenario(
                            src_scen.id)
                        remote_scen.title = src_scen.title
                        for attr in sorted(src_scen.extra_attributes(),
                                           key=lambda x: x._id):
                            dst_attr = remote_scen.create_extra_attribute(
                                attr.type, attr.name, attr.default_value)
                            dst_attr.description = attr.description
                        for field in src_scen.network_fields():
                            remote_scen.create_network_field(
                                field.type, field.name, field.atype,
                                field.description)
                        remote_scen.has_traffic_results = src_scen.has_traffic_results
                        remote_scen.has_transit_results = src_scen.has_transit_results
                        remote_scen.publish_network(src_scen.get_network())
                    for function in src_emmebank.functions():
                        create_function(function.id, function.expression,
                                        remote_emmebank)
                    init_matrices(["traffic_skims", "traffic_demand"], periods,
                                  remote_scen)
                finally:
                    remote_emmebank.dispose()

            src_scen = src_scenarios[0]
            with _m.logbook_trace("Copy demand matrices to remote database"):
                with _eb.Emmebank(_join(remote_db_dir,
                                        "emmebank")) as remote_emmebank:
                    demand_matrices = init_matrices.get_matrix_names(
                        "traffic_demand", periods, src_scen)
                    for matrix_name in demand_matrices:
                        matrix = remote_emmebank.matrix(matrix_name)
                        src_matrix = src_emmebank.matrix(matrix_name)
                        if matrix.type == "SCALAR":
                            matrix.data = src_matrix.data
                        else:
                            matrix.set_data(src_matrix.get_data(src_scen.id),
                                            src_scen.id)
            skim_matrices = init_matrices.get_matrix_names(
                "traffic_skims", periods, src_scen)
            return remote_db_dir, skim_matrices