コード例 #1
0
def reduce_colours(img_rgb, final_colours):

    if not isinstance(img_rgb, np.ndarray):
        img_rgb = np.asarray(img_rgb) / 255

    final_img = img_rgb.copy()

    # TODO: check if the RGB2LAB conversion MUST occurs at the very last
    # or if the problems I had were because of code problem uh

    pb = ProgressBar('Reducing colours')

    for i in range(final_img.shape[0]):
        for j in range(final_img.shape[1]):
            c1 = color.rgb2lab([[final_img[i, j]]])[0][0]
            c2 = [color.rgb2lab([[x]])[0][0] for x in final_colours]
            distances = [dst(c1, x) for x in c2]
            final_img[i, j] = final_colours[distances.index(min(distances))]

            pb.set_value(
                floor((((i * final_img.shape[1]) + j) /
                       (final_img.shape[0] * final_img.shape[1])) * 100))
            QApplication.processEvents()

    pb.close()

    return final_img
コード例 #2
0
ファイル: bxplorer_data.py プロジェクト: yangbochang/Bxplorer
    def append_root(self, root):
        ''' 添加一个root '''

        data = self.read()

        # 如果目录已存在,或是现有Root集的子路径,跳出;否则添加目录
        for _root in data['Root']:
            if _root == root or _root in root:
                return
        data['Root'].append(root)

        # 初始化一个进度条
        progress_bar = ProgressBar('Code Files')

        # 添加目录下的所有文件
        file_reader = FileReader()
        file_list = file_reader.walk_folder(root)
        total_number = len(file_list)
        for index, file in enumerate(file_list):

            # 获取文件基本信息
            ## 获取文件标识码
            file_code = file_reader.code_file(file)
            ## 获取文件名和文件扩展名
            file_basename = os.path.basename(file)
            file_name, file_extension = os.path.splitext(file_basename)
            ## 获取文件大小
            file_size_num = (int)(file_code.split('-')[-1])
            file_size_num = round(file_size_num / 1024 / 1024)
            file_size = str(file_size_num) + ' MB' if file_size_num < 1024 \
                else str(round(file_size_num / 1024, 2)) + ' GB'

            # 如果在已有数据中找不到文件,进行添加
            if file not in data['File']:
                data['File'][file] = {
                    'code': file_code,
                    'extension': file_extension,
                    'name': file_name,
                    'path': file,
                    'size': file_size,
                }

            # 进度条即时显示
            progress_bar.set_value(index + 1, total_number)
            QApplication.processEvents()

        # 循环结束,关闭进度条
        progress_bar.close()
        # 回填更新后的数据
        self.write(data)
コード例 #3
0
	def redraw_graphs(self):
		def ts(x):
			return x.total_seconds()
		if self.list_of_files !=None:
			# get data from the list of	 files given
			# we'll open the files one by one, fetch the line
			# get the timestamp from the line contaning ===Current Time===
			# and then looking for any of the selected metrics
			# put the results in the the pandas dataframe
			#and then call the redraw events
			self.metric_column=self.metric_column_d[self.metric]
			rows_list=[]
			self.first_time=False
			priortime=None
			nfiles=len(self.list_of_files)
			pbar=ProgressBar(desc="Loading Files")
			n=.5/nfiles
			for fname in self.list_of_files:
				if fname[-3:]=="bz2":
					datfile=bz2.BZ2File(fname)
				else:
					datfile=open(fname,'r')
				
				lines=datfile.readlines()
				cellname=fname[fname.rindex('_',)+1:fname.index('.',fname.rindex('_',))]
				pbar.setDescription("opening:"+os.path.basename(fname))
				pbar.setValue(100*n)
				n+=.5/nfiles
				QtWidgets.QApplication.processEvents()
#				print ("cellname=",cellname)
				for s1 in lines:
					s=s1.rstrip().decode("utf-8")
					#print(s)
					if re.search("PM|AM$",s)!=None:
						# get the date after that
						timeint=dt.datetime.strptime(s,"%m/%d/%Y %I:%M:%S %p")
						timest=timeint.strftime("%Y-%m-%d_%H:%M:%S")
						if priortime is None:
							timedelta=0
						else:
							timedelta=(timeint-priortime).total_seconds()
						priortime=timeint
					else:
						if self.devices=='.':
							mre=re.search("^nvme|^sd[a-l] .*$",s)
						else:
							mre=re.search("^"+self.devices+" .*$",s)
#							mre=re.search("^nvme0n1 .*$",s)
						if mre!=None:
							#disk=s[0:mre.span()[0]].rstrip()
							#print(s)
							l2f=s.split()
							#print(timeint,float(l2f[3]))
							data_list={'Cell':cellname, 'Type':('Flash' if l2f[0][0]=='n' else 'Disk'), 'Disk':l2f[0],'Metric':float(l2f[self.metric_column]),'Timestamp':timeint}
							rows_list.append(data_list)
				datfile.close()
				pbar.setValue(100*n)
				n+=.5/nfiles
				QtWidgets.QApplication.processEvents()
			self.current_metrics=pd.DataFrame(rows_list)#, ignore_index=True)
			#print(self.current_metrics.head())
			pbar.close()
		for i in self.metric_graph:
			self.metric_graph[i].remove_graph()
		for i in self.current_metrics.Cell.unique():
			self.metric_graph[i]=CellGraphrtPage(self,i,False)
			self.metric_graph[i+'A']=CellGraphrtPage(self,i,True)
			self.metric_graph[i].redraw_events()
			self.metric_graph[i+'A'].redraw_events()