| 33 | | |
| 34 | | def dependencies(self): |
| 35 | | return [ self.agent_zone_id, self.location_zone_id, |
| 36 | | "income_breaks = 1 * (household.income < 25000) +" + \ |
| 37 | | " 2 * numpy.logical_and(household.income >= 25000, household.income < 45000) +" + \ |
| 38 | | " 3 * numpy.logical_and(household.income >= 45000, household.income < 75000) +" + \ |
| 39 | | " 4 * (household.income >= 75000)", |
| 40 | | "income_breaks = ( person.disaggregate(household.income_breaks) ).astype(int32)"] |
| 41 | | |
| 42 | | def compute(self, dataset_pool): |
| 43 | | interaction_dataset = self.get_dataset() |
| 44 | | income_breaks = interaction_dataset.get_dataset(1).get_attribute_by_index("income_breaks", |
| 45 | | interaction_dataset.get_2d_index_of_dataset1()) |
| 46 | | unique_income_breaks = unique_values(income_breaks.ravel()) |
| 47 | | self.add_dependencies(["travel_data.logsum_hbw_am_income_" + str(i) for i in unique_income_breaks]) |
| 48 | | |
| 49 | | travel_data = dataset_pool.get_dataset('travel_data') |
| 50 | | var1 = interaction_dataset.get_dataset(1).get_attribute_by_index(self.agent_zone_id, |
| 51 | | interaction_dataset.get_2d_index_of_dataset1()) |
| 52 | | var2 = interaction_dataset.get_2d_dataset_attribute(self.location_zone_id) |
| 53 | | if self.direction_from_home: |
| 54 | | home_zone = var1 |
| 55 | | work_zone = var2 |
| 56 | | else: |
| 57 | | home_zone = var2 |
| 58 | | work_zone = var1 |
| 59 | | times = resize(array([self.default_value], dtype=float32), home_zone.shape) |
| 60 | | positions = ones(home_zone.shape, dtype="int32") |
| 61 | | #create indices for 2d array of (origin, destination) |
| 62 | | ij = map(lambda x, y: (x, y), where(positions)[0], where(positions)[1]) |
| 63 | | for a in ij: |
| 64 | | i, j = a |
| 65 | | try: |
| 66 | | times[i,j] = travel_data.get_attribute_by_id("logsum_hbw_am_income_" + str(income_breaks[i, j]) , (home_zone[i,j], work_zone[i,j])) |
| 67 | | except: |
| 68 | | logger.log_warning("zone pairs (%s, %s) is not in zoneset; value set to %s." % (home_zone[i,j], work_zone[i,j], self.default_value)) |
| 69 | | |
| 70 | | return times |
| 71 | | |