pyworkflow.object module

This modules holds the base classes for the ORM implementation. The Object class is the root in the hierarchy and some other basic classes.

class pyworkflow.object.Boolean(value=None, **kwargs)[source]

Bases: pyworkflow.object.Scalar

Boolean object

class pyworkflow.object.CsvList(pType=<class 'str'>, **kwargs)[source]

Bases: pyworkflow.object.Scalar, list

This class will store a list of objects in a single DB row separated by comma. pType: the type of the list elements, int, bool, str

clear()[source]

Remove all items from list.

get()[source]

Get the value, if internal value is None the default argument passed is returned.

getObjValue()[source]

Return the internal value for storage. This is a good place to do some update of the internal value before been stored

isEmpty()[source]
class pyworkflow.object.Dict(default=None)[source]

Bases: dict

Simple wrapper around dict class to have a default value.

class pyworkflow.object.Float(value=None, **kwargs)[source]

Bases: pyworkflow.object.Scalar

Float object

EQUAL_PRECISION = 0.001
equalAttributes(other, ignore=[], verbose=False)[source]

Compare that all attributes are equal

classmethod setPrecision(newPrecision)[source]

Set the precision to compare float values. Mainly used for testing purposes.

class pyworkflow.object.Integer(value=None, **kwargs)[source]

Bases: pyworkflow.object.Scalar

Integer object

increment()[source]

Add 1 to the current value.

class pyworkflow.object.List(value=None, **kwargs)[source]

Bases: pyworkflow.object.Object, list

ITEM_PREFIX = '__item__'

Class to store a list of objects

clear()[source]

Remove all items from list.

getAttributes()[source]

Return the list of attributes than are subclasses of Object

getSize()[source]
isEmpty()[source]
class pyworkflow.object.Object(value=None, **kwargs)[source]

Bases: object

All objects in our Domain should inherit from this class that will contains all base properties

cleanObjId()[source]

This function will set to None this object id and the id of all its children attributes. This function should be used when retrieving an object from a mapper and storing in a different one.

clone()[source]
copy(other, copyId=True, ignoreAttrs=[])[source]

Copy all attributes values from one object to the other. The attributes will be created if needed with the corresponding type. Params:

other: the other object from which to make the copy. copyId: if true, the _objId will be also copied. ignoreAttrs: pass a list with attributes names to ignore.
copyAttributes(other, *attrNames)[source]

Copy attributes in attrNames from other to self. If the name X is in attrNames, it would be equivalent to: self.X.set(other.X.get()) This method is more useful for Scalar attributes. There are two patchs for Pointer and PointerList.

copyObjId(other)[source]

Copy the object id form other to self.

equalAttributes(other, ignore=[], verbose=False)[source]

Compare that all attributes are equal

evalCondition(condition)[source]

Check if condition is meet. Params:

condition: the condition string, it can contains variables
or methods without arguments to be evaluated.
Examples:
hasCTF hasCTF and not hasAlignment
Return:
The value of the condition evaluated with values
get()[source]

Return internal value

getAttributeValue(attrName, defaultValue=None)[source]

Get the attribute value given its name. Equivalent to getattr(self, name).get()

getAttributes()[source]

Return the list of attributes than are subclasses of Object

getAttributesToStore()[source]

Return the list of attributes than are subclasses of Object and will be stored

getClass()[source]
getClassName()[source]
classmethod getDoc()[source]
getLastName()[source]

If the name contains parent path, remove it and only return the attribute name in its parent.

getMappedDict()[source]
getName()[source]
getNameId()[source]

Return an unique and readable id that identifies this object.

getNestedValue(key)[source]

Retrieve the value of nested attributes like: _ctfModel.defocusU.

getObjComment()[source]

Return the comment associated with this object

getObjCreation()[source]

Return the stored creation time of the object.

getObjCreationAsDate()[source]

Return the stored creation time of the object as date

getObjDict(includeClass=False, includeBasic=False)[source]

