ViSUSpy
From
Initialization
IdxModule.attach() unittest.main(exit=False) IdxModule.detach()
Write an IDX file
dataset_box=NdBox(NdPoint(0,0,0),NdPoint.one(16,16,16)) idxfile=IdxFile(); idxfile.box=NdBox(dataset_box) idxfile.fields.push_back(Field("myfield",DType.fromString("uint32"))) bSaved=idxfile.save(self.filename) self.assertTrue(bSaved) dataset=Dataset.loadDataset(self.filename) self.assertIsNotNone(dataset) access=dataset.get().createAccess() sampleid=0 for Z in range(0,16): slice_box=dataset.get().getBox().getZSlab(Z,Z+1) query=QueryPtr(Query(dataset.get(),ord('w'))) query.get().position=Position(slice_box) self.assertTrue(dataset.get().beginQuery(query)) self.assertEqual(query.get().nsamples.innerProduct(),16*16) buffer=Array(query.get().nsamples,query.get().field.dtype) query.get().buffer=buffer fill=convertToNumPyArray(buffer) for Y in range(16): for X in range(16): fill[Y,X]=sampleid sampleid+=1 success = dataset.get().executeQuery(access,query)
Read from IDX file
dataset=Dataset_loadDataset(self.filename) self.assertIsNotNone(dataset) box=dataset.get().getBox() field=dataset.get().getDefaultField() access=dataset.get().createAccess() sampleid=0 for Z in range(0,16): slice_box=box.getZSlab(Z,Z+1) query=QueryPtr(Query(dataset.get(),ord('r'))) query.get().position=Position(slice_box) self.assertTrue(dataset.get().beginQuery(query)) self.assertEqual(query.get().nsamples.innerProduct(),16*16) self.assertTrue(dataset.get().executeQuery(access,query)) check=convertToNumPyArray(query.get().buffer) for Y in range(16): for X in range(16): self.assertEqual(check[Y,X],sampleid) sampleid+=1