def test_va(self): self.start() self.assertEqual(gxva.__version__, geosoft.__version__) with gxva.GXva(width=12, dtype=np.float) as va: self.assertTrue(isinstance(va.gxva, gxapi.GXVA)) self.assertEqual(va.fid, (0.0, 1.0)) self.assertEqual(va.width, 12) fid = (10.1, 0.99) with gxva.GXva(width=7, dtype=np.float, fid=fid) as va: self.assertEqual(va.fid, fid) self.assertEqual(va.width, 7) fid = (-45, 7) va.fid = fid self.assertEqual(va.fid, fid) va.refid((-40, 8), 4) self.assertEqual(va.fid, (-40, 8)) self.assertEqual(va.length, 4) self.assertEqual(va.dimensions, (4, 7)) self.assertEqual(va.gxtype, gxu.gx_dtype(np.float)) self.assertEqual(va.np.shape, (4, 7)) va.length = 16 self.assertEqual(va.fid, (-40, 8)) self.assertEqual(va.length, 16) self.assertEqual(va.dimensions, (16, 7)) self.assertEqual(va.gxtype, gxu.gx_dtype(np.float)) self.assertEqual(va.np.shape, (16, 7))
def test_read_write_channel_vv_va(self): self.start(gsys.func_name()) with gxgdb.GXdb.open(self.gdb_name) as gdb: gdb.delete_channel('test_chan_vv') vv = gxvv.GXvv(np.array([1., 2., 3.]), fid=(-10, 2.5)) gdb.write_channel_vv('T46', 'test_chan_vv', vv) vv = gdb.read_channel_vv('T46', 'test_chan_vv') self.assertEqual(vv.length, 3) self.assertEqual(vv.fid, (-10.0, 2.5)) va = gdb.read_channel_va('T46', 'test_chan_vv') self.assertEqual(va.width, 1) self.assertEqual(va.length, 3) self.assertEqual(va.fid, (-10.0, 2.5)) gdb.delete_channel('test_chan_vv') va = gxva.GXva(np.array([[1., 2., 3.], [8, 9, 10]]), fid=(-10, 2.5)) gdb.write_channel_va('T46', 'test_chan_va', va) self.assertRaises(gxgdb.GDBException, gdb.read_channel_vv, 'T46', 'test_chan_va') va = gdb.read_channel_va('T46', 'test_chan_va') self.assertEqual(va.width, 3) self.assertEqual(va.length, 2) self.assertEqual(va.fid, (-10.0, 2.5)) gdb.delete_channel('test_chan_va')
def test_uom(self): self.start() npdata = np.array(range(45)).reshape((9, 5)) with gxva.GXva(npdata, unit_of_measure='maki') as va: self.assertEqual(va.unit_of_measure, 'maki') va.unit_of_measure = 'nT' self.assertEqual(va.unit_of_measure, 'nT')
def test_exceptions(self): self.start(gsys.func_name()) self.assertRaises(gxva.VAException, gxva.GXva, np.array([["bones", "queens", "geology"], ["a", "b", "c"]])) with gxva.GXva(width=7, dtype=np.float) as va: self.assertRaises(gxva.VAException, va.get_np, dtype="U7") with gxva.GXva(np.array(range(45)).reshape((9, 5))) as va: self.assertRaises(gxva.VAException, va.get_np, n=0) with gxva.GXva(np.array(range(45)).reshape((9, 5))) as va: self.assertRaises(gxva.VAException, va.get_np, n_col=0) with gxva.GXva(np.array(range(40)).reshape((20, 2))) as va: self.assertRaises(gxva.VAException, va.set_np, np.array(range(3)))
def test_dummy_nan(self): self.start() npdata = np.array(range(45), dtype=np.float32).reshape((9, 5)) npdata[0, 1] = np.nan with gxva.GXva(npdata) as va: self.assertTrue(npdata[0, 1]) self.assertEqual(tuple(va[0][0])[4], 4.) self.assertTrue(np.isnan(va[0][0][1]))
def test_iterator(self): self.start() npdata = np.array(range(45)).reshape((9, 5)) with gxva.GXva(npdata) as va: self.assertEqual(tuple(va[0][0]), (0, 1, 2, 3, 4)) self.assertEqual(va[4][1], 4) list2d = [v[0] for v in va] self.assertEqual(tuple(list2d[1]), (5, 6, 7, 8, 9)) self.assertEqual(va.np.shape, (9, 5))
def test_empty(self): self.start() empty = np.array([[], []]) va = gxva.GXva(empty, width=2) self.assertEqual(len(va), 0) self.assertEqual(va.np.size, 0) va.set_data(empty) self.assertEqual(len(va), 0) self.assertEqual(va.np.size, 0)
def test_va(self): self.start(gsys.func_name()) self.assertEqual(gxva.__version__, geosoft.__version__) with gxva.GXva(width=12, dtype=np.float) as va: self.assertEqual(va.fid, (0.0,1.0)) self.assertEqual(va.width, 12) fid = (10.1,0.99) with gxva.GXva(width=7, dtype=np.float, fid=fid) as va: self.assertEqual(va.fid, fid) self.assertEqual(va.width, 7) fid = (-45,7) va.fid = fid self.assertEqual(va.fid,fid) va.reFid((-40,8),4) self.assertEqual(va.fid,(-40,8)) self.assertEqual(va.length,4) self.assertEqual(va.dimensions, (4,7)) self.assertEqual(va.gxtype, gxu.gx_dtype(np.float))
def test_va(self): self.start() max = gxapi.iMAX // 16 print('max', max) npdata = np.empty(max * 2).reshape((max, 2)) with gxva.GXva(npdata) as va: self.assertTrue(va.length, gxapi.iMAX) del npdata gc.collect() npdata = np.empty((gxapi.iMAX + 1) * 2).reshape(((gxapi.iMAX + 1), 2)) self.assertRaises(gxva.VAException, gxva.GXva, npdata) del npdata gc.collect()
def test_np(self): self.start() fid = (99, 0.1) npdata = np.array(range(45)).reshape((9, 5)) with gxva.GXva(npdata, fid=fid) as va: self.assertEqual(va.fid, fid) self.assertEqual(va.length, npdata.shape[0]) self.assertEqual(va.width, npdata.shape[1]) np2 = va.get_data(va.dtype) self.assertEqual(np2[0].shape, npdata.shape) np2, fid2 = va.get_data(dtype=va.dtype, start=1) self.assertEqual(fid2, (99.1, .1)) self.assertEqual(np2.shape, (8, 5)) self.assertEqual(va.get_data(start=6)[0].shape, (3, 5)) try: self.assertEqual( va.get_data(dtype=va.dtype, start=50)[0].shape, (0, )) self.assertTrue(False) except gxva.VAException: pass np3, fid3 = va.get_data(np.int) self.assertEqual(fid3, fid) self.assertEqual(np3[0, 0], 0) self.assertEqual(np3[1, 4], 9) np3, fid3 = va.get_data(np.float64) self.assertEqual(fid3, fid) self.assertEqual(np3[0, 0], 0.0) self.assertEqual(np3[1, 4], 9.0) np3, fid3 = va.get_data(np.float64, n=2) self.assertEqual(fid3, fid) self.assertEqual(np3.shape[0], 2) self.assertEqual(np3[0, 0], 0.0) self.assertEqual(np3[1, 4], 9.0) np3, fid3 = va.get_data(np.float64, n=99) self.assertEqual(fid3, fid) self.assertEqual(np3.shape[0], va.length) np3, fid3 = va.get_data(np.float64, n_col=3) self.assertEqual(fid3, fid) self.assertEqual(np3.shape[1], 3) np3, fid3 = va.get_data(np.float64, n_col=99) self.assertEqual(fid3, fid) self.assertEqual(np3.shape[1], va.width) npdata = np.array(range(64), dtype=np.int).reshape(4, 16) npdata[1, 2] = gxapi.iDUMMY with gxva.GXva(npdata, fid=fid) as va: np3, fid = va.get_data(dtype=np.int64) self.assertEqual(np3[0, 0], 0.) self.assertEqual(np3[2, 11], 43) self.assertEqual(np3[1, 2], gxapi.GS_S8DM) np3, fid = va.get_data(dtype=np.int32) self.assertEqual(np3[0, 0], 0.) self.assertEqual(np3[2, 11], 43) self.assertEqual(np3[1, 2], gxapi.GS_S4DM) self.assertEqual(np3[1, 2], gxapi.iDUMMY) np3, fid = va.get_data(np.float) self.assertEqual(np3[0, 0], 0.) self.assertEqual(np3[2, 11], 43.) self.assertTrue(np.isnan(np3[1, 2])) d = np.array(range(32), dtype=np.int).reshape(-1, va.width) d[0, 3] = gxu.gx_dummy(d.dtype) va.set_data(d) np3, fid = va.get_data(dtype=np.int32) self.assertEqual(np3.shape[0], 2) self.assertEqual(np3[0, 0], 0) self.assertEqual(np3[1, 15], 31) self.assertEqual(np3[0, 3], gxapi.GS_S4DM)
def test_np(self): self.start(gsys.func_name()) fid = (99,0.1) npdata = np.array(range(45)).reshape((9,5)) with gxva.GXva(npdata, fid=fid) as va: self.assertEqual(va.fid, fid) self.assertEqual(va.length, npdata.shape[0]) self.assertEqual(va.width, npdata.shape[1]) np2 = va.get_np(va.dtype) self.assertEqual(np2[0].shape, npdata.shape) np2,fid2 = va.get_np(dtype=va.dtype, start=1) self.assertEqual(fid2,(99.1,.1)) self.assertEqual(np2.shape, (8, 5)) self.assertEqual(va.get_np(start=6)[0].shape, (3, 5)) try: self.assertEqual(va.get_np(dtype=va.dtype, start=50)[0].shape, (0,)) self.assertTrue(False) except gxva.VAException: pass np3,fid3 = va.get_np(np.int) self.assertEqual(fid3,fid) self.assertEqual(np3[0, 0], 0) self.assertEqual(np3[1, 4], 9) np3, fid3 = va.get_np(np.float64) self.assertEqual(fid3, fid) self.assertEqual(np3[0, 0], 0.0) self.assertEqual(np3[1, 4], 9.0) np3, fid3 = va.get_np(np.float64, n=2) self.assertEqual(fid3, fid) self.assertEqual(np3.shape[0], 2) self.assertEqual(np3[0, 0], 0.0) self.assertEqual(np3[1, 4], 9.0) np3, fid3 = va.get_np(np.float64, n=99) self.assertEqual(fid3, fid) self.assertEqual(np3.shape[0], va.length) np3, fid3 = va.get_np(np.float64, n_col=3) self.assertEqual(fid3, fid) self.assertEqual(np3.shape[1], 3) np3, fid3 = va.get_np(np.float64, n_col=99) self.assertEqual(fid3, fid) self.assertEqual(np3.shape[1], va.width) npdata = np.array(range(64), dtype=np.int).reshape(4, 16) with gxva.GXva(npdata, fid=fid) as va: np3, fid = va.get_np(dtype=np.int64) self.assertEqual(np3[0, 0], 0.) self.assertEqual(np3[2, 11], 43) np3, fid = va.get_np(np.float) self.assertEqual(np3[0, 0], 0.) self.assertEqual(np3[2, 11], 43.) va.set_np(np.array(range(32), dtype=np.int)) np3, fid = va.get_np(dtype=np.int64) self.assertEqual(np3.shape[0], 2) self.assertEqual(np3[0,0], 0) self.assertEqual(np3[1,15], 31)