pwem.emlib.metadata.utils module

class pwem.emlib.metadata.utils.Row[source]

Bases: object

Support Xmipp class to store label and value pairs corresponding to a Metadata row.

addToMd(md)[source]
clone()[source]

Return another Row that have exactly the same values as self.

containsAll(labels)[source]

Check if all labels are present in the row. Params:

row: the Row object. labels: either a dict or list object containing the labels

(in the case of dicts, label are the dict.values())

containsAny(labels)[source]

Check if at least one of labels is present in the row. Params:

row: the Row object. labels: either a dict or list object containing the labels

(in the case of dicts, label are the dict.values())

containsLabel(label)[source]
copyFromRow(other)[source]
getObjId()[source]
getValue(label, default=None)[source]

Return the value of the row for a given label.

getValueAsObject(label, default=None)[source]

Same as getValue, but making an Object wrapping.

hasLabel(label)[source]
printDict()[source]

Fancy printing of the row, mainly for debugging.

readFromFile(fn)[source]
readFromMd(md, objId)[source]

Get all row values from a given id of a metadata.

removeLabel(label)[source]
setValue(label, value)[source]

args: this list should contains tuples with MetaData Label and the desired value

writeToFile(fn)[source]
writeToMd(md, objId)[source]

Set back row values to a metadata row.

class pwem.emlib.metadata.utils.RowMetaData(filename=None)[source]

Bases: object

This class is a wrapper for MetaData in row mode. Where only one object is used.

containsLabel(label)[source]
getValue(label)[source]
read(filename)[source]
setValue(label, value)[source]
write(filename, mode=1)[source]
class pwem.emlib.metadata.utils.SetMdIterator(md, sortByLabel=None, keyLabel=199, updateItemCallback=None, skipDisabled=False)[source]

Bases: object

Class to iterate over an input set and skip elements not present in metadata. This class can be used in copyItems when the number of elements in the set is higher that in metadata.

updateItem(item, row)[source]

This function should be passed to copyItems as callback and it will filter the items not present in the metadata.

pwem.emlib.metadata.utils.dropColumns(mdObj, *labels)[source]

Drop all columns from a given metadata. Labels can be either string or int.

pwem.emlib.metadata.utils.getFirstRow(mdOrFn)[source]

Return the first object of a metadata. Params:

mdOrFn: you can pass a metadata or a filename as argument.

pwem.emlib.metadata.utils.getLabel(value)[source]

Return the label value either from an int value or an string.

pwem.emlib.metadata.utils.getSize(filename)[source]

Return the metadata size without parsing entirely.

pwem.emlib.metadata.utils.isEmpty(filename)[source]

Use getMdSize to check if metadata is empty.

pwem.emlib.metadata.utils.iterRows(md, sortByLabel=None)[source]

Iterate over the rows of the given metadata. Params:

md: a MetaData object or a filename (MetaData will be read) sortByLabel: a label to sort the metadata before iterate.

pwem.emlib.metadata.utils.joinBlocks(inputMd, blockPrefix=None)[source]
pwem.emlib.metadata.utils.keepColumns(mdObj, *labels)[source]

Drop all columns from mdObj that are not in labels. Labels can be either string or int.

pwem.emlib.metadata.utils.label2Python(label)[source]

Return the Python type (int, float, bool) for a given metadata label (LABEL_INT, LABEL_DOUBLE..etc)