[backend/util] progress bar, some docstrings

This commit is contained in:
Jan Grewe 2020-07-28 13:33:29 +02:00
parent 5ba629c1ae
commit fec628034c

View File

@ -3,6 +3,7 @@ import numpy as np
import nixio as nix import nixio as nix
import re import re
import os import os
import sys
import glob import glob
import datetime as dt import datetime as dt
import subprocess import subprocess
@ -14,6 +15,18 @@ except AttributeError:
MonkeyPatch.patch_fromisoformat() MonkeyPatch.patch_fromisoformat()
def progress(count, total, status='', bar_len=60):
"""
modified after https://gist.github.com/vladignatyev/06860ec2040cb497f0f3
by Vladimir Ignatev published under MIT License
"""
percents = count / total
filled_len = int(percents * bar_len)
bar = '=' * filled_len + '-' * (bar_len - filled_len)
sys.stderr.write('[%s] %.2f%s ...%s\r' % (bar, percents * 100, '%', status))
sys.stderr.flush()
def read_info_file(file_name): def read_info_file(file_name):
""" """
@ -220,6 +233,15 @@ def read_dataset_info(info_file):
def nix_metadata_to_dict(section): def nix_metadata_to_dict(section):
"""Converts a nix.Section to a dictionary. Keys are the property names, values are
always a list of values. Additional information such as unit, definition etc are discarded.
Args:
section (nix.Section): The section
Returns:
dict: the dictionary containing the section info.
"""
info = {} info = {}
for p in section.props: for p in section.props:
info[p.name] = [v.value for v in p.values] info[p.name] = [v.value for v in p.values]
@ -229,6 +251,16 @@ def nix_metadata_to_dict(section):
def nix_metadata_to_yaml(section, cur_depth=0, val_count=1): def nix_metadata_to_yaml(section, cur_depth=0, val_count=1):
"""Convert a section to yaml
Args:
section ([type]): [description]
cur_depth (int, optional): [description]. Defaults to 0.
val_count (int, optional): [description]. Defaults to 1.
Returns:
[type]: [description]
"""
assert(isinstance(section, nix.section.SectionMixin)) assert(isinstance(section, nix.section.SectionMixin))
yaml = "%s%s:\n" % ("\t" * cur_depth, section.name) yaml = "%s%s:\n" % ("\t" * cur_depth, section.name)
for p in section.props: for p in section.props:
@ -306,6 +338,6 @@ if __name__ == "__main__":
embed() embed()
f.close() f.close()
""" """
dataset = "/Users/jan/zwischenlager/2012-03-23-ad" dataset = "/data/apteronotus/2012-03-23-ad"
settings = read_stimuli_file(os.path.join(dataset, "stimuli.dat")) settings = read_stimuli_file(dataset)
embed() embed()