Ejemplo n.º 1
0
    def run(self, config, year):
        """Runs the VISUM executables, using appropriate info from config. 
        Assumes the VISUM input files are present. 
        Raise an exception if the VISUM run fails. 
        """
        tm_config = config['travel_model_configuration']
	
        #Get config params
        visum_dir, fileName = tm_config[year]['version']
	visum_version_number = tm_config['visum_version_number']
        
        #Startup Visum
        Visum = load_version_file(visum_dir, fileName)

        #Load procedure file and execute
        parFileName = tm_config[year]['procedure_file']	
        try:
	    Visum.Procedures.Open(parFileName)
	    Visum.Procedures.Execute()
        except Exception:
	    error_msg = "Loading and executing procedures file failed"
	    raise StandardError(error_msg)

	#Save version file
	#This saves over the existing version file
        try:
        	Visum.SaveVersion(fileName)
        except Exception:
        	error_msg = "Saving version file failed"
        	raise StandardError(error_msg)
Ejemplo n.º 2
0
    def run(self, config, year):
        """Runs the VISUM executables, using appropriate info from config. 
        Assumes the VISUM input files are present. 
        Raise an exception if the VISUM run fails. 
        """
        tm_config = config['travel_model_configuration']

        #Get config params
        visum_dir, fileName = tm_config[year]['version']
        visum_version_number = tm_config['visum_version_number']

        #Startup Visum
        Visum = load_version_file(visum_dir, fileName)

        #Load procedure file and execute
        parFileName = tm_config[year]['procedure_file']
        try:
            Visum.Procedures.Open(parFileName)
            Visum.Procedures.Execute()
        except Exception:
            error_msg = "Loading and executing procedures file failed"
            raise StandardError(error_msg)

#Save version file
#This saves over the existing version file
        try:
            Visum.SaveVersion(fileName)
        except Exception:
            error_msg = "Saving version file failed"
            raise StandardError(error_msg)
    def run(self, config, year):
        GetCacheDataIntoTravelModel.run(self, config, year)
        # this will call self.create_travel_model_input_file and compute variables for data transfer
        zone_set = SessionConfiguration().get_dataset_from_pool('zone')

        tm_config = config['travel_model_configuration']
        attribute_names = [
            VariableName(v).get_alias()
            for v in tm_config["urbansim_to_tm_variables"]
        ]

        # -- Start Visum Specific Code -- #

        #Get config params
        visum_dir, fileName = tm_config[year]['version']
        visum_version_number = tm_config['visum_version_number']

        #Startup Visum
        Visum = load_version_file(visum_dir, fileName, visum_version_number)

        #Set zone attributes in Visum
        try:
            for attrName in attribute_names:
                tempData = zone_set.get_attribute(attrName).tolist()
                #attribute must be defined in the version file
                if self.__attributeExists(Visum, attrName):
                    #is h.SetMulti case-sensitive?
                    #can h.SetMulti accept a numpy array?
                    h.SetMulti(Visum.Net.Zones, attrName, tempData)
                else:
                    #2 = float, 4 = num decimal places
                    Visum.Net.Zones.AddUserDefinedAttribute(
                        attrName, attrName, attrName, 2, 4)
                    h.SetMulti(Visum.Net.Zones, attrName, tempData)
        except Exception:
            error_msg = "Setting zone attribute " + attrName + " failed"
            raise StandardError(error_msg)

        #Save version file
        #This saves over the existing version file
        try:
            Visum.SaveVersion(fileName)
        except Exception:
            error_msg = "Saving version file failed"
            raise StandardError(error_msg)
    def get_travel_data_from_travel_model(self, config, year, zone_set):
        """
        """

        tm_config = config['travel_model_configuration']

        data_dict = {}
        table_name = "travel_data"
        storage = StorageFactory().get_storage('dict_storage')
        travel_data_set = None

        #Get config params
        visum_dir, fileName = tm_config[year]['version']
        visum_version_number = tm_config['visum_version_number']

        #Startup Visum
        Visum = load_version_file(visum_dir, fileName, visum_version_number)

        matrices = tm_config["tm_to_urbansim_variables"]
        #Get matrices
        #Note that matrix objects must be defined in version file before getting or setting
        try:
            #Get demand matrices
            if matrices.has_key('od'):
                for od_mat_num, od_mat_name in matrices["od"].iteritems():
                    mat = h.GetODMatrix(
                        Visum, od_mat_num)  #returns a 2d numarray object
                    data_dict[od_mat_name] = ravel(
                        mat)  #flatten to 1d and convert to numpy
                    #mat.tofile(visum_dir + "/od" + str(od_mat_num) + ".mtx") #temp hack to save it

            #Get skim matrices
            if matrices.has_key('skim'):
                for skim_mat_num, skim_mat_name in matrices["skim"].iteritems(
                ):
                    mat = h.GetSkimMatrix(
                        Visum, skim_mat_num)  #returns a 2d numarray object
                    data_dict[skim_mat_name] = ravel(
                        mat)  #flatten to 1d and convert to numpy
                #mat.tofile(visum_dir + "/skim" + str(skim_mat_num) + ".mtx") #temp hack to save it
        except Exception, e:
            error_msg = "Getting matrices failed: %s " % e
            raise StandardError(error_msg)
    def get_travel_data_from_travel_model(self, config, year, zone_set):
        """
        """

        tm_config = config['travel_model_configuration']

        data_dict = {}
        table_name = "travel_data"
        storage = StorageFactory().get_storage('dict_storage')
        travel_data_set = None

        #Get config params
        visum_dir, fileName = tm_config[year]['version']
        visum_version_number = tm_config['visum_version_number']

        #Startup Visum
        Visum = load_version_file(visum_dir, fileName, visum_version_number)

        matrices = tm_config["tm_to_urbansim_variables"]
        #Get matrices
        #Note that matrix objects must be defined in version file before getting or setting
        try:
            #Get demand matrices
            if matrices.has_key('od'):
                for od_mat_num, od_mat_name in matrices["od"].iteritems():
                    mat = h.GetODMatrix(Visum, od_mat_num) #returns a 2d numarray object
                    data_dict[od_mat_name] = ravel(mat)    #flatten to 1d and convert to numpy
                    #mat.tofile(visum_dir + "/od" + str(od_mat_num) + ".mtx") #temp hack to save it

            #Get skim matrices    
            if matrices.has_key('skim'):
                for skim_mat_num,skim_mat_name in matrices["skim"].iteritems():
                    mat = h.GetSkimMatrix(Visum, skim_mat_num) #returns a 2d numarray object
                    data_dict[skim_mat_name] = ravel(mat)      #flatten to 1d and convert to numpy
                #mat.tofile(visum_dir + "/skim" + str(skim_mat_num) + ".mtx") #temp hack to save it
        except Exception, e:
            error_msg = "Getting matrices failed: %s " % e
            raise StandardError(error_msg)