uAll = np.concatenate((Uf.reshape(uSize[0]*uSize[1],uSize[2]), Vf.reshape(uSize[0]*uSize[1],uSize[2]), Wf.reshape(uSize[0]*uSize[1],uSize[2])), axis = 0)
uAll.shape      

num_modes = 50;
modes, eig_vals = mr.compute_POD_matrices_snaps_method(uAll, list(range(num_modes)))

menergy = eig_vals/np.sum(eig_vals)
menergy_sum = np.zeros(len(menergy))
for i in range(len(menergy)):
    menergy_sum[i] = np.sum(menergy[:i]);

menergy_sum[-1]

"""
Explanation: Run POD
Test shape of matrix needed for POD function
num_vecs = 50;  #<-- equivalent to the number of PIV snapshots (Also number of total POD modes)
vecs = np.random.random((100, num_vecs))
vecs.shape
End of explanation
"""


reload(PODutils)
Umodes, Vmodes, Wmodes = PODutils.reconstructPODmodes(modes,uSize,num_modes,3)

Wmodes.shape

#Calculate the mode coefficients
C = modes.transpose()*uAll

C.shape

"""
Explanation: fig, ax = plt.subplots()
ax.bar(range(num_modes),menergy[1:num_modes]*100)
End of explanation
"""


ind = np.arange(num_modes)  # the x locations for the groups
width = 1       # the width of the bars

f = plt.figure()
ax = plt.gca()
ax2 = plt.twinx()
rect = ax.bar(ind,menergy[:num_modes], width, color='gray')
line = ax2.plot(ind,menergy_sum[:num_modes],'--r')

ax.set_xlabel("Mode Number",fontsize=14)
ax.set_ylabel("Scaled Mode Energy",fontsize=14)
ax2.set_ylabel("Integrated Energy",fontsize=14,color='red')

"""
Explanation: Plot modal energy and contribution total
End of explanation
"""


reload(PODutils)
PODutils.plotPODmodes3D(X,Y,Umodes,Vmodes,Wmodes,list(range(5)))

"""
Explanation: Plot some modes
End of explanation
"""


reload(PODutils)
PODutils.plotPODcoeff(C,list(range(6)),20)

"""
Explanation: Plot the variation of the coefficients
End of explanation
"""


