# 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


import skimage.external.tifffile as tiff
import numpy as np
import os
    import pandas as pd
    import pandas as pd
from MEHI.utils.tool import exeTime
        def func(name):
            img_pwd = os.path.join(pwd, name)
            if img_pwd.endswith('.tif'):
                img = tiff.imread(img_pwd)
            return img
        rdd_file = sc.parallelize(names)
        return np.squeeze(np.array(rdd_file.map(func).collect()))
    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)


# 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


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

        def func(name):
            img_pwd = os.path.join(pwd, name)
            if img_pwd.endswith('.tif'):
                img = tiff.imread(img_pwd)
            return img
        rdd_file = sc.parallelize(names)
        return np.squeeze(np.array(rdd_file.map(func).collect()))
    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