Example #1
0
    def prepare_for_estimate(self,
                             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,
                             categories=None):

        from opus_core.model import get_specification_for_estimation
        specification = get_specification_for_estimation(
            specification_dict, specification_storage, specification_table)
        projects = None
        # create agents for estimation
        if events_for_estimation_storage is not None:
            event_set = DevelopmentEventDataset(
                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'])
            projects = DevelopmentProjectCreator(
            ).create_projects_from_history(event_set, self.project_type,
                                           self.units, categories)
        return (specification, projects)
    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)
    def prepare_for_estimate(self, 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,
                              categories=None):

        from opus_core.model import get_specification_for_estimation
        specification = get_specification_for_estimation(specification_dict,
                                                          specification_storage,
                                                          specification_table)
        projects = None
        # create agents for estimation
        if events_for_estimation_storage is not None:
            event_set = DevelopmentEventDataset(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'])
            projects = DevelopmentProjectCreator().create_projects_from_history(
                                               event_set, self.project_type,
                                               self.units, categories)
        return (specification, projects)
Example #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)