Axon python API modules

This part of the API is in the Python path, it may be imported without running Brainvisa.

Modules organization


This module contains the classes that manage BrainVisa set of options, accessible throught the menu BrainVISA -> Preferences.


brainvisa.processing.qt4gui: GUI Modules

The classes related to the graphical user interface are located in qt4gui modules. They use PyQt API, a set of Python bindings for Qt application framework:

Some qtgui modules also exist but are mainly just redirections to the corresponding qt4gui module. It was useful when we maintained the compatibility with qt3 but is no more the case.

Note that the qt4gui modules do work for both Qt4 and Qt5. GUI Modules


brainvisa.anatomist: a specialized wrapper for Anatomist

class brainvisa.anatomist.AWindowChoice(noSelectionLabel=None, aslist=False)[source]


A process parameter to choose an Anatomist window. This parameter is a choice between several anatomist windows. By default, if anatomist isn’t started or if there’s no opened windows, the choice offer the possibility to create any type of anatomist window.

If anatomist is started, the set of opened window is added to the choices list.

The list of choices is not updated automatically, to refresh the choices it is necessary to open a new instance of the process.


args (list) – list of possible value, each value can be a string or a tuple.


Updates choice list. Adds to default choices curently opened anatomist windows.

class brainvisa.anatomist.Anatomist(*args, **kwargs)[source]

Bases: anatomist.threaded.api.Anatomist

The __init__ method of Singleton derived class should do nothing. Derived classes must define __singleton_init__() instead of __init__.


Exits Anatomist application. if anatomist is closed, the singleton instance is deleted. So next time the constructor is called, a new instance will be created.


Creates a new referential using the informations in the file.


fileref (string or Diskitem) – name or diskitem of a file (minf file, extension .referential) containing informations about the referential : its name and uuid



Return type

the newly created referential


Creates a new window and opens it.

  • wintype (str) – Type of window to open ("Axial", "Sagittal", "Coronal", "3D", "Browser", "Profile", …)

  • geometry (int vector) – Position on screen and size of the new window (x, y, w, h)

  • block (AWindowsBlock or QWidget) – A parent block in which the new window must be added. In Anatomist 4.6.2 and later, the block may be a regular QWidget (this is only OK in direct implementation mode)

  • no_decoration (bool) – Indicates if decorations (menus, buttons) can be painted around the view.

  • options (dict) – Internal advanced options.


window – The newly created window

Return type



Creates a window containing other windows.

An id is reserved for that block but the bound object isn’t created. It will be created first time a window is added to the block with createWindow method.

  • nbCols (int) – Number of columns of the windows block

  • nbRows (int) – Number of rows of the windows block (exclusive with nbCols)

  • widget (QWidget (optional)) – New in Anatomist 4.6.2, only applies to the direct implementation. Existing parent widget to be used as a block


block – A window which can contain several AWindow

Return type



Loads an object from a file (volume, mesh, graph, texture…)

  • fileref (string or Diskitem) – name of the file that contains the object to load or a Diskitem representing this file.

  • objectName (string) – object name

  • restrict_object_types (dictionary) – object -> accpepted types list. Ex: {'Volume' : ['S16', 'FLOAT']}

  • forceReload (boolean) – if True the object will be loaded even if it is already loaded in Anatomist. Otherwise, the already loaded one is returned.

  • loadReferential (boolean) – if True, use brainvisa database informations to search referential and transformations associated to this object and load them.



Return type

the loaded object


Search and load transformations between this referential and spm referential.


referential (Referential) – the referential for which searching transformations


This method is redefined to print logs in brainvisa log system.


Log an event received from anatomist application.

  • event (string) – event name

  • params (string) – event parameters


Loads an image, opens it in a new window in the object’s referential. A palette is assigned to the object (Rainbow2) in order to see the bias.

  • fileRef (string or ReadDiskItem) – file name for the bias corrected image

  • forceReload (boolean) – if True, the image is reloaded if already in memory.

  • wintype (string) – “Axial”, “Coronal”, “Sagittal”, “3D” (or other)

  • hanfile (string or ReadDiskItem) – optional file name for histogram analysis file. If present it will be used to set palette bounds.

  • parent (QWidget or anatomist block) – parent widget or block


Fusions an irm image with a mask. A palette is associated to the mask to highlight it in the fusion. Fusion method is Fusion2DMethod. Resulting image is opened in a new window.

  • mriFile (Diskitem or string) – file containing the mri image

  • maskFile (Diskitem or string) – file containing the mask to apply

  • palette (APalette) – palette to use for the mask

  • mode (string) – mix color mode (geometric, linear, replace, decal, blend, add or combine)

  • rate (float) – mix rate in linear mode

  • wintype (string) – type of window to open


Loads a mesh and opens it in a 3D window. The window is assigned the object’s referential.


Loads the image in anatomist, opens it in a new window and assigns the image’s referential to the window.


fileRef (string or DiskItem) – filename of the image to load.


Return type

dictionary {"object" : the loaded object, "window" : the new window, "file" : the readed file}


Load a mesh file and apply the texture with the palette


class brainvisa.toolboxes.Toolbox(name, toolboxDirectory, icon=None, description=None)[source]

Bases: object

@type name: string @ivar name: toolbox name. It can be the name given in the constructor, or the userName specified in the toolbox .py file. @type id: string @ivar id: identifier for the toolbox. @type processTree: ProcessTree @ivar processTree: content of the toolbox

