Add multithread support for some CPU processing classes
Some processing classes like CCDCorrection
and UnsharpMask
are quite slow.
However they are easy to parallelize with native python multi-threading, as the underlying processing function release the GIL.
from nabu.preproc.ccd import CCDCorrection
from multiprocessing.pool import ThreadPool
ccd_cor = CCDCorrection(img_shape)
threads_pool = ThreadPool(6)
def img_median_filter(image):
out = ccd_cor.median_filter(image)
# In-place, can easily be extended to out-of-place
image[:] = out[:]
# map() creates a list containing the result from each thread
# so returning the processed image ends up duplicating all the images stack memory.
# Therefore, it is very important to return None
return None
threads_pool.map(img_median_filter, img_stack)
Edited by Pierre Paleo