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


Python BaseManager.defaultdict方法代码示例

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


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

示例1: i_images_processing

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import defaultdict [as 别名]
 def i_images_processing(self, vs): 
     
     """
     Interface function to launch processing VHRS images :func:`i_vhrs` and satellite images :func:`i_img_sat` in multi-processing.
     
     :param vs: Boolean variable to launch processing because of interface checkbox -> 0 or 1.
 
         - 0 means, not texture processing
         - 1 means, launch texture processing
     :type vs: int
     """
     
     # Multiprocessing
     mgr = BaseManager()
     mgr.register('defaultdict', defaultdict, DictProxy)
     mgr.start()
     self.out_ndvistats_folder_tab = mgr.defaultdict(list)
     
     p_img_sat = Process(target=self.i_img_sat)
     p_img_sat.start()
     if self.mp == 0:
         p_img_sat.join()
     
     if vs == 1:
         p_vhrs = Process(target=self.i_vhrs)#, args=(vs, ))
         p_vhrs.start()
         p_vhrs.join()
     
     if self.mp == 1:
         p_img_sat.join()
     
     # List of output raster path
     self.raster_path.append(self.out_ndvistats_folder_tab[0])
     # List of output raster band
     self.list_band_outraster.append(1)
     
     if vs == 1:
         self.raster_path.append(self.out_ndvistats_folder_tab['sfs'])
         self.list_band_outraster.append(4)
         self.raster_path.append(self.out_ndvistats_folder_tab['haralick'])
         self.list_band_outraster.append(2)
     
     # To slope, to extract scree
     if self.path_mnt != '':
         self.raster_path.append(self.path_mnt)
         self.list_band_outraster.append(1)
         
     self.raster_path.append(self.out_ndvistats_folder_tab[1])
     # example raster path tab :
     #                [path_folder_dpt + '/' + folder_processing + '/' + classif_year + '/Min_2014.TIF',\
     #                os.path.dirname(path_ortho) + '/Clip_buffer_surface_dep_18_IRCOrtho65_2m_sfs.TIF',\
     #                os.path.dirname(path_ortho) + '/Clip_buffer_surface_dep_18_IRCOrtho65_2m_haralick.TIF',\
     #                path_folder_dpt + '/' + folder_processing + '/' + classif_year + '/Max_2014.TIF']
     
     # List of output raster band
     self.list_band_outraster.append(1) #[1, 4, 2, 1]
     
     print("End of images processing !")
开发者ID:SylvioL,项目名称:PHYMOBAT,代码行数:60,代码来源:Processing.py

示例2: i_classifier

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import defaultdict [as 别名]
    def i_classifier(self): 
        """
        Interface function to launch decision tree classification with a input segmentation :func:`Segmentation.Segmentation`.
        
        This function store optimal threshold by class **Segmentation.out_threshold**. Then compute zonal statistics by polygons
        for every images in multi-processing (if **mp** = 1).
        """ 
        
        # Multiprocessing
        mgr = BaseManager()
        mgr.register('defaultdict', defaultdict, DictProxy)
        mgr.start()
        multi_process_var = [] # Multi processing variable
          
        # Extract final cartography
        out_carto = Segmentation(self.path_segm, self.path_area) 
        out_carto.output_file = self.output_name_moba
        out_carto.out_class_name = self.in_class_name
        out_carto.out_threshold = []
        for ind_th in range(len(self.sample_name)):
            out_carto.out_threshold.append(self.decis[ind_th].threshold[0])
            if '>' in self.decis[ind_th].threshold[0]:
                out_carto.out_threshold.append(self.decis[ind_th].threshold[0].replace('>', '<='))
            elif '<' in self.decis[ind_th].threshold[0]:
                out_carto.out_threshold.append(self.decis[ind_th].threshold[0].replace('<', '>='))
        #     out_carto.zonal_stats((raster_path[ind_th], list_band_outraster[ind_th]))
            multi_process_var.append([self.raster_path[ind_th], self.list_band_outraster[ind_th]])
         
        # Compute zonal stats on slope raster
        multi_process_var.append([self.raster_path[ind_th+1], self.list_band_outraster[ind_th+1]])
        out_carto.out_threshold.append('<'+str(self.slope_degree)) # To agriculture
        out_carto.out_threshold.append('>='+str(self.slope_degree)) # To scree
        if self.path_mnt != '':
            # Add class indexes
            self.tree_direction[0].append(6)
            self.tree_direction[0].append(7)
            
        # Compute zonal stats on Max NDVI raster  
        try:  
            # out_carto.zonal_stats((raster_path[ind_th+1], list_band_outraster[ind_th+1]))
            multi_process_var.append([self.raster_path[ind_th+2], self.list_band_outraster[ind_th+2]])
            # Compute stats twice, because there is 3 classes and not 2
            # out_carto.zonal_stats((raster_path[ind_th+1], list_band_outraster[ind_th+1]))
            multi_process_var.append([self.raster_path[ind_th+2], self.list_band_outraster[ind_th+2]])
        except:
            print('Not MNT on the 3rd step')
            multi_process_var.append([self.raster_path[ind_th+1], self.list_band_outraster[ind_th+1]])
            multi_process_var.append([self.raster_path[ind_th+1], self.list_band_outraster[ind_th+1]])

        # Compute zonal stats with multi processing
        out_carto.stats_dict = mgr.defaultdict(list)
        p = []
        kwargs = {}
        for i in range(len(multi_process_var)):
            kwargs['rank'] = i
            kwargs['nb_img'] = len(multi_process_var)
            p.append(Process(target=out_carto.zonal_stats, args=(multi_process_var[i], ), kwargs=kwargs))
            p[i].start()
            
            if self.mp == 0:
                p[i].join()
        
        if self.mp == 1:       
            for i in range(len(multi_process_var)):
                p[i].join()

        # If there is more one fieldnames line edit fulled in classification tab
        if len(self.sample_name) > 2:
            # Compute the biomass and density distribution
            out_carto.compute_biomass_density()
            
        out_carto.class_tab_final = defaultdict(list)
        self.i_tree_direction()
        out_carto.decision_tree(self.tree_direction)
        
        # If there is more one fieldnames line edit fulled in classification tab
        if len(self.sample_name) > 2:     
            # Compute biomass and density scale
            out_carto.append_scale(self.in_class_name[2], 'self.stats_dict[ind_stats][3]/self.max_bio')
            out_carto.append_scale(self.in_class_name[3], 'self.stats_dict[ind_stats][2]/self.max_wood_idm')
          
        # Final cartography
        out_carto.create_cartography(self.out_fieldname_carto, self.out_fieldtype_carto)
开发者ID:SylvioL,项目名称:PHYMOBAT,代码行数:85,代码来源:Processing.py


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