def prepare_for_estimate_alt(self, agent_set, add_member_prefix=True, specification_dict=None, specification_storage=None,
                              specification_table=None, events_for_estimation_storage=None,
                              events_for_estimation_table=None, urbansim_constant=None, base_year=0,
                              building_categories=None,
                              location_id_variable=None, dataset_pool=None, **kwargs):
        """Remove new buildings of this type and add new projects from event history instead."""
        type = self.group_member.get_member_name()
        agent_set.resources["building_categories"] = building_categories
        agent_set.compute_variables(["urbansim.%s.building_age" % agent_set.get_dataset_name(),
                                     "urbansim.%s.is_building_type_%s" % (agent_set.get_dataset_name(),
                                     type)], dataset_pool = dataset_pool)
        idx_new_buildings = where(logical_and(where(ma.filled(agent_set.get_attribute("building_age"),
                                         urbansim_constant['recent_years'] + 1) <= urbansim_constant['recent_years'], 1, 0),
                                  agent_set.get_attribute("is_building_type_%s" % type)))[0]
        # create agents for estimation
        if events_for_estimation_storage is not None:
            agent_set.remove_elements(idx_new_buildings)
            event_set = DevelopmentEventDataset(urbansim_constant,
                                            in_storage = events_for_estimation_storage,
                                            in_table_name= events_for_estimation_table)
            event_set.remove_non_recent_data(base_year, urbansim_constant['recent_years'])
            BuildingCreator().add_events_from_history_to_existing_buildings(agent_set,
                                               event_set, type,
                                               self.group_member.get_member_code(),
                                               self.units, building_categories, dataset_pool=dataset_pool)
        if location_id_variable:
            agent_set.compute_variables(location_id_variable, dataset_pool=dataset_pool)

        if events_for_estimation_storage is None:
            agent_set.compute_variables(["urbansim.%s.size_category_%s" % (agent_set.get_dataset_name(),
                                                                           self.group_member.get_member_name()),
                                         "urbansim.%s.building_age" % agent_set.get_dataset_name()],
                           dataset_pool = dataset_pool)
        idx_new_buildings = where(ma.filled(agent_set.get_attribute("building_age"),
                                         urbansim_constant['recent_years']+1) <= urbansim_constant['recent_years'])[0]
        if (specification_dict is not None) or (specification_storage is not None):
            specification, dummy = AgentLocationChoiceModelMember.prepare_for_estimate(self, add_member_prefix,
                                                               specification_dict, specification_storage,
                                                               specification_table,
                                                               location_id_variable=location_id_variable,
                                                               data_objects=dataset_pool.datasets_in_pool(), **kwargs)
        else:
            specification = None
        return (specification, idx_new_buildings)
Exemple #2
0
 def prepare_for_estimate(self,
                          agent_set,
                          add_member_prefix=True,
                          specification_dict=None,
                          specification_storage=None,
                          specification_table=None,
                          urbansim_constant=None,
                          building_categories=None,
                          location_id_variable=None,
                          dataset_pool=None,
                          **kwargs):
     """Return index of buildings that are younger than 'recent_years'+2"""
     type = self.group_member.get_member_name()
     if location_id_variable:
         agent_set.compute_variables(location_id_variable,
                                     dataset_pool=dataset_pool)
     agent_set.resources["building_categories"] = building_categories
     agent_set.compute_variables("urbansim.%s.size_category_%s" %
                                 (agent_set.get_dataset_name(),
                                  self.group_member.get_member_name()),
                                 dataset_pool=dataset_pool)
     agent_set.compute_variables([
         "urbansim.%s.building_age" % agent_set.get_dataset_name(),
         "urbansim.%s.is_building_type_%s" %
         (agent_set.get_dataset_name(), type)
     ],
                                 dataset_pool=dataset_pool)
     index = where(
         logical_and(
             ma.filled(agent_set.get_attribute("building_age"),
                       urbansim_constant['recent_years'] + 2) <=
             urbansim_constant['recent_years'] + 1,
             agent_set.get_attribute("is_building_type_%s" % type)))[0]
     specification, dummy = AgentLocationChoiceModelMember.prepare_for_estimate(
         self,
         add_member_prefix,
         specification_dict,
         specification_storage,
         specification_table,
         location_id_variable=location_id_variable,
         data_objects=dataset_pool.datasets_in_pool(),
         **kwargs)
     return (specification, index)
 def prepare_for_estimate(self, agent_set, add_member_prefix=True, specification_dict=None, specification_storage=None,
                           specification_table=None, urbansim_constant=None, building_categories=None,
                           location_id_variable=None, dataset_pool=None, **kwargs):
     """Return index of buildings that are younger than 'recent_years'+2"""
     type = self.group_member.get_member_name()
     if location_id_variable:
         agent_set.compute_variables(location_id_variable, dataset_pool=dataset_pool)
     agent_set.resources["building_categories"] = building_categories
     agent_set.compute_variables("urbansim.%s.size_category_%s" % (agent_set.get_dataset_name(), self.group_member.get_member_name()),
                        dataset_pool=dataset_pool)
     agent_set.compute_variables(["urbansim.%s.building_age" % agent_set.get_dataset_name(),
                                  "urbansim.%s.is_building_type_%s" % (agent_set.get_dataset_name(),
                                  type)], dataset_pool=dataset_pool)
     index = where(logical_and(ma.filled(agent_set.get_attribute("building_age"),
                                      urbansim_constant['recent_years']+2) <= urbansim_constant['recent_years']+1,
                               agent_set.get_attribute("is_building_type_%s" % type)))[0]
     specification, dummy = AgentLocationChoiceModelMember.prepare_for_estimate(self, add_member_prefix,
                                                            specification_dict, specification_storage,
                                                            specification_table,
                                                            location_id_variable=location_id_variable,
                                                            data_objects=dataset_pool.datasets_in_pool(),
                                                                                **kwargs)
     return (specification, index)
