PyOphidia is a GPLv3-licensed Python package for interacting with the Ophidia framework.
It is an alternative to Oph_Term, the Ophidia no-GUI interpreter component, and a convenient way to submit SOAP HTTPS requests to an Ophidia server or to develop your own application using Python.
It runs on Python 2.7, 3.3, 3.4 and 3.5, has no Python dependencies and is pure-Python code. It requires a running Ophidia instance for client-server interactions. The latest PyOphidia version (v1.5.0) is compatible with Ophidia v1.2.0.
It provides 2 main modules:
To install PyOphidia with conda run the following command:
conda install -c conda-forge pyophidia
To install the latest developement version run the following commands:
git clone https://github.com/OphidiaBigData/PyOphidia
cd PyOphidia
python setup.py install
Import PyOphidia
Import client module from PyOphidia package:
from PyOphidia import client
Instantiate a client
Create a new Client() using the login parameters username, password, host and port. It will also try to resume the last session the user was connected to, as well as the last working directory and the last produced cube.
ophclient = client.Client(username="oph-user",password="oph-passwd",server="127.0.0.1",port="11732")
In case of authentication token is used:
ophclient = client.Client(token="token",server="127.0.0.1",port="11732")
Client attributes
Client methods
To display the command output set “display=True”
Submit a request
Execute the request oph_list level=2:
ophclient.submit("oph_list level=2", display=True)
Set a Client for the Cube class
Instantiate a new Client common to all Cube instances:
from PyOphidia import cube
cube.Cube.setclient(username="oph-user",password="oph-passwd",server="127.0.0.1",port="11732")
Cube attributes
Instance attributes:
Class attributes:
Create a new container
Create a new container to contain our cubes called test, with 3 double dimensions (lat, lon and time):
cube.Cube.createcontainer(container='test',dim='lat|lon|time',dim_type='double|double|double',hierarchy='oph_base|oph_base|oph_time')
Import a new cube
Import the variable T2M from the NetCDF file /path/to/file.nc into a new cube inside the test container. Use lat and lon as explicit dimensions and time as implicit dimension expressed in days:
mycube = cube.Cube(container='test',exp_dim='lat|lon',imp_dim='time',measure='T2M',src_path='/path/to/file.nc',exp_concept_level='c|c',imp_concept_level='d')
Create a Cube object with an existing cube identifier
Instantiate a new Cube using the PID of an existing cube:
mycube2 = cube.Cube(pid='http://127.0.0.1/1/2')
Show a Cube structure and info
To shows metadata information about a data cube, its size and the dimensions related to it:
mycube2.info()
For the operators such as “cubeschema”, “cubesize”, “cubeelements”, “explore”, “hierarchy”, “info”, “list”, “loggingbk”, “operators”, “search”, “showgrid”, “man”, “metadata”, “primitives”, “provenance”, “search”, “showgrid”, “tasks” and other operators that provide verbose output, the display parameter by default is “True”. For the rest of operators, to display the result, “dispay=True” should be set.
Subset a Cube
To perform a subsetting operation along dimensions of a data cube (dimension values are used as input filters):
mycube3 = mycube2.subset(subset_dims='lat|lon',subset_filter='1:10|20:30',subset_type='coord')
Explore Cube
To explore a data cube filtering the data along its dimensions:
mycube2.explore(subset_dims='lat|lon',subset_filter='1:10|20:30',subset_type='coord')
Export to NetCDF file
To export data into a single NetCDF file:
mycube3.exportnc2(output_path='/home/user')
Export to Python array
To exports data in a python-friendly format:
data = mycube3.export_array(show_time='yes')