Commit 665fef35 authored by Katharina Anders's avatar Katharina Anders

adapted for Python3

parent aad9afb7
......@@ -9,7 +9,7 @@ __version__ = "1.0"
def info():
print '''TERRAIN PROBABILITY SCRIPT
print('''TERRAIN PROBABILITY SCRIPT
This script uses amplitude and echo width of returns to assign
a terrain probability to each point of a point cloud based on
......@@ -21,7 +21,7 @@ def info():
Vienna, Austria. 157-162.
Script (c) 3DGeo, Heidelberg University (2017-)
'''
''')
try:
import sys
......@@ -31,8 +31,8 @@ try:
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
except:
print "Could not import required modules. Please ensure availability of:"
print "numpy, scipy, and matplotlib"
print("Could not import required modules. Please ensure availability of:")
print("numpy, scipy, and matplotlib")
def countLines(file):
with open(file,"r") as ifo:
......@@ -43,7 +43,7 @@ def countLines(file):
def readInput(infile,colAmpl,colEW,linecount):
print "\nReading input data..."
print("\nReading input data...")
data = np.empty([linecount, 2]) # array with [echowidth, amplitude]
with open(infile, "r") as ifo:
c = 0
......@@ -55,8 +55,8 @@ def readInput(infile,colAmpl,colEW,linecount):
data[c, 1] = amplitude
c += 1
if c % 10000 == 0:
print "\r%i lines of %i read" % (c, linecount),
print "\r%i of %i lines read" % (c, linecount)
print("\r%i lines of %i read" % (c, linecount),)
print("\r%i of %i lines read" % (c, linecount))
return data
......@@ -65,7 +65,7 @@ def func(x, a, b, c):
def createsub(data,num):
print "Extracting a subset of size %i from the input point cloud data..." % num
print("Extracting a subset of size %i from the input point cloud data..." % num)
np.random.shuffle(data)
data_sub = data[:num]
return data_sub
......@@ -84,9 +84,9 @@ def clip_data(data_sub,medEW):
return data_lefteq
def usage():
print "--- USAGE ---"
print "%s <input point cloud file> <column id with amplitude values> <column id with echo width values> <number of points to use as point cloud subset (default: 150 mio.)" % sys.argv[0]
print "(e.g.: %s ALS_data.txt 4 5 15000000)" % sys.argv[0]
print("--- USAGE ---")
print("%s <input point cloud file> <column id with amplitude values> <column id with echo width values> <number of points to use as point cloud subset (default: 150 mio.)" % sys.argv[0])
print("(e.g.: %s ALS_data.txt 4 5 15000000)" % sys.argv[0])
def main():
try:
......@@ -99,9 +99,9 @@ def main():
numPtsUsed=150000000
basename=os.path.basename(infile).strip().split(".")[0]
except:
print "Error in script call\n"
print("Error in script call\n")
usage()
print "\nExit"
print("\nExit")
sys.exit()
info()
......@@ -118,13 +118,13 @@ def main():
linecount = numPtsUsed
# statistics
print "\nDetermining median values of echo width and amplitude..."
print("\nDetermining median values of echo width and amplitude...")
medEW, medAMP = np.ma.median(data, axis=0)
data_lefteq=clip_data(data, medEW)
# extract upper points for curve fit to flank (threshold: 90% ampl. for 0.1 bins of echo width)
print "Fitting curve to point distribution..."
print("Fitting curve to point distribution...")
data_inline = []
n=data_lefteq.size
bin_start=n
......@@ -152,7 +152,7 @@ def main():
try:
popt, pcov = curve_fit(func, xdata, ydata)
except:
print "ERROR: Could not fit a curve to the input data. Try increasing the subset size to a representative number or check the input file."
print("ERROR: Could not fit a curve to the input data. Try increasing the subset size to a representative number or check the input file.")
sys.exit(-1)
# fit curve to data flipped to right flank
......@@ -167,10 +167,10 @@ def main():
try:
popt_mirr_shft, pcov_mirr_shft = curve_fit(func, xdata_r_shifted, ydata_r)
except:
print "ERROR: Could not fit a mirrored curve to the input data. Try increasing the subset size to a representative number."
print("ERROR: Could not fit a mirrored curve to the input data. Try increasing the subset size to a representative number.")
sys.exit(-1)
print "Generating scatter plot..."
print("Generating scatter plot...")
fig = plt.figure()
ax = fig.add_subplot(111)
......@@ -204,7 +204,7 @@ def main():
#plt.show()
figname="scatter_terrain_probability.png"
plt.savefig(figname,dpi=300)
print "Plot written to:", figname
print("Plot written to:", figname)
# construct curve values
# y_left = func(xdata, *popt)
......@@ -213,7 +213,7 @@ def main():
# store terrain probability info as attribute to new file
print "\nAdding terrain probability to point cloud file: 0%% done",
print("\nAdding terrain probability to point cloud file: 0%% done",)
c=0
p=5
outfile= basename + "_terrainprob.txt"
......@@ -248,14 +248,14 @@ def main():
progress=int(c/linecount*100)
if progress>p:
p+=5
print "\rAdding terrain probability to point cloud file: %i%% done" % (progress),
print("\rAdding terrain probability to point cloud file: %i%% done" % (progress),)
print "\rTerrain probability written to new point cloud file: %s" % outfile
print("\rTerrain probability written to new point cloud file: %s" % outfile)
# duration of process
endtime=time.time()
runtime=endtime-starttime
print "\nFinished script process after %i sec\n" % int(runtime)
print("\nFinished script process after %i sec\n" % int(runtime))
if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment