Package bar :: Module base
[hide private]
[frames] | no frames]

Module base

The module provides classes necessary to handle basic CAF slide manipulations.

Import Graph
Import Graph


Note: BAR_TRACER_DEFAULT_SETTINGS requires providing following elements:

  1. DumpEachStepSVG, DumpEachStepPNG: (bool) determines if every step of tracing process will be saved as PNG or SVG file (tracing results)
  2. DumpWrongSeed: (bool) determines if snapshot with incorectly placed labels will be saved as PNG files
  3. DumpVBrain: (bool) determines,if consecutive steps of generating whole brain outline will be stored
  4. DumpDirectory: (str) defines directory where all snapshots are stored
  5. DetectUnlabelled: (bool) defines if unlabelled areas are detected
  6. CacheLevel: (int) MaxGrowLevel
  7. MinFiterTimesApplication: (int) defines intensity of Min filter used for generating consecutive images in cache
  8. GrowDefaultBoundaryColor: (int) boundary color
  9. RegionAlreadyTraced: (int) colour of areas denoted as traced
  10. PoTraceConf: (str : ...) traced properties, see CONF_DEFAULT_POTRACE_PROPERTIES for details
  11. NewPathIdTemplate: (str) template of path id (eg. 'structure%d_%s_%s')
  12. BestFillAlgorithm: (function) reference for function for defining best gap filling level. This setting may be used to provide custom 'selectBestGapFillingLevel' function

Classes [hide private]
  barObject
Parental class for BAR elements.
  barAtlasSlideElement
General class describing all elements that are part of slide.
  barStructureLabel
Parental class for all classes representing slide labels.
  barRegularLabel
Regular label is used to indicate area corresponding to ordinary brain structure.
  barSpotLabel
Spot label is used to indicate point (spot).
  barCommentLabel
Comment labels are not related to brain structures.
  barMetadataElement
Basic class representing metadata objects.
  barBregmaMetadataElement
Class of objects representing bregma metadata elements.
  barTransfMatrixMetadataElement
Class of objects representing stereotectical coordinates transformation matrix.
  barMarker
Class of objects representing markers.
  barCoordinateMarker
Class of objects representing marker of slide position in coronal plane.
  barCoronalMarker
Class of objects representing marker of anterior-posterior slide position.
  barPath
Class of objects describing enclosed path denoting particular area in the slice.
  barGenericStructure
Class of containers of paths related to one structure.
  barBoundingBox
Bounding box is a clever class that stores bounding box and implements simple operations that may be performed on bounding boxes such as extracting bounding box from SVG path definition, merging, printing etc.
  barVectorSlide
An abstract class representing all types of vector slides - slides that are based on SVG drawings.
  barSlideRenderer
Class holding all operation related to rasterizing SVG slides.
  barPretracedSlide
Class of objects representing countur slides.
  barTracedSlide
Class of objects representing CAF slides.
  barTracedSlideRenderer
barTracedSlide class extension with method necessary to render CAF slide.
  barPretracedSlideRenderer
Class which converts contour slides into CAF slides.
  barCafSlide
barTracedSlide class extension with method necessary to render CAF slide.
  barContourSlide
Class which converts contour slides into CAF slides.
Functions [hide private]
{str : str, ...}
getDictionaryFromFile(fileName, keyColumn=0, valueColumn=1)
Returns: dictionary read from file
 
_printRed(str)
Print given string to stderr using red color.
 
debugOutput(msg, error=False)
Print debug message to stderr.
(_clsTransfMatrixMetadataElement, _clsBregmaMetadataElement)
processMarkers(m1, m2, bm)
Calculate stereotectical coordinates transformation matrix and anterior-posterior coordinate of slide from given markers.
str or bool
validateStructureName(structureName)
Returns: structureName if structure name if correct, Flase otherwise.
xml.dom.minidom.Document
cleanPotraceOutput(tracerOutput)
Create SVG document (with fixed paths) from provided PoTrace output.
str
CleanFilename(filename)
Strip filename from prohibited characters.
[?, ...]
flatten(x)
Create a flat sequence containing all elements retrieved from the sequence recursively contained sub-sequences (iterables).
 
_removeWhitespacesXML(domNode, unlink=True)
Remove unnecessary white spaces from given XML element.
 
_recurseTextNodeExtract(tspanElement)
    Default widht and height of the slide renderer class
 
