Пример #1
0
 def test_convert_to_navigation_units_Undefined(self):
     self.axes_list[0]['units'] = t.Undefined
     am = AxesManager(self.axes_list)
     am.convert_units(axes='navigation', same_units=True)
     assert am['x'].units == t.Undefined
     nt.assert_almost_equal(am['x'].scale, 1.5E-9)
     assert am['y'].units == 'm'
     nt.assert_almost_equal(am['y'].scale, 0.5E-9)
     assert am['energy'].units == 'eV'
     nt.assert_almost_equal(am['energy'].scale, 5)
Пример #2
0
 def test_convert_to_navigation_units_Undefined(self):
     self.axes_list[0]['units'] = t.Undefined
     am = AxesManager(self.axes_list)
     am.convert_units(axes='navigation', same_units=True)
     assert am['x'].units == t.Undefined
     nt.assert_almost_equal(am['x'].scale, 1.5E-9)
     assert am['y'].units == 'm'
     nt.assert_almost_equal(am['y'].scale, 0.5E-9)
     assert am['energy'].units == 'eV'
     nt.assert_almost_equal(am['energy'].scale, 5)
Пример #3
0
 def test_convert_to_navigation_units_different(self):
     # Don't convert the units since the units of the navigation axes are
     # different
     self.axes_list.insert(0,
                           {'name': 'time',
                            'navigate': True,
                            'offset': 0.0,
                            'scale': 1.5,
                            'size': 20,
                            'units': 's'})
     am = AxesManager(self.axes_list)
     am.convert_units(axes='navigation', same_units=True)
     assert am['time'].units == 's'
     nt.assert_almost_equal(am['time'].scale, 1.5)
     assert am['x'].units == 'nm'
     nt.assert_almost_equal(am['x'].scale, 1.5)
     assert am['y'].units == 'nm'
     nt.assert_almost_equal(am['y'].scale, 0.5)
     assert am['energy'].units == 'eV'
     nt.assert_almost_equal(am['energy'].scale, 5)
Пример #4
0
 def test_convert_to_navigation_units_different(self):
     # Don't convert the units since the units of the navigation axes are
     # different
     self.axes_list.insert(
         0, {
             'name': 'time',
             'navigate': True,
             'offset': 0.0,
             'scale': 1.5,
             'size': 20,
             'units': 's'
         })
     am = AxesManager(self.axes_list)
     am.convert_units(axes='navigation', same_units=True)
     assert am['time'].units == 's'
     nt.assert_almost_equal(am['time'].scale, 1.5)
     assert am['x'].units == 'nm'
     nt.assert_almost_equal(am['x'].scale, 1.5)
     assert am['y'].units == 'nm'
     nt.assert_almost_equal(am['y'].scale, 0.5)
     assert am['energy'].units == 'eV'
     nt.assert_almost_equal(am['energy'].scale, 5)
