def prepare_for_run(self, add_member_prefix=True, specification_storage=None, specification_table=None, coefficients_storage=None,
                         coefficients_table=None, **kwargs):
        if add_member_prefix:
            specification_table, coefficients_table = \
                self.group_member.add_member_prefix_to_table_names([specification_table, coefficients_table])

        return RegressionModel.prepare_for_run(self, specification_storage=specification_storage, specification_table=specification_table, 
                                               coefficients_storage=coefficients_storage, coefficients_table=coefficients_table, **kwargs)
    def prepare_for_run(self,
                        add_member_prefix=True,
                        specification_storage=None,
                        specification_table=None,
                        coefficients_storage=None,
                        coefficients_table=None,
                        **kwargs):
        if add_member_prefix:
            specification_table, coefficients_table = \
                self.group_member.add_member_prefix_to_table_names([specification_table, coefficients_table])

        return RegressionModel.prepare_for_run(
            self,
            specification_storage=specification_storage,
            specification_table=specification_table,
            coefficients_storage=coefficients_storage,
            coefficients_table=coefficients_table,
            **kwargs)
示例#3
0
 def prepare_for_run(self, *args, **kwargs):
     spec, coef, dummy = RegressionModel.prepare_for_run(
         self, *args, **kwargs)
     return (spec, coef)
    def prepare_for_run(self, dataset_pool, 
                        create_proposal_set=True,
                        parcel_filter_for_new_development=None, 
                        parcel_filter_for_redevelopment=None, 
                        template_filter=None,
                        spec_replace_module_variable_pair=None,
                        proposed_units_variable="urbansim_parcel.development_project_proposal.units_proposed",
                        **kwargs):
        """create development project proposal dataset from parcels and development templates.
        spec_replace_module_variable_pair is a tuple with two elements: module name, variable within the module
        that contans a dictionary of model variables to be replaced in the specification.
        """
        specification, coefficients, dummy = RegressionModel.prepare_for_run(self, **kwargs)
        try:
            existing_proposal_set_parent = dataset_pool.get_dataset('development_project_proposal')
            #load proposals whose status_id are not of id_tentative or id_not_available
            available_idx = where(logical_and(existing_proposal_set_parent.get_attribute("status_id") != DevelopmentProjectProposalDataset.id_tentative,
                                              existing_proposal_set_parent.get_attribute("status_id") != DevelopmentProjectProposalDataset.id_not_available))[0]
            existing_proposal_set = DatasetSubset(existing_proposal_set_parent, available_idx)
            # Code updated by Hanyi Li, MAG 6/8/2010
            # Replacing the cached 'development_project_proposal' dataset with
            # the filtered dataset 'existing_proposal_set'
            dataset_pool.replace_dataset(existing_proposal_set_parent.get_dataset_name(), existing_proposal_set)
        except:
            existing_proposal_set = None
        
        parcels = dataset_pool.get_dataset('parcel')
        templates = dataset_pool.get_dataset('development_template')

        # It is important that during this method no variable flushing happens, since
        # we create datasets of the same name for different purposes (new development and redevelopment)
        # and flushing would mix them up
        flush_variables_current = SessionConfiguration().get('flush_variables', False)
        SessionConfiguration().put_data({'flush_variables': False})
        
        # Code added by Jesse Ayers, MAG, 9/14/2009
        # Getting an index of parcels that have actively developing projects (those on a velocity function)
        # and making sure that new proposals are not generated for them
        if existing_proposal_set:
            parcels_with_proposals = existing_proposal_set.get_attribute('parcel_id')
            parcels_with_proposals_idx = parcels.get_id_index(parcels_with_proposals)
            if parcel_filter_for_new_development is not None:
                if parcel_filter_for_new_development[parcel_filter_for_new_development.find('=')+1] == '=':
                    filter = 'flter = numpy.logical_and(parcel.number_of_agents(development_project_proposal) == 0, %s)' % parcel_filter_for_new_development
                else:
                    parcel_filter_for_new_development = parcel_filter_for_new_development[parcel_filter_for_new_development.find('=')+1:].lstrip()
                    filter = 'flter = numpy.logical_and(parcel.number_of_agents(development_project_proposal) == 0, %s)' % parcel_filter_for_new_development
                index1 = where(parcels.compute_variables(filter))[0]

        else:
            if parcel_filter_for_new_development is not None:
                index1 = where(parcels.compute_variables(parcel_filter_for_new_development))[0]
            else:
                index1 = None
            
        if template_filter is not None:
            try:
                index2 = where(templates.compute_variables(template_filter))[0]
            except Exception, e:
                logger.log_warning( "template_filter is set to %s, but there is an error when computing it: %s"
                                   % (template_filter, e) )
                index2 = None
