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.CsvList(pType=<class 'str'>, **kwargs)[source]
-
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
- 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
- class pyworkflow.object.List(value=None, **kwargs)[source]
-
- ITEM_PREFIX = '__item__'
Class to store a list of objects
- 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.
- 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
- getAttributeValue(attrName, defaultValue=None)[source]
Get the attribute value given its name. Equivalent to getattr(self, name).get()
- getAttributesToStore()[source]
Return the list of attributes than are subclasses of Object and will be stored
- getLastName()[source]
If the name contains parent path, remove it and only return the attribute name in its parent.
- 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
- getObjValue()[source]
Return the internal value for storage. This is a good place to do some update of the internal value before been stored
- getValuesFromDict(objDict)[source]
Retrieve the values of the attributes for each of the keys that comes in the objDict.
- 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.
- 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.
- getUniqueId()[source]
Return the unique id concatenating the id of the direct pointed object plus the extended attribute.
- class pyworkflow.object.Scalar(value=None, **kwargs)[source]
Bases:
Object
Base class for basic types
- get(default=None)[source]
Get the value, if internal value is None the default argument passed is returned.
- hasPointer()[source]
Return True if this Scalar has an internal pointer from where the value will be retrieved with the get() method.
- 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 by
- 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.
- 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.
- 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
- 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
- indexes = ['_index']
- 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
- loadProperty(propertyName, defaultValue=None)[source]
Get the value of a property and set its value as an object attribute.
- class pyworkflow.object.String(value=None, **kwargs)[source]
Bases:
Scalar
String object.
- DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
- FS = '.%f'
- 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