Commit f0b5d4c8 authored by Jonathan Barés's avatar Jonathan Barés

Code is converted to work with Python3.

In 03 a piece of code is added to compute the local orientation of the root.
parent a9c0950a
...@@ -18,9 +18,6 @@ Nl=965 ...@@ -18,9 +18,6 @@ Nl=965
##Number of processor for post-processing parallelization: ##Number of processor for post-processing parallelization:
NbProc=5 NbProc=5
#Define global variables:
global row, col, timePic
#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~# #~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#
#Rename file and create time vectors: #Rename file and create time vectors:
...@@ -36,7 +33,7 @@ null=os.system('mkdir picturePl') ...@@ -36,7 +33,7 @@ null=os.system('mkdir picturePl')
null=os.system('mkdir pictureWh') null=os.system('mkdir pictureWh')
##Loop over picture names: ##Loop over picture names:
cnt=0 cnt=0
for it1 in xrange(Ni,Nl+1): for it1 in range(Ni,Nl+1):
try: try:
###Find picture names: ###Find picture names:
namCurPl=glob.glob('%04d'%it1+'_*_Pl.jpg')[0] namCurPl=glob.glob('%04d'%it1+'_*_Pl.jpg')[0]
...@@ -61,14 +58,14 @@ print('... is rotating pictures') ...@@ -61,14 +58,14 @@ print('... is rotating pictures')
##Function to rotate pictures: ##Function to rotate pictures:
def RotatePicture(iPct): def RotatePicture(iPct):
print iPct print(iPct)
null=os.system('convert picturePl/'+'%04d'%iPct+'.jpg -rotate 90 picturePl/'+'%04d'%iPct+'.jpg') null=os.system('convert picturePl/'+'%04d'%iPct+'.jpg -rotate 90 picturePl/'+'%04d'%iPct+'.jpg')
null=os.system('convert pictureWh/'+'%04d'%iPct+'.jpg -rotate 90 pictureWh/'+'%04d'%iPct+'.jpg') null=os.system('convert pictureWh/'+'%04d'%iPct+'.jpg -rotate 90 pictureWh/'+'%04d'%iPct+'.jpg')
return 0 return 0
##Parallelization of the rotation: ##Parallelization of the rotation:
p=Pool(NbProc) p=Pool(NbProc)
null=p.map(RotatePicture,xrange(NbStp)) null=p.map(RotatePicture,range(NbStp))
p.close() p.close()
#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~# #~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#
...@@ -81,7 +78,7 @@ row,col=pict1.shape ...@@ -81,7 +78,7 @@ row,col=pict1.shape
##Function to measure the shift: ##Function to measure the shift:
def MeasurePictureShift(iPct): def MeasurePictureShift(iPct):
global row, col global row, col
print iPct print(iPct)
###Load pictures: ###Load pictures:
pict1=misc.imread('picturePl/'+'%04d'%iPct+'.jpg')[:,:,1] pict1=misc.imread('picturePl/'+'%04d'%iPct+'.jpg')[:,:,1]
pict2=misc.imread('picturePl/'+'%04d'%(iPct+1)+'.jpg')[:,:,1] pict2=misc.imread('picturePl/'+'%04d'%(iPct+1)+'.jpg')[:,:,1]
...@@ -104,7 +101,7 @@ def MeasurePictureShift(iPct): ...@@ -104,7 +101,7 @@ def MeasurePictureShift(iPct):
##Parallelization of the shift computation: ##Parallelization of the shift computation:
print('... is centering pictures (measure displacement)') print('... is centering pictures (measure displacement)')
p=Pool(NbProc) p=Pool(NbProc)
xShiftVec0,yShiftVec0,test0=zip(*p.map(MeasurePictureShift,xrange(NbStp-1))) xShiftVec0,yShiftVec0,test0=zip(*p.map(MeasurePictureShift,range(NbStp-1)))
xShiftVec0=np.array(xShiftVec0); yShiftVec0=np.array(yShiftVec0); test0=np.array(test0) xShiftVec0=np.array(xShiftVec0); yShiftVec0=np.array(yShiftVec0); test0=np.array(test0)
p.close() p.close()
...@@ -150,7 +147,7 @@ if len(II)>1: ...@@ -150,7 +147,7 @@ if len(II)>1:
##Add the shifts: ##Add the shifts:
xShiftVec=np.zeros(NbStp) xShiftVec=np.zeros(NbStp)
yShiftVec=np.zeros(NbStp) yShiftVec=np.zeros(NbStp)
for it in xrange(1,NbStp): for it in range(1,NbStp):
xShiftVec[it]=xShiftVec[it-1]+xShiftVec0[it-1] xShiftVec[it]=xShiftVec[it-1]+xShiftVec0[it-1]
yShiftVec[it]=yShiftVec[it-1]+yShiftVec0[it-1] yShiftVec[it]=yShiftVec[it-1]+yShiftVec0[it-1]
...@@ -165,7 +162,7 @@ xShiftVecN=(MaxSft-xShiftVec).astype(int) ...@@ -165,7 +162,7 @@ xShiftVecN=(MaxSft-xShiftVec).astype(int)
##Function to reframe the pictures: ##Function to reframe the pictures:
def ReframePicture(iPct): def ReframePicture(iPct):
print iPct print(iPct)
###Load pictures: ###Load pictures:
pict0=misc.imread('picturePl/'+'%04d'%iPct+'.jpg') pict0=misc.imread('picturePl/'+'%04d'%iPct+'.jpg')
pict1=misc.imread('pictureWh/'+'%04d'%iPct+'.jpg') pict1=misc.imread('pictureWh/'+'%04d'%iPct+'.jpg')
...@@ -179,12 +176,10 @@ def ReframePicture(iPct): ...@@ -179,12 +176,10 @@ def ReframePicture(iPct):
##Parallelization of the cropping: ##Parallelization of the cropping:
print('... is centering pictures (crop)') print('... is centering pictures (crop)')
p=Pool(NbProc) p=Pool(NbProc)
null=p.map(ReframePicture,xrange(NbStp)) null=p.map(ReframePicture,range(NbStp))
p.close() p.close()
##Select the area of interest: ##Select the area of interest:
###Waiting:
print raw_input('Is waiting. Press ENTER to move...')
###Open the last picture: ###Open the last picture:
pict1=mpimg.imread('pictureWh/'+'%04d'%(NbStp-1)+'.jpg') pict1=mpimg.imread('pictureWh/'+'%04d'%(NbStp-1)+'.jpg')
###Define selection functions: ###Define selection functions:
...@@ -215,7 +210,7 @@ plt.close() ...@@ -215,7 +210,7 @@ plt.close()
##Function to crop the pictures: ##Function to crop the pictures:
def CropPicture(iPct): def CropPicture(iPct):
global x1, y1, x2, y2 global x1, y1, x2, y2
print iPct print(iPct)
###Load pictures: ###Load pictures:
pict0=misc.imread('picturePl/'+'%04d'%iPct+'.jpg') pict0=misc.imread('picturePl/'+'%04d'%iPct+'.jpg')
pict1=misc.imread('pictureWh/'+'%04d'%iPct+'.jpg') pict1=misc.imread('pictureWh/'+'%04d'%iPct+'.jpg')
...@@ -229,7 +224,7 @@ def CropPicture(iPct): ...@@ -229,7 +224,7 @@ def CropPicture(iPct):
##Parallelization of the cropping: ##Parallelization of the cropping:
print('... is cropping pictures') print('... is cropping pictures')
p=Pool(NbProc) p=Pool(NbProc)
null=p.map(CropPicture,xrange(NbStp)) null=p.map(CropPicture,range(NbStp))
p.close() p.close()
...@@ -243,7 +238,7 @@ null=os.system('mkdir tmpWh') ...@@ -243,7 +238,7 @@ null=os.system('mkdir tmpWh')
##function to plot the pictures with the time: ##function to plot the pictures with the time:
def PlotPicture(iPct): def PlotPicture(iPct):
global timePic global timePic
print iPct print(iPct)
###Load the time: ###Load the time:
t0=timePic[iPct] t0=timePic[iPct]
h0,m0=divmod(t0,60) h0,m0=divmod(t0,60)
...@@ -266,7 +261,7 @@ def PlotPicture(iPct): ...@@ -266,7 +261,7 @@ def PlotPicture(iPct):
##Parallelization of the cropping: ##Parallelization of the cropping:
print('... is plotting pictures') print('... is plotting pictures')
p=Pool(1) p=Pool(1)
null=p.map(PlotPicture,xrange(NbStp)) null=p.map(PlotPicture,range(NbStp))
p.close() p.close()
##Make movies: ##Make movies:
......
...@@ -134,7 +134,6 @@ print('Is extracting root mask...') ...@@ -134,7 +134,6 @@ print('Is extracting root mask...')
os.system('mkdir pictureSkeleton/mask') os.system('mkdir pictureSkeleton/mask')
###Loop over the pictures: ###Loop over the pictures:
for iPct in range(NbStp): for iPct in range(NbStp):
global Imin,Imax,Jmin,Jmax,timePic,JIseed,ThrdPict,pict_mask
print(str(iPct)+' / '+str(NbStp)) print(str(iPct)+' / '+str(NbStp))
####Load pictures: ####Load pictures:
pictA=misc.imread('pictureWh/'+'%04d'%iPct+'.jpg')[:,:,0] pictA=misc.imread('pictureWh/'+'%04d'%iPct+'.jpg')[:,:,0]
...@@ -162,7 +161,7 @@ for iPct in range(NbStp): ...@@ -162,7 +161,7 @@ for iPct in range(NbStp):
#####Get current pixels #####Get current pixels
I=np.where(pictA==itArea) I=np.where(pictA==itArea)
#####If current area is big enough to be considered: #####If current area is big enough to be considered:
if (len(I[0])>1000): if (len(I[0])>500):
#####If the seed point is in the current area this is the root: #####If the seed point is in the current area this is the root:
if np.min(np.sqrt((I[0]-JIseed[0][1])**2.+(I[1]-JIseed[0][0])**2.))<2: if np.min(np.sqrt((I[0]-JIseed[0][1])**2.+(I[1]-JIseed[0][0])**2.))<2:
flag1=0 flag1=0
...@@ -206,7 +205,7 @@ os.system('mkdir rootTip/byStep') ...@@ -206,7 +205,7 @@ os.system('mkdir rootTip/byStep')
timePic=np.loadtxt('time.txt') timePic=np.loadtxt('time.txt')
##Loop over the steps: ##Loop over the steps:
for iPct in xrange(NbStp): for iPct in range(NbStp):
###Load the mask: ###Load the mask:
pict4=misc.imread('pictureSkeleton/mask/'+'%04d'%iPct+'.png') pict4=misc.imread('pictureSkeleton/mask/'+'%04d'%iPct+'.png')
###Computation of the mask contour: ###Computation of the mask contour:
...@@ -230,7 +229,7 @@ for iPct in xrange(NbStp): ...@@ -230,7 +229,7 @@ for iPct in xrange(NbStp):
####Computation of the cross-product: ####Computation of the cross-product:
Curv=np.zeros(len(contour)) Curv=np.zeros(len(contour))
for itCurv in xrange(1,len(contour)-1): for itCurv in range(1,len(contour)-1):
x0=X0[itCurv-1]; y0=Y0[itCurv-1] x0=X0[itCurv-1]; y0=Y0[itCurv-1]
x1=X0[itCurv]; y1=Y0[itCurv] x1=X0[itCurv]; y1=Y0[itCurv]
x2=X0[itCurv+1]; y2=Y0[itCurv+1] x2=X0[itCurv+1]; y2=Y0[itCurv+1]
...@@ -289,7 +288,7 @@ for iPct in xrange(NbStp): ...@@ -289,7 +288,7 @@ for iPct in xrange(NbStp):
##Plot and save root tip pathes in color time evolution: ##Plot and save root tip pathes in color time evolution:
###Loop over the steps: ###Loop over the steps:
X=[]; Y=[]; T=[] X=[]; Y=[]; T=[]
for iPct in xrange(NbStp): for iPct in range(NbStp):
if os.path.isfile('rootTip/byStep/'+'%04d'%iPct+'.txt'): if os.path.isfile('rootTip/byStep/'+'%04d'%iPct+'.txt'):
XY_tmp=np.loadtxt('rootTip/byStep/'+'%04d'%iPct+'.txt') XY_tmp=np.loadtxt('rootTip/byStep/'+'%04d'%iPct+'.txt')
if XY_tmp.ndim>1: if XY_tmp.ndim>1:
...@@ -324,7 +323,7 @@ plt.close() ...@@ -324,7 +323,7 @@ plt.close()
os.system('mkdir rootTip/byTip') os.system('mkdir rootTip/byTip')
###Loop over the steps ###Loop over the steps
for iPct in xrange(NbStp): for iPct in range(NbStp):
###Load current tips position vector: ###Load current tips position vector:
A=np.loadtxt('rootTip/byStep/'+'%04d'%iPct+'.txt') A=np.loadtxt('rootTip/byStep/'+'%04d'%iPct+'.txt')
if (A.ndim>0): if (A.ndim>0):
...@@ -340,7 +339,7 @@ for iPct in xrange(NbStp): ...@@ -340,7 +339,7 @@ for iPct in xrange(NbStp):
tc=timePic[iPct] tc=timePic[iPct]
if (iPct==0): if (iPct==0):
###Initialize storage matrix: ###Initialize storage matrix:
for iPt in xrange(len(Xc)): for iPt in range(len(Xc)):
if (iPt==0): if (iPt==0):
MatRoot=[np.array([Xc[iPt],Yc[iPt],tc])] MatRoot=[np.array([Xc[iPt],Yc[iPt],tc])]
else: else:
...@@ -354,7 +353,7 @@ for iPct in xrange(NbStp): ...@@ -354,7 +353,7 @@ for iPct in xrange(NbStp):
Xc=np.delete(Xc,0); Yc=np.delete(Yc,0) Xc=np.delete(Xc,0); Yc=np.delete(Yc,0)
####Measure the distance to the previously detected tips: ####Measure the distance to the previously detected tips:
Dc=np.zeros(len(MatRoot)) Dc=np.zeros(len(MatRoot))
for iPt in xrange(len(MatRoot)): for iPt in range(len(MatRoot)):
#####Load the last position: #####Load the last position:
if (MatRoot[iPt].ndim==1): if (MatRoot[iPt].ndim==1):
xcc=MatRoot[iPt][0]; ycc=MatRoot[iPt][1] xcc=MatRoot[iPt][0]; ycc=MatRoot[iPt][1]
...@@ -376,7 +375,7 @@ for iPct in xrange(NbStp): ...@@ -376,7 +375,7 @@ for iPct in xrange(NbStp):
MatRoot0=MatRoot MatRoot0=MatRoot
MatRoot=[] MatRoot=[]
###Loop over detected roots: ###Loop over detected roots:
for iMrt in xrange(len(MatRoot0)): for iMrt in range(len(MatRoot0)):
if (MatRoot0[iMrt].ndim>1): if (MatRoot0[iMrt].ndim>1):
####Load the current root: ####Load the current root:
curRoot=MatRoot0[iMrt] curRoot=MatRoot0[iMrt]
...@@ -390,7 +389,7 @@ for iMrt in xrange(len(MatRoot0)): ...@@ -390,7 +389,7 @@ for iMrt in xrange(len(MatRoot0)):
MatRoot=MatRoot+[MatRoot0[iMrt]] MatRoot=MatRoot+[MatRoot0[iMrt]]
# ! Debug !: # ! Debug !:
#~ for iMrt in xrange(len(MatRoot)): #~ for iMrt in range(len(MatRoot)):
#~ curRoot=MatRoot0[iMrt] #~ curRoot=MatRoot0[iMrt]
#~ plt.plot(curRoot[:,0],curRoot[:,1],'-') #~ plt.plot(curRoot[:,0],curRoot[:,1],'-')
...@@ -401,7 +400,7 @@ for iMrt in xrange(len(MatRoot0)): ...@@ -401,7 +400,7 @@ for iMrt in xrange(len(MatRoot0)):
###Prepare to store the speed amplitude: ###Prepare to store the speed amplitude:
Vmin=float("inf"); Vmax=0. Vmin=float("inf"); Vmax=0.
###Loop over root trajectories: ###Loop over root trajectories:
for iMrt in xrange(len(MatRoot)): for iMrt in range(len(MatRoot)):
####Get the current trajectory: ####Get the current trajectory:
Xc=MatRoot[iMrt][:,0]; Yc=MatRoot[iMrt][:,1]; Tc=MatRoot[iMrt][:,2] Xc=MatRoot[iMrt][:,0]; Yc=MatRoot[iMrt][:,1]; Tc=MatRoot[iMrt][:,2]
####Compute the speed: ####Compute the speed:
...@@ -423,7 +422,7 @@ for iMrt in xrange(len(MatRoot)): ...@@ -423,7 +422,7 @@ for iMrt in xrange(len(MatRoot)):
##Storage of the data: ##Storage of the data:
for iMrt in xrange(len(MatRoot)): for iMrt in range(len(MatRoot)):
np.savetxt('rootTip/byTip/'+'%04d'%iMrt+'.txt',MatRoot[iMrt],delimiter=' ') np.savetxt('rootTip/byTip/'+'%04d'%iMrt+'.txt',MatRoot[iMrt],delimiter=' ')
##Plot by speed: ##Plot by speed:
...@@ -431,7 +430,7 @@ for iMrt in xrange(len(MatRoot)): ...@@ -431,7 +430,7 @@ for iMrt in xrange(len(MatRoot)):
pict4=misc.imread('pictureSkeleton/mask/'+'%04d'%(NbStp-1)+'.png') pict4=misc.imread('pictureSkeleton/mask/'+'%04d'%(NbStp-1)+'.png')
plt.imshow(pict4,plt.cm.Greys) plt.imshow(pict4,plt.cm.Greys)
###Loop over roots: ###Loop over roots:
for iMrt in xrange(len(MatRoot)): for iMrt in range(len(MatRoot)):
Xc=MatRoot[iMrt][:,0]; Yc=MatRoot[iMrt][:,1]; Tc=MatRoot[iMrt][:,2]; Vc=MatRoot[iMrt][:,3] Xc=MatRoot[iMrt][:,0]; Yc=MatRoot[iMrt][:,1]; Tc=MatRoot[iMrt][:,2]; Vc=MatRoot[iMrt][:,3]
if iMrt==0: if iMrt==0:
sc=plt.scatter(Xc,Yc,c=Vc,s=5,cmap=plt.cm.get_cmap('jet')) sc=plt.scatter(Xc,Yc,c=Vc,s=5,cmap=plt.cm.get_cmap('jet'))
...@@ -454,7 +453,7 @@ os.system('mkdir tmp') ...@@ -454,7 +453,7 @@ os.system('mkdir tmp')
def PlotSkeleton(iPct): def PlotSkeleton(iPct):
global timePic global timePic
print iPct print(iPct)
###Load the time: ###Load the time:
t0=timePic[iPct] t0=timePic[iPct]
h0,m0=divmod(t0,60) h0,m0=divmod(t0,60)
...@@ -470,7 +469,7 @@ def PlotSkeleton(iPct): ...@@ -470,7 +469,7 @@ def PlotSkeleton(iPct):
##Cropping: ##Cropping:
print('... is plotting root skeleton') print('... is plotting root skeleton')
for itStp in xrange(NbStp): for itStp in range(NbStp):
PlotSkeleton(itStp) PlotSkeleton(itStp)
##Make movie: ##Make movie:
...@@ -485,7 +484,7 @@ null=os.system('rm -f -R tmp') ...@@ -485,7 +484,7 @@ null=os.system('rm -f -R tmp')
os.system('mkdir tmp') os.system('mkdir tmp')
fig = plt.figure() fig = plt.figure()
ax = fig.gca(projection='3d') ax = fig.gca(projection='3d')
for iMrt in xrange(len(MatRoot)): for iMrt in range(len(MatRoot)):
Xc=MatRoot[iMrt][:,0]; Yc=MatRoot[iMrt][:,1]; Tc=MatRoot[iMrt][:,2]; Xc=MatRoot[iMrt][:,0]; Yc=MatRoot[iMrt][:,1]; Tc=MatRoot[iMrt][:,2];
ax.plot(Tc/(24*60),Xc,-Yc,'k-',linewidth=3) ax.plot(Tc/(24*60),Xc,-Yc,'k-',linewidth=3)
...@@ -494,7 +493,7 @@ ax.set_xlabel('time (d)') ...@@ -494,7 +493,7 @@ ax.set_xlabel('time (d)')
ax.set_ylabel('x (px)') ax.set_ylabel('x (px)')
ax.set_zlabel('y (px)') ax.set_zlabel('y (px)')
ang=np.linspace(70,70+360,360) ang=np.linspace(70,70+360,360)
for iPic in xrange(len(ang)): for iPic in range(len(ang)):
ax.view_init(5,ang[iPic]) ax.view_init(5,ang[iPic])
plt.savefig('tmp/'+'%04d'%iPic+'.png',dpi=150) plt.savefig('tmp/'+'%04d'%iPic+'.png',dpi=150)
......
...@@ -45,7 +45,7 @@ while flag0: ...@@ -45,7 +45,7 @@ while flag0:
X0=np.vstack(MatRoot)[:,0] X0=np.vstack(MatRoot)[:,0]
Y0=-np.vstack(MatRoot)[:,1] Y0=-np.vstack(MatRoot)[:,1]
####Plot them ####Plot them
for iMrt in xrange(len(MatRoot)): for iMrt in range(len(MatRoot)):
Xc=MatRoot[iMrt][:,0]; Yc=MatRoot[iMrt][:,1] Xc=MatRoot[iMrt][:,0]; Yc=MatRoot[iMrt][:,1]
plt.plot(Xc,-Yc,'-',markersize=5,linewidth=2) plt.plot(Xc,-Yc,'-',markersize=5,linewidth=2)
...@@ -126,7 +126,7 @@ for NU in range(3): ...@@ -126,7 +126,7 @@ for NU in range(3):
#~ plt.show() #~ plt.show()
#~ plt.close() #~ plt.close()
##Compute the speed from the smothed signal: !!! attention certain diff T nuls a verifier!!! ##Compute the speed from the smothed signal: !!! attention parfois certain diff T nuls a verifier!!!
###Direct computation: ###Direct computation:
V=np.zeros(len(T)) V=np.zeros(len(T))
V[1:]=np.sqrt((P[1:,0]-P[0:-1,0])**2.+(P[1:,1]-P[0:-1,1])**2.)/(T[1:]-T[0:-1]) V[1:]=np.sqrt((P[1:,0]-P[0:-1,0])**2.+(P[1:,1]-P[0:-1,1])**2.)/(T[1:]-T[0:-1])
...@@ -140,12 +140,19 @@ Vn=np.convolve(V,np.ones(20)/20.,mode='same') ...@@ -140,12 +140,19 @@ Vn=np.convolve(V,np.ones(20)/20.,mode='same')
#~ plt.show() #~ plt.show()
#~ plt.close() #~ plt.close()
##Plot result:
plt.plot(T,Vn,'-k',linewidth=3)
plt.xlabel('time (min)')
plt.ylabel('tip speed (px/min)')
plt.savefig('mainRoot/rootTip/speedTip.png',dpi=400)
plt.savefig('mainRoot/rootTip/speedTip.svg')
##Saved data: ##Saved data:
os.system('mkdir mainRoot') os.system('mkdir mainRoot')
os.system('mkdir mainRoot/rootTip') os.system('mkdir mainRoot/rootTip')
np.savetxt('mainRoot/rootTip/position.txt',P) np.savetxt('mainRoot/rootTip/position.txt',P)
np.savetxt('mainRoot/rootTip/time.txt',T) np.savetxt('mainRoot/rootTip/time.txt',T)
np.savetxt('mainRoot/rootTip/speedTip.txt',V) np.savetxt('mainRoot/rootTip/speedTip.txt',Vn)
#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~# #~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#
...@@ -181,7 +188,7 @@ def GetWeightSkel(iPct): ...@@ -181,7 +188,7 @@ def GetWeightSkel(iPct):
###Parallelization of the skeleton: ###Parallelization of the skeleton:
p=Pool(NbProc) p=Pool(NbProc)
null=p.map(GetWeightSkel,xrange(NbStp)) null=p.map(GetWeightSkel,range(NbStp))
p.close() p.close()
##Function to follow the main root: ##Function to follow the main root:
...@@ -374,7 +381,6 @@ a=plt.ginput(1,timeout=-1) ...@@ -374,7 +381,6 @@ a=plt.ginput(1,timeout=-1)
plt.close() plt.close()
S_max=int(a[0][0]) S_max=int(a[0][0])
##Fix pathes: ##Fix pathes:
###Loop over root path: ###Loop over root path:
for iPct in range(1,NbStp): for iPct in range(1,NbStp):
...@@ -421,6 +427,8 @@ for iPct in range(NbStp): ...@@ -421,6 +427,8 @@ for iPct in range(NbStp):
sc=plt.scatter(np.zeros(len(time0)),np.zeros(len(time0)),c=time0,s=0,cmap=cm) sc=plt.scatter(np.zeros(len(time0)),np.zeros(len(time0)),c=time0,s=0,cmap=cm)
plt.colorbar(sc) plt.colorbar(sc)
plt.axis('equal') plt.axis('equal')
plt.xlabel('px')
plt.ylabel('px')
plt.savefig('mainRoot/mainRoot.png',dpi=400) plt.savefig('mainRoot/mainRoot.png',dpi=400)
plt.savefig('mainRoot/mainRoot.svg') plt.savefig('mainRoot/mainRoot.svg')
plt.show() plt.show()
...@@ -478,15 +486,15 @@ vec_V[1:]=(vec_L_smth[1:]-vec_L_smth[0:-1])/(time0[1:]-time0[0:-1]) ...@@ -478,15 +486,15 @@ vec_V[1:]=(vec_L_smth[1:]-vec_L_smth[0:-1])/(time0[1:]-time0[0:-1])
plt.plot(time0,vec_V,'-k',linewidth=3) plt.plot(time0,vec_V,'-k',linewidth=3)
plt.xlabel('time (min)') plt.xlabel('time (min)')
plt.ylabel('main root growth speed (px/min)') plt.ylabel('main root growth speed (px/min)')
plt.savefig('mainRoot/mainRootSpeed.png',dpi=400) plt.savefig('mainRoot/mainRootLengthSpeed.png',dpi=400)
plt.savefig('mainRoot/mainRootSpeed.svg') plt.savefig('mainRoot/mainRootLengthSpeed.svg')
plt.show() plt.show()
plt.close() plt.close()
###Save data: ###Save data:
np.savetxt('mainRoot/speedLength.txt',vec_V) np.savetxt('mainRoot/speedLength.txt',vec_V)
##Computation of the main root curvature evolution: ##Computation of the main root curvature and orientation evolution:
###Function to compute curvature: ###Function to compute curvature and local orientation:
def GetCurvature(iPct): def GetCurvature(iPct):
print(str(iPct)+' / '+str(NbStp)) print(str(iPct)+' / '+str(NbStp))
####Load root path coordinates: ####Load root path coordinates:
...@@ -525,12 +533,20 @@ def GetCurvature(iPct): ...@@ -525,12 +533,20 @@ def GetCurvature(iPct):
####Store curvature: ####Store curvature:
np.savetxt('mainRoot/rootCurvature/'+str(iPct).zfill(4)+'.txt',C0) np.savetxt('mainRoot/rootCurvature/'+str(iPct).zfill(4)+'.txt',C0)
####Local orientation computation:
O0=np.arctan2(J1(s[1:])-J1(s[0:-1]),-I1(s[1:])+I1(s[0:-1]))*180./m.pi
O0=np.append(O0,O0[-1])
####Store curvature:
np.savetxt('mainRoot/rootOrientation/'+str(iPct).zfill(4)+'.txt',O0)
###Make storage folder: ###Make storage folder:
os.system('mkdir mainRoot/rootCurvature') os.system('mkdir mainRoot/rootCurvature')
os.system('mkdir mainRoot/rootOrientation')
###Parallelization of the main root curvature computation: ###Parallelization of the main root curvature computation:
p=Pool(NbProc) p=Pool(NbProc)
null=p.map(GetCurvature,xrange(NbStp)) null=p.map(GetCurvature,range(NbStp))
p.close() p.close()
###Display the curvature: ###Display the curvature:
...@@ -558,8 +574,9 @@ plt.imshow(matDisp,vmin=Cm,vmax=CM,cmap=plt.cm.get_cmap('jet'),aspect='auto') ...@@ -558,8 +574,9 @@ plt.imshow(matDisp,vmin=Cm,vmax=CM,cmap=plt.cm.get_cmap('jet'),aspect='auto')
plt.colorbar() plt.colorbar()
plt.title('root curvature (1/px)') plt.title('root curvature (1/px)')
plt.xlabel('curvilinear coordinate (px)') plt.xlabel('curvilinear coordinate (px)')
plt.ylabel('time') plt.ylabel('time (min)')
ax.set_yticks([]) ax.set_yticks([0,0.2*matDisp.shape[0],0.4*matDisp.shape[0],0.6*matDisp.shape[0],0.8*matDisp.shape[0],matDisp.shape[0]])
ax.set_yticklabels([str(int(time0[-1])),str(int(time0[int(len(time0)*0.8)])),str(int(time0[int(len(time0)*0.6)])),str(int(time0[int(len(time0)*0.4)])),str(int(time0[int(len(time0)*0.2)])),'0'])
plt.savefig('mainRoot/mainRootCurvature1.png',dpi=400) plt.savefig('mainRoot/mainRootCurvature1.png',dpi=400)
plt.savefig('mainRoot/mainRootCurvature1.svg') plt.savefig('mainRoot/mainRootCurvature1.svg')
plt.show() plt.show()
...@@ -579,11 +596,63 @@ for iPct in range(NbStp): ...@@ -579,11 +596,63 @@ for iPct in range(NbStp):
plt.title('root curvature magnitude (1/px)') plt.title('root curvature magnitude (1/px)')
plt.axis('equal') plt.axis('equal')
plt.xlabel('px')
plt.ylabel('px')
plt.savefig('mainRoot/mainRootCurvature2.png',dpi=400) plt.savefig('mainRoot/mainRootCurvature2.png',dpi=400)
#~ plt.savefig('mainRoot/mainRootCurvature2.svg') #~ plt.savefig('mainRoot/mainRootCurvature2.svg')
plt.show() plt.show()
plt.close() plt.close()
###Display the local orientation:
####Color amplitude:
N0=0
for it in range(NbStp):
n0=len(np.loadtxt('mainRoot/rootOrientation/'+str(it).zfill(4)+'.txt'))
if N0<n0:
N0=n0
####In matrix form:
matDisp=float('nan')*np.ones((len(time0),N0))
for iPct in range(NbStp):
if os.path.isfile('mainRoot/rootOrientation/'+str(iPct).zfill(4)+'.txt'):
O0=np.loadtxt('mainRoot/rootOrientation/'+str(iPct).zfill(4)+'.txt')
O0=O0[np.arange(len(O0)-1,0,-1)]
matDisp[-1-iPct,0:len(O0)]=O0