def run(self, current_year_emme2_dir, current_year, dataset_pool, config=None): """Writes to the an emme2 input file in the [current_year_emme2_dir]/tripgen/inputtg/tazdata.ma2. """ missing_dataset = '' try: missing_dataset = 'constant_taz_column' taz_col_set = dataset_pool.get_dataset("constant_taz_column") taz_col_set.load_dataset() missing_dataset = 'zone' zone_set = dataset_pool.get_dataset("zone") zone_set.load_dataset() missing_dataset = 'household' household_set = dataset_pool.get_dataset("household") except: raise Exception("Dataset %s is missing from dataset_pool" % missing_dataset) """specify travel input file name: [current_year_emme2_dir]/tripgen/inputtg/tazdata.ma2 """ full_path = os.path.join(current_year_emme2_dir, 'tripgen', 'inputtg') if not os.path.exists(full_path): os.makedirs(full_path) tm_input_file = os.path.join(full_path, 'tazdata.ma2') tm_year = self._decade_floor(current_year) logger.log_status("calculating entries for emme2 input file") taz_col_set.compute_variables("zone_id=constant_taz_column.taz") current_taz_col = DatasetSubset(taz_col_set, index=where(taz_col_set.get_attribute("year")==tm_year)[0]) current_taz_col._id_names = ['taz'] current_taz_col._create_id_mapping() zone_set.join(current_taz_col, "pctmf", join_attribute='zone_id') zone_set.join(current_taz_col, "gqi", join_attribute='zone_id') zone_set.join(current_taz_col, "gqn", join_attribute='zone_id') zone_set.join(current_taz_col, "fteuniv", join_attribute='zone_id') zone_set.join(current_taz_col, "den", new_name='density', join_attribute='zone_id') value_122 = zeros(zone_set.size()) index_122 = zone_set.try_get_id_index(array([58,59,60,71,72,73,84,85,86,150,251,266,489,578,687,688,797,868])) value_122[index_122[index_122 != -1]] = 1 zone_set.add_attribute(data=value_122, name="v122") value_123 = zeros(zone_set.size()) index_123 = zone_set.try_get_id_index(array([531,646,847,850,888,894,899,910])) value_123[index_123[index_123 != -1]] = 1 zone_set.add_attribute(data=value_123, name="v123") value_124 = logical_not(value_122 + value_123) zone_set.add_attribute(data=value_124, name="v124") """specify which variables are passing from urbansim to travel model; the order matters""" variables_list = self.get_variables_list(dataset_pool) zone_set.compute_variables(variables_list, dataset_pool=dataset_pool ) return self._write_to_file(zone_set, variables_list, tm_input_file)
def _write_input_file_1(self, current_year_emme2_dir, input_dir, current_year, dataset_pool, config=None): missing_dataset = '' try: missing_dataset = 'group_quarter' taz_col_set = dataset_pool.get_dataset("group_quarter") taz_col_set.load_dataset() missing_dataset = 'zone' zone_set = dataset_pool.get_dataset("zone") zone_set.load_dataset() missing_dataset = 'household' household_set = dataset_pool.get_dataset("household") except: raise Exception("Dataset %s is missing from dataset_pool" % missing_dataset) """specify travel input file name """ if not os.path.exists(input_dir): os.makedirs(input_dir) tm_input_file = os.path.join(input_dir, 'tazdata.in') tm_year = self._get_tm_year(current_year, taz_col_set) logger.log_status("calculating entries for emme%s input file" % self.emme_version) taz_col_set.compute_variables("zone_id=group_quarter.taz") current_taz_col = DatasetSubset(taz_col_set, index=where(taz_col_set.get_attribute("year")==tm_year)[0]) current_taz_col._id_names = ['taz'] current_taz_col._create_id_mapping() zone_set.join(current_taz_col, "gqdorm", join_attribute='zone_id') zone_set.join(current_taz_col, "gqmil", join_attribute='zone_id') zone_set.join(current_taz_col, "gqoth", join_attribute='zone_id') zone_set.join(current_taz_col, "fteuniv", join_attribute='zone_id') """specify which variables are passing from urbansim to travel model; the order matters""" variables_list = self.get_variables_list(dataset_pool) zone_set.compute_variables(variables_list, dataset_pool=dataset_pool ) return self._write_to_file(zone_set, variables_list, tm_input_file, tm_year)