def test_nonuniform(self):
        surf = read_xyz(os.path.join(DATADIR, 'example.xyz'))
        self.assertFalse(surf.is_uniform)
        self.assertEqual(surf.dim, 1)

        surf = surf.detrend(detrend_mode='height')
        self.assertFalse(surf.is_uniform)
        self.assertEqual(surf.dim, 1)
def test_read_1d():
    surface = read_xyz(os.path.join(DATADIR, 'example.xyz'))
    assert not surface.is_uniform
    x, y = surface.positions_and_heights()
    assert len(x) > 0
    assert len(x) == len(y)
    assert not surface.is_uniform
    assert surface.dim == 1
    assert not surface.is_periodic
Ejemplo n.º 3
0
    def test_read(self):
        surface = read_xyz(
            os.path.join(DATADIR, 'line_scan_1_minimal_spaces.asc'))

        self.assertFalse(surface.is_uniform)
        self.assertEqual(surface.dim, 1)

        x, y = surface.positions_and_heights()
        self.assertGreater(len(x), 0)
        self.assertEqual(len(x), len(y))
    def test_simple_nonuniform_line_scan(self):
        surf = read_xyz(
            os.path.join(DATADIR, 'line_scan_1_minimal_spaces.asc'))

        self.assertAlmostEqual(surf.physical_sizes, (9.0,))

        self.assertFalse(surf.is_uniform)
        self.assertFalse('unit' in surf.info)

        bw = surf.bandwidth()
        self.assertAlmostEqual(bw[0], (8 * 1. + 2 * 0.5 / 10) / 9)
        self.assertAlmostEqual(bw[1], 9)
def test_read_2d(filename):
    """
    Here the order of points in the input file shouldn't matter.
    """
    surface = read_xyz(os.path.join(DATADIR, filename))
    assert surface.is_uniform
    x, y, z = surface.positions_and_heights()
    assert x.shape == (4, 4)
    assert y.shape == (4, 4)
    assert z.shape == (4, 4)
    assert surface.dim == 2
    assert not surface.is_periodic
    assert_allclose(z, [[1., 1., 1., 1.], [1., 2., 2., 1.], [1., 1., 1., 1.],
                        [1., 1., 1., 1.]])
def test_nonuniform_unit_conversion(file_format_examples):
    surf = read_xyz(os.path.join(file_format_examples, 'example.xyz'),
                    unit='um')
    assert surf.unit == 'um'

    surf2 = surf.to_unit('mm')
    assert surf2.info['unit'] == 'mm'
    assert surf2.unit == 'mm'

    np.testing.assert_almost_equal(
        tuple(p / 1000 for p in surf.physical_sizes), surf2.physical_sizes)
    np.testing.assert_almost_equal(tuple(p / 1000 for p in surf.positions()),
                                   surf2.positions())
    np.testing.assert_almost_equal(surf.rms_height_from_profile() / 1000,
                                   surf2.rms_height_from_profile())
    np.testing.assert_almost_equal(surf.rms_slope_from_profile(),
                                   surf2.rms_slope_from_profile())
    np.testing.assert_almost_equal(surf.rms_curvature_from_profile() * 1000,
                                   surf2.rms_curvature_from_profile())
def test_nonuniform_scaled_topography(file_format_examples):
    surf = read_xyz(os.path.join(file_format_examples, 'example.xyz'))
    sx, = surf.physical_sizes
    for fac in [1.0, 2.0, np.pi]:
        surf2 = surf.scale(fac)
        np.testing.assert_almost_equal(fac * surf.rms_height_from_profile(),
                                       surf2.rms_height_from_profile())
        np.testing.assert_almost_equal(surf.positions(), surf2.positions())

        surf2 = surf.scale(fac, 2 * fac)
        np.testing.assert_almost_equal(fac * surf.rms_height_from_profile(),
                                       surf2.rms_height_from_profile())
        np.testing.assert_almost_equal(2 * fac * surf.positions(),
                                       surf2.positions())

        sx2, = surf2.physical_sizes
        np.testing.assert_almost_equal(2 * fac * sx, sx2)

        x = surf.positions()
        x2 = surf2.positions()
        np.testing.assert_almost_equal(2 * fac * x, x2)

        x2, h2 = surf2.positions_and_heights()
        np.testing.assert_almost_equal(2 * fac * x, x2)
 def test_detrend(self):
     t = read_xyz(os.path.join(DATADIR, 'example.xyz'))
     self.assertFalse(t.detrend('center').is_periodic)
     self.assertFalse(t.detrend('height').is_periodic)