コード例 #1
0
    def get_sampling_weights(self, config, agent_set=None, agents_index=None, **kwargs):
        where_developable = AgentLocationChoiceModelMember.apply_filter(self, self.filter, None, agent_set,
                                                                        agents_index)
        if self.developable_maximum_unit_variable:
            varlist = [self.developable_maximum_unit_variable]
        else:
            varlist = []
        if self.developable_minimum_unit_variable is not None:
            varlist.append(self.developable_minimum_unit_variable)
        self.choice_set.compute_variables(varlist, dataset_pool = self.dataset_pool)
        if self.developable_maximum_unit_variable is not None:
            max_capacity = clip_to_zero_if_needed(self.choice_set.get_attribute_by_index(
                                 self.developable_maximum_unit_variable, where_developable),
                              "get_weights_for_sampling_locations - computing developable_maximum_unit_variable")
        else:
            max_capacity = ones(where_developable.size) * agent_set.get_attribute(self.units).max()

        if self.developable_minimum_unit_variable is not None:
            min_capacity = clip_to_zero_if_needed(self.choice_set.get_attribute_by_index(
                             self.developable_minimum_unit_variable, where_developable),
                              "get_weights_for_sampling_locations - computing developable_minimum_unit_variable")
        else:
            min_capacity = zeros(max_capacity.size)

        if max_capacity.sum(dtype="float32") == 0:
            raise RuntimeError, "There are no choices with any capacity for %s buildings." % agent_set.what

        #how many buildings fit in each developable location
        max_building_size = sort(max_capacity)[-max(50,int(where_developable.size*0.001))]
        proposed_building_sizes = agent_set.get_attribute_by_index(self.units_full_name, agents_index)
        if proposed_building_sizes.max() > max_building_size: # change the size if there is not enough space
            logger.log_status("Maximum building size: %s" % proposed_building_sizes.max())
            self.modify_agents_size(agent_set, minimum(proposed_building_sizes,max_building_size), agents_index)
            proposed_building_sizes = agent_set.get_attribute_by_index(self.units_full_name, agents_index)
            if self.run_config.get("agent_units_string", None): # needs to be corrected
                if VariableName(self.run_config["agent_units_string"]).get_alias() not in agent_set.get_known_attribute_names():
                    agent_set.compute_variables(self.run_config["agent_units_string"])
                self.run_config["agent_units_all"] = agent_set.get_attribute_by_index(self.run_config["agent_units_string"], agents_index)
            logger.log_warning("Not enough building capacity. Large building sizes reduced to %s" % max_building_size)
        proposed_building_sizes = reshape(proposed_building_sizes, (proposed_building_sizes.size,1))
        weight_array = logical_and(proposed_building_sizes >= reshape(min_capacity, (1, min_capacity.size)),
                        (reshape(max_capacity, (1, max_capacity.size)) >=
                             proposed_building_sizes))

        # for memory reasons, discard columns that have only zeros
        keep = where(weight_array.sum(axis=0, dtype=int32))[0]
        where_developable = where_developable[keep]
        weight_array = take(weight_array, keep, axis=1)
        if where_developable.size <= 0:
            logger.log_warning("No developable locations available.")
            
        self.filter_index = where_developable
         
        return weight_array
コード例 #2
0
 def compute(self, dataset_pool):
     sqft = self.get_dataset().get_attribute(self.sqft)
     num_of_job_spaces = ma.filled(self.get_dataset().get_attribute(self.commercial_sqft)/ 
                 ma.masked_where(sqft == 0, sqft.astype(float32)), 0.0).astype(int32)
     return  clip_to_zero_if_needed(num_of_job_spaces - 
                 self.get_dataset().get_attribute(self.number_of_commercial_jobs),
                                       'vacant_commercial_job_space')
