Skip to content

Commit

Permalink
numpy int alias is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathijs van Gorcum committed Oct 12, 2023
1 parent d70c10c commit 09010b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
24 changes: 12 additions & 12 deletions drop_analysis/edge_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ def analysis(edgeleft,edgeright,baseinput,framesize,k=100,PO=3,fittype='Polyfit'
"""
import numpy as np

#use shapely linestrings to find the intersectionpoints between the edges and baseline
#use shapely linestrings to find the intersection points between the edges and baseline
baseline=LineString(baseinput)
rightline=LineString(np.column_stack((edgeright,(range(0,framesize[0])))))
leftline=LineString(np.column_stack((edgeleft,(range(0,framesize[0])))))
leftcontact=baseline.intersection(leftline)
rightcontact=baseline.intersection(rightline)
fitpointsleft=edgeleft[range(np.int(np.floor(leftcontact.y)),np.int(np.floor(leftcontact.y)-k),-1)]
fitpointsleft=edgeleft[range(int(np.floor(leftcontact.y)),int(np.floor(leftcontact.y)-k),-1)]

#if no edge was detected the value is set to 0 (ie. the edge of the image) so discard all these points
if any(fitpointsleft==0):
fitpointsleft=np.delete(fitpointsleft,range(np.argmax(fitpointsleft==0),k))
fitpointsright=edgeright[range(np.int(np.floor(rightcontact.y)),np.int(np.floor(rightcontact.y)-k),-1)]
fitpointsright=edgeright[range(int(np.floor(rightcontact.y)),int(np.floor(rightcontact.y)-k),-1)]
if any(fitpointsright==0):
fitpointsright=np.delete(fitpointsright,range(np.argmax(fitpointsright==0),k))

Expand All @@ -46,20 +46,20 @@ def volumecalc(leftcontact,rightcontact,edgeleft,edgeright):
"""
import numpy as np
dropvolume=0
for height in range (0,min(np.int(np.floor(leftcontact.y)),np.int(np.floor(rightcontact.y)))):
for height in range (0,min(int(np.floor(leftcontact.y)),int(np.floor(rightcontact.y)))):
dropvolume=dropvolume+np.pi*np.square((edgeright[height]-edgeleft[height])/2)
#using cylindrical slice we calculate the remaining volume
slantedbasediff=max(np.floor(leftcontact.y),np.floor(rightcontact.y))-min(np.floor(leftcontact.y),np.floor(rightcontact.y))
#we assume that the radius is constant over the range of the slanted baseline, for small angles this is probably accurate, but for larger angles this can result in a significant error.
baseradius=(edgeright[np.int(min(np.floor(leftcontact.y),np.floor(rightcontact.y)))]-edgeleft[np.int(min(np.floor(leftcontact.y),np.floor(rightcontact.y)))])/2
baseradius=(edgeright[int(min(np.floor(leftcontact.y),np.floor(rightcontact.y)))]-edgeleft[int(min(np.floor(leftcontact.y),np.floor(rightcontact.y)))])/2
dropvolume=dropvolume+.5*np.pi*np.square(baseradius)*slantedbasediff
return dropvolume

def centerofgravitycalc(leftcontact,rightcontact,edgeleft,edgeright):
yvarleft =np.append(leftcontact.y,range(np.int(np.floor(leftcontact.y)),0,-1))
yvarright=np.append(rightcontact.y,range(np.int(np.floor(rightcontact.y)),0,-1))
edgerightadd=np.append(rightcontact.x,edgeright[range(np.int(np.floor(rightcontact.y)),0,-1)])
edgeleftadd=np.append(leftcontact.x,edgeleft[range(np.int(np.floor(leftcontact.y)),0,-1)])
yvarleft =np.append(leftcontact.y,range(int(np.floor(leftcontact.y)),0,-1))
yvarright=np.append(rightcontact.y,range(int(np.floor(rightcontact.y)),0,-1))
edgerightadd=np.append(rightcontact.x,edgeright[range(int(np.floor(rightcontact.y)),0,-1)])
edgeleftadd=np.append(leftcontact.x,edgeleft[range(int(np.floor(leftcontact.y)),0,-1)])
totaledge=np.append(edgeleftadd,np.flip(edgerightadd))
totalyvar=np.append(yvarleft,np.flip(yvarright))
edgexy=np.column_stack((totaledge,totalyvar))
Expand Down Expand Up @@ -107,8 +107,8 @@ def analysellipse(fitpointsleft,fitpointsright,leftcontact,rightcontact,baseinpu
from ellipse import LsqEllipse
from shapely.geometry import LineString
import numpy as np
yvarleft=range(np.int(np.floor(leftcontact.y)),np.int(np.floor(leftcontact.y)-k),-1)
yvarright=range(np.int(np.floor(rightcontact.y)),np.int(np.floor(rightcontact.y)-k),-1)
yvarleft=range(int(np.floor(leftcontact.y)),int(np.floor(leftcontact.y)-k),-1)
yvarright=range(int(np.floor(rightcontact.y)),int(np.floor(rightcontact.y)-k),-1)
edge=np.append(fitpointsleft,fitpointsright)
yvart=np.append(yvarleft,yvarright)
totalfitpoints=np.array(list(zip(edge, yvart)))
Expand All @@ -117,7 +117,7 @@ def analysellipse(fitpointsleft,fitpointsright,leftcontact,rightcontact,baseinpu

#pointsfitted=reg.return_fit(1000)
a,b,c,d,e,f=reg.coefficients
y=np.linspace(min(np.int(np.floor(leftcontact.y)),np.int(np.floor(rightcontact.y)))-k,max(np.int(np.floor(leftcontact.y)),np.int(np.floor(rightcontact.y)))+k,framesize[0]*10)
y=np.linspace(min(int(np.floor(leftcontact.y)),int(np.floor(rightcontact.y)))-k,max(int(np.floor(leftcontact.y)),int(np.floor(rightcontact.y)))+k,framesize[0]*10)

#split ellipse in two parts with a vertical cut, to find the contact points
#xellipse1&2 are just the function for ellipse solved for x(y)
Expand Down
12 changes: 6 additions & 6 deletions drop_analysis/edge_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ def subpixel_detection(image,thresh,mode):
"""
edge detection, allowing for two subpixel detection methods
"""
erffitsize=np.int(40)
erffitsize=int(40)
framesize=image.shape
edgeleft=np.zeros(framesize[0])
edgeright=np.zeros(framesize[0])
for y in range(framesize[0]-1): #edge detection, go line by line on horizontal
edgeleft[y]=np.argmax(image[y,0:framesize[1]]<thresh) #edge detection on pixel scale
edgeright[y]=np.int(framesize[1]-np.argmax(image[y,range(framesize[1]-1,0,-1)]<thresh))
edgeright[y]=int(framesize[1]-np.argmax(image[y,range(framesize[1]-1,0,-1)]<thresh))
if mode == 'Linear':
leftsubpxcorr,rightsubpxcorr=linear_subpixel(edgeleft[y],edgeright[y],image[y,:],thresh)
elif mode == 'Errorfunction':
Expand All @@ -35,11 +35,11 @@ def linear_subpixel(edgeleft,edgeright,imagerow,thresh):
"""
if edgeleft!=0:
#subpixel correction with using corr=(threshold-intensity(edge-1))/(intensity(edge)-intensity(edge-1))
leftsubpxcorr=(thresh-np.float64(imagerow[np.int(edgeleft-1)]))/(np.float64(imagerow[np.int(edgeleft)])-np.float64(imagerow[np.int(edgeleft-1)]))-1
leftsubpxcorr=(thresh-np.float64(imagerow[int(edgeleft-1)]))/(np.float64(imagerow[int(edgeleft)])-np.float64(imagerow[int(edgeleft-1)]))-1
else:
leftsubpxcorr=0
if edgeright!=len(imagerow):
rightsubpxcorr=(thresh-np.float64(imagerow[np.int(edgeright-1)]))/(np.float64(imagerow[np.int(edgeright)])-np.float64(imagerow[np.int(edgeright-1)]))-1
rightsubpxcorr=(thresh-np.float64(imagerow[int(edgeright-1)]))/(np.float64(imagerow[int(edgeright)])-np.float64(imagerow[int(edgeright-1)]))-1
else:
rightsubpxcorr=0
return leftsubpxcorr,rightsubpxcorr
Expand All @@ -51,14 +51,14 @@ def errorfunc_subpixel(edgeleft,edgeright,imagerow,erffitsize):
def errorfunction(x,xdata,y): #define errorfunction to fit with a least squares fit.
return x[0]*(1+sp.special.erf(xdata*x[1]+x[2]))+x[3] - y
if (edgeleft-erffitsize)>=0 and (edgeleft-erffitsize)<=len(imagerow):
fitparts=np.array(imagerow[range(np.int(edgeleft)-erffitsize,np.int(edgeleft)+erffitsize)]) #take out part of the image around the edge to fit the error function
fitparts=np.array(imagerow[range(int(edgeleft)-erffitsize,int(edgeleft)+erffitsize)]) #take out part of the image around the edge to fit the error function
guess=(max(fitparts)-min(fitparts))/2,-.22,0,min(fitparts) #initial guess for error function
lstsqrsol=least_squares(errorfunction,guess,args=(np.array(range(-erffitsize,erffitsize)),fitparts)) #least sqaures fit
leftsubpxcorr=-lstsqrsol.x[2]/lstsqrsol.x[1] #add the subpixel correction
else:
leftsubpxcorr=0
if (edgeright-erffitsize)>=0 and (edgeright+erffitsize)<len(imagerow):
fitparts=np.array(imagerow[range(np.int(edgeright)-erffitsize,np.int(edgeright)+erffitsize)])
fitparts=np.array(imagerow[range(int(edgeright)-erffitsize,int(edgeright)+erffitsize)])
guess=(max(fitparts)-min(fitparts))/2,.22,0,min(fitparts)
lstsqrsol=least_squares(errorfunction,guess,args=(np.array(range(-erffitsize,erffitsize)),fitparts))
rightsubpxcorr=-lstsqrsol.x[2]/lstsqrsol.x[1]
Expand Down

0 comments on commit 09010b8

Please sign in to comment.