getSlideTemplate(valuesDict)
Variables [hide private]
  BAR_XML_NAMESPACE = 'http://www.3dbar.org'
  BAR_XML_NAMESPACE_PREFIX = 'bar:'
  BAR_DEFAULT_GROWLEVEL = 0
  BAR_COORDINATE_MARKER_TEMPLATE = '(%f,%f)'
  BAR_CORONAL_MARKER_TEMPLATE = 'Bregma:%f'
  BAR_REGULAR_LABEL_PREFIX = ''
  BAR_COMMENT_LABEL_PREFIX = ','
  BAR_SPOT_LABEL_PREFIX = '.'
  BAR_LABEL_MAX_LENGTH = 200
  BAR_REGULAR_LABEL_COLOUR = '#232323'
  BAR_COMMENT_LABEL_COLOUR = '#FF0000'
  BAR_SPOT_LABEL_COLOUR = '#FF0000'
  BAR_BREGMA_METADATA_TAGNAME = 'coronalcoord'
  BAR_TRAMAT_METADATA_TAGNAME = 'transformationmatrix'
  BAR_DATA_LOCATION_ELEMENT = 'defs'
  BAR_XML_ENCODING = 'utf-8'
  CONF_DEFAULT_CONTOUR_WIDTH = '0.2'
  CONF_DEFAULT_CONTOUR_COLOUR = '#ff3300'
  CONF_DEFAULT_VBRAIN_LABEL_LOC = (10, 10)
  CONF_DEFAULT_PATH_ATTRIBUTES = {'d': None, 'fill': None, 'id':...
  CONF_DEFAULT_PATH_ATTRIBUTES_NS = {'growlevel': 0, 'type': None}
  DEFAULT_TEXT_ELEMENTS_ATTRIBUTES = {'fill': '#000000', 'font-f...
  CONF_DEFAULT_TEXT_ATTRIBUTES_NS = {'growlevel': 0}
  DEFAULT_MARKER_ATTRIBUTES = {'fill': '#000000', 'font-family':...
  CONF_ALOWED_STRUCTURE_CHARACTERS = re.compile(r'(?i)^[a-z0-9A-...
  __package__ = 'bar'
    Default widht and height of the slide renderer class
  CONF_DEFAULT_RENDER_WIDTH = 1200
  CONF_DEFAULT_RENDER_HEIGHT = 900
  CONF_SLIDE_TEMPLATE = '\n<svg baseProfile="full" id="body"\nhe...
  CONF_DEFAULT_SLIDE_TEMPLATE = '\n<svg baseProfile="full" id="b...
{str : ... } CONF_DEFAULT_RENDERING_PROPS = {'ReferenceHeight': 900, 'Refer...
default settings for rasterizing SVG slides used by barSlideRenderer; CONF_DEFAULT_RENDERING_PROPS['ReferenceWidth'] and CONF_DEFAULT_RENDERING_PROPS['ReferenceHeight'] are dimensions of the slide in 1:1 scale (in pixels) while CONF_DEFAULT_RENDERING_PROPS['imageSize'] is a tuple (w, h) holding size of the rasterized slide.
    Potrace tracing directives
str CONF_POTRACE_ACCURACY_PARAMETER = '0.001'
accurary of potrace tracing; consult potrace manual for details
str CONF_POTRACE_HEIGHT_STRING = '900pt'
reference image height for potrace
str CONF_POTRACE_WIDTH_STRING = '1200pt'
reference image width for potrace
str CONF_POTRACE_SVG_RESOLUTION_STRING = '300x300'
reference resolution for potrace (eg.
  CONF_DEFAULT_POTRACE_PROPERTIES = {'potrace_accuracy_parameter...
    Tracing properties
{str : ... } BAR_TRACER_DEFAULT_SETTINGS = {'CacheLevel': 5, 'DetectUnlabel...
all settings used by barPretracedSlideRenderer to perform conversion from contour slide to CAF slide; requires providing following elements:
    GrowLevel settings
  CONF_GAPFILLING_MAXLEVEL = 5
Function Details [hide private]

getDictionaryFromFile(fileName, keyColumn=0, valueColumn=1)

 
Parameters:
  • fileName (str) - location of the file
  • keyColumn (int) - column containing keys
  • valueColumn (int) - column containing values
Returns: {str : str, ...}
dictionary read from file

_printRed(str)

 

Print given string to stderr using red color.

Parameters:
  • str (str) - string to be printed

debugOutput(msg, error=False)

 

Print debug message to stderr. Error messages are printed in red colour.

If the message is not an error message it is printed only if __debug__ == True.

Parameters:
  • msg (str) - debug message
  • error (bool) - indicates if the debug message is an error message

processMarkers(m1, m2, bm)

 

Calculate stereotectical coordinates transformation matrix and anterior-posterior coordinate of slide from given markers.

Parameters:
Returns: (_clsTransfMatrixMetadataElement, _clsBregmaMetadataElement)
representation of metadata elements containing stereotectical coordinates transformation matrix and anterior-posterior coordinate of slide.

validateStructureName(structureName)

 
Parameters:
  • structureName (str) - name to be verified
Returns: str or bool
structureName if structure name if correct, Flase otherwise.

Note: Name is validated only when debug mode is not disabled. It means that reconstruction modules can have disabled __debug__ mode while parsers should always run WITHOUT python -OO switch.

cleanPotraceOutput(tracerOutput)

 

Create SVG document (with fixed paths) from provided PoTrace output.

Parameters:
  • tracerOutput (str) - string produced by PoTrace
Returns: xml.dom.minidom.Document
SVG image fixed by the procedure.

CleanFilename(filename)

 

Strip filename from prohibited characters. Prohibited characters are replaced by underscore characted.

Parameters:
  • filename (str) - filename to strip
Returns: str
corrected filename

flatten(x)

 

Create a flat sequence containing all elements retrieved from the sequence recursively contained sub-sequences (iterables).

Examples: >>> [1, 2, [3,4], (5,6)] [1, 2, [3, 4], (5, 6)] >>> flatten([[[1,2,3], (42,None)], [4,5], [6], 7, MyVector(8,9,10)]) [1, 2, 3, 42, None, 4, 5, 6, 7, 8, 9, 10]

Parameters:
  • x (sequence) - sequence to be flatted
Returns: [?, ...]
created sequence

_removeWhitespacesXML(domNode, unlink=True)

 

Remove unnecessary white spaces from given XML element.

Parameters:
  • domNode (xml.dom.minidom.Node) - XML element
  • unlink - indicates if memory allocated for unnecessary DOM nodes has to be released immediately (has to be True when no cyclic garbage colector is availiable)
  • nlink (bool)

Variables Details [hide private]

CONF_DEFAULT_PATH_ATTRIBUTES

Value:
{'d': None, 'fill': None, 'id': None, 'stroke': 'none'}

DEFAULT_TEXT_ELEMENTS_ATTRIBUTES

Value:
{'fill': '#000000',
 'font-family': 'Helvetica,sans-serif',
 'font-size': '18px',
 'id': None,
 'stroke': 'none',
 'x': None,
 'y': None}

DEFAULT_MARKER_ATTRIBUTES

Value:
{'fill': '#000000',
 'font-family': 'Helvetica,sans-serif',
 'font-size': '18px',
 'id': None,
 'stroke': 'none',
 'x': None,
 'y': None}

CONF_ALOWED_STRUCTURE_CHARACTERS

Value:
re.compile(r'(?i)^[a-z0-9A-Z-]*$')

CONF_SLIDE_TEMPLATE

Value:
'''
<svg baseProfile="full" id="body"
height="%(width)s"
width="%(height)s"
viewBox="0 0 %(height)s %(width)s"
preserveAspectRatio="none"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
...

CONF_DEFAULT_SLIDE_TEMPLATE

Value:
'''
<svg baseProfile="full" id="body"
height="900"
width="1200"
viewBox="0 0 1200 900"
preserveAspectRatio="none"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
...

CONF_DEFAULT_RENDERING_PROPS

default settings for rasterizing SVG slides used by barSlideRenderer; CONF_DEFAULT_RENDERING_PROPS['ReferenceWidth'] and CONF_DEFAULT_RENDERING_PROPS['ReferenceHeight'] are dimensions of the slide in 1:1 scale (in pixels) while CONF_DEFAULT_RENDERING_PROPS['imageSize'] is a tuple (w, h) holding size of the rasterized slide. Usually CONF_DEFAULT_RENDERING_PROPS['imageSize'] is few times larger than CONF_DEFAULT_RENDERING_PROPS['ReferenceHeight'] and CONF_DEFAULT_RENDERING_PROPS['ReferenceWidth'] allowing to more precise tracing and automatic label generation
Type:
{str : ... }
Value:
{'ReferenceHeight': 900,
 'ReferenceWidth': 1200,
 'imageSize': (1200, 900)}

CONF_POTRACE_SVG_RESOLUTION_STRING

reference resolution for potrace (eg. '300x300'); provides resolution in dpi; final image will be scaled using this reference resolution so setting it porperly is very important; consult potrace manual for details
Type:
str
Value:
'300x300'

CONF_DEFAULT_POTRACE_PROPERTIES

Value:
{'potrace_accuracy_parameter': '0.001',
 'potrace_height_string': '900pt',
 'potrace_svg_resolution_string': '300x300',
 'potrace_width_string': '1200pt'}

BAR_TRACER_DEFAULT_SETTINGS

all settings used by barPretracedSlideRenderer to perform conversion from contour slide to CAF slide; requires providing following elements:
Type:
{str : ... }
Value:
{'CacheLevel': 5,
 'DetectUnlabelled': True,
 'DumpDirectory': '.',
 'DumpEachStepPNG': False,
 'DumpEachStepSVG': False,
 'DumpVBrain': False,
 'DumpWrongSeed': True,
 'GrowDefaultBoundaryColor': 200,
...