Return all attributes and values in a dictionary. Nested attributes will be separated with a dot in the dict key. Params:

includeClass: if True, the values will be a tuple (ClassName, value)
otherwise only the values of the attributes
includeBasic: if True include the id, label and comment.
object.id: objId object.label: objLabel object.comment: objComment
getObjId()[source]

Return object id

getObjLabel()[source]

Return the label associated with this object

getObjName()[source]
getObjParentId()[source]
getObjValue()[source]

Return the internal value for storage. This is a good place to do some update of the internal value before been stored

getStore()[source]

Return True if the object will be stored by the mapper

getValuesFromDict(objDict)[source]

Retrieve the values of the attributes for each of the keys that comes in the objDict.

getValuesFromMappedDict(mappedDict)[source]
hasAttribute(attrName)[source]
hasAttributeExt(attrName)[source]
hasObjId()[source]
hasObjParentId()[source]
hasValue()[source]
isEnabled()[source]

Return if object is enabled

isPointer()[source]

If this is true, the value field is a pointer to another object

printAll(name=None, level=0)[source]

Print object and all its attributes. Mainly for debugging

printObjDict(includeClasses=False)[source]

Print object dictionary. Mainly for debugging

set(value)[source]

Set the internal value, if it is different from None call the convert function in subclasses

setAttributeValue(attrName, value, ignoreMissing=False)[source]

Set the attribute value given its name. Equivalent to setattr(self, name).set(value) If the attrName contains dot: x.y it will be equivalent to getattr(getattr(self, ‘x’), ‘y’).set(value) If ignoreMissing is True, unexisting attrName will not raise an exception.

setAttributesFromDict(attrDict, setBasic=True, ignoreMissing=False)[source]

Set object attributes from the dict obtained from getObjDict. WARNING: this function is yet experimental and not fully tested.

setEnabled(enabled)[source]
setName(name)[source]
setObjComment(comment)[source]

Set the comment to better identify this object

setObjCreation(creation)[source]

Set the creation time of the object.

setObjId(newId)[source]

Set the object id

setObjLabel(label)[source]

Set the label to better identify this object

setStore(value)[source]

set the store flag

strId()[source]

String representation of id

trace(callback)[source]

Add an observer when the set method is called.

pyworkflow.object.ObjectWrap(value)[source]

This function will act as a simple Factory to create objects from Python basic types

class pyworkflow.object.OrderedObject(value=None, **kwargs)[source]

Bases: pyworkflow.object.Object

This is based on Object, but keep the list of the attributes to store in the same order of insertion, this can be useful where order matters

deleteAttribute(attrName)[source]

Delete an attribute.

getAttributes()[source]

Return the list of attributes than are subclasses of Object and will be stored

class pyworkflow.object.Pointer(value=None, **kwargs)[source]

Bases: pyworkflow.object.Object

Reference object to other one

EXTENDED_ATTR = '__attribute__'
EXTENDED_ITEMID = '__itemid__'
addExtended(attribute)[source]

Similar to setExtended, but concatenating more extensions instead of replacing the previous value.

get(default=None)[source]

Get the pointed object. By default all pointers store a “pointed object” value. The _extended attribute allows to also point to internal attributes or items (in case of sets) of the pointed object.

getAttributes()[source]

Return the list of attributes than are subclasses of Object

getExtended()[source]
getExtendedParts()[source]

Return the extended components as a list.

getUniqueId()[source]

Return an unique id concatenating the id of the direct pointed object plus the extended attribute.

hasExtended()[source]
hasValue()[source]
pointsNone()[source]
removeExtended()[source]

Remove the last part of the extended attribute.

set(other)[source]

Set the pointer value but cleaning the extended property.

setExtended(attribute)[source]

Set the attribute name of the “pointed object” that will be the result of the get() action.

setExtendedParts(parts)[source]

Set the extedend attribute but using a list as input.

class pyworkflow.object.PointerList(value=None, **kwargs)[source]

