def main(): ''' read data from file ''' print('Reading files') file1='F:/temp/Brisbane_2014_LGA_SW_502000_6965000_1K_Las.laz' tic = time.perf_counter() inFile1 = File(file1, mode='r') toc = time.perf_counter() print(f"{len(inFile1.points):d} records read from {file1:s} in {toc - tic:0.4f} seconds") print('permuting data') tic = time.perf_counter() xvalues=inFile1.get_x_scaled() yvalues=inFile1.get_y_scaled() zvalues=inFile1.get_z_scaled() tvalues=inFile1.get_gps_time() pointclasses=inFile1.get_classification() #tile lower left corner originx, originy=502000,6965000 xoffset=randrange(-500000,500000) yoffset=randrange(-500000,500000) zoffset=randrange(-200,200)``
print("Frequency of unique values of the said array:") print(np.asarray((unique_elements, counts_elements))) src_ids = inFile.get_pt_src_id() print("First number of returns:",num_returns[0]) unique_elements, counts_elements = np.unique(src_ids, return_counts=True) print("Frequency of", "source ids", "of the said array:") print(np.asarray((unique_elements, counts_elements))) #get_scan_dir_flag() flight_lines = inFile.get_edge_flight_line() raw_classes = inFile.get_raw_classification() classes = inFile.get_classification() #scanner_channel = inFile.get_scanner_channel() synthetics = inFile.get_synthetic() key_points = inFile.get_key_point() withehelds_points = inFile.get_withheld() try: overlap = inFile.get_overlap() except laspy.util.LaspyException as err: print("Overlap error: {0}".format(err)) #print(format(err))
if os.path.exists(bootstrap_dir) == False: os.mkdir(bootstrap_dir) figure_dir = os.path.join(args.outputdir, 'figure') if os.path.exists(figure_dir) == False: os.mkdir(figure_dir) pickle_dir = os.path.join(args.outputdir, 'pickle') if os.path.exists(pickle_dir) == False: os.mkdir(pickle_dir) ### Loading data and filtering print('\nLoading input file: %s'%args.inlas) inFile = File(args.inlas, mode='r') pc_xyzic = np.vstack((inFile.get_x()*inFile.header.scale[0]+inFile.header.offset[0], inFile.get_y()*inFile.header.scale[1]+inFile.header.offset[1], inFile.get_z()*inFile.header.scale[2]+inFile.header.offset[2], inFile.get_intensity(), inFile.get_classification())).transpose() #pc_xyzic is now a point cloud with x, y, z, intensity, and classification #if args.store_color == True: # pc_i = inFile.get_intensity().copy() # pc_blue = inFile.get_blue().copy() # pc_green = inFile.get_green().copy() # pc_red = inFile.get_red().copy() print('Loaded %s points'%"{:,}".format(pc_xyzic.shape[0])) if args.ground_only == True: print('\nFiltering points to only work with ground points (class == 2)... ',end='\n') #get only ground points: idx_ground = np.where(pc_xyzic[:,4] == 2)[0] pc_xyzig = pc_xyzic[idx_ground,0:4] pc_xyzg = pc_xyzic[idx_ground,0:3] #pc_xyzg is a point cloud with x, y, z, and for class == 2 only
def geninfo(tilename, ori, rec, validClasses): tdata = OrderedDict() tilecheckPassed = 'Passed' print(tilename) if os.path.isfile(ori) and os.path.isfile(rec): ''' read data from file ''' try: oriFile = File(ori, mode='r') recFile = File(rec, mode='r') except: print(f'File Corrupted : {tilename}') tdata = { "Classification": "None", "Classification_Test": "None", "Critical Failure - Unable to read file": "None", "Version Test": "None", "PDRF": "None", "PDRF Test": "None", "GlobalEncoding": "None", "GlobalEncoding Test": "None", "Number of points": "None", "Number of points Tetst": "None", "Points Test": "None", "GPS times": "None", "GPS Test": "None", "Returns": "None", "Returns Test": "None", "Intensity": "None", "Intensity Test": "None", "Scale": "None", "Scale Test": "None", "Status": "Failed", "Boundaries": "None", "Boundary Test": "None" } return (True, tdata, 'None') ''' create dataframe ori file ''' #tic = time.perf_counter() dataori = {} dataori["points"] = pd.DataFrame(oriFile.points["point"]) dataori["points"].columns = (x.lower() for x in dataori["points"].columns) dataori["points"].loc[:, ["x", "y", "z"]] *= oriFile.header.scale dataori["points"].loc[:, ["x", "y", "z"]] += oriFile.header.offset dataori["header"] = oriFile.header ''' create dataframe rec file ''' datarec = {} datarec["points"] = pd.DataFrame(recFile.points["point"]) datarec["points"].columns = (x.lower() for x in datarec["points"].columns) # rescale and offset datarec["points"].loc[:, ["x", "y", "z"]] *= recFile.header.scale datarec["points"].loc[:, ["x", "y", "z"]] += recFile.header.offset datarec["header"] = recFile.header #toc = time.perf_counter() #print(f"data frame created in {toc - tic:0.4f} seconds") # Header Information ############################################################ # version test ############################################################ o_version = oriFile.header.version r_version = recFile.header.version if o_version != r_version: version_test = 'Failed' tdata['Version'] = f'Ori - {o_version} Rec - {r_version}' tdata['Version Test'] = 'Warning' #print(f"Version test Failed for {tilename}") tilecheckPassed = 'Warning' else: version_test = 'Passed' tdata['Version'] = f'{o_version}' tdata['Version Test'] = 'Passed' #print(f"Version test Passed for {tilename}") ########################################################### # Data Format ID testt (PDRF) ############################################################ o_pdrf = oriFile.header.data_format_id r_pdrf = recFile.header.data_format_id if o_pdrf != r_pdrf: tdata['PDRF'] = f'Ori-{o_pdrf} Rec - {r_pdrf}' tdata['PDRF Test'] = 'Failed' tilecheckPassed = 'Warning' else: tdata['PDRF'] = f'{o_pdrf}' tdata['PDRF Test'] = 'Passed' ########################################################### # Global Engoding test ########################################################### o_ge = oriFile.header.global_encoding r_ge = recFile.header.global_encoding if o_ge != r_ge: tdata['GlobalEncoding'] = f'Ori-{o_ge} Rec - {r_ge}' tdata['GlobalEncoding Test'] = 'Failed' tilecheckPassed = 'Warning' else: tdata['GlobalEncoding'] = f'{o_ge}' tdata['GlobalEncoding Test'] = 'Passed' ########################################################## # Bounding Box Test ######################################################### #check Min Max recxmin = round(min(datarec["points"]["x"]), 3) recymin = round(min(datarec["points"]["y"]), 3) reczmin = round(min(datarec["points"]["z"]), 3) recxmax = round(max(datarec["points"]["x"]), 3) recymax = round(max(datarec["points"]["y"]), 3) reczmax = round(max(datarec["points"]["z"]), 3) #print(recxmin,recymin) r_xmin = round(recFile.header.min[0], 3) r_ymin = round(recFile.header.min[1], 3) r_zmin = round(recFile.header.min[2], 3) r_xmax = round(recFile.header.max[0], 3) r_ymax = round(recFile.header.max[1], 3) r_zmax = round(recFile.header.max[2], 3) #print(r_xmin,r_ymin) if recxmin != r_xmin or recymin != r_ymin: tdata[ 'Boundaries'] = f'Ori - min[{recxmin},{recymin},{reczmin}],max[{recxmax},{recymax},{reczmax}] Rec - min[{r_xmin},{r_ymin},{r_zmin}],max[{r_xmax},{r_ymax},{r_zmax}]' tdata['Boundary Test'] = 'Failed' tilecheckPassed = 'Warning' else: tdata[ 'Boundaries'] = f'min[{recxmin},{recymin}],max[{recxmax},{recymax}]' tdata['Boundary Test'] = 'Passed' ######################################################### # Classification Test ######################################################### #get classification all_classes = set(list(range(0, 256))) valid_classes = set(validClasses) invalid_classes = all_classes - valid_classes #print(invalid_classes) #o_class = oriFile.get_classification() r_class = recFile.get_classification() check = list(invalid_classes.intersection(r_class)) if len(check) > 0: tdata['Classification'] = check tdata['Classification Test'] = 'Failed' #print(f"Version test Failed for {tilename}") tilecheckPassed = 'Failed' else: tdata['Classification'] = None tdata['Classification Test'] = 'Passed' ########################################################### # Number of points Test ########################################################## o_len = len(dataori['points']) r_len = len(datarec['points']) if o_len != r_len: tdata['Number of points'] = f'Ori - {o_len} Rec - {r_len}' tdata['Number of Points Test'] = 'Failed' print(f"Number of points test Failed for {tilename}") tilecheckPassed = 'Failed' else: len_test = 'Passed' tdata['Number of points'] = len(datarec['points']) tdata['Number of Points Test'] = 'Passed' #print(f"Number of points test Passed for {tilename}") ########################################################### # Points Test ########################################################### tic = time.perf_counter() x0 = dataori['points']['x'] x1 = datarec['points']['x'] y0 = dataori['points']['y'] y1 = datarec['points']['y'] z0 = dataori['points']['z'] z1 = datarec['points']['z'] #print(x0.all()!=x1.all()) #print(y0.all()!=y1.all()) #print(z0.all()!=z1.all()) if x0.all() != x1.all() or y0.all() != y1.all() or z0.all() != z1.all( ): tdata['Points Test'] = 'Failed' toc = time.perf_counter() print(f"Points test Failed - {toc - tic:0.4f} seconds") tilecheckPassed = 'Failed' else: #print(f'{tilename} XYZ matched') tdata['Points Test'] = 'Passed' toc = time.perf_counter() #print(f"Points test Passed - {toc - tic:0.4f} seconds") ############################################################# # GPS time test ############################################################## r_gps = [ min(datarec['points']['gps_time']), max(datarec['points']['gps_time']) ] o_gps = [ min(dataori['points']['gps_time']), max(dataori['points']['gps_time']) ] if o_gps != r_gps: gps_test = 'Failed' tdata['GPS times'] = f'Ori - {o_gps} Rec - {r_gps}' tdata['GPS Test'] = 'Failed' print(f"GPS Times test Failed for {tilename}") tilecheckPassed = 'Failed' else: gps_test = 'Passed' tdata['GPS times'] = r_gps tdata['GPS Test'] = 'Passed' #print(f"GPS Times test Passed for {tilename}") ############################################################### # Intensity test ############################################################### r_intensity = [ min(datarec['points']['intensity']), max(datarec['points']['intensity']) ] o_intensity = [ min(dataori['points']['intensity']), max(dataori['points']['intensity']) ] if o_intensity != r_intensity: intensity_test = 'Failed' tdata['Intensity'] = f'Ori - {o_intensity} Rec - {r_intensity}' tdata['Intensity Test'] = 'Failed' print(f"Intensity test Failed for {tilename}") tilecheckPassed = 'Failed' else: intensity_test = 'Passed' tdata['Intensity'] = f'{o_intensity}' tdata['Intensity Test'] = 'Passed' #print(f"Intensity test Passed for {tilename}") ############################################################### # Scale test ################################################################ o_scale = oriFile.header.scale r_scale = recFile.header.scale #print(o_offscale,r_offscale) if o_scale != r_scale: tdata['Scale'] = f'Ori-{o_scale} Rec - {r_scale}' tdata['Scale Test'] = 'Failed' print(f"Scale test Failed for {tilename}") tilecheckPassed = 'Failed' else: tdata['Scale'] = f'{o_scale}' tdata['Scale Test'] = 'Passed' #print(f"Offset_Scale test Passed for {tilename}") ############################################################## # Returns test ############################################################# o_returns = oriFile.get_return_num() r_returns = recFile.get_return_num() #nr0=oriFile.get_num_returns() #nr1=recFile.get_num_returns() #nr1=datarec['points']['number of returns'] if o_returns.all() != r_returns.all(): returns_test = 'Failed' returns = [i for i, j in zip(o_returns, r_returns) if i != j] tdata['Returns'] = f'Returns not matching {returns}' tdata['Returns Test'] = 'Failed' tilecheckPassed = 'Failed' #print(f"Point Returns test Failed for {tilename}") else: returns_test = 'Passed' tdata['Returns'] = f'{min(o_returns),max(o_returns)}' tdata['Returns Test'] = 'Passed' #print(f"Point Returns test Passed for {tilename}") ##returns=[i for i, j in zip(o_returns, r_returns) if i != j] #print(returns) tdata['Status'] = tilecheckPassed return (True, tdata, 'None') else: print(f'One of the files could not be found for Tile {tilename}') tdata = { "Classification": "None", "Classification_Test": "None", "Version": "None", "Version Test": "None", "PDRF": "None", "PDRF Test": "None", "GlobalEncoding": "None", "GlobalEncoding Test": "None", "Number of points": "None", "Number of points Tetst": "None", "Points Test": "None", "GPS times": "None", "GPS Test": "None", "Returns": "None", "Returns Test": "None", "Intensity": "None", "Intensity Test": "None", "Scale": "None", "Scale Test": "None", "Status": "None", "Boundaries": "None", "Boundary Test": "None" } return (True, tdata, 'None')
tic = time.perf_counter() inFile1 = File(file1, mode='r') toc = time.perf_counter() print(f"{len(inFile1.points):d} records read from {file1:s} in {toc - tic:0.4f} seconds") tic = time.perf_counter() inFile2 = File(file2, mode='r') toc = time.perf_counter() print(f"{len(inFile2.points):d} records read from {file2:s} in {toc - tic:0.4f} seconds") print('Creating voxels') tic = time.perf_counter() xvalues1=inFile1.get_x_scaled() yvalues1=inFile1.get_y_scaled() zvalues1=inFile1.get_z_scaled() classvalues1=inFile1.get_classification() vox1={} for i in range(0, len(xvalues1)): if i%10000==0: print(i) x=xvalues1[i] y=yvalues1[i] z=zvalues1[i] key=(math.floor(x/voxelsize)*voxelsize,math.floor(y/voxelsize)*voxelsize,math.floor(z/voxelsize)*voxelsize) if not key in vox1.keys(): vox1[key]={} vox1[key]['x']=[] vox1[key]['y']=[] vox1[key]['z']=[]