示例#5
0
 def prepare_for_run(self, *args, **kwargs):
     spec, coef, dummy = RegressionModel.prepare_for_run(self, *args, **kwargs)
     return (spec, coef)
    def prepare_for_run(
            self,
            dataset_pool,
            create_proposal_set=True,
            parcel_filter_for_new_development=None,
            parcel_filter_for_redevelopment=None,
            template_filter=None,
            spec_replace_module_variable_pair=None,
            proposed_units_variable="urbansim_parcel.development_project_proposal.units_proposed",
            **kwargs):
        """create development project proposal dataset from parcels and development templates.
        spec_replace_module_variable_pair is a tuple with two elements: module name, variable within the module
        that contans a dictionary of model variables to be replaced in the specification.
        """
        specification, coefficients, dummy = RegressionModel.prepare_for_run(
            self, **kwargs)
        try:
            existing_proposal_set_parent = dataset_pool.get_dataset(
                'development_project_proposal')
            #load proposals whose status_id are not of id_tentative or id_not_available
            available_idx = where(
                logical_and(
                    existing_proposal_set_parent.get_attribute("status_id") !=
                    DevelopmentProjectProposalDataset.id_tentative,
                    existing_proposal_set_parent.get_attribute("status_id") !=
                    DevelopmentProjectProposalDataset.id_not_available))[0]
            existing_proposal_set = DatasetSubset(existing_proposal_set_parent,
                                                  available_idx)
            # Code updated by Hanyi Li, MAG 6/8/2010
            # Replacing the cached 'development_project_proposal' dataset with
            # the filtered dataset 'existing_proposal_set'
            dataset_pool.replace_dataset(
                existing_proposal_set_parent.get_dataset_name(),
                existing_proposal_set)
        except:
            existing_proposal_set = None

        parcels = dataset_pool.get_dataset('parcel')
        templates = dataset_pool.get_dataset('development_template')

        # It is important that during this method no variable flushing happens, since
        # we create datasets of the same name for different purposes (new development and redevelopment)
        # and flushing would mix them up
        flush_variables_current = SessionConfiguration().get(
            'flush_variables', False)
        SessionConfiguration().put_data({'flush_variables': False})

        # Code added by Jesse Ayers, MAG, 9/14/2009
        # Getting an index of parcels that have actively developing projects (those on a velocity function)
        # and making sure that new proposals are not generated for them
        if existing_proposal_set:
            parcels_with_proposals = existing_proposal_set.get_attribute(
                'parcel_id')
            parcels_with_proposals_idx = parcels.get_id_index(
                parcels_with_proposals)
            if parcel_filter_for_new_development is not None:
                if parcel_filter_for_new_development[
                        parcel_filter_for_new_development.find('=') +
                        1] == '=':
                    filter = 'flter = numpy.logical_and(parcel.number_of_agents(development_project_proposal) == 0, %s)' % parcel_filter_for_new_development
                else:
                    parcel_filter_for_new_development = parcel_filter_for_new_development[
                        parcel_filter_for_new_development.find('=') +
                        1:].lstrip()
                    filter = 'flter = numpy.logical_and(parcel.number_of_agents(development_project_proposal) == 0, %s)' % parcel_filter_for_new_development
                index1 = where(parcels.compute_variables(filter))[0]

        else:
            if parcel_filter_for_new_development is not None:
                index1 = where(
                    parcels.compute_variables(
                        parcel_filter_for_new_development))[0]
            else:
                index1 = None

        if template_filter is not None:
            try:
                index2 = where(templates.compute_variables(template_filter))[0]
            except Exception, e:
                logger.log_warning(
                    "template_filter is set to %s, but there is an error when computing it: %s"
                    % (template_filter, e))
                index2 = None