def cal_min():
    s = open(dir + '/%s.spec.f8'%base)
    s = np.fromfile(s, dtype='<f8')
    s = s.reshape((s.shape[0]/120, 120))

    m = open(dir + base%'/%s.mgc')
    m = np.fromfile(m, dtype='<f4')
    m = m.reshape((m.shape[0]/120, 120))

    diff = m.shape[0] - s.shape[0]
    print 'diff', diff
    print 'mean s', (s**2).mean()
    print 'mean m', (s**2).mean()
    error = []
    min = 1000000
    min_i = 0

    if diff > 0:
        for i in range(diff):
            e =  ((m[i:i-diff] - s)**2).mean()
            if e < min:
                min = e
                min_i = i
            print i, e

        sp = Image.fromarray(s * 1000)
        sp.save(dir + '/%s.sp_orig.gif'%base)
        mgc = Image.fromarray(m[min_i:min_i-diff] * 1000)
        mgc.save(dir + '/%s.mgc_slice.gif'%base)

    elif diff < 0:
        diff = abs(diff)
        for i in range(diff):
            e =  ((s[i:i-diff] - m)**2).mean()
            if e < min:
                min = e
                min_i = i
            print i, e
        sp = Image.fromarray(s[min_i:min_i-diff] * 1000)
        sp.save(dir + '/%s.sp_slice.gif'%base)
        mgc = Image.fromarray(m * 1000)
        mgc.save(dir + '/%s.mgc_orig.gif'%base)

    print 'min', min_i, min
dataset/ETHPy150Open hycis/Pynet/scripts/tmp.py/cal_min/swapped operands of `%`