samuroi package

The SamuROIWindow class

samuroi.SamuROIWindow

The SamuROIData class

class samuroi.SamuROIData(data, morphology=None)[source]

This is the main data structure of SamuROI. It combines various aspects of rois, overlays and the video data that is to be analysed.

The most important data attributes of this class are (see respective documentation for further info):

Whenever some of there attributes are changed via their property setter functions (e.g. samudata.threshold = 5) those setters will emit a signal via some event object (see samuroi.util.event.Event). E.g. the events for the above attributes are:

If one wants to get notified about any of those changes, one can simply connect to the events:

def my_callback():
    print "I got triggered :-D"
samudata.masks.added.append(my_callback)

In this manner GUI updates and other custom tasks can be completely separated from the data structure.

active_frame

The number of the selected frame of the dataset.

Getter:Set active frame number.
Setter:Change to some other frame. This will trigger the samuroi.SamuROIData.active_frame_changed event.
Type:int in range [0,n_frames(
active_frame_changed

This is a signal which should be triggered whenever the active frame has changed.

branchmasks
Returns:A generator object that allows iteration over all branch masks in the document.
circlemasks
Returns:A generator object that allows iteration over all circle masks in the document.
data

The main video data onto which all masks get applied.

Getter:Get the present video data.
Setter:Change to some other video data. Changing the data will trigger the samuroi.SamuROIData.data_changed event.
Type:3d numpy array dtype should be float or int
data_changed

This is a signal which should be triggered whenever the underlying 3D numpy data has changed.

load_hdf5(filename, mask=True, pixels=True, branches=True, circles=True, polygons=True, data=True, segmentations=True)[source]

Load data that from hd5 file.

Parameters:
  • filename – The filename/path to read from (include extension)
  • mask – flag whether to read the mask if it is stored in file.
  • pixels – flag whether to read the pixel masks if some are stored in file.
  • branches – flag whether to read the branch masks if some are stored in file.
  • circles – flag whether to read the circle masks if some are stored in file.
  • polygons – flag whether to read the polygon masks if some are stored in file.
  • data – flag whether to read the data if it is stored in file.
  • segmentations – flag whether to read the segmentations if it is stored in file.
load_swc(swc)[source]

Load the content from the given swc object.

Branches with only a single coordinate will be loaded as circles. Branches with more than one coordinate as “tubes”.

Parameters:swc – A object of type samuroi.plugins.swc.SWCFile.
masks

A joined set of all masks of type samuroi.maskset.MaskSet. Use masks.remove(some_mask) and masks.add(some_mask) to manipulate the set. Insertions and removements will trigger events that can be connected to.

morphology

An image which describes the static morphology. A good choice is to use the maximum projection over the non normalized data. :getter: obtain the morphology image. :setter: set the morphology image, will trigger the samuroi.SamuROIData.morphology_changed event. :type: 2D numpy array with same image shape as data.

morphology_changed

This signal will be triggered when the morphology image changed.

no_postprocessor
Returns:A default postprocessor which does nothing.
overlay

The overlay is a binary mask with the same shape as the video data such that it can be applied to every frame of the video data. One can automatically set an overlay via samuroi.SamuROIData.threshold, or provide a custom overlay.

Getter:Get the present overlay
Setter:Set the overlay to given binary mask. This will trigger overlay_changed.
Type:numpy.ndarray(dtype=bool,shape=self.data.shape[0:2])
overlay_changed

This is a signal which should be triggered whenever the 2D overlay mask has changed.

pixelmasks
Returns:A generator object that allows iteration over all pixel masks in the document.
polymasks
Returns:A generator object that allows iteration over all polygon masks in the document.
postprocessor

A postprocessor is a function which can be applied on traces. It takes a 1D numpy array as argument and returns a transformed array with the same shape. Defaults to samuroi.SamuROIData.no_postprocessor.

Getter:get the function object.
Setter:set the function object. Will trigger postprocessor_changed event.
Type:callable object (1D numpy array -> 1D numpy array)
postprocessor_changed

This is a signal which should be triggered whenever the postprocessor has changed.

save_hdf5(filename, mask=True, pixels=True, branches=True, circles=True, polygons=True, data=False, traces=True, segmentations=True)[source]

The structure of the hdf5 file will be as follows:

  • overlay (dataset, optional, binary mask defined by threshold value, threshold is stored as attribute)
  • data (dataset, optional, the full 3D dataset from which the traces were generated)
  • branches/circles... (groups holding different kinds of datasets for masks)
  • traces (group that holds a hierarchy for the traces.)
Parameters:
  • filename – filename to use, suffix ”.h5” will be added if missing.
  • mask – flag whether mask should be stored in file.
  • pixels
  • branches
  • circles
  • polygons
  • data – flag whether data should be stored in file.
  • traces
  • segmentations
Returns:

segmentationmasks
Returns:A generator object that allows iteration over all segmentation masks in the document.
threshold

The threshold value controls the overlay mask. Higher threshold values will exclude larger areas. Lower threshold values are less restrictive. The threshold value will be initialized to the 90percentile of the mean data.

Getter:Get the present threshold value
Setter:Set the threshold value. This will trigger a recalculation of samuroi.SamuROIData.overlay which in turn will trigger overlay_changed.
Type:float
threshold_changed

This signal will be triggered when the threshold is changed.

The MaskSet class

class samuroi.maskset.MaskSet(iterable=[])[source]

This class inherits from: collections.MutableSet uses generic mixin functions and therefore only needs to reimplement the following functions:

  • __contains__
  • __iter__
  • __len__
  • add()
  • discard()
add(elem)[source]

Add given mask to the set if it is not already included. Will trigger the samuroi.maskset.MaskSet.added event in case it is added.

Parameters:elem – The mask to add.
added

A signal that will be triggered when an item was added to the set.

clear()

This is slow (creates N new iterators!) but effective.

discard(elem)[source]

Remove the given mask from the set. If the mask is not in the set do nothing. If a mask gets removed this will trigger samuroi.maskset.MaskSet.preremove and samuroi.maskset.MaskSet.removed

Parameters:elem – the mask to be removed.
isdisjoint(other)

Return True if two sets have a null intersection.

pop()

Return the popped value. Raise KeyError if empty.

preremove

A signal that will be triggered when an item is about to be removed from the set.

remove(value)

Remove an element. If not a member, raise a KeyError.

removed

A signal that will be triggered when an item was removed from the set.

types()[source]

Get the set of different types of masks which are in the maskset.

Returns:An iterable object of types.