# Path: rawe/collocation/trajectory.py
# def load_traj(filename):
# def make_pps(traj):
#     def __init__(self,ocp,v_opt):
#     def getDvs(self):
#     def lookup(self,name,timestep=None,nicpIdx=None,degIdx=None):
#     def save(self,filename):
#     def saveMat(self,filename,dataname='rawesomeTrajectory'):
#     def getTimeSeries(self,name):
#     def subplot(self,names,title=None,style=None):
#     def plot(self,names,title=None,style=None):
#     def _plot(self,names,title,style=None,showLegend=True):
# class Trajectory(object):
# class TrajectoryPlotter(Trajectory):


from rawe.collocation import trajectory
import numpy


def interpolate(traj,pps,times,names):
    ############# interpolate ###########
    sys.stdout.write('reticulating splines... ')

    h = (traj.tgrid[-1,0,0] - traj.tgrid[0,0,0])/float(traj.dvMap._nk*traj.dvMap._nicp)
    h *= traj.dvMap._nk*traj.dvMap._nicp/float(self.nk*self.nicp)
    h *= numLoops

    t0 = 0.0
    x_interp_times = []
    for timestepIdx in range(self.nk):
        for nicpIdx in range(self.nicp):
            for degIdx in range(self.deg+1):
                time = t0 + h*self.lagrangePoly.tau_root[degIdx]
                if time > traj.tgrid[-1,0,0]:
                    time -= traj.tgrid[-1,0,0]
                x_interp_times.append(time)
            t0 += h
            if t0 > traj.tgrid[-1,0,0]:
                t0 -= traj.tgrid[-1,0,0]
    x_interp_times.append(t0)

if __name__=='__main__':
    traj = trajectory.load_traj('data/transition_backup.dat')
    print 'making piecewise polys ...'

# Path: rawe/collocation/trajectory.py
# def load_traj(filename):
# def make_pps(traj):
#     def __init__(self,ocp,v_opt):
#     def getDvs(self):
#     def lookup(self,name,timestep=None,nicpIdx=None,degIdx=None):
#     def save(self,filename):
#     def saveMat(self,filename,dataname='rawesomeTrajectory'):
#     def getTimeSeries(self,name):
#     def subplot(self,names,title=None,style=None):
#     def plot(self,names,title=None,style=None):
#     def _plot(self,names,title,style=None,showLegend=True):
# class Trajectory(object):
# class TrajectoryPlotter(Trajectory):


# Path: examples/carousel/convert_trajectory.py
from rawe.collocation import trajectory
import numpy



def interpolate(traj,pps,times,names):
    ############# interpolate ###########
    sys.stdout.write('reticulating splines... ')

    h = (traj.tgrid[-1,0,0] - traj.tgrid[0,0,0])/float(traj.dvMap._nk*traj.dvMap._nicp)
    h *= traj.dvMap._nk*traj.dvMap._nicp/float(self.nk*self.nicp)
    h *= numLoops

    t0 = 0.0
    x_interp_times = []
    for timestepIdx in range(self.nk):
        for nicpIdx in range(self.nicp):
            for degIdx in range(self.deg+1):
                time = t0 + h*self.lagrangePoly.tau_root[degIdx]
                if time > traj.tgrid[-1,0,0]:
                    time -= traj.tgrid[-1,0,0]
                x_interp_times.append(time)
            t0 += h
            if t0 > traj.tgrid[-1,0,0]:
                t0 -= traj.tgrid[-1,0,0]
    x_interp_times.append(t0)

if __name__=='__main__':
    traj = trajectory.load_traj('data/transition_backup.dat')
    print 'making piecewise polys ...'

    pps = trajectory.make_pps(traj)