def test_change_strategy(self): m = self.model samf = m.create_samfire(workers=N_WORKERS, setup=False) from hyperspy.samfire_utils.local_strategies import ReducedChiSquaredStrategy from hyperspy.samfire_utils.global_strategies import HistogramStrategy ind = (0, 0) samf.metadata.marker[ind] = -2 samf.strategies.append(ReducedChiSquaredStrategy()) samf.change_strategy(2) assert samf.metadata.marker[ind] == -1 assert samf._active_strategy_ind == 2 samf.change_strategy(samf.strategies[1]) assert samf._active_strategy_ind == 1 assert samf.metadata.marker[ind] == -2 new_strat = HistogramStrategy() samf.strategies.append(new_strat) samf.change_strategy(3) assert samf._active_strategy_ind == 3 assert samf.active_strategy is new_strat assert samf.metadata.marker[ind] == -2 samf.stop() del samf
def __init__(self, model, workers=None, setup=True, **kwargs): # constants: if workers is None: workers = max(1, cpu_count() - 1) self.model = model self.metadata = DictionaryTreeBrowser() self._scale = 1.0 # -1 -> done pixel, use # -2 -> done, ignore when diffusion # 0 -> bad fit/no info # >0 -> select when turn comes self.metadata.add_node('marker') self.metadata.add_node('goodness_test') marker = np.empty(self.model.axes_manager.navigation_shape[::-1]) marker.fill(self._scale) self.metadata.marker = marker self.strategies = StrategyList(self) self.strategies.append(ReducedChiSquaredStrategy()) self.strategies.append(HistogramStrategy()) self._active_strategy_ind = 0 self.update_every = max(10, workers * 2) # some sensible number.... from hyperspy.samfire_utils.fit_tests import red_chisq_test self.metadata.goodness_test = red_chisq_test(tolerance=1.0) self.metadata._gt_dump = None from hyperspy.samfire_utils.samfire_kernel import single_kernel self.single_kernel = single_kernel self._workers = workers if len(kwargs) or setup: self._setup(**kwargs) self.refresh_database()
def test_change_strategy(self): m = self.model samf = m.create_samfire(setup=False) from hyperspy.samfire_utils.local_strategies import ReducedChiSquaredStrategy from hyperspy.samfire_utils.global_strategies import HistogramStrategy ind = (0, 0) samf.metadata.marker[ind] = -2 samf.strategies.append(ReducedChiSquaredStrategy()) samf.change_strategy(2) nt.assert_equal(samf.metadata.marker[ind], -1) nt.assert_equal(samf._active_strategy_ind, 2) samf.change_strategy(samf.strategies[1]) nt.assert_equal(samf._active_strategy_ind, 1) nt.assert_equal(samf.metadata.marker[ind], -2) new_strat = HistogramStrategy() samf.strategies.append(new_strat) samf.change_strategy(3) nt.assert_equal(samf._active_strategy_ind, 3) nt.assert_is(samf.active_strategy, new_strat) nt.assert_equal(samf.metadata.marker[ind], -2)