GitLab will be upgraded on June 23rd evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

Commit 541a3c70 authored by Thomas Vincent's avatar Thomas Vincent

make progress work again

parent 25ca8b31
......@@ -24,7 +24,7 @@
#
# ###########################################################################*/
from __future__ import absolute_import
from __future__ import absolute_import, division
__authors__ = ["D. Naudet"]
__date__ = "01/06/2016"
......@@ -32,10 +32,8 @@ __license__ = "MIT"
import logging
import functools
import ctypes
import multiprocessing
from threading import Thread
import multiprocessing.sharedctypes as mp_sharedctypes
import numpy as np
from scipy.optimize import leastsq
......@@ -115,6 +113,7 @@ class PeakFitter(Thread):
background=BackgroundTypes.NONE):
super(PeakFitter, self).__init__()
self.__progress = 0
self.__results = None
self.__thread = None
self.__callback = None
......@@ -128,8 +127,6 @@ class PeakFitter(Thread):
self.__background = background
self.__n_proc = n_proc if n_proc else config.DEFAULT_PROCESS_NUMBER
self.__shared_progress = mp_sharedctypes.RawArray(ctypes.c_int32,
self.__n_proc)
if roi_indices is not None:
self.__roi_indices = np.array(roi_indices[:])
......@@ -183,25 +180,23 @@ class PeakFitter(Thread):
self.__thread.start()
def progress(self):
return (100.0 *
np.frombuffer(self.__shared_progress, dtype='int32').max() /
(len(self.__indices) - 1))
return 100 * self.__progress / len(self.__indices)
def __peak_fit(self):
self.__progress = 0
self.__set_status(self.RUNNING)
# TODO
progress = np.frombuffer(self.__shared_progress, dtype='int32')
progress[:] = 0
pool = multiprocessing.Pool(self.__n_proc)
fit_results = pool.map(
functools.partial(_fit_process,
qspace_f=self.__qspace_f,
fit_type=self.__fit_type,
background_type=self.__background,
roiIndices=self.__roi_indices),
self.__indices)
fit_results = []
for result in pool.imap(
functools.partial(_fit_process,
qspace_f=self.__qspace_f,
fit_type=self.__fit_type,
background_type=self.__background,
roiIndices=self.__roi_indices),
self.__indices):
fit_results.append(result)
self.__progress += 1
pool.close()
pool.join()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment