Difference between revisions of "ViSUSpy"

From
Jump to: navigation, search
(Initialization)
(Library imports)
Line 13: Line 13:
 
   from VisusDbPy    import *
 
   from VisusDbPy    import *
  
These modules allow the basic interactions with IDX datasets, which can be either local or remote (served by a [[ViSUS Server]])
+
These modules allow the basic interactions with IDX datasets, which can be either local or remote (served by a [[ViSUS Server]]).
  
 
== Initialization ==  
 
== Initialization ==  

Revision as of 15:58, 9 March 2018

ViSUSpy is a library that allows the user to use the ViSUS framework from python.

In the following sections we provide some examples on how to use it.

Library imports

To import and use the library in your python application you need to use the following imports:

 from visuspy import *
 from VisusKernelPy import *
 from VisusIdxPy    import *
 from VisusDbPy     import *

These modules allow the basic interactions with IDX datasets, which can be either local or remote (served by a ViSUS Server).

Initialization

 IdxModule.attach()
 unittest.main(exit=False)
 IdxModule.detach()

Write data to 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