コード例 #3
0
 def compute(self, dataset_pool):
     sqft = self.get_dataset().get_attribute(self.sqft)
     num_of_job_spaces = ma.filled(self.get_dataset().get_attribute(self.commercial_sqft)/ 
                 ma.masked_where(sqft == 0, sqft.astype(float32)), 0.0).astype(int32)
     return  clip_to_zero_if_needed(num_of_job_spaces - 
                 self.get_dataset().get_attribute(self.number_of_commercial_jobs),
                                       'vacant_commercial_job_space')
コード例 #4
0
def compute_supply_and_add_to_location_set(location_set, grouping_location_set, units_variable,
                                    vacant_units_variable, movers_variable, supply_attribute_name,
                                    secondary_residence_variable=None, multiplicator=1.0, resources=None):
    """All variable names are in fully-qualified form defined for the
    'location_set'. Their are aggregated for the grouping_location_set.
    'supply_attribute_name' is in a short form and will be added to the location_set.
    """
    aggregate_string = grouping_location_set.get_dataset_name() + ".aggregate(%s)"
    if secondary_residence_variable:
        gr_secondary_residence_variable = aggregate_string % secondary_residence_variable
    else:
        gr_secondary_residence_variable = None
    lambdas = compute_lambda_for_vacancy(grouping_location_set,
                                         aggregate_string % units_variable,
                                         aggregate_string % vacant_units_variable,
                                         aggregate_string % movers_variable,
                                         gr_secondary_residence_variable, multiplicator, resources)
    supply, dummy = compute_supply_and_vacancy_rate(location_set, grouping_location_set, lambdas,
                                    vacant_units_variable, movers_variable, resources)
    logger.log_status("lambda for estimating annual supply computed from:")
    logger.log_status("T: %s, V: %s, M: %s" % (units_variable, vacant_units_variable,
                                               movers_variable))
    if secondary_residence_variable:
        logger.log_status("S: %s" % secondary_residence_variable)
    location_set.add_primary_attribute(clip_to_zero_if_needed(supply, supply_attribute_name), supply_attribute_name)
    def check_vacancy_rates(self, target_vacancy):
        self.current_target_vacancy = target_vacancy
        type_ids = target_vacancy.get_attribute("building_type_id")
        is_residential = target_vacancy.get_attribute("is_residential")
        buildings = self.dataset_pool.get_dataset("building")
        building_type_ids = buildings.get_attribute("building_type_id")
        building_zone_ids = buildings.get_attribute("zone_id")
        for index in arange(target_vacancy.size()):
            ##TODO allow target vacancies to vary across zones/sub region geographies
            #zone_id = target_vacancy.get_attribute_by_index("zone_id", index)
            #if zone_id != self.zone: continue
            type_id = type_ids[index]
            target = self.target_vacancies[type_id]
            is_matched_type = building_type_ids == type_id
            if is_residential[index]:
                unit_name = self.variables_for_computing_vacancies[
                    "residential"]
            else:
                unit_name = self.variables_for_computing_vacancies[
                    "non_residential"]
            is_in_right_zone = building_zone_ids == self.zone
            self.proposed_units[type_id] = 0
            self.demolished_units[type_id] = 0
            self.existing_units[type_id] = buildings.get_attribute(unit_name)[
                is_matched_type * is_in_right_zone].astype("float32").sum()
            self.existing_units[
                type_id] += self.proposed_units_from_previous_iterations.get(
                    type_id, 0)
            self.occupied_units[type_id] = 0
            if unit_name == "residential_units":
                if self.type["residential"]:
                    self.occupied_units[type_id] = int(
                        max(self.existing_units[type_id], 1) /
                        self.existing_to_occupied_ratio_residential)
                    vr = (self.existing_units[type_id] -
                          self.occupied_units[type_id]) / float(
                              max(self.existing_units[type_id], 1))
                else:
                    vr = 1.0

            else:
                if self.type["non_residential"]:
                    already_occupied = buildings.get_attribute(
                        "occupied_building_sqft_by_non_home_based_jobs")[
                            is_matched_type * is_in_right_zone].sum()
                    remaining_existing_units = clip_to_zero_if_needed(
                        self.existing_units[type_id] - already_occupied)
                    self.occupied_units[type_id] = int(
                        remaining_existing_units /
                        self.existing_to_occupied_ratio_non_residential)
                    vr = (self.existing_units[type_id] -
                          (self.occupied_units[type_id] + already_occupied)
                          ) / float(max(self.existing_units[type_id], 1))
                    self.existing_units[type_id] = remaining_existing_units
                else:
                    #vr = (self.existing_units[type_id] - self.occupied_units[type_id]) / float(max(self.existing_units[type_id],1))
                    vr = 1.0
            #print 'vacancy_rates:', type_id, vr
            if vr < target:
                self.accepting_proposals[type_id] = True
