iFit: Python interface

  1. Requirements: Python/NumPy
  2. Usage
  3. The commands to use

This feature is experimental.

Requirements: Python/NumPy

Install Python(x,y) for Windows, Anaconda or Entought Canopy for Windows and MacOSX. Linux flavors provide numpy as e.g. RPM and Debian packages.The IPython package is also recommended. Both Python 2 and 3 are supported.

The minimal required packages are:
but it is recommended to use the ipython notebook:
which can all be installed on Ubuntu/Debian systems with:


To use the IPython notebook, launch:
command from a terminal. A browser will appear with an iPython notebook session ready to be used. Remember to execute command 'cells' possibly in order, by pressing Shift-Return on each. As the string specifier with Matlab is the single quote, we recommend to use the double quote string within Python (as in the example below).

Alternatively, navigate to the iFit/Applications/Python directory and launch manually IPython or Python:

% ipython notebook PyMatlab.ipynb


% python

Then issue the command:

>>> from matlab import Matlab
>>> m = Matlab()
>>> m.eval("addpath(genpath('../..'))")
or, when using the standalone version:
>>> from matlab import Matlab
>>> m = Matlab('ifit')

From there on, any iFit and Matlab expression can be executed from Python.

>>> m.eval("a=iData('filename')")		# to import a data file
>>> m.eval("a=iData(peaks)") # as an example
>>> m.eval("plot(a)") # generate a Matlab plot
>>> m.eval("b = a/2")
>>> b=m.get("b.Signal") # get the signal as a Numpy Array
>>> ax = m.get("getaxis(b, 1:ndims(b))") # get all axes values, here 'x' and 'y' axes.
The main idea is that any call to iFit/Matlab should be prepended with 'm.' and use the set/get/eval methods.

iFit objects are stored as Python NumPy arrays. Refer to the Methods page to learn about all methods that can be called for iData and iFunc objects.

The commands to use

In addition, there are specialized methods to communicate with iFit/Matlab:
m.set('name', value)
assigns name=value in the iFit/Matlab workspace.
retrieves the named variable from the iFit/Matlab workspace.
evaluates the expression/code in the iFit/Matlab workspace. The expression can contain control statements.

E. Farhi - iFit Python - Nov. 27, 2018 2.0.2 - back to Main iFit Page ILL,
          Grenoble, France <www.ill.eu>