Improve process time (Python)

المشرف العام

Administrator
طاقم الإدارة
I have a working code for a project, but right now to run through the data it would take years to be completed. Please help me to improve it:

import laspyimport laspy.fileimport numpy as npheader = laspy.header.Header()inFile2 = laspy.file.File("C:\\Users\\Geri\\Desktop\\Sync\\CODETEST\\inverz2.las", mode = "r")inFile3 = laspy.file.File("C:\\Users\\Geri\\Desktop\\Sync\\CODETEST\\inverz3.las", mode = "r")inFile = laspy.file.File("C:\\Users\\Geri\\Desktop\\Sync\\CODETEST\\final.las", mode = "rw")point_records = inFile2.pointspoint_records = inFile3.pointszstarter=3285017.181zrange=219.768t=0listx1=np.array([], dtype=float)listy1=np.array([], dtype=float)listz1=np.array([], dtype=float)while t < 1155817: z=0 q=0 p=0.1 while z==0: xmin=inFile3.x[t]-p ymin=inFile3.y[t]-p xmax=inFile3.x[t]+p ymax=inFile3.y[t]+p print t n=0 for points in inFile2.points: ax=inFile2.x[n] ay=inFile2.y[n] if ax > xmin and ax < xmax and ay < ymax and ay > ymin: Till this point the code tries to find the closest neighbor for the input point. The method only works for a data with a few hundred points, but it's too slow for a bigger one.

print inFile3.x[t] print inFile2.x[n] newx = [inFile3.x[t]-((inFile3.x[t]-inFile2.x[n])/2)] newy = [inFile3.y[t]-((inFile3.y[t]-inFile2.y[n])/2)] processz = newy-newx ratioz=(processz-zstarter)/zrange newz = [inFile3.z[t]-((inFile3.z[t]-inFile2.z[n])*ratioz)] listx1=np.append(listx1, (newx)) listy1=np.append(listy1, (newy)) listz1=np.append(listz1, (newz)) n+=1 q+=1 t+=1 else: n+=1 print n if q>0 or p==1: z+=1 else: p+=0.1inFile.x = listx1inFile.y = listy1inFile.z = listz1inFile.close() Unfortunately I can't install the pyflann or the scipy (for k neighboor) to use them so that's why I tried this workaround. I'm wondering if it's posibble to create a buffer around the selected point and just select by that polygon the new point (like in ArcGIS) (FYI I have an ArcGIS 10.2.2 and a standalone python 2.7)



أكثر...
 
أعلى