def run(self, current_year_emme2_dir, current_year, dataset_pool, config=None): """Writes emme2 input files into the [current_year_emme2_dir]/tripgen/inputtg/ """ tm_input_file_1 = HHJobsTravelModelInputFileWriter.run( self, current_year_emme2_dir, current_year, dataset_pool, config) # writes TAZDATA.MA2 missing_dataset = '' try: missing_dataset = 'person' person_set = dataset_pool.get_dataset("person") except: raise "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') tm_input_files = [ os.path.join(full_path, 'tazdata.mf91'), os.path.join(full_path, 'tazdata.mf92'), os.path.join(full_path, 'tazdata.mf93'), os.path.join(full_path, 'tazdata.mf94') ] first_quarter, median_income, third_quarter = self._get_income_group_quartiles( dataset_pool) logger.log_status("calculating entries for emme2 *.mf9x input files") household_variables_to_compute = [ "is_income_group_1 = household.income < %s" % first_quarter, "is_income_group_2 = numpy.logical_and(household.income >= %s, household.income < %s)" % (first_quarter, median_income), "is_income_group_3 = numpy.logical_and(household.income >= %s, household.income < %s)" % (median_income, third_quarter), "is_income_group_4 = household.income >= %s" % third_quarter ] dataset_pool.get_dataset("household").compute_variables( household_variables_to_compute, dataset_pool=dataset_pool) person_variables_to_compute = [ "income_group_1 = person.disaggregate(household.is_income_group_1)", "income_group_2 = person.disaggregate(household.is_income_group_2)", "income_group_3 = person.disaggregate(household.is_income_group_3)", "income_group_4 = person.disaggregate(household.is_income_group_4)", "urbansim_parcel.person.zone_id", "urbansim_parcel.person.is_placed_non_home_based_worker_with_job", "job_zone_id = person.disaggregate(urbansim_parcel.job.zone_id)" ] person_set.compute_variables(person_variables_to_compute, dataset_pool=dataset_pool) return [tm_input_file_1] + self._write_workplaces_to_files( person_set, tm_input_files)
def run(self, current_year_emme2_dir, current_year, dataset_pool, config=None): """Writes emme2 input files into the [current_year_emme2_dir]/tripgen/inputtg/ """ tm_input_file_1 = HHJobsTravelModelInputFileWriter.run(self, current_year_emme2_dir, current_year, dataset_pool, config) # writes TAZDATA.MA2 self.compute_houshold_and_persons_variables(dataset_pool) """specify travel input file name: [current_year_emme2_dir]/tripgen/inputtg/tazdata.ma2 """ full_path = os.path.join(current_year_emme2_dir, 'tripgen', 'inputtg') tm_input_files = [os.path.join(full_path, 'tazdata.mf91'), os.path.join(full_path, 'tazdata.mf92'), os.path.join(full_path, 'tazdata.mf93'), os.path.join(full_path, 'tazdata.mf94')] return [tm_input_file_1] + self._write_workplaces_to_files(dataset_pool.get_dataset("person"), tm_input_files)
def run(self, current_year_emme2_dir, current_year, dataset_pool, config=None): """Writes emme2 input files into the [current_year_emme2_dir]/tripgen/inputtg/ """ tm_input_file_1 = HHJobsTravelModelInputFileWriter.run(self, current_year_emme2_dir, current_year, dataset_pool, config) # writes TAZDATA.MA2 missing_dataset = '' try: missing_dataset = 'person' person_set = dataset_pool.get_dataset("person") except: raise "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') tm_input_files = [os.path.join(full_path, 'tazdata.mf91'), os.path.join(full_path, 'tazdata.mf92'), os.path.join(full_path, 'tazdata.mf93'), os.path.join(full_path, 'tazdata.mf94')] first_quarter, median_income, third_quarter = self._get_income_group_quartiles(dataset_pool) logger.log_status("calculating entries for emme2 *.mf9x input files") household_variables_to_compute = ["is_income_group_1 = household.income < %s" % first_quarter, "is_income_group_2 = numpy.logical_and(household.income >= %s, household.income < %s)" % (first_quarter, median_income), "is_income_group_3 = numpy.logical_and(household.income >= %s, household.income < %s)" % (median_income, third_quarter), "is_income_group_4 = household.income >= %s" % third_quarter] dataset_pool.get_dataset("household").compute_variables(household_variables_to_compute, dataset_pool=dataset_pool) person_variables_to_compute = [ "income_group_1 = person.disaggregate(household.is_income_group_1)", "income_group_2 = person.disaggregate(household.is_income_group_2)", "income_group_3 = person.disaggregate(household.is_income_group_3)", "income_group_4 = person.disaggregate(household.is_income_group_4)", "urbansim_parcel.person.zone_id", "urbansim_parcel.person.is_placed_non_home_based_worker_with_job", "job_zone_id = person.disaggregate(urbansim_parcel.job.zone_id)" ] person_set.compute_variables(person_variables_to_compute, dataset_pool=dataset_pool) return [tm_input_file_1] + self._write_workplaces_to_files(person_set, tm_input_files)
def test_create_tripgen_travel_model_input_file(self): in_storage = StorageFactory().get_storage( 'sql_storage', storage_location=self.database) sc = SessionConfiguration(new_instance=True, package_order=['urbansim', 'psrc'], in_storage=in_storage) dataset_pool = sc.get_dataset_pool() #zone_set = dataset_pool.get_dataset('zone') #hh_set = dataset_pool.get_dataset('household') #job_set = dataset_pool.get_dataset('job') #taz_col_set = dataset_pool.get_dataset('constant_taz_column') TravelModelInputFileWriter().run(self.tempdir_path, 2000, dataset_pool) logger.log_status('tazdata path: ', self.tempdir_path) # expected values - data format: {zone:{column_value:value}} expected_tazdata = { 1: { 101: 19.9, 102: 2., 103: 0., 104: 1., 105: 0., 106: 3., 107: 11., 109: 1., 110: 0., 111: 0., 112: 0., 113: 0., 114: 0., 115: 0., 116: 0., 117: 0., 118: 0., 119: 0., 120: 2., 121: 42., 122: 0., 123: 0., 124: 11. }, 2: { 101: 29.9, 102: 0., 103: 2., 104: 1., 105: 3., 106: 1., 107: 3., 109: 0., 110: 0., 111: 0., 112: 0., 113: 3., 114: 0., 115: 0., 116: 0., 117: 0., 118: 1., 119: 1., 120: 0., 121: 241., 122: 0., 123: 0., 124: 3. } } # get real data from file real_tazdata = {1: {}, 2: {}} tazdata_file = open( os.path.join(self.tempdir_path, 'tripgen', 'inputtg', 'tazdata.ma2'), 'r') for a_line in tazdata_file.readlines(): if a_line[0].isspace(): numbers = a_line.replace( ':', ' ').split() # data line format: 1 101: 15.5 zone_id = int(numbers[0]) column_var = int(numbers[1]) value = float(numbers[2]) if value != -1: real_tazdata[zone_id][column_var] = value for zone in expected_tazdata.keys(): for col_var in expected_tazdata[zone].keys(): self.assertAlmostEqual(real_tazdata[zone][col_var], expected_tazdata[zone][col_var], 3,\ "zone %d, column variable %d did not match up."%(zone, col_var))