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: Scalar

Boolean object

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

Bases: 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.

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

Compare that all attributes are equal

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: 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: Scalar

Integer object

increment()[source]

Add 1 to the current value.

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

Bases: 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 that 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 contain 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(copyEnable=False)[source]

Clones the object

Parameters

(False) (copyEnable) – clone also the enable flag

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

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

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

  • copyEnable – Pass true if you want enabled flag to be copied

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

Examples of condition:

"hasCTF"
"hasCTF and not hasAlignment"
Parameters

condition – the condition string, it can contain variables or methods without arguments to be evaluated.

:return The value of the condition evaluated with values

static fillObjDict(prefix, objDict, includeClass, k, v, includePointers=False)[source]
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 that are subclasses of Object

getAttributesToStore()[source]

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

getClass()[source]
classmethod 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, includePointers=False)[source]

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

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

  • includePointers – If true pointer are also added using Pointer.getUniqueId –> “2.outputTomograms”

:return a dictionary

includeBasic example:

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=True)[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, non-existing 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: Object

Legacy class, to be removed. Object should give same functionality and is faster

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

Bases: 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 that are subclasses of Object

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

Return the extended components as a list.

getUniqueId()[source]

Return the 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, cleanExtended=True)[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 extended attribute but using a list as input.

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

Bases: 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: 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: Object

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

ITEM_TYPE = None
STREAM_CLOSED = 2
STREAM_OPEN = 1
aggregate(operations, operationLabel, groupByLabels=None)[source]

This method operate on sets of values. They are used with a GROUP BY clause to group values into subsets

Parameters
  • operations – list of aggregate function such as COUNT, MAX, MIN,…

  • operationLabel – label to use by the aggregate function

  • groupByLabels – list of labels to group

Returns

the aggregated value of each group

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]
copy(other, copyId=True, ignoreAttrs=['_mapperPath', '_size', '_streamState'])[source]

Copies the attributes of the set

Parameters
  • other – Set to copy attributes from

  • copyId – True. Copies the objId.

  • ignoreAttrs – Attributes list to ignore while copying. _mapperPath, _size and _streamState

are ignored by default.

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.

fmtDate(date)[source]

Formats a python date to a valid string for the mapper

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

Return the first item in the Set.

getIdSet()[source]

Return a Python set object containing all ids.

getItem(field, value)[source]

Alternative to [] to get a single item form the set.

Parameters
  • field – attribute of the item to look up for. Should be a unique identifier

  • value – value to look for

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.

getUniqueValues(attributes, where=None)[source]

Returns a list (for a single label) or a dictionary with unique values for the passed labels. If more than one label is passed it will be unique rows similar ti SQL unique clause.

:param attributes (string or list) item attribute/s to retrieve unique row values :param where (string) condition to filter the results

hasChangedSince(time)[source]
Returns if the set has changed since the timestamp passed as parameter. It will check

the last modified time of the file this set uses to persists.

Parameters

time – timestamp to compare to the last modification time

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

Return true if have a representative image.

indexes = ['_index']
isEmpty()[source]
static isItemEnabled(item)[source]

Returns if the item is enabled…to be used as a callback. In some other cases (new user subsets) this method will be replaced

isStreamClosed()[source]
isStreamOpen()[source]
iterItems(orderBy='id', direction='ASC', where=None, limit=None, iterate=True)[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.

Parameters

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: 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]

Converts the given string value to a datetime object.

Parameters
  • strValue – string representation of the date

  • formatStr – if None, uses the default cls:String.DATETIME_FORMAT.

  • fs – Use femto seconds or not, only when format=None

getListFromRange()[source]

Returns a list from a string with values as described at getListFromRangeString. Useful for NumericRangeParam params

getListFromValues(length=None, caster=<class 'int'>)[source]

Returns a list from a string with values as described at getListFromValues. Useful for