Bases: pyworkflow.object.List

append(value)[source]

Append Pointer of objects to the list. If value is a Pointer, just add it to the list. If is another subclass of Object, create a Pointer first and append the pointer.

class pyworkflow.object.Scalar(value=None, **kwargs)[source]

Bases: pyworkflow.object.Object

Base class for basic types

equalAttributes(other, ignore=[], verbose=False)[source]

Compare that all attributes are equal

get(default=None)[source]

Get the value, if internal value is None the default argument passed is returned.

getPointer()[source]

Return the internal pointer of this Scalar or None.

hasPointer()[source]

Return True if this Scalar has an internal pointer from where the value will be retrieved with the get() method.

hasValue()[source]
multiply(value)[source]
setPointer(pointer)[source]

Set an internal pointer from this Scalar. Then, the value (retrieved with get) will be obtained from the pointed object.

sum(value)[source]
swap(other)[source]

Swap the contained value between self and other objects.

class pyworkflow.object.Set(filename=None, prefix='', mapperClass=None, classesDict=None, **kwargs)[source]

Bases: pyworkflow.object.OrderedObject

This class will be a container implementation for elements. It will use an extra sqlite file to store the elements. All items will have an unique id that identifies each element in the set.

FILE_TEMPLATE_NAME = 'set%s.sqlite'
ITEM_TYPE = None
STREAM_CLOSED = 2
STREAM_OPEN = 1
aggregate(operations, operationLabel, groupByLabels=None)[source]
append(item)[source]

Add an item to the set. If the item has already an id, use it. If not, keep a counter with the max id and assign the next one.

clear()[source]
close()[source]
classmethod create(path, template=None, suffix='', **kwargs)[source]

Create a set and set the filename using the suffix. If the file exists, it will be delete.

enableAppend()[source]

By default, when a Set is loaded, it is opened in read-only mode, so no new insertions are allowed. This function will allow to append more items to an existing set.

equalItemAttributes(other, ignore=[], verbose=False)[source]

Compare that all items in self and other return True for equalAttributes.

getFileName()[source]
getFiles()[source]
getFirstItem()[source]

Return the first item in the Set.

getIdSet()[source]

Return a Python set object containing all ids.

getPrefix()[source]
getProperty(key, defaultValue=None)[source]
getRepresentative()[source]
getSize()[source]

Return the number of images

getStreamState()[source]
getSubset(n)[source]

Return a subset of n element, making a clone of each.

hasProperty(key)[source]
hasRepresentative()[source]

Return true if have a representative image.

indexes = ['_index']
isEmpty()[source]
isStreamClosed()[source]
isStreamOpen()[source]
iterItems(orderBy='id', direction='ASC', where='1', limit=None)[source]
load()[source]

Load extra data from files.

loadAllProperties()[source]

Retrieve all properties stored by the mapper.

loadProperty(propertyName, defaultValue=None)[source]

Get the value of a property and set its value as an object attribute.

setClassesDict(classesDict)[source]

Set the dictionary with classes where to look for classes names.

setMapperClass(MapperClass)[source]

Set the mapper to be used for storage.

setRepresentative(representative)[source]
setStreamState(newState)[source]
update(item)[source]

Update an existing item.

write(properties=True)[source]

Commit the changes made to the Set underlying database. Params:

properties: this flag controls when to write Set attributes to
special table ‘Properties’ in the database. False value is use for example in SetOfClasses for not writing each Class2D properties.
class pyworkflow.object.String(value=None, **kwargs)[source]

Bases: pyworkflow.object.Scalar

String object.

DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
FS = '.%f'
datetime(formatStr=None, fs=True)[source]

Get the datetime from this object string value.

empty()[source]

Return true if None or len == 0

classmethod getDatetime(strValue, formatStr=None, fs=True)[source]

Get the datetime from the given string value. Params:

strValue: string representation of the date formatStr: if is None, use the default DATETIME_FORMAT. fs: Use femto seconds or not, only when format=None