当前位置: 首页>>代码示例>>Python>>正文


Python SessionConfiguration.get_storage方法代码示例

本文整理汇总了Python中opus_core.session_configuration.SessionConfiguration.get_storage方法的典型用法代码示例。如果您正苦于以下问题:Python SessionConfiguration.get_storage方法的具体用法?Python SessionConfiguration.get_storage怎么用?Python SessionConfiguration.get_storage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在opus_core.session_configuration.SessionConfiguration的用法示例。


在下文中一共展示了SessionConfiguration.get_storage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from opus_core.session_configuration import SessionConfiguration [as 别名]
# 或者: from opus_core.session_configuration.SessionConfiguration import get_storage [as 别名]
    def run(self, demographic_data_file, 
            household_dataset,
            person_dataset, 
            year=None,
            keep_attributes=None,
            keep_attributes_p=None,
            fill_value=-1,
            demographic_attributes=None,
            demographic_attributes_p=None,
            dataset_pool=None
            ): 
        """
        demographic_data_file: an hdf5 file that contains households and persons data
                               in pandas DataFrame format.  
                               Run paris/scripts/prepare_demographic_data.py to create
                               the file.
        household_dataset: opus dataset of household
        person_dataset: opus dataset of household
        year: integer, optional
        keep_attributes: list, attributes to keep from household dataset
        keep_attributes_p: list, attributes to keep from person dataset
        fill_value: fill attributes with fill_value for new households
        demographic_attributes: dictionary, attributes to load from external
                                demographic file.  The key of the dictionary is 
                                attribute name for household data, its value is
                                the expression to compute the attribute value.
                                See unittest for example.
        demographic_attributes_p: Same as demographic_attributes, for persons 
        dataset_pool: opus DatasetPool object, optional
        """
        if dataset_pool is None:
            dataset_pool = SessionConfiguration().get_dataset_pool()

        if not os.path.isabs(demographic_data_file):
            demographic_data_file = os.path.join(dataset_pool.get_storage().get_storage_location(), demographic_data_file)
        
        if year is None:
            year = SimulationState().get_current_time()
        ## this relies on the order of household_id in
        ## households data and persons attributes summarized 
        ## by household_id is the same
        fh = h5py.File(demographic_data_file, 'r')
        year_str = str(year)
        dmgh_current = fh[year_str]
        
        household_id = household_dataset.get_id_name()[0]
        person_id = person_dataset.get_id_name()[0]

        hhs_new = compound_array_to_dataset(dmgh_current['household'],
                                        table_name='households',
                                        id_name=household_id,
                                        dataset_name=household_dataset.dataset_name)
        ps_new = compound_array_to_dataset(dmgh_current['person'],
                                       table_name='persons',
                                       id_name=person_id,
                                       dataset_name=person_dataset.dataset_name)

        dataset_pool.replace_dataset(household_dataset.dataset_name, hhs_new)
        dataset_pool.replace_dataset(person_dataset.dataset_name, ps_new)
        
        hh_ids = hhs_new[household_id]
        n_hhs = hh_ids.size
        results = {}
        results[household_id] = hh_ids
        for k, v in demographic_attributes.iteritems():
            results[k] = hhs_new.compute_variables(v)

        logger.log_status( ('Loaded demographic characteristics {0} for {1} ' +\
                            'households from external file {2}.').format(
                            demographic_attributes.keys(), n_hhs, 
                            demographic_data_file) )

        p_ids = ps_new[person_id]
        n_ps = p_ids.size
        results_p = {}
        results_p[person_id] = p_ids
        for k, v in demographic_attributes_p.iteritems():
            results_p[k] = ps_new.compute_variables(v)

        logger.log_status( ('Loaded demographic characteristics {0} for {1} ' +\
                            'persons from external file {2}.').format(
                            demographic_attributes_p.keys(), n_ps, 
                            demographic_data_file) )

        is_existing = in1d(hh_ids, household_dataset[household_id])
        for attr in keep_attributes:
            dtype = household_dataset[attr].dtype
            values = fill_value * ones(n_hhs, dtype=dtype)
            values[is_existing] = household_dataset.get_attribute_by_id(attr,
                                                            hh_ids[is_existing])
            results[attr] = values

        is_existing = in1d(p_ids, person_dataset[person_id])
        for attr in keep_attributes_p:
            if attr in person_dataset.get_known_attribute_names():
                dtype = person_dataset[attr].dtype

                if dtype.type is string_:
                    values = empty(n_ps, dtype=dtype)
                else:
#.........这里部分代码省略.........
开发者ID:psrc,项目名称:urbansim,代码行数:103,代码来源:external_demographic_model.py


注:本文中的opus_core.session_configuration.SessionConfiguration.get_storage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。