示例#1
0
    def test_Table(self):
        table = ds.Table(ds.Column('x', int, 5), ds.Column('y', float, 0.0),
                         ds.Column('name', str))

        # Add a row to the table
        table.addRow(1, x=12, y=11.0, name='jose')
        table.addRow(2, x=22, y=21.0, name='juan')
        table.addRow(3, x=32, y=31.0, name='pedro')
        # Expect an exception, since name is not provided and have not default
        self.assertRaises(Exception, table.addRow, 100, y=3.0)

        row = table.getRow(1)
        print row

        self.assertEqual(table.getSize(), 3, "Bad table size")

        # Update a value of a row
        table.updateRow(1, name='pepe')
        row = table.getRow(1)
        print row
        self.assertEqual(row.name, 'pepe', "Error updating name in row")
示例#2
0
    def _convertMdToTable(self, md):
        """ Convert a metatada into a table. """

        labels = md.getActiveLabels()
        hasTransformation = self._hasTransformation(labels)
        columns = [self._convertLabelToColumn(l, md) for l in labels]
        #NAPA de LUXE (xmipp deberia saber a que campo va asignado el transformation matrix)
        if hasTransformation:
            columns.append(ds.Column("image_transformationMatrix", str))

        labelsStr = [col.getName() for col in columns]

        table = ds.Table(*columns)

        for objId in md:
            values = [md.getValue(l, objId) for l in labels]
            if hasTransformation:
                values.append(self._getTransformation(md, objId))
            d = dict(zip(labelsStr, values))
            table.addRow(objId, **d)

        return table