コード例 #6
0
 def compute(self, dataset_pool):
     bt = dataset_pool.get_dataset('building_type')
     ds = self.get_dataset()
     idx = bt.get_attribute("name") == self.type
     units_name = bt.get_attribute("units")[idx][0]
     dependent_variable = my_attribute_label("developable_maximum_%s" % units_name)
     if dependent_variable not in self.dependencies():
         ds.compute_variables([dependent_variable])
         self.add_dependencies([dependent_variable])
     return clip_to_zero_if_needed(ds.get_attribute(dependent_variable), "developable_%s_capacity" % self.type)
コード例 #7
0
 def check_vacancy_rates(self, target_vacancy):
     self.current_target_vacancy = target_vacancy
     type_ids = target_vacancy.get_attribute("building_type_id")
     is_residential = target_vacancy.get_attribute("is_residential")
     buildings = self.dataset_pool.get_dataset("building")
     building_type_ids = buildings.get_attribute("building_type_id")
     building_zone_ids = buildings.get_attribute("zone_id")
     for index in arange(target_vacancy.size()):
         ##TODO allow target vacancies to vary across zones/sub region geographies
         # zone_id = target_vacancy.get_attribute_by_index("zone_id", index)
         # if zone_id != self.zone: continue
         type_id = type_ids[index]
         target = self.target_vacancies[type_id]
         is_matched_type = building_type_ids == type_id
         unit_name = self.unit_name[is_residential[index]]
         is_in_right_zone = building_zone_ids == self.zone
         self.proposed_units[type_id] = 0
         self.demolished_units[type_id] = 0
         self.existing_units[type_id] = (
             buildings.get_attribute(unit_name)[is_matched_type * is_in_right_zone].astype("float32").sum()
         )
         self.existing_units[type_id] += self.proposed_units_from_previous_iterations.get(type_id, 0)
         self.occupied_units[type_id] = 0
         if is_residential[index]:
             if self.type["residential"] and self.build_in_zone["residential"]:
                 self.occupied_units[type_id] = int(
                     max(self.existing_units[type_id], 1) / self.existing_to_occupied_ratio_residential
                 )
                 vr = max(self.existing_units[type_id] - self.occupied_units[type_id], 0) / float(
                     max(self.existing_units[type_id], 1)
                 )
             else:
                 vr = 1.0
         else:
             if self.type["non_residential"] and self.build_in_zone["non_residential"]:
                 already_occupied = buildings.get_attribute("occupied_building_sqft_by_non_home_based_jobs")[
                     is_matched_type * is_in_right_zone
                 ].sum()
                 remaining_existing_units = clip_to_zero_if_needed(self.existing_units[type_id] - already_occupied)
                 self.occupied_units[type_id] = int(
                     remaining_existing_units / self.existing_to_occupied_ratio_non_residential
                 )
                 vr = max(
                     self.existing_units[type_id] - (self.occupied_units[type_id] + already_occupied), 1
                 ) / float(max(self.existing_units[type_id], 1))
                 self.existing_units[type_id] = remaining_existing_units
             else:
                 # vr = (self.existing_units[type_id] - self.occupied_units[type_id]) / float(max(self.existing_units[type_id],1))
                 vr = 1.0
         # print 'vacancy_rates:', type_id, vr
         if is_residential[index]:
             self.accepting_proposals[type_id] = self.build_in_zone["residential"] and vr < target
         else:
             self.accepting_proposals[type_id] = self.build_in_zone["non_residential"] and vr < target