Пример #5
0
class TestAxesManager:

    def setup_method(self, method):
        self.axes_list = [
            {'name': 'x',
             'navigate': True,
             'offset': 0.0,
             'scale': 1.5E-9,
             'size': 1024,
             'units': 'm'},
            {'name': 'y',
             'navigate': True,
             'offset': 0.0,
             'scale': 0.5E-9,
             'size': 1024,
             'units': 'm'},
            {'name': 'energy',
             'navigate': False,
             'offset': 0.0,
             'scale': 5.0,
             'size': 4096,
             'units': 'eV'}]

        self.am = AxesManager(self.axes_list)

        self.axes_list2 = [
            {'name': 'x',
             'navigate': True,
             'offset': 0.0,
             'scale': 1.5E-9,
             'size': 1024,
             'units': 'm'},
            {'name': 'energy',
             'navigate': False,
             'offset': 0.0,
             'scale': 2.5,
             'size': 4096,
             'units': 'eV'},
            {'name': 'energy2',
             'navigate': False,
             'offset': 0.0,
             'scale': 5.0,
             'size': 4096,
             'units': 'eV'}]
        self.am2 = AxesManager(self.axes_list2)

    def test_compact_unit(self):
        self.am.convert_units()
        assert self.am['x'].units == 'nm'
        nt.assert_almost_equal(self.am['x'].scale, 1.5)
        assert self.am['y'].units == 'nm'
        nt.assert_almost_equal(self.am['y'].scale, 0.5)
        assert self.am['energy'].units == 'keV'
        nt.assert_almost_equal(self.am['energy'].scale, 0.005)

    def test_convert_to_navigation_units(self):
        self.am.convert_units(axes='navigation', units='mm')
        nt.assert_almost_equal(self.am['x'].scale, 1.5E-6)
        assert self.am['x'].units == 'mm'
        nt.assert_almost_equal(self.am['y'].scale, 0.5E-6)
        assert self.am['y'].units == 'mm'
        nt.assert_almost_equal(self.am['energy'].scale,
                               self.axes_list[-1]['scale'])

    def test_convert_units_axes_integer(self):
        # convert only the first axis
        self.am.convert_units(axes=0, units='nm', same_units=False)
        nt.assert_almost_equal(self.am[0].scale, 0.5)
        assert self.am[0].units == 'nm'
        nt.assert_almost_equal(self.am['x'].scale, 1.5E-9)
        assert self.am['x'].units == 'm'
        nt.assert_almost_equal(self.am['energy'].scale,
                               self.axes_list[-1]['scale'])

        self.am.convert_units(axes=0, units='nm', same_units=True)
        nt.assert_almost_equal(self.am[0].scale, 0.5)
        assert self.am[0].units == 'nm'
        nt.assert_almost_equal(self.am['x'].scale, 1.5)
        assert self.am['x'].units == 'nm'

    def test_convert_to_navigation_units_list(self):
        self.am.convert_units(axes='navigation', units=['mm', 'nm'],
                              same_units=False)
        nt.assert_almost_equal(self.am['x'].scale, 1.5)
        assert self.am['x'].units == 'nm'
        nt.assert_almost_equal(self.am['y'].scale, 0.5E-6)
        assert self.am['y'].units == 'mm'
        nt.assert_almost_equal(self.am['energy'].scale,
                               self.axes_list[-1]['scale'])

    def test_convert_to_navigation_units_list_same_units(self):
        self.am.convert_units(axes='navigation', units=['mm', 'nm'],
                              same_units=True)
        assert self.am['x'].units == 'mm'
        nt.assert_almost_equal(self.am['x'].scale, 1.5e-6)
        assert self.am['y'].units == 'mm'
        nt.assert_almost_equal(self.am['y'].scale, 0.5e-6)
        assert self.am['energy'].units == 'eV'
        nt.assert_almost_equal(self.am['energy'].scale, 5)

    def test_convert_to_navigation_units_different(self):
        # Don't convert the units since the units of the navigation axes are
        # different
        self.axes_list.insert(0,
                              {'name': 'time',
                               'navigate': True,
                               'offset': 0.0,
                               'scale': 1.5,
                               'size': 20,
                               'units': 's'})
        am = AxesManager(self.axes_list)
        am.convert_units(axes='navigation', same_units=True)
        assert am['time'].units == 's'
        nt.assert_almost_equal(am['time'].scale, 1.5)
        assert am['x'].units == 'nm'
        nt.assert_almost_equal(am['x'].scale, 1.5)
        assert am['y'].units == 'nm'
        nt.assert_almost_equal(am['y'].scale, 0.5)
        assert am['energy'].units == 'eV'
        nt.assert_almost_equal(am['energy'].scale, 5)

    def test_convert_to_navigation_units_Undefined(self):
        self.axes_list[0]['units'] = t.Undefined
        am = AxesManager(self.axes_list)
        am.convert_units(axes='navigation', same_units=True)
        assert am['x'].units == t.Undefined
        nt.assert_almost_equal(am['x'].scale, 1.5E-9)
        assert am['y'].units == 'm'
        nt.assert_almost_equal(am['y'].scale, 0.5E-9)
        assert am['energy'].units == 'eV'
        nt.assert_almost_equal(am['energy'].scale, 5)

    def test_convert_to_signal_units(self):
        self.am.convert_units(axes='signal', units='keV')
        nt.assert_almost_equal(self.am['x'].scale, self.axes_list[0]['scale'])
        assert self.am['x'].units == self.axes_list[0]['units']
        nt.assert_almost_equal(self.am['y'].scale, self.axes_list[1]['scale'])
        assert self.am['y'].units == self.axes_list[1]['units']
        nt.assert_almost_equal(self.am['energy'].scale, 0.005)
        assert self.am['energy'].units == 'keV'

    def test_convert_to_units_list(self):
        self.am.convert_units(units=['µm', 'nm', 'meV'], same_units=False)
        nt.assert_almost_equal(self.am['x'].scale, 1.5)
        assert self.am['x'].units == 'nm'
        nt.assert_almost_equal(self.am['y'].scale, 0.5E-3)
        assert self.am['y'].units == 'um'
        nt.assert_almost_equal(self.am['energy'].scale, 5E3)
        assert self.am['energy'].units == 'meV'

    def test_convert_to_units_list_same_units(self):
        self.am2.convert_units(units=['µm', 'eV', 'meV'], same_units=True)
        nt.assert_almost_equal(self.am2['x'].scale, 0.0015)
        assert self.am2['x'].units == 'um'
        nt.assert_almost_equal(self.am2['energy'].scale,
                               self.axes_list2[1]['scale'])
        assert self.am2['energy'].units == self.axes_list2[1]['units']
        nt.assert_almost_equal(self.am2['energy2'].scale,
                               self.axes_list2[2]['scale'])
        assert self.am2['energy2'].units == self.axes_list2[2]['units']

    def test_convert_to_units_list_signal2D(self):
        self.am2.convert_units(units=['µm', 'eV', 'meV'], same_units=False)
        nt.assert_almost_equal(self.am2['x'].scale, 0.0015)
        assert self.am2['x'].units == 'um'
        nt.assert_almost_equal(self.am2['energy'].scale, 2500)
        assert self.am2['energy'].units == 'meV'
        nt.assert_almost_equal(self.am2['energy2'].scale, 5.0)
        assert self.am2['energy2'].units == 'eV'

    @pytest.mark.parametrize("same_units", (True, False))
    def test_convert_to_units_unsupported_units(self, same_units):
        with assert_warns(
                message="not supported for conversion.",
                category=UserWarning):
            self.am.convert_units('navigation', units='toto',
                                  same_units=same_units)
        assert_deep_almost_equal(self.am._get_axes_dicts(),
                                 self.axes_list)
