#!/usr/bin/env python
# -*- coding: utf8 -*-
# Soubor:  interpolace.py
# Datum:   14.02.2013 13:11
# Autor:   Marek Nožka, nozka <@t> spseol <d.t> cz
# Licence: GNU/GPL 
# Úloha:   několik poznámek k intepolacím
#          http://docs.scipy.org/doc/scipy/reference/interpolate.html
#          http://docs.scipy.org/doc/scipy/reference/tutorial/integrate.html
###################################################3 
import matplotlib as mpl
mpl.use('GTKAgg')
mpl.use('Qt4Agg')
mpl.rc('font', family = 'serif', serif = 'cmr10') 
mpl.rcParams['text.usetex']=True
mpl.rcParams['text.latex.unicode']=True

#import numpy as num
import scipy.interpolate as interpol
import pylab as lab
from pylab import pi
#interactive mode 
#lab.ion()
#lab.ioff()

x= "0 0.3 0.5 0.8 1  2  3".split()
y= "0 0.1 0.5 1   3 10 30".split()
# z řetězců čísla
x=map(float,x)
y=map(float,y)

lab.figure(1)
lab.title('Interpolace')
lab.plot(x,y,'ro',label='vzorky')
lab.grid()
lab.xlim([min(x)-1,max(x)+1])
lab.ylim([min(y)-1,max(y)+1])

newX = lab.linspace(min(x), max(x),300)
# spline
newY = interpol.spline(x,y,newX)
lab.plot(newX,newY,label='spline')

# UnivariateSpline
funkce=interpol.UnivariateSpline(x,y,s=0)
newY=funkce(newX)
lab.plot(newX,newY,label='UnivariateSpline s=0')

funkce=interpol.UnivariateSpline(x,y)
newY=funkce(newX)
lab.plot(newX,newY,label='UnivariateSpline')

#LSQUnivariateSpline
funkce = interpol.LSQUnivariateSpline(x,y,[0.5, 0.8])
newY = funkce(newX)
lab.plot(newX,newY,label='LSQUnivariateSpline',alpha=0.5)

# interp1d
# ( linear , nearest ,  zero ,  slinear ,  quadratic,  cubic )
funkce = interpol.interp1d(x,y, kind='quadratic')
newY = funkce(newX)
lab.plot(newX,newY,label='interp1d quadratic',alpha=0.5)
# interp1d
# ( linear , nearest ,  zero ,  slinear ,  quadratic,  cubic )
funkce = interpol.interp1d(x,y, kind='nearest')
newY = funkce(newX)
lab.plot(newX,newY,label='interp1d nearest',alpha=0.5)

lab.legend(loc='best')
lab.show()
