Exemplo n.º 1
0
    def test_main_result(self):
        worker = create_worker('worker')
        worker.create_model(self.model_dictionary, self.model_letter)
        worker.setup_test(self.gt_dump)
        worker.set_optional_names(
            {self.model[comp].name
             for comp in self.optional_comps})
        self.vals.update({
            'signal.data':
            self.model.signal(),
            'fitting_kwargs': {},
            'variance.data':
            self.model.signal.metadata.Signal.Noise_properties.variance()
        })
        keyword, (_id, _ind, result, found_solution) = \
            worker.run_pixel(self.ind, self.vals)
        nt.assert_equal(_id, 'worker')
        nt.assert_equal(_ind, self.ind)
        nt.assert_true(found_solution)

        nt.assert_equal(result['dof.data'][()], 9)

        lor_components = [
            key for key in result['components'].keys() if key.find('l') == 0
        ]
        nt.assert_equal(len(result['components']), 3)
        nt.assert_equal(len(lor_components), 2)

        gauss_name = list(
            set(result['components'].keys()) - set(lor_components))[0]

        gauss = result['components'][gauss_name]
        np.testing.assert_allclose(gauss['A'][0]['values'],
                                   self.areas[0],
                                   rtol=0.05)
        np.testing.assert_allclose(gauss['sigma'][0]['values'],
                                   self.widths[0],
                                   rtol=0.05)
        np.testing.assert_allclose(gauss['centre'][0]['values'],
                                   self.centres[0],
                                   rtol=0.05)

        lor1 = result['components'][lor_components[0]]
        lor1_values = tuple(lor1[par][0]['values']
                            for par in ['A', 'gamma', 'centre'])
        lor2 = result['components'][lor_components[1]]
        lor2_values = tuple(lor2[par][0]['values']
                            for par in ['A', 'gamma', 'centre'])

        possible_values1 = (self.areas[1], self.widths[1], self.centres[1])
        possible_values2 = (self.areas[2], self.widths[2], self.centres[2])

        nt.assert_true(
            (np.allclose(lor1_values, possible_values1, rtol=0.05)
             or np.allclose(lor1_values, possible_values2, rtol=0.05)))

        nt.assert_true(
            (np.allclose(lor2_values, possible_values1, rtol=0.05)
             or np.allclose(lor2_values, possible_values2, rtol=0.05)))
Exemplo n.º 2
0
 def test_add_model(self):
     worker = create_worker('worker')
     worker.create_model(self.model_dictionary, self.model_letter)
     from hyperspy.model import BaseModel
     nt.assert_is_instance(worker.model, BaseModel)
     for component in worker.model:
         nt.assert_false(component.active_is_multidimensional)
         nt.assert_true(component.active)
Exemplo n.º 3
0
 def test_add_model(self):
     worker = create_worker('worker')
     worker.create_model(self.model_dictionary, self.model_letter)
     from hyperspy.model import BaseModel
     nt.assert_is_instance(worker.model, BaseModel)
     for component in worker.model:
         nt.assert_false(component.active_is_multidimensional)
         nt.assert_true(component.active)
Exemplo n.º 4
0
 def test_add_model(self):
     worker = create_worker('worker')
     worker.create_model(self.model_dictionary, self.model_letter)
     from hyperspy.model import BaseModel
     assert isinstance(worker.model, BaseModel)
     for component in worker.model:
         assert not component.active_is_multidimensional
         assert component.active
Exemplo n.º 5
0
 def test_add_model(self):
     worker = create_worker('worker')
     worker.create_model(self.model_dictionary, self.model_letter)
     from hyperspy.model import BaseModel
     assert isinstance(worker.model, BaseModel)
     for component in worker.model:
         assert not component.active_is_multidimensional
         assert component.active
Exemplo n.º 6
0
def test_create_worker_defaults():
    worker = create_worker('worker')
    nt.assert_equal(worker.identity, 'worker')
    nt.assert_is_none(worker.shared_queue)
    nt.assert_is_none(worker.result_queue)
    nt.assert_is_none(worker.individual_queue)
    np.testing.assert_equal(worker.best_AICc, np.inf)
    np.testing.assert_equal(worker.best_values, [])
    np.testing.assert_equal(worker.best_dof, np.inf)
    np.testing.assert_equal(worker.last_time, 1)
Exemplo n.º 7
0
def test_create_worker_defaults():
    worker = create_worker('worker')
    nt.assert_equal(worker.identity, 'worker')
    nt.assert_is_none(worker.shared_queue)
    nt.assert_is_none(worker.result_queue)
    nt.assert_is_none(worker.individual_queue)
    np.testing.assert_equal(worker.best_AICc, np.inf)
    np.testing.assert_equal(worker.best_values, [])
    np.testing.assert_equal(worker.best_dof, np.inf)
    np.testing.assert_equal(worker.last_time, 1)
Exemplo n.º 8
0
    def test_main_result(self):
        worker = create_worker('worker')
        worker.create_model(self.model_dictionary, self.model_letter)
        worker.setup_test(self.gt_dump)
        worker.set_optional_names({self.model[comp].name for comp in
                                   self.optional_comps})
        self.vals.update({
            'signal.data': self.model.signal(),
            'fitting_kwargs': {},
            'variance.data':
            self.model.signal.metadata.Signal.Noise_properties.variance()
        })
        keyword, (_id, _ind, result, found_solution) = \
            worker.run_pixel(self.ind, self.vals)
        nt.assert_equal(_id, 'worker')
        nt.assert_equal(_ind, self.ind)
        nt.assert_true(found_solution)

        nt.assert_equal(result['dof.data'][()], 9)

        lor_components = [key for key in result['components'].keys() if
                          key.find('l') == 0]
        nt.assert_equal(len(result['components']), 3)
        nt.assert_equal(len(lor_components), 2)

        gauss_name = list(set(result['components'].keys()) -
                          set(lor_components))[0]

        gauss = result['components'][gauss_name]
        np.testing.assert_allclose(gauss['A'][0]['values'], self.areas[0],
                                   rtol=0.05)
        np.testing.assert_allclose(gauss['sigma'][0]['values'], self.widths[0],
                                   rtol=0.05)
        np.testing.assert_allclose(gauss['centre'][0]['values'],
                                   self.centres[0], rtol=0.05)

        lor1 = result['components'][lor_components[0]]
        lor1_values = tuple(lor1[par][0]['values'] for par in ['A', 'gamma',
                                                               'centre'])
        lor2 = result['components'][lor_components[1]]
        lor2_values = tuple(lor2[par][0]['values'] for par in ['A', 'gamma',
                                                               'centre'])

        possible_values1 = (self.areas[1], self.widths[1], self.centres[1])
        possible_values2 = (self.areas[2], self.widths[2], self.centres[2])

        nt.assert_true((np.allclose(lor1_values, possible_values1, rtol=0.05)
                        or
                        np.allclose(lor1_values, possible_values2, rtol=0.05)))

        nt.assert_true((np.allclose(lor2_values, possible_values1, rtol=0.05)
                        or
                        np.allclose(lor2_values, possible_values2, rtol=0.05)))