def rowToObject(row, obj, attrDict, extraLabels={}): """ This function will convert from a XmippMdRow to an EMObject. Params: row: the XmippMdRow instance (input) obj: the EMObject instance (output) attrDict: dictionary with the map between obj attributes(keys) and row MDLabels in Xmipp (values). extraLabels: a list with extra labels that could be included as properties with the label name such as: _rlnSomeThing """ obj.setEnabled(row.getValue(md.RLN_IMAGE_ENABLED, 1) > 0) for attr, label in attrDict.iteritems(): value = row.getValue(label) if not hasattr(obj, attr): setattr(obj, attr, ObjectWrap(value)) else: getattr(obj, attr).set(value) attrLabels = attrDict.values() for label in extraLabels: if label not in attrLabels and row.hasLabel(label): labelStr = md.label2Str(label) setattr(obj, '_' + labelStr, row.getValueAsObject(label))
def rowToObject(row, obj, attrDict, extraLabels=[]): """ This function will convert from a md Row to an EMObject. Params: row: the Row instance (input) obj: the EMObject instance (output) attrDict: dictionary with the map between obj attributes(keys) and row MDLabels in Bsoft (values). """ # Bsoft does not have analogous label for MDL_ENABLED obj.setEnabled(True) for attr, label in attrDict.items(): # all Bsoft labels are strings, so convert to float value = float(row.getValue(label)) if not hasattr(obj, attr): setattr(obj, attr, ObjectWrap(value)) else: getattr(obj, attr).set(value) attrLabels = attrDict.values() for label in extraLabels: if label not in attrLabels and row.hasLabel(label): labelStr = md.label2Str(label) setattr(obj, '_' + labelStr, row.getValueAsObject(label))
def createExtraLabels(self, item, row, extraLabels): """ Create new Objects for each extra label if contained in the columnObj. It will set the self._extraLabels property. Args: item: Object item that will have new extra labels objects row: column object that should have a method hasColumn extraLabels: list of label names that will be set if present in columnObj """ self._extraLabels = [l for l in extraLabels if row.hasColumn(l)] for label in self._extraLabels: setattr(item, '_' + label, ObjectWrap(getattr(row, label)))
def rowToCtfModel(ctfRow, ctfModel): """ Create a CTFModel from a row of a meta """ if ctfRow.containsAll(CTF_DICT): for attr, label in CTF_DICT.iteritems(): value = ctfRow.getValue(label) if not hasattr(ctfModel, attr): setattr(ctfModel, attr, ObjectWrap(value)) else: getattr(ctfModel, attr).set(value) ctfModel.standardize() else: ctfModel = None return ctfModel
def getValueAsObject(self, label, default=None): """ Same as getValue, but making an Object wrapping. """ return ObjectWrap(self.getValue(label, default))