added first pass of CLI options. can change output resoltion and output

filename.
This commit is contained in:
gabriel venberg 2021-03-18 00:30:34 -05:00
parent 6335c4b474
commit 9787052272

View file

@ -1,7 +1,6 @@
#! /usr/bin/env python3 #! /usr/bin/env python3
#command line arguments: #command line arguments:
# --help, -h, outputs usage of the program # -x, -y, width and hight of the output image
# -x, -y, outputs width and hight of the output image
# --output, -o, name of output file. if there are multiple input files, there will be a number prepended to this. # --output, -o, name of output file. if there are multiple input files, there will be a number prepended to this.
# after all comamnd line arguments, file or files(space seperated) to process. # after all comamnd line arguments, file or files(space seperated) to process.
@ -10,11 +9,30 @@ import numpy as np
import sys, argparse, laspy, logging import sys, argparse, laspy, logging
import seaborn as sns; sns.set_theme() import seaborn as sns; sns.set_theme()
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from PIL import Image
logging.basicConfig(format='%(asctime)s:%(message)s', level=logging.INFO) logging.basicConfig(format='%(asctime)s:%(message)s', level=logging.INFO)
#logging.basicConfig(format='%(asctime)s:%(message)s', level=logging.DEBUG) #logging.basicConfig(format='%(asctime)s:%(message)s', level=logging.DEBUG)
def parse_arguments():
parser = argparse.ArgumentParser(description='create a top down hightmap from a LIDAR point file.')
parser.add_argument('file', help='.las file to process.')
parser.add_argument('-x', default=100, type=int, help='horizontal size (in cells) of the output image. Defaults to 100')
parser.add_argument('-y', default=100, type=int, help='vertical size (in cells) if the output image. Defaults to 100')
parser.add_argument('-o', '--output', help='name of output file. will default to [name of input file].png if not given.')
args=parser.parse_args()
imgX=args.x
imgY=args.y
inFile=args.file
if args.output==None:
outFile = f'{os.path.dirname(inFile)}/{os.path.basename(inFile)}.png'
else:
outFile=args.output
print(f'outputing to {outFile}')
def scale(array, desiredmaxX, desiredmaxY): def scale(array, desiredmaxX, desiredmaxY):
logging.debug(f'xMax is {np.max(array[:,xDim])} and xMin is {np.min(array[:,xDim])}') logging.debug(f'xMax is {np.max(array[:,xDim])} and xMin is {np.min(array[:,xDim])}')
logging.debug(f'yMax is {np.max(array[:,yDim])} and yMin is {np.min(array[:,yDim])}') logging.debug(f'yMax is {np.max(array[:,yDim])} and yMin is {np.min(array[:,yDim])}')
@ -34,18 +52,11 @@ def scale(array, desiredmaxX, desiredmaxY):
return array return array
imgX=500
imgY=500
#TODO: make it iterate over multiple files. #TODO: make it iterate over multiple files.
inFile = os.path.realpath(sys.argv[1]) parse_arguments()
lasFile = laspy.file.File(inFile, mode = 'r')
outFile = f'{os.path.dirname(inFile)}/{imgX}*{imgY}{os.path.basename(inFile)}.png'
print(f'outputing to {outFile}')
#import each dimention scaled. #import each dimention scaled.
lasFile=laspy.file.File(inFile, mode = 'r')
z = lasFile.z z = lasFile.z
x = lasFile.x x = lasFile.x
y = lasFile.y y = lasFile.y
@ -53,7 +64,7 @@ intensity = lasFile.intensity
points = np.stack((z,x,y), axis=-1) points = np.stack((z,x,y), axis=-1)
#dimention that will be z(top down) dimention in final heatmap. TODO: auto detect this based on dimention with least variance. #dimention that will be z(top down) dimention in final heatmap. TODO: auto detect this based on dimention with least variance, while being overridable on the command line.
zDim=1 zDim=1
xDim=2 xDim=2
yDim=0 yDim=0