ViSUSpy

From
Jump to: navigation, search

The OpenVisus library is also available in python through a series of packages.

You can install the library using python pip:

python -m pip install OpenVisus
python -m OpenVisus configure

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 OpenVisus import *

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

Important: your code that interacts with IDX datasets has always to attach the DbModule first, as following:

DbModule.attach()
# your program code
DbModule.detach()

Read data into a NumPy array

In order to facilitate interoperation with existing python scientific libraries as NumPy we provide two function to convert data arrays from/to ViSUS Array an NumPy array.

import numpy

# load a remote dataset
dataset=LoadDataset("http://atlantis.sci.utah.edu/mod_visus?dataset=BlueMarble")

# get the bounding box of the dataset 
# the box is defined by a set of 2 points (p1 and p2)
# which define the two corners of a bounding box
box=dataset.getLogicBox()

# get the default field of a dataset
field=dataset.getDefaultField()

access=dataset.createAccess()

# select the resolution we need
resolution = 21

# initialize query
query=BoxQuery(dataset, field, time,ord('r'))

query.logic_box=dataset.getLogicBox()
query.end_resolutions.push_back(resolution)

# execute the query
dataset.beginQuery(query)
dataset.executeQuery(access,query)

# convert our buffer to a numpy array.
# This is useful when we want to read data from 
# and IDX dataset and use this array with other libraries
data=Array.toNumPy(query.buffer,bSqueeze=True,bShareMem=False)