コード例 #8
0
 def compute(self, dataset_pool):
     bt = dataset_pool.get_dataset('building_type')
     ds = self.get_dataset()
     idx = bt.get_attribute("name") == self.type
     units_name = bt.get_attribute("units")[idx][0]
     dependent_variable = my_attribute_label("developable_maximum_%s" %
                                             units_name)
     if dependent_variable not in self.dependencies():
         ds.compute_variables([dependent_variable])
         self.add_dependencies([dependent_variable])
     return clip_to_zero_if_needed(ds.get_attribute(dependent_variable),
                                   "developable_%s_capacity" % self.type)
コード例 #9
0
def compute_supply_and_add_to_location_set(location_set,
                                           grouping_location_set,
                                           units_variable,
                                           vacant_units_variable,
                                           movers_variable,
                                           supply_attribute_name,
                                           secondary_residence_variable=None,
                                           multiplicator=1.0,
                                           resources=None):
    """All variable names are in fully-qualified form defined for the
    'location_set'. Their are aggregated for the grouping_location_set.
    'supply_attribute_name' is in a short form and will be added to the location_set.
    """
    aggregate_string = grouping_location_set.get_dataset_name(
    ) + ".aggregate(%s)"
    if secondary_residence_variable:
        gr_secondary_residence_variable = aggregate_string % secondary_residence_variable
    else:
        gr_secondary_residence_variable = None
    lambdas = compute_lambda_for_vacancy(
        grouping_location_set, aggregate_string % units_variable,
        aggregate_string % vacant_units_variable,
        aggregate_string % movers_variable, gr_secondary_residence_variable,
        multiplicator, resources)
    supply, dummy = compute_supply_and_vacancy_rate(location_set,
                                                    grouping_location_set,
                                                    lambdas,
                                                    vacant_units_variable,
                                                    movers_variable, resources)
    logger.log_status("lambda for estimating annual supply computed from:")
    logger.log_status("T: %s, V: %s, M: %s" %
                      (units_variable, vacant_units_variable, movers_variable))
    if secondary_residence_variable:
        logger.log_status("S: %s" % secondary_residence_variable)
    location_set.add_primary_attribute(
        clip_to_zero_if_needed(supply, supply_attribute_name),
        supply_attribute_name)
コード例 #10
0
 def compute(self, dataset_pool):
     units = self.get_dataset().get_attribute(self.units)
     return clip_to_zero_if_needed(
         units -
         self.get_dataset().get_attribute(self.number_of_households),
         'vacant_%s_units_from_buildings' % self.type)
