__author__ = 'Newsteinwell'
import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate
from scipy.interpolate import interp1d

import load_data as ld
import gauss_filter as gf

#sampling
bandwidth=50

[FC1_data,x1]=ld.load_data_FC1()
gau_fil_data=gf.smoothListGaussian(FC1_data,bandwidth)

#cubic-spline
# x=np.arange(0,2*np.pi+np.pi/4,2*np.pi/8)
# y=np.sin(x)
batches_len=2000   #Because the memory limit, we interpolated the whole data in batches, batches_len is the length of batches.
start_num=np.arange(0,len(gau_fil_data),batches_len)
xnew=[]
ynew=[]

for i in range(len(start_num)):
    print (i)
    x=x1[start_num[i]:start_num[i]+batches_len]
    y=gau_fil_data[start_num[i]:start_num[i]+batches_len]

    f2 = interp1d(x, y, kind='cubic')
    xnew=np.arange(x[0],x[len(x)-1],0.5)
    ynew.append(f2(xnew))
    plt.show()

    pdb.set_trace()


    print '\n load data successfully!'

    ##remove raw data peak
    FC1_data = rm_p.rm_p(FC1_data)
    FC2_data = rm_p.rm_p(FC2_data)
    print '\n remove_peak successfully!'
  
#    pdb.set_trace()

    ##process the raw data with gauss filter
    gau_fil_data_FC1=gf.smoothListGaussian(FC1_data,degree=bandwidth)
    gau_fil_data_FC2=gf.smoothListGaussian(FC2_data,degree=bandwidth)
    print '\n Gauss filter the raw data successfully!'

    ##sampling the filtered data
    # sampled_data_FC1=sp.sampling(x1,gau_fil_data_FC1)
    # sampled_data_FC2=sp.sampling(x2,gau_fil_data_FC2)
    # print '\n Sample the data successfully!'

    ##interpolate the filtered data with nearest value
    sampled_data_FC1=int_nea.interpolate_nearest(x1,gau_fil_data_FC1)
    sampled_data_FC2=int_nea.interpolate_nearest(x2,gau_fil_data_FC2)
    print '\n interpolate the data successfully!'

    ##save the sampled data
    wsd.wri_sam_data(sampled_data_FC1,FC='FC1')