# 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 numpy as np
import math
    import scipy.optimize as sciop
    import scipy.optimize as sciop
from MEHI.utils.tool import exeTime
    from MEHI.udf._trans import trans
    from MEHI.udf._update import update
    from skimage.feature import register_translation
    from scipy.ndimage import fourier_shift

    '''
    ditto
    '''
    def cb(xk):
        print xk
    ret = sciop.fmin_powell(update, vec0, args=(imgA,imgB), callback=cb, ftol=ftol)
    return ret

@exeTime
def execute(img_stack, vec):
    '''
    Usage:
     - Affine Transform the img stack using vec
    '''
    def func(frame):
        ret = _trans(frame, vec)
        ret = np.array(ret)
        return ret
    return np.array(map(func, img_stack))

@exeTime
def mutual_information(img_stack, vec=None):
    if not vec:
        def wrap(imgA, imgB, ftol=0.1):
            vec = c_powell(imgA, imgB, [0,0,0,1,1,0,0], ftol)
            return execute(img_stack, vec)
        return wrap
    else:
        return execute(img_stack, vec)
                  

# 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/serial/registration.py
import numpy as np
import math
    import scipy.optimize as sciop
    import scipy.optimize as sciop
from MEHI.utils.tool import exeTime
    from MEHI.udf._trans import trans
    from MEHI.udf._update import update
    from skimage.feature import register_translation
    from scipy.ndimage import fourier_shift

    '''
    ditto
    '''
    def cb(xk):
        print xk
    ret = sciop.fmin_powell(update, vec0, args=(imgA,imgB), callback=cb, ftol=ftol)
    return ret

@exeTime
def execute(img_stack, vec):
    '''
    Usage:
     - Affine Transform the img stack using vec
    '''
    def func(frame):
        ret = _trans(frame, vec)
        ret = np.array(ret)
        return ret
    return np.array(map(func, img_stack))

@exeTime
def mutual_information(img_stack, vec=None):
    if not vec:
        def wrap(imgA, imgB, ftol=0.1):
            vec = c_powell(imgA, imgB, [0,0,0,1,1,0,0], ftol)
            return execute(img_stack, vec)
        return wrap
    else:
        return execute(img_stack, vec)
                  

@exeTime
