diff --git a/las_outputs.py b/las_outputs.py index 04dfce1..ec6adb2 100644 --- a/las_outputs.py +++ b/las_outputs.py @@ -22,7 +22,7 @@ from cycler import cycler import matplotlib.pyplot as plt from matplotlib.ticker import MultipleLocator -import neilson_volumes +import nielsen_volumes from survey_tools import call_lastools, extract_pts, update_survey_output diff --git a/nielsen_volumes.py b/nielsen_volumes.py new file mode 100644 index 0000000..81a9389 --- /dev/null +++ b/nielsen_volumes.py @@ -0,0 +1,188 @@ +# +import scipy.interpolate +import numpy as np +import copy +import math + + +repose_angle=34 #angle of repose of sand +repose_slope=1/math.tan(math.radians(repose_angle)) + +def insertZerochainage(chainage, elevation): + #this inserts a 0 every time the profile crosses the axis + #need to update the chainage elevation for every point that drops below the required chainage + ii=0 + while ii=0 and y[i-1]>=0: + area=area+0.5*(x[i]-x[i-1])*(y[i]+y[i-1]) + i=i+1 + + return area + +def findIntersection(x11,y11,x12,y12,x21,y21,x22,y22): + #find the intersection of a two lines defined by four points + try: + m1=(y12-y11)/(x12-x11) + b1=y11-m1*x11 + except (ZeroDivisionError,FloatingPointError): + x_inter=x11 + m2=(y22-y21)/(x22-x21) + b2=y21-m2*x21 + y_inter=m2*x_inter+b2 + + return x_inter, y_inter + + try: + m2=(y22-y21)/(x22-x21) + b2=y21-m2*x21 + except (ZeroDivisionError, FloatingPointError): + x_inter=x21 + y_inter=m1*x_inter +b1 + + return x_inter, y_inter + + x_inter=(b2-b1)/(m1-m2) + y_inter=m1*x_inter+b1 + + return x_inter, y_inter + +def findZerochainage(chainage0, elevation0, max_beach_slope=5, min_beach_slope=50): + #often the photogrammetry has a repeated point at the end. Check for this and remove extra if required + while chainage0[-1]==chainage0[-2] and elevation0[-1]==elevation0[-2]: + chainage0 = chainage0[:-1] + elevation0 = elevation0[:-1] + + #check if the profile ever goes below zero + ii=len(elevation0)-1 + below_0=False + while ii>len(elevation0)/2: + if elevation0[ii]<0: + below_0=True + while elevation0[ii]<0: + ii=ii-1 + j=ii+1 #so you don't have to search for this again + ii=0 + else: + ii=ii-1 + + # if Below_0 = True, we can use the actual zero value + if below_0==True: + chainage0=chainage0[0:j+1] + elevation0=elevation0[0:j+1] + elevation_inter=scipy.interpolate.interp1d(elevation0[-2:],chainage0[-2:]) + chainage_0=float(elevation_inter(0)) + chainage0[j]=chainage_0 + elevation0[j]=0 + #otherwise need to extrapolate + else: + #find the slope between the last two points + try: + beachslope = 1/((elevation0[-2] - elevation0[-1])/(chainage0[-1] - chainage0[-2])) + except ZeroDivisionError: + beachslope= 999 + if beachslope>min_beach_slope: + beachslope = min_beach_slope + elif beachslope