Navigation Menu

Skip to content

Commit

Permalink
assert stats and features are equal length
Browse files Browse the repository at this point in the history
  • Loading branch information
perrygeo committed Jul 4, 2016
1 parent 96219a4 commit a1e78e8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions examples/multiproc.py
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import itertools
from multiprocessing import Pool
import multiprocessing

from rasterstats import zonal_stats
Expand All @@ -12,7 +11,7 @@


def chunks(data, n):
"""Yield successive n-sized chunks from list data."""
"""Yield successive n-sized chunks from a slice-able iterable."""
for i in range(0, len(data), n):
yield data[i:i+n]

Expand All @@ -29,10 +28,12 @@ def zonal_stats_partial(feats):

# Create a process pool using all cores
cores = multiprocessing.cpu_count()
p = Pool(cores)
p = multiprocessing.Pool(cores)

# parallel map
stats_lists = p.map(zonal_stats_partial, chunks(features, cores))

# flatten to a single list
stats = itertools.chain(*stats_lists)
stats = list(itertools.chain(*stats_lists))

assert len(stats) == len(features)

0 comments on commit a1e78e8

Please sign in to comment.