@type name: string @param name: toolbox name. @type toolboxDirectory: string @param toolboxDirectory: main directory for this toolbox. @type description: string @param description: short text describing the toolbox. It’s optional, it can be set in init file. It will be printed in a tooltip.

Gets the links between this toolbox and other toolboxes reading the minf file of the toolbox (if there is one). Must be called only after having loaded all toolboxes to be sure that all referenced processes are loaded. @rtype: list of ProcessTree @return : links to other toolboxes. each process tree represents another toolbox and contains part of current toolbox that must be added in the other toolbox.


@rtype: iterator of Toolbox @return: all loaded toolboxes.


@rtype: Toobox @return: the toolbox whose id is given. The id of a toolbox is its directory name (lowercase) or if it doesn’t have a named directory, the toolbox’s name in lowercase.

brainvisa.toolboxes.readToolboxes(toolboxesDir, homeBrainVISADir)[source]

Search for toolboxes directory in neuroConfig.toolboxesDir (brainvisa/toolboxes) and in brainvisaHomeDir (.brainvisa).



exception brainvisa.validation.ValidationError[source]

Bases: RuntimeError

This class inherits from RuntimeError and defines an exception that will be raised by processes validation functions.


class brainvisa.history.HistoricalEvent(uuid=None)[source]

Bases: object

class brainvisa.history.HistoryBook(directory=None, database=None, dirBvsession=None, compression=False)[source]

Bases: object

An L{HistoryBook} contains some L{HistoricalEvent}.

class brainvisa.history.ProcessExecutionEvent(uuid=None, content={})[source]

Bases: brainvisa.history.HistoricalEvent

This object enables to store the state of a Process instance in a dictionary format.


Manage an id / database in order to give an id for each bvsession.


This module defines the class MultipleExecfile that is used to read Brainvisa ontology files.

class brainvisa.multipleExecfile.MultipleExecfile(localDict=None, globalDict=None)[source]

Bases: object

This object enables to execute several python files that can have dependencies between us. One file can include another to indicate that it needs something defined in this other file.



list of string indicating the possible file extensions for the files that can be executed via this object.


Set of paths where the files to execute are searched.


Global dictionary that will be used to execute the files.


Local dictionary that will be used to execute the files.


execute(*args, **kwargs)[source]

Executes the files listed in args if they are found in the includePath passing globalDict and localDict as global and local namespaces.

kwargs may contain a parameter continue_on_error. If it is True, the execution won’t be stopped by the first exception, the exceptions will be stored in a list and returned at the end of the method.


The list of exception that occured during files execution.


Returns the list of executed files.


Finds the file in includePath trying to append the fileExtensions to its name.


localFileName (string) – name of the searched file, possibly wihtout extension, relative to the include path.

Return type



absolute path to the found file, else None.


class brainvisa.registration.DatabasesTransformationManager[source]

Bases: object

TransformationsManager linked with BrainVISA database system.

copyReferential(sourceDiskItem, destinationDiskItem, copy_transformations=True)[source]

Copy the referential of sourceDiskItem to the one of destinationDiskItem. The minf file of destinationDiskItem is saved by this function.

  • sourceDiskItem (DiskItem) –

  • destinationDiskItem (DiskItem) –

  • copy_transformations (bool (optional)) – if True (default) transformations are also copied from the source disk item header onto the destination. Set it to False if you explicitely manage the destination disk item header transformations.


Creates the file for the referential diskitem and add it to the database and to the transformation manager.

createNewReferentialFor(diskItem, name=None, description=None, dimension_count=3, referentialType=None, simulation=False, output_diskitem=None)[source]

Create a new referential for an object stored in a DiskItem and record it in the database. Returns None if the referential has not been created because its location in the database cannot be found with ReadDiskItem( ‘Referential’, ‘Referential’ ).findValue( diskItem ).

findOrCreateReferential(referentialType, diskItem, name=None, description=None, dimension_count=3, simulation=False, assign=False, output_diskitem=None)[source]

Search a referential of type referentialType for the data diskitem. if simulation is false, the referential will be created and added to the database and transformation manager. if assign is True, the referential will be assign to the diskitem.

findPaths(source_referential, destination_referential, maxLength=None, bidirectional=False, extensive=True)[source]

Return a generator object that iterate over all the transformation paths going from source_referential to destination_referential. A transformation path is a list of transformation objects. The paths are returned in increasing length order. If maxlength is set to a non null positive value, it limits the size of the paths returned. Source and destination referentials can be given either as string uuid or as referential object.

If extensive is False, not all paths will be searched, and a faster algorithm will be used which may stop when at least one matching path is found. But ambiguous paths will not necessarily be detected.

findReferentialNeighbours(ref, bidirectional=True, flat_output=False)[source]

From one referential, find all referentials directly linked by transforms and return a tuple (referentials, paths), where paths is a dictionary which contains a list of transforms that leads to each referential (key of the dictionary) from the source_referential (a transform is a triplet (uuid_transform, uuid_from, uuid_to))

If flat_output is True, the output is a list of tuples (transform, source, dest).


Return the referential object corresponding to the given diskItem or uuid. Return None if the diskItem has no referential or the referential is not in the manager.

removeReferential(db, diskItem, uuid, eraseFiles=False)[source]

Test if there is no transformation with uuid then remove the diskItem

setReferentialTo(diskItem, referential)[source]

Assign to the given diskItem the given referential (as Referential object or uuid)