def test_adios_var_getitem(self): v = self.f['temperature'] val = v.read() self.assertRaises(ValueError, v.__getitem__, Slicee()[..., ...]) self.assertTrue((val == v[:, ...]).all()) self.assertTrue((val == v[:, ::1]).all()) ## equivalent to v[::2] ##self.assertRaises(IndexError, v.__getitem__, Slicee()[::2]) self.assertRaises(TypeError, v.__getitem__, Slicee()[:, :, :])
def test_adios_group(self): self.assertRaises(KeyError, self.f.__getitem__, Slicee()['/subgroup']) g = self.f['/subgroup/subsubgroup'] self.assertEqual(g.vars.keys(), ['othervar']) self.assertEqual(g.attrs.keys(), ['otherattr']) self.assertEqual(g['othervar'][...], 99) self.assertEqual(g['otherattr'][...], 'another')
def test_adios_var_read_fancy(self): v = self.f['temperature'] m = np.arange(10) % 3 != 0 self.assertTrue((v[:, m] == self.tt[:, m]).all()) self.assertTrue((v[1, m] == self.tt[1, m]).all()) self.assertEqual(v[1, m].shape, (6, )) self.assertTrue((v[:1, m] == self.tt[:1, m]).all()) self.assertRaises(ValueError, v.__getitem__, Slicee()[3, m])
def test_adios_var_array(self): v = self.f['temperature'] self.assertEqual(v.ndim, 2) self.assertEqual(v.dims, (2L, 10L)) self.assertEqual(v.nsteps, 5) val = v.read() self.assertEqual(val.dtype, np.dtype('float64')) self.assertEqual(val.ndim, v.ndim + 1) self.assertEqual(val.shape, (5, self.size, self.NX)) self.assertTrue((val == v[:]).all()) self.assertTrue((val == v[:, :]).all()) self.assertTrue((val == v[:, :, :]).all()) self.assertRaises(IndexError, v.__getitem__, Slicee()[::2]) self.assertRaises(IndexError, v.__getitem__, Slicee()[:, :, :, :]) self.assertTrue((v.read(offset=(0, 5), count=(2, 5)) == v[:, :, 5:]).all()) self.assertTrue((v.read(offset=(0, 5), count=(2, 5)) == v[:, :, -5:]).all())
def test_fancyselection(self): sgen = Slicee() shape = (10, 20, 30) m1 = np.arange(10) % 3 != 0 m2 = np.arange(20) % 3 != 0 x1 = sel.FancySelection(shape) x1[m1, :, :] self.assertEqual(x1.shape, shape) self.assertEqual(x1.mshape, np.zeros(shape)[m1, :, :].shape) x2 = sel.FancySelection(shape) self.assertRaises(ValueError, x2.__getitem__, sgen[m2, :])
def test_simpleselection_ellipsis(self): sgen = Slicee() shape = (10, 20, 30) x = sel.select(shape, sgen[:, 1]) self.assertEqual(x.mshape, (10, 30)) x = sel.select(shape, sgen[..., 1]) self.assertEqual(x.mshape, (10, 20)) x = sel.select(shape, sgen[...]) self.assertEqual(x.mshape, (10, 20, 30)) x = sel.select(shape, sgen[:, ...]) self.assertEqual(x.mshape, (10, 20, 30))
def test_simpleselection_noninclusive(self): sgen = Slicee() shape = (10, 20, 30) x = sel.select(shape, sgen[:, :, 15]) self.assertEqual(x.mshape, (10, 20)) x = sel.select(shape, sgen[:, 15, :]) self.assertEqual(x.mshape, (10, 30)) x = sel.select(shape, sgen[:, 15:16, :]) self.assertEqual(x.mshape, (10, 1, 30)) x = sel.select(shape, sgen[:, 15:17, :]) self.assertEqual(x.mshape, (10, 2, 30))
def test_adios_var_getitem(self): v = self.f['temperature'] self.assertTrue((v[0,] == v.read(from_steps=0, nsteps=1)).all()) self.assertTrue((v[1,] == v.read(from_steps=1, nsteps=1)).all()) self.assertTrue((v[:2,] == v.read(from_steps=0, nsteps=2)).all()) self.assertTrue((v[0:2,] == v.read(from_steps=0, nsteps=2)).all()) self.assertTrue((v[:2,:1,:5] == v.read(offset=(0,0), count=(1,5), from_steps=0, nsteps=2)).all()) self.assertTrue((v[-1,...] == v.read(from_steps=4, nsteps=1)).all()) self.assertTrue((v[-2,...] == v.read(from_steps=3, nsteps=1)).all()) #import ipdb; ipdb.set_trace() self.assertTrue((v[:,...,-1] == v.read(offset=(0,9), count=(2,1), scalar=(False,True))).all()) self.assertTrue((v[:,...,-3:-1] == v.read(offset=(0,7), count=(2,2))).all()) self.assertRaises(ValueError, v.__getitem__, Slicee()[:,:,-1:-2])
def test_simpleselection(self): sgen = Slicee() shape = (10, 20, 30) x = sel.select(shape, sgen[5]) self.assertEqual(x.shape, shape) self.assertEqual(x.mshape, (20, 30)) x = sel.select(shape, sgen[5, :]) self.assertEqual(x.mshape, (20, 30)) x = sel.select(shape, sgen[5, ...]) self.assertEqual(x.mshape, (20, 30)) self.assertRaises(ValueError, sel.select, shape, sgen[20]) self.assertRaises(ValueError, sel.select, shape, sgen[..., 40]) self.assertRaises(ValueError, sel.select, shape, sgen[..., 30, 20]) shape = (10, ) x = sel.select(shape, sgen[1]) self.assertEqual(x.mshape, ()) self.assertRaises(ValueError, sel.select, shape, sgen[10])
def test_adios_var_getitem(self): v = self.f['temperature'] self.assertTrue((v[0, ] == v.read(from_steps=0, nsteps=1)).all()) self.assertTrue((v[1, ] == v.read(from_steps=1, nsteps=1)).all()) self.assertTrue((v[:2, ] == v.read(from_steps=0, nsteps=2)).all()) self.assertTrue((v[0:2, ] == v.read(from_steps=0, nsteps=2)).all()) self.assertTrue((v[:2, :1, :5] == v.read(offset=(0, 0), count=(1, 5), from_steps=0, nsteps=2)).all()) self.assertTrue((v[-1, ...] == v.read(from_steps=4, nsteps=1)).all()) self.assertTrue((v[-2, ...] == v.read(from_steps=3, nsteps=1)).all()) self.assertTrue((v[:, ..., -1] == v.read(offset=(0, 9), count=(2, 1))).all()) self.assertTrue((v[:, ..., -3:-1] == v.read(offset=(0, 7), count=(2, 2))).all()) self.assertRaises(IndexError, v.__getitem__, Slicee()[:, :, -1:-2])
def test_adios_file_getitem(self): self.assertRaises(TypeError, self.f.__getitem__, Slicee()[1]) self.assertRaises(KeyError, self.f.__getitem__, Slicee()[:, :]) self.assertRaises(KeyError, self.f.__getitem__, Slicee()['NONE'])
def test_simpleselection_erros(self): sgen = Slicee() shape = (10, 20, 30) self.assertRaises(ValueError, sel.select, shape, sgen[..., ...])