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

210 views Asked by At

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()
0

There are 0 answers