PyAnatomist programming documentation¶
This API enables to drive Anatomist application throught python scripts : running Anatomist, loading volumes, meshes, graphs, viewing them in windows, merging objects, changing colour palette…
organization: NeuroSpin and IFR 4
license: CeCILL-v2 (GPL-compatible)
From version 4.7.0 and later, PyAnatomist work with both Python 2 (2.7 and later) and Python 3 (3.4 and later) (provided C++/python bindings have been compiled appropriately).
The main entry point is one of the
anatomist.base.Anatomist-inhertied classes which must be instantiated before any operation can be performed.
It represents Anatomist application. This class contains a number of nested classes:
anatomist.base.Anatomist.AWindow… that represents handling elements of Anatomist application.
The entry point of this API is the module api, you can import it as below :
>>> import anatomist.api as anatomist
And then create an instance of Anatomist :
>>> a = anatomist.Anatomist()
So you can send commands to Anatomist application, for example creating a window :
>>> window = a.createWindow('3D')
Several means of driving Anatomist in python scripts exist : Python bindings for the C++ library (SIP bindings), or sending commands via a network socket. Behind a general interface, this api provides 2 implementations, one for each method.
anatomist.basemodule contains the general interface : classes and methods that exist in all implementations. This module also provides the general API documentation.
anatomist.socket.apimodule contains an implementation using socket communication with an Anatomist application run in another process in server mode.
anatomist.direct.apimodule contains an implementation using sip bindings of Anatomist C++ api.
anatomist.threaded.apimodule is a thread safe layer for the direct module. Useful if you have to use anatomist api in a multi-threaded environment.
anatomist.headlessmodule is an off-screen redirection of Anatomist display.
anatomist.notebookmodule is a Jupyter Notebook widget proxy, rendering the contents of an Anatomist view.
anatomist.cppmodule contains sip bindings of Anatomist C++ api. It is a low level module, only for advanced user.
Work in progress work in progress module
The direct implementation provides more features as it handles C++ binding objects: all bound features are available. Socket implementation provides features that can be expressed with Anatomist commands system, so a limited set of features. But it runs Anatomist application in a separate process so potential errors in Anatomist don’t crash the application that uses the API.
By default, the implementation used when you import anatomist.api is the direct implementation. If you want to switch to another implementation, use setDefaultImplementation of this module. For example to use the socket implementation :
>>> import anatomist >>> anatomist.setDefaultImplementation(anatomist.SOCKET) >>> import anatomist.api as anatomist
Another specific implementation for Brainvisa also exists: brainvisa.anatomist module in brainvisa. It enables to use brainvisa database informations on loaded objects to automatically load associated referentials and transformations. It uses the same api, so it is possible to switch from one implementation to the other.
By default, brainvisa module uses the direct implementation.
In addition to the Python APIs, the
Anatomist.execute method of Anatomist also grants access to the commands system which offers many functionalities, some of which have not been wrapped yet int the more “pythonic” API.
Use this constant to load anatomist api socket implementation. See
Use this constant to load anatomist api direct implementation (sip bindings). See
Use this constant to load anatomist api threaded direct implementation. See
Identifier of the anatomist api headless implementation. See
Identifier of the anatomist api notebook implementation (inside a jupyter notebook). See
Changes the default implementation of this api. The selected implementation will be loaded on importation of anatomist.api.
Table of contents¶
- Common base API
- Direct bindings implementation
- Socket implementation
- Thread-safe implementation of the direct bindings
- Utility sub-module for the threaded implementation
- Low-level C++ API bindings
- Headless implementation
- Anatomist NoteBook widget
- Work in progress
- PyAnatomist tutorial
- Programming with Anatomist in Python language
- Description of the API
- Using the API
- Run Anatomist
- Load an object
- View an object
- Windows block
- Move the cursor
- View header information
- Change the color palette
- View meshes
- Change mesh material
- Fusion between two volumes
- Load a transformation
- Load an existing referential
- Load referential information from file header
- Display a ROI graph
- Sending a command to Anatomist
- Using the direct implementation
- At the end, cleanup the temporary working directory
- PyAnatomist / PyAims tutorial : mixing Anatomist and AIMS in Python language
- How to
- Use / change Anatomist settings
- Apply transformations to objects
- Use Anatomist to perform off-screen rendering and snapshots
- Anatomist notebook extension demo