def test_crop_reverses_indexing(self, mixed): axis = UniformDataAxis(size=10, scale=0.1, offset=10) if mixed: i1, i2 = 2, -6 else: i1, i2 = -8, -6 axis.crop(i1, i2) assert axis.size == 2 np.testing.assert_almost_equal(axis.axis[0], 10.2) np.testing.assert_almost_equal(axis.axis[-1], 10.3) np.testing.assert_almost_equal(axis.offset, 10.2) np.testing.assert_almost_equal(axis.scale, 0.1)
def test_crop(self, use_indices): axis = UniformDataAxis(size=10, scale=0.1, offset=10) start = 10.2 if use_indices: start = axis.value2index(start) axis.crop(start) assert axis.size == 8 np.testing.assert_almost_equal(axis.axis[0], 10.2) np.testing.assert_almost_equal(axis.axis[-1], 10.9) np.testing.assert_almost_equal(axis.offset, 10.2) np.testing.assert_almost_equal(axis.scale, 0.1) axis = UniformDataAxis(size=10, scale=0.1, offset=10) end = 10.4 if use_indices: end = axis.value2index(end) axis.crop(start, end) assert axis.size == 2 np.testing.assert_almost_equal(axis.axis[0], 10.2) np.testing.assert_almost_equal(axis.axis[-1], 10.3) np.testing.assert_almost_equal(axis.offset, 10.2) np.testing.assert_almost_equal(axis.scale, 0.1) axis = UniformDataAxis(size=10, scale=0.1, offset=10) axis.crop(None, end) assert axis.size == 4 np.testing.assert_almost_equal(axis.axis[0], 10.0) np.testing.assert_almost_equal(axis.axis[-1], 10.3) np.testing.assert_almost_equal(axis.offset, 10.0) np.testing.assert_almost_equal(axis.scale, 0.1)