Axon python API modules

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

Modules organization

brainvisa.configuration

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

brainvisa.data

brainvisa.processing

brainvisa.tools

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.

brainvisa.data.qt4gui: GUI Modules

brainvisa.shelltools

brainvisa.anatomist: a specialized wrapper for Anatomist

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

Bases: brainvisa.data.neuroData.Choice

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.

Parameters

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

refreshChoices(*args)[source]

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__.

close(**kwargs)

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.

createReferential(**kwargs)

Creates a new referential using the informations in the file.

Parameters

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

Returns

Referential

Return type

the newly created referential

createWindow(**kwargs)

Creates a new window and opens it.

Parameters
  • 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.

Returns

window – The newly created window

Return type

AWindow

createWindowsBlock(**kwargs)

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.

Parameters
  • 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

Returns

block – A window which can contain several AWindow

Return type

AWindowsBlock

loadObject(**kwargs)

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

Parameters
  • 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.

Returns

AObject

Return type

the loaded object

loadTransformations(**kwargs)

Search and load transformations between this referential and spm referential.

Parameters

referential (Referential) – the referential for which searching transformations

log(**kwargs)

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

logEvent(**kwargs)

Log an event received from anatomist application.

Parameters
  • event (string) – event name

  • params (string) – event parameters

viewBias(**kwargs)

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.

Parameters
  • 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

viewMaskOnMRI(**kwargs)

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.

Parameters
  • 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

viewMesh(**kwargs)

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

viewObject(**kwargs)

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

Parameters

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

Returns

Return type

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

viewTextureOnMesh(**kwargs)

Load a mesh file and apply the texture with the palette

brainvisa.toolboxes

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.

brainvisa.toolboxes.allToolboxes()[source]

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

brainvisa.toolboxes.getToolbox(id)[source]

@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).

brainvisa.workflow

brainvisa.validation

exception brainvisa.validation.ValidationError[source]

Bases: RuntimeError

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

brainvisa.history

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.

brainvisa.history.sessionId(database)[source]

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

brainvisa.multipleExecfile

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.

Attributes

fileExtensions

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

includePath

Set of paths where the files to execute are searched.

globalDict

Global dictionary that will be used to execute the files.

localDict

Local dictionary that will be used to execute the files.

Methods

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.

Returns

The list of exception that occured during files execution.

executedFiles()[source]

Returns the list of executed files.

findFile(localFileName)[source]

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

Parameters

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

Return type

string

Returns

absolute path to the found file, else None.

brainvisa.registration

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.

Parameters
  • 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.

createNewReferential(referential)[source]

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).

referential(diskItemOrId)[source]

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)