# Path: MEHI/utils/tool.py
# def exeTime(func):
#     '''
#     Usage:
#      - just put '@exeTime'(with out quotation) before your function
#      - will show the running time
#     '''
#     import time
#     def wraper(*args, **args2):
#         s = time.time()
#         ret = func(*args, **args2)
#         e = time.time()
#         msg = "%3.3fs taken for {%s}" % (e-s, func.__name__)
#         log('time')(msg)
#         return ret
#     return wraper
# 
# def bar(level):
#     '''
#     Usage:
#      - this will show a progress bar
#      - e.g. bar('info')(msg, i, 100)
#     '''
#     from MEHI.utils.configuration import loglevel
#     if level in loglevel:
#         def wraper(msg, i, end):
#             if i <= end:
#                 sys.stdout.write('[' + bcolors.decode(level) + level + bcolors.decode('endc') + '] ('+ str(i)+'/' + str(end) + ') '+ msg + '\r')
#                 sys.stdout.flush()
#             if i == end:
#                 print
#         return wraper
#     else:
#         def wraper(msg, i, end):
#             pass
#         return wraper


import skimage.external.tifffile as tiff
import numpy as np
import os
    import pandas as pd
    import pandas as pd
    import zlib
from MEHI.utils.tool import exeTime,bar
        return np.array(img_stack)
    else:
        return tiff.imread(pwd)

@exeTime 
def save_tiff(img_stack, pwd):
    '''
    Usage:
     - write the img_stack
    '''
    if pwd.endswith('.tif'):
        tiff.imsave(pwd, img_stack) 
    else:
        for z,frame in enumerate(img_stack):
            fname = pwd + '_%03d' % (z+1) + '.tif'
            dir, file = os.path.split(fname)
            if not os.path.exists(dir):
                os.makedirs(dir)
            tiff.imsave(fname, frame)

@exeTime
def load_table(pwd):
    return pd.read_pickle(pwd)

@exeTime
def save_table(tab, pwd):
    pd.to_pickle(pwd)
    pd.to_csv(pwd)



# Path: MEHI/utils/tool.py
# def exeTime(func):
#     '''
#     Usage:
#      - just put '@exeTime'(with out quotation) before your function
#      - will show the running time
#     '''
#     import time
#     def wraper(*args, **args2):
#         s = time.time()
#         ret = func(*args, **args2)
#         e = time.time()
#         msg = "%3.3fs taken for {%s}" % (e-s, func.__name__)
#         log('time')(msg)
#         return ret
#     return wraper
# 
# def bar(level):
#     '''
#     Usage:
#      - this will show a progress bar
#      - e.g. bar('info')(msg, i, 100)
#     '''
#     from MEHI.utils.configuration import loglevel
#     if level in loglevel:
#         def wraper(msg, i, end):
#             if i <= end:
#                 sys.stdout.write('[' + bcolors.decode(level) + level + bcolors.decode('endc') + '] ('+ str(i)+'/' + str(end) + ') '+ msg + '\r')
#                 sys.stdout.flush()
#             if i == end:
#                 print
#         return wraper
#     else:
#         def wraper(msg, i, end):
#             pass
#         return wraper


# Path: MEHI/serial/IO.py
import skimage.external.tifffile as tiff
import numpy as np
import os
    import pandas as pd
    import pandas as pd
    import zlib
from MEHI.utils.tool import exeTime,bar

        return np.array(img_stack)
    else:
        return tiff.imread(pwd)

@exeTime 
def save_tiff(img_stack, pwd):
    '''
    Usage:
     - write the img_stack
    '''
    if pwd.endswith('.tif'):
        tiff.imsave(pwd, img_stack) 
    else:
        for z,frame in enumerate(img_stack):
            fname = pwd + '_%03d' % (z+1) + '.tif'
            dir, file = os.path.split(fname)
            if not os.path.exists(dir):
                os.makedirs(dir)
            tiff.imsave(fname, frame)

@exeTime
def load_table(pwd):
    return pd.read_pickle(pwd)

@exeTime
def save_table(tab, pwd):
    pd.to_pickle(pwd)
    pd.to_csv(pwd)



@exeTime