API Reference

Scilab2Py

class scilab2py.Scilab2Py(executable=None, logger=None, timeout=None, oned_as='row', temp_dir=None, convert_to_float=True)

Manages a Scilab session.

Uses MAT files to pass data between Scilab and Numpy. The function must either exist as an file in this directory or on Scilab’s path.

You may provide a logger object for logging events, or the scilab.get_log() default will be used. Events will be logged as debug unless verbose is set when calling a command, then they will be logged as info.

Parameters:

executable : str, optional

Name of the Scilab executable, can be a system path.

logger : logging object, optional

Optional logger to use for Scilab2Py session

timeout : float, opional

Timeout in seconds for commands

oned_as : {‘row’, ‘column’}, optional

If ‘column’, write 1-D numpy arrays as column vectors. If ‘row’, write 1-D numpy arrays as row vectors.}

temp_dir : str, optional

If specified, the session’s MAT files will be created in the directory, otherwise a default directory is used. This can be a shared memory (tmpfs) path.

Start Scilab and create our MAT helpers

exit()

Closes this Scilab session and removes temp files

push(name, var, verbose=False, timeout=None)

Put a variable or variables into the Scilab session.

Parameters:

name : str or list

Name of the variable(s).

var : object or list

The value(s) to pass.

timeout : float

Time to wait for response from Scilab (per character).

Examples

>>> from scilab2py import Scilab2Py
>>> sci = Scilab2Py()
>>> y = [1, 2]
>>> sci.push('y', y)
>>> sci.pull('y')
array([[ 1.,  2.]])
>>> sci.push(['x', 'y'], ['spam', [1., 2., 3., 4.]])
>>> sci.pull(['x', 'y'])  
[u'spam', array([[ 1.,  2.,  3.,  4.]])]
pull(var, verbose=False, timeout=None)

Retrieve a value or values from the Scilab session.

Parameters:

var : str or list

Name of the variable(s) to retrieve.

timeout : float

Time to wait for response from Scilab (per character).

Returns:

out : object

Object returned by Scilab.

Raises:

Scilab2PyError

If the variable does not exist in the Scilab session.

Examples:

>>> from scilab2py import Scilab2Py
>>> sci = Scilab2Py()
>>> y = [1, 2]
>>> sci.push('y', y)
>>> sci.pull('y')
array([[ 1.,  2.]])
>>> sci.push(['x', 'y'], ['spam', [1, 2, 3, 4]])
>>> sci.pull(['x', 'y'])  
[u'spam', array([[ 1.,  2.,  3.,  4.]])]
eval(cmds, verbose=True, timeout=None, log=True, plot_dir=None, plot_name='plot', plot_format='png', plot_width=620, plot_height=590, return_both=False)

Perform Scilab command or commands.

Parameters:

cmd : str or list

Commands(s) to pass directly to Scilab.

verbose : bool, optional

Log Scilab output at info level.

timeout : float

Time to wait for response from Scilab (per character).

plot_dir: str, optional

If specificed, save the session’s plot figures to the plot directory instead of displaying the plot window.

plot_name : str, optional

Saved plots will start with plot_name and end with “_%%.xxx’ where %% is the plot number and xxx is the plot_format.

plot_format: str, optional

The format in which to save the plot (PNG by default).

plot_width: int, optional

The plot with in pixels.

plot_height: int, optional

The plot height in pixels.

return_both : bool, optional

If True, return an (printed output, value) tuple. If “ans =” is in the printed output, the printed output will have that portion removed.

Returns:

out : str

Results printed by Scilab.

Raises:

Scilab2PyError

If the command(s) fail.

restart()

Restart an Scilab session in a clean state

Utils

class scilab2py.Scilab2PyError

Called when we can’t open Scilab or Scilab throws an error

scilab2py.get_log(name=None)

Return a console logger.

Output may be sent to the logger using the debug, info, warning, error and critical methods.

Parameters:

name : str

Name of the log.

References

[R1]Logging facility for Python, http://docs.python.org/library/logging.html
class scilab2py.Struct

Scilab style struct, enhanced.

Supports dictionary and attribute style access. Can be pickled, and supports code completion in a REPL.

Examples

>>> from pprint import pprint
>>> from scilab2py import Struct
>>> a = Struct()
>>> a.b = 'spam'  # a["b"] == 'spam'
>>> a.c["d"] = 'eggs'  # a.c.d == 'eggs'
>>> pprint(a)
{'b': 'spam', 'c': {'d': 'eggs'}}
scilab2py.kill_scilab()[source]

Kill all Scilab instances (cross-platform).

This will restart the “Scilab” instance. If you have instantiated Any other Scilab2Py objects, you must restart them.