Пример #6
0
class TestAxesManager:
    def setup_method(self, method):
        self.axes_list = [{
            'name': 'x',
            'navigate': True,
            'offset': 0.0,
            'scale': 1.5E-9,
            'size': 1024,
            'units': 'm'
        }, {
            'name': 'y',
            'navigate': True,
            'offset': 0.0,
            'scale': 0.5E-9,
            'size': 1024,
            'units': 'm'
        }, {
            'name': 'energy',
            'navigate': False,
            'offset': 0.0,
            'scale': 5.0,
            'size': 4096,
            'units': 'eV'
        }]

        self.am = AxesManager(self.axes_list)

        self.axes_list2 = [{
            'name': 'x',
            'navigate': True,
            'offset': 0.0,
            'scale': 1.5E-9,
            'size': 1024,
            'units': 'm'
        }, {
            'name': 'energy',
            'navigate': False,
            'offset': 0.0,
            'scale': 2.5,
            'size': 4096,
            'units': 'eV'
        }, {
            'name': 'energy2',
            'navigate': False,
            'offset': 0.0,
            'scale': 5.0,
            'size': 4096,
            'units': 'eV'
        }]
        self.am2 = AxesManager(self.axes_list2)

    def test_compact_unit(self):
        self.am.convert_units()
        assert self.am['x'].units == 'nm'
        nt.assert_almost_equal(self.am['x'].scale, 1.5)
        assert self.am['y'].units == 'nm'
        nt.assert_almost_equal(self.am['y'].scale, 0.5)
        assert self.am['energy'].units == 'keV'
        nt.assert_almost_equal(self.am['energy'].scale, 0.005)

    def test_convert_to_navigation_units(self):
        self.am.convert_units(axes='navigation', units='mm')
        nt.assert_almost_equal(self.am['x'].scale, 1.5E-6)
        assert self.am['x'].units == 'mm'
        nt.assert_almost_equal(self.am['y'].scale, 0.5E-6)
        assert self.am['y'].units == 'mm'
        nt.assert_almost_equal(self.am['energy'].scale,
                               self.axes_list[-1]['scale'])

    def test_convert_units_axes_integer(self):
        # convert only the first axis
        self.am.convert_units(axes=0, units='nm', same_units=False)
        nt.assert_almost_equal(self.am[0].scale, 0.5)
        assert self.am[0].units == 'nm'
        nt.assert_almost_equal(self.am['x'].scale, 1.5E-9)
        assert self.am['x'].units == 'm'
        nt.assert_almost_equal(self.am['energy'].scale,
                               self.axes_list[-1]['scale'])

        self.am.convert_units(axes=0, units='nm', same_units=True)
        nt.assert_almost_equal(self.am[0].scale, 0.5)
        assert self.am[0].units == 'nm'
        nt.assert_almost_equal(self.am['x'].scale, 1.5)
        assert self.am['x'].units == 'nm'

    def test_convert_to_navigation_units_list(self):
        self.am.convert_units(axes='navigation',
                              units=['mm', 'nm'],
                              same_units=False)
        nt.assert_almost_equal(self.am['x'].scale, 1.5)
        assert self.am['x'].units == 'nm'
        nt.assert_almost_equal(self.am['y'].scale, 0.5E-6)
        assert self.am['y'].units == 'mm'
        nt.assert_almost_equal(self.am['energy'].scale,
                               self.axes_list[-1]['scale'])

    def test_convert_to_navigation_units_list_same_units(self):
        self.am.convert_units(axes='navigation',
                              units=['mm', 'nm'],
                              same_units=True)
        assert self.am['x'].units == 'mm'
        nt.assert_almost_equal(self.am['x'].scale, 1.5e-6)
        assert self.am['y'].units == 'mm'
        nt.assert_almost_equal(self.am['y'].scale, 0.5e-6)
        assert self.am['energy'].units == 'eV'
        nt.assert_almost_equal(self.am['energy'].scale, 5)

    def test_convert_to_navigation_units_different(self):
        # Don't convert the units since the units of the navigation axes are
        # different
        self.axes_list.insert(
            0, {
                'name': 'time',
                'navigate': True,
                'offset': 0.0,
                'scale': 1.5,
                'size': 20,
                'units': 's'
            })
        am = AxesManager(self.axes_list)
        am.convert_units(axes='navigation', same_units=True)
        assert am['time'].units == 's'
        nt.assert_almost_equal(am['time'].scale, 1.5)
        assert am['x'].units == 'nm'
        nt.assert_almost_equal(am['x'].scale, 1.5)
        assert am['y'].units == 'nm'
        nt.assert_almost_equal(am['y'].scale, 0.5)
        assert am['energy'].units == 'eV'
        nt.assert_almost_equal(am['energy'].scale, 5)

    def test_convert_to_navigation_units_Undefined(self):
        self.axes_list[0]['units'] = t.Undefined
        am = AxesManager(self.axes_list)
        am.convert_units(axes='navigation', same_units=True)
        assert am['x'].units == t.Undefined
        nt.assert_almost_equal(am['x'].scale, 1.5E-9)
        assert am['y'].units == 'm'
        nt.assert_almost_equal(am['y'].scale, 0.5E-9)
        assert am['energy'].units == 'eV'
        nt.assert_almost_equal(am['energy'].scale, 5)

    def test_convert_to_signal_units(self):
        self.am.convert_units(axes='signal', units='keV')
        nt.assert_almost_equal(self.am['x'].scale, self.axes_list[0]['scale'])
        assert self.am['x'].units == self.axes_list[0]['units']
        nt.assert_almost_equal(self.am['y'].scale, self.axes_list[1]['scale'])
        assert self.am['y'].units == self.axes_list[1]['units']
        nt.assert_almost_equal(self.am['energy'].scale, 0.005)
        assert self.am['energy'].units == 'keV'

    def test_convert_to_units_list(self):
        self.am.convert_units(units=['µm', 'nm', 'meV'], same_units=False)
        nt.assert_almost_equal(self.am['x'].scale, 1.5)
        assert self.am['x'].units == 'nm'
        nt.assert_almost_equal(self.am['y'].scale, 0.5E-3)
        assert self.am['y'].units == 'um'
        nt.assert_almost_equal(self.am['energy'].scale, 5E3)
        assert self.am['energy'].units == 'meV'

    def test_convert_to_units_list_same_units(self):
        self.am2.convert_units(units=['µm', 'eV', 'meV'], same_units=True)
        nt.assert_almost_equal(self.am2['x'].scale, 0.0015)
        assert self.am2['x'].units == 'um'
        nt.assert_almost_equal(self.am2['energy'].scale,
                               self.axes_list2[1]['scale'])
        assert self.am2['energy'].units == self.axes_list2[1]['units']
        nt.assert_almost_equal(self.am2['energy2'].scale,
                               self.axes_list2[2]['scale'])
        assert self.am2['energy2'].units == self.axes_list2[2]['units']

    def test_convert_to_units_list_signal2D(self):
        self.am2.convert_units(units=['µm', 'eV', 'meV'], same_units=False)
        nt.assert_almost_equal(self.am2['x'].scale, 0.0015)
        assert self.am2['x'].units == 'um'
        nt.assert_almost_equal(self.am2['energy'].scale, 2500)
        assert self.am2['energy'].units == 'meV'
        nt.assert_almost_equal(self.am2['energy2'].scale, 5.0)
        assert self.am2['energy2'].units == 'eV'

    @pytest.mark.parametrize("same_units", (True, False))
    def test_convert_to_units_unsupported_units(self, same_units):
        with assert_warns(message="not supported for conversion.",
                          category=UserWarning):
            self.am.convert_units('navigation',
                                  units='toto',
                                  same_units=same_units)
        assert_deep_almost_equal(self.am._get_axes_dicts(), self.axes_list)
