The ODI client

The ODI client can read data from a local ODI server or from a remote server using REST. The OdiClient class is instantiated using one of the newInstance() methods. The instance properties are defined in the file ${HOME}/.odi/instances.txt (see example below). If the url property is defined the newInstance() method will return an OdiClientHttp class, else it will return an OdiClientLocal class. Both types of OdiClient classes have the same read functionality, while only the OdiClientLocal class has write functionality.

All methods of OdiClient, and its subclasses, return Map or List objects. These classes are generic enough to be easily mapped to data types in different languages:



Download odi-all-4.1.2.jar and in Matlab add it with the javaclasspath command. Alternatively the full path of the Jar file can be added to the javaclasspath.txt file in the user's .matlab folder.

The following three Matlab files are useful for transforming Java List and Map objects into Matlab structures, cell arrays, and matrices.


>> import se.irf.lund.odi.OdiClient
>> odi = OdiClient.newInstance('rest3');
>> tic; odi.selectDataset('ace_mfi_h0'); toc
Elapsed time is 0.159282 seconds. 
>> map2struct(odi.metadata)

ans = 

      metadata_odi: [1x1 struct]
    metadata_spase: '<?xml version="1.0" encoding="UTF-16"?> <Spase xmlns="http://www...'
      metadata_cdf: [1x1 struct]

>> odi.setLimit(10000);
>> tic; data = odi.readData; toc
Elapsed time is 1.730317 seconds.
>> tic; x = map2struct(data); toc
Elapsed time is 4.983345 seconds.
>> x

x = 

               epoch: {10000x1 cell}
              b_meas: {10000x1 cell}
    b_meas_vec_gse_1: {10000x1 cell}
    b_meas_vec_gse_2: {10000x1 cell}
    b_meas_vec_gse_3: {10000x1 cell}
    b_meas_vec_gsm_1: {10000x1 cell}
    b_meas_vec_gsm_2: {10000x1 cell}
    b_meas_vec_gsm_3: {10000x1 cell}
          b_meas_rms: {10000x1 cell}
              q_flag: {10000x1 cell}
      position_gse_1: {10000x1 cell}
      position_gse_2: {10000x1 cell}
      position_gse_3: {10000x1 cell}
      position_gsm_1: {10000x1 cell}
      position_gsm_2: {10000x1 cell}
      position_gsm_3: {10000x1 cell}

>> tic; x = data2struct(data); toc
Elapsed time is 0.649287 seconds.
>> x

x = 

               epoch: [10000x1 double]
              b_meas: [10000x1 double]
    b_meas_vec_gse_1: [10000x1 double]
    b_meas_vec_gse_2: [10000x1 double]
    b_meas_vec_gse_3: [10000x1 double]
    b_meas_vec_gsm_1: [10000x1 double]
    b_meas_vec_gsm_2: [10000x1 double]
    b_meas_vec_gsm_3: [10000x1 double]
          b_meas_rms: [10000x1 double]
              q_flag: [10000x1 double]
      position_gse_1: [10000x1 double]
      position_gse_2: [10000x1 double]
      position_gse_3: [10000x1 double]
      position_gsm_1: [10000x1 double]
      position_gsm_2: [10000x1 double]
      position_gsm_3: [10000x1 double]




If Jython is not installed go to and follow instructions. It can be tested by typing


in the terminal. The Jython binary file must exist on the search path for the above to work.

Download odi-all-4.1.2.jar and add it to the CLASSPATH variable, e.g.

export CLASSPATH=${CLASSPATH}:<jar dir>/odi-all-4.1.2.jar

In your home directory, if the folder .odi does not exist, create it and add a file called instances.txt. Add the lines

user=<user for this site>
password=<password for this site>


Start Jython by typing jython which should show something like

Jython 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:48:36) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_25
Type "help", "copyright", "credits" or "license" for more information.

Try the following commands:

import se.irf.lund.odi.OdiClient as client
odi = client.newInstance("rest3")
x = odi.readData()

Cython with Py4J


The Python with Cython interpreter uses Py4J to connect to a locally running JVM instance which provides access to the Java OdiClient. With pip it can be installed with

pip install py4j


Example using IPython notebook: OdiTest

Before an OdiClient object can be instantiated in Python a JVM server needs to be started. This is achieved by the OdiClientPython class. Before running the Python examples the server is started with

java -cp <path to jar>/odi-all-4.1.2.jar se.irf.lund.odi.OdiClientPython

Then the Python interpreter is started. In the examples below the IPython interactive shell has been used. But ordinary python can also be used, but then the special commands %timeit and %pylab can not be used.

$ ipython
#Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
#Type "copyright", "credits" or "license" for more information.
#IPython 2.2.0 -- An enhanced Interactive Python.
#?         -> Introduction and overview of IPython's features.
#%quickref -> Quick reference.
#help      -> Python's own help system.
#object?   -> Details about 'object', use 'object??' for extra details.

from py4j.java_gateway import JavaGateway
gateway = JavaGateway()
odi = gateway.entry_point.newInstance("rest3")
odi.metadata()         # => {u'metadata_odi': {u'odi_name': u'ace_mfi_h0', u'odi_table_name': u'dataset_ace_mfi_h0', ...
%timeit odi.readData() # => 1 loops, best of 3: 1.79 s per loop
x = odi.readData()
x['epoch'][9999]       # => 63040537596000.0
x.keys()               # => [u'epoch', u'b_meas', u'b_meas_vec_gse_1', u'b_meas_vec_gse_2', ...
%pylab                 # IPython plot package.

JAR file

Java doc