Exemple #4
0
    def prepare_for_estimate_alt(self,
                                 agent_set,
                                 add_member_prefix=True,
                                 specification_dict=None,
                                 specification_storage=None,
                                 specification_table=None,
                                 events_for_estimation_storage=None,
                                 events_for_estimation_table=None,
                                 urbansim_constant=None,
                                 base_year=0,
                                 building_categories=None,
                                 location_id_variable=None,
                                 dataset_pool=None,
                                 **kwargs):
        """Remove new buildings of this type and add new projects from event history instead."""
        type = self.group_member.get_member_name()
        agent_set.resources["building_categories"] = building_categories
        agent_set.compute_variables([
            "urbansim.%s.building_age" % agent_set.get_dataset_name(),
            "urbansim.%s.is_building_type_%s" %
            (agent_set.get_dataset_name(), type)
        ],
                                    dataset_pool=dataset_pool)
        idx_new_buildings = where(
            logical_and(
                where(
                    ma.filled(agent_set.get_attribute("building_age"),
                              urbansim_constant['recent_years'] + 1) <=
                    urbansim_constant['recent_years'], 1, 0),
                agent_set.get_attribute("is_building_type_%s" % type)))[0]
        # create agents for estimation
        if events_for_estimation_storage is not None:
            agent_set.remove_elements(idx_new_buildings)
            event_set = DevelopmentEventDataset(
                urbansim_constant,
                in_storage=events_for_estimation_storage,
                in_table_name=events_for_estimation_table)
            event_set.remove_non_recent_data(base_year,
                                             urbansim_constant['recent_years'])
            BuildingCreator().add_events_from_history_to_existing_buildings(
                agent_set,
                event_set,
                type,
                self.group_member.get_member_code(),
                self.units,
                building_categories,
                dataset_pool=dataset_pool)
        if location_id_variable:
            agent_set.compute_variables(location_id_variable,
                                        dataset_pool=dataset_pool)

        if events_for_estimation_storage is None:
            agent_set.compute_variables([
                "urbansim.%s.size_category_%s" %
                (agent_set.get_dataset_name(),
                 self.group_member.get_member_name()),
                "urbansim.%s.building_age" % agent_set.get_dataset_name()
            ],
                                        dataset_pool=dataset_pool)
        idx_new_buildings = where(
            ma.filled(agent_set.get_attribute(
                "building_age"), urbansim_constant['recent_years'] +
                      1) <= urbansim_constant['recent_years'])[0]
        if (specification_dict is not None) or (specification_storage
                                                is not None):
            specification, dummy = AgentLocationChoiceModelMember.prepare_for_estimate(
                self,
                add_member_prefix,
                specification_dict,
                specification_storage,
                specification_table,
                location_id_variable=location_id_variable,
                data_objects=dataset_pool.datasets_in_pool(),
                **kwargs)
        else:
            specification = None
        return (specification, idx_new_buildings)