# Elastic Curve Alignment¶

Otherwise known as time warping in the literature is at the center of elastic functional data analysis. Here our goal is to separate out the horizontal and vertical variability of the open/closed curves

:

import fdasrsf as fs
import numpy as np


:

data = np.load('../../bin/MPEG7.npz',allow_pickle=True)
Xdata = data['Xdata']
curve = Xdata[0,1]
n,M = curve.shape
K = Xdata.shape

beta = np.zeros((n,M,K))
for i in range(0,K):
beta[:,:,i] = Xdata[0,i]


We will then construct the fdacurve object

:

obj = fs.fdacurve(beta,N=M)


We then will compute karcher mean of the curves

:

obj.karcher_mean()

Computing Karcher Mean of 20 curves in SRVF space..
updating step: 1
updating step: 2
updating step: 3
updating step: 4
updating step: 5
updating step: 6
updating step: 7


We then can align the curves to the karcher mean

:

obj.srvf_align(rotation=False)


Plot the results

:

obj.plot()   ## Shape PCA¶

We then can compute the Karcher covariance and compute the shape pca

:

obj.karcher_cov()
obj.shape_pca()


Plot the principal directions

:

obj.plot_pca()     