Пример #7
0
class TestAxesManager:

    def setup(self):
        self.axes_list = [
            {'name': 'x',
             'navigate': True,
             'offset': 0.0,
             'scale': 1E-6,
             'size': 1024,
             'units': 'm'},
            {'name': 'y',
             'navigate': True,
             'offset': 0.0,
             'scale': 0.5E-9,
             'size': 1024,
             'units': 'm'},
            {'name': 'energy',
             'navigate': False,
             'offset': 0.0,
             'scale': 5.0,
             'size': 4096,
             'units': 'eV'}]

        self.am = AxesManager(self.axes_list)

    def test_convenient_scale_unit(self):
        self.am.convert_units()
        nt.assert_almost_equal(self.am['x'].scale, 1.0, places=5)
        nt.assert_equal(self.am['x'].units, 'µm')
        nt.assert_almost_equal(self.am['y'].scale, 0.5, places=5)
        nt.assert_equal(self.am['y'].units, 'nm')
        nt.assert_almost_equal(self.am['energy'].scale, 0.005, places=5)
        nt.assert_equal(self.am['energy'].units, 'keV')
        
    def test_convert_to_navigation_units(self):
        self.am.convert_units(axes='navigation', units='µm')
        nt.assert_almost_equal(self.am['x'].scale, 1.0, places=5)
        nt.assert_equal(self.am['x'].units, 'µm')
        nt.assert_almost_equal(self.am['y'].scale, 0.5E-3, places=5)
        nt.assert_equal(self.am['y'].units, 'µm')
        nt.assert_almost_equal(self.am['energy'].scale,
                               self.axes_list[-1]['scale'], places=5)
        nt.assert_equal(self.am['energy'].units, self.axes_list[-1]['units'])

    def test_convert_to_navigation_units_list(self):
        self.am.convert_units(axes='navigation', units=['µm', 'nm'])
        nt.assert_almost_equal(self.am['x'].scale, 1000.0, places=5)
        nt.assert_equal(self.am['x'].units, 'nm')
        nt.assert_almost_equal(self.am['y'].scale, 0.5E-3, places=5)
        nt.assert_equal(self.am['y'].units, 'µm')
        nt.assert_almost_equal(self.am['energy'].scale,
                               self.axes_list[-1]['scale'], places=5)
        nt.assert_equal(self.am['energy'].units, self.axes_list[-1]['units'])
        
    def test_convert_to_signal_units(self):
        self.am.convert_units(axes='signal', units='keV')
        nt.assert_almost_equal(self.am['x'].scale, self.axes_list[0]['scale'],
                               places=5)
        nt.assert_equal(self.am['x'].units, self.axes_list[0]['units'])
        nt.assert_almost_equal(self.am['y'].scale, self.axes_list[1]['scale'],
                               places=5)
        nt.assert_equal(self.am['y'].units, self.axes_list[1]['units'])
        nt.assert_almost_equal(self.am['energy'].scale, 0.005, places=5)
        nt.assert_equal(self.am['energy'].units, 'keV')
        
    def test_convert_to_units_list(self):
        self.am.convert_units(units=['µm', 'nm', 'meV'])
        nt.assert_almost_equal(self.am['x'].scale, 1000.0, places=5)
        nt.assert_equal(self.am['x'].units, 'nm')
        nt.assert_almost_equal(self.am['y'].scale, 0.5E-3, places=5)
        nt.assert_equal(self.am['y'].units, 'µm')
        nt.assert_almost_equal(self.am['energy'].scale, 5E3, places=5)
        nt.assert_equal(self.am['energy'].units, 'meV')