def test_correctly_chooses_parallel(): # forcing 1 core should always return False assert multiprocessing_necessary((100, 10, 10), cores=1) is False # shapes less than 10 should return false assert multiprocessing_necessary((10, 10, 10), cores=12) is False assert multiprocessing_necessary(10, cores=12) is False # shapes over 10 should return True assert multiprocessing_necessary((11, 10, 10), cores=12) is True assert multiprocessing_necessary(11, cores=12) is True
def filter_func(images: Images, diff=None, radius=_default_radius, axis=0, cores=None, progress=None): """ :param images: Input data :param diff: Pixel value difference above which to crop bright pixels :param radius: Size of the median filter to apply :param cores: The number of cores that will be used to process the data. :return: The processed 3D numpy.ndarray """ if not utility.multiprocessing_necessary(images.data.shape, cores): cores = 1 if diff and radius and diff > 0 and radius > 0: data = images.projections if axis == 0 else images.sinograms func = psm.create_partial(OutliersISISFilter._execute, psm.return_fwd_func, diff=diff, radius=radius) psm.execute( data, func, cores, progress=progress, msg=f"Outliers with threshold {diff} and kernel {radius}") return images
def filter_func(data, diff=None, radius=_default_radius, mode=_default_mode, axis=0, type=_default_dim, cores=None, progress=None): """ Requires tomopy to be available. :param data: Input data as a 3D numpy.ndarray :param diff: Pixel value difference above which to crop bright pixels :param radius: Size of the median filter to apply :param mode: Spot brightness to remove. Either 'bright' or 'dark'. :param cores: The number of cores that will be used to process the data. :return: The processed 3D numpy.ndarray """ progress = Progress.ensure_instance(progress, task_name='Outliers', num_steps=3) if not utility.multiprocessing_necessary(data.data.shape, cores): cores = 1 if diff and radius and diff > 0 and radius > 0: with progress: progress.update( msg="Applying outliers with threshold: {0} and " "radius {1}".format(diff, radius)) sample = data.data # By default tomopy only clears bright outliers. # As a workaround inverting the image makes the dark outliers the brightest if mode == OUTLIERS_DARK: np.negative(sample, out=sample) tomopy = importer.do_importing('tomopy') if type == "2D": tomopy.misc.corr.remove_outlier(sample, diff, radius, axis, ncore=cores, out=sample) else: tomopy.misc.corr.remove_outlier1d(sample, diff, radius, axis, ncore=cores, out=sample) progress.update() # reverse the inversion if mode == OUTLIERS_DARK: np.negative(sample, out=sample) return data
def test_correctly_chooses_parallel(shape: Union[int, List, Tuple[int, int, int]], cores: int, should_be_parallel: bool): assert multiprocessing_necessary(shape, cores) is should_be_parallel