コード例 #11
0
    def get_sampling_weights(self,
                             config,
                             agent_set=None,
                             agents_index=None,
                             **kwargs):
        where_developable = AgentLocationChoiceModelMember.apply_filter(
            self, self.filter, None, agent_set, agents_index)
        if self.developable_maximum_unit_variable:
            varlist = [self.developable_maximum_unit_variable]
        else:
            varlist = []
        if self.developable_minimum_unit_variable is not None:
            varlist.append(self.developable_minimum_unit_variable)
        self.choice_set.compute_variables(varlist,
                                          dataset_pool=self.dataset_pool)
        if self.developable_maximum_unit_variable is not None:
            max_capacity = clip_to_zero_if_needed(
                self.choice_set.get_attribute_by_index(
                    self.developable_maximum_unit_variable, where_developable),
                "get_weights_for_sampling_locations - computing developable_maximum_unit_variable"
            )
        else:
            max_capacity = ones(
                where_developable.size) * agent_set.get_attribute(
                    self.units).max()

        if self.developable_minimum_unit_variable is not None:
            min_capacity = clip_to_zero_if_needed(
                self.choice_set.get_attribute_by_index(
                    self.developable_minimum_unit_variable, where_developable),
                "get_weights_for_sampling_locations - computing developable_minimum_unit_variable"
            )
        else:
            min_capacity = zeros(max_capacity.size)

        if max_capacity.sum(dtype="float32") == 0:
            raise RuntimeError, "There are no choices with any capacity for %s buildings." % agent_set.what

        #how many buildings fit in each developable location
        max_building_size = sort(
            max_capacity)[-max(50, int(where_developable.size * 0.001))]
        proposed_building_sizes = agent_set.get_attribute_by_index(
            self.units_full_name, agents_index)
        if proposed_building_sizes.max(
        ) > max_building_size:  # change the size if there is not enough space
            logger.log_status("Maximum building size: %s" %
                              proposed_building_sizes.max())
            self.modify_agents_size(
                agent_set, minimum(proposed_building_sizes, max_building_size),
                agents_index)
            proposed_building_sizes = agent_set.get_attribute_by_index(
                self.units_full_name, agents_index)
            if self.run_config.get("agent_units_string",
                                   None):  # needs to be corrected
                if VariableName(
                        self.run_config["agent_units_string"]).get_alias(
                        ) not in agent_set.get_known_attribute_names():
                    agent_set.compute_variables(
                        self.run_config["agent_units_string"])
                self.run_config[
                    "agent_units_all"] = agent_set.get_attribute_by_index(
                        self.run_config["agent_units_string"], agents_index)
            logger.log_warning(
                "Not enough building capacity. Large building sizes reduced to %s"
                % max_building_size)
        proposed_building_sizes = reshape(proposed_building_sizes,
                                          (proposed_building_sizes.size, 1))
        weight_array = logical_and(
            proposed_building_sizes >= reshape(min_capacity,
                                               (1, min_capacity.size)),
            (reshape(max_capacity,
                     (1, max_capacity.size)) >= proposed_building_sizes))

        # for memory reasons, discard columns that have only zeros
        keep = where(weight_array.sum(axis=0, dtype=int32))[0]
        where_developable = where_developable[keep]
        weight_array = take(weight_array, keep, axis=1)
        if where_developable.size <= 0:
            logger.log_warning("No developable locations available.")

        self.filter_index = where_developable

        return weight_array
コード例 #12
0
 def compute(self, dataset_pool):
     resunits = self.get_dataset().get_attribute(self.residential_units)
     return clip_to_zero_if_needed(resunits - 
                 self.get_dataset().get_attribute(self.number_of_households),
                                       'vacant_residential_units')
コード例 #13
0
 def compute(self, dataset_pool):
     indsqft = self.get_dataset().get_attribute(self.industrial_sqft)
     return clip_to_zero_if_needed(indsqft - 
                 self.get_dataset().get_attribute(self.sqft_of_industrial_jobs),
                                       'vacant_industrial_sqft')
コード例 #14
0
 def compute(self,  dataset_pool):
     buildings = self.get_dataset() 
     return clip_to_zero_if_needed(buildings.get_attribute("total_home_based_job_space") - 
                                   buildings.get_attribute("number_of_home_based_jobs"))
コード例 #15
0
 def compute(self,  dataset_pool):
     emp_submarkets = self.get_dataset() 
     return clip_to_zero_if_needed(emp_submarkets.get_attribute("total_home_based_job_space") - 
                                   emp_submarkets.get_attribute("number_of_home_based_jobs"))
コード例 #16
0
 def compute(self, dataset_pool):
     sqft = self.get_dataset().get_attribute(self.buildings_sqft_variable)
     return clip_to_zero_if_needed(
         sqft - self.get_dataset().get_attribute(self.sqft_of_jobs), "vacant_%s_sqft_from_buildings" % self.type
     )
コード例 #17
0
 def compute(self, dataset_pool):
     resunits = self.get_dataset().get_attribute(self.residential_units)
     return clip_to_zero_if_needed(
         resunits -
         self.get_dataset().get_attribute(self.number_of_households),
         'vacant_residential_units')
