Python: improve the efficency of my script using multiprocessing module (tips and suggestions)

孤者浪人 提交于 2019-12-13 00:48:10

问题


I am a beginner of Python (few weeks) and recently i had read some post in Stackoverflow about multiprocessing module. Normally i work with million of points format data (*.las file. This video to understand the source of my data) and I have interest to understand better how use multiprocessing module.

I use Python 2.7 on windows 7, intel core i7-3770CPU

Normally I use this def wrote from me as a Benchmark to understand:

# load line-by-line the las file, check if the points are inside the polygon
# if yes save a new *.las file

import shapefile
import numpy
import numpy as np
from numpy import nonzero
from matplotlib.mlab import griddata
from matplotlib.nxutils import pnpoly
from liblas import file as lasfile

def LAS2LASClip(inFile,poly,outFile):
    f = lasfile.File(inFile,None,'r') # open LAS
    h = f.header
    # change the software id to libLAS
    h.software_id = "Python 2.7"
    file_out = lasfile.File(outFile,mode='w',header= h)
    f.close()
    sf = shapefile.Reader(poly) #open shpfile
    shapes = sf.shapes()
    for i in xrange(len(shapes)):
        verts = np.array(shapes[i].points,float)
        inside_points = [p for p in lasfile.File(inFile,None,'r') if pnpoly(p.x, p.y, verts)]
        for p in inside_points:
            file_out.write(p)
    file_out.close()

来源:https://stackoverflow.com/questions/12883237/python-improve-the-efficency-of-my-script-using-multiprocessing-module-tips-an

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!