コード例 #18
0
 def compute(self,  dataset_pool):
     return clip_to_zero_if_needed(
            self.get_dataset().get_attribute("residential_units") - \
            self.get_dataset().get_attribute("number_of_households") )
コード例 #19
0
 def compute(self, dataset_pool):
     return clip_to_zero_if_needed(
            self.get_dataset().get_attribute("non_residential_sqft") - \
            self.get_dataset().get_attribute("occupied_building_sqft"))
コード例 #20
0
 def compute(self, dataset_pool):
     sqft = self.get_dataset().get_attribute(self.buildings_sqft_variable)
     return clip_to_zero_if_needed(sqft - 
                 self.get_dataset().get_attribute(self.sqft_of_jobs), 'vacant_%s_sqft_from_buildings' % self.type)
コード例 #21
0
 def compute(self, dataset_pool):
     comsqft = self.get_dataset().get_attribute(self.commercial_sqft)
     return clip_to_zero_if_needed(comsqft - 
                 self.get_dataset().get_attribute(self.sqft_of_commercial_jobs), 'vacant_commercial_sqft')
コード例 #22
0
 def compute(self, dataset_pool):
     comsqft = self.get_dataset().get_attribute(self.commercial_sqft)
     return clip_to_zero_if_needed(
         comsqft -
         self.get_dataset().get_attribute(self.sqft_of_commercial_jobs),
         'vacant_commercial_sqft')
コード例 #23
0
 def compute(self, dataset_pool):
     return clip_to_zero_if_needed(self.get_dataset().get_attribute(self.number_of_households) - 
                 self.get_dataset().get_attribute(self.number_of_home_based_jobs), 'vacant_home_based_job_space')
コード例 #24
0
 def compute(self, dataset_pool):
     sqft = self.get_dataset().get_attribute(self.total_sqft)
     return clip_to_zero_if_needed(sqft - 
                 self.get_dataset().get_attribute(self.sqft_of_jobs),
                                       'vacant_%s_sqft' % self.type)
コード例 #25
0
 def compute(self, dataset_pool):
     return clip_to_zero_if_needed(
            self.get_dataset().get_attribute("residential_units") - \
            self.get_dataset().get_attribute("number_of_households") )
コード例 #26
0
 def compute(self, dataset_pool):
     units = self.get_dataset().get_attribute(self.units)
     return clip_to_zero_if_needed(units - 
                 self.get_dataset().get_attribute(self.number_of_households), 'vacant_%s_units_from_buildings' % self.type)
コード例 #27
0
ファイル: vacant_building_sqft.py プロジェクト: psrc/urbansim
 def compute(self,  dataset_pool):
     return clip_to_zero_if_needed(
            self.get_dataset().get_attribute("non_residential_sqft") - \
            self.get_dataset().get_attribute("occupied_building_sqft"))
 def compute(self, dataset_pool):
     ds = self.get_dataset()
     return  clip_to_zero_if_needed(ds.get_attribute(self.possible_jobs) - 
                 ds.get_attribute(self.number_of_jobs), self.variable_name)
コード例 #29
0
 def compute(self, dataset_pool):
     indsqft = self.get_dataset().get_attribute(self.industrial_sqft)
     return clip_to_zero_if_needed(
         indsqft -
         self.get_dataset().get_attribute(self.sqft_of_industrial_jobs),
         'vacant_industrial_sqft')
コード例 #30
0
 def compute(self, dataset_pool):
     ds = self.get_dataset()
     return clip_to_zero_if_needed(
         ds.get_attribute(self.possible_jobs) -
         ds.get_attribute(self.number_of_jobs), self.variable_name)
コード例 #31
0
 def compute(self, dataset_pool):
     buildings = self.get_dataset()
     return clip_to_zero_if_needed(
         buildings.get_attribute("total_home_based_job_space") -
         buildings.get_attribute("number_of_home_based_jobs"))