Exemplo n.º 1
0
    def set_node_array(self, node, name, array):
        """Store a new numpy array inside a node. Possibly overwrite the array if it already existed.

        Internally, it stores a name.npy file in numpy format.

        :param name: The name of the array.
        :param array: The numpy array to store.
        """
        utils.store_numpy_array_in_repository(node.uuid, name, array)
        self.set_attribute(node, 'array|{}'.format(name), list(array.shape))
Exemplo n.º 2
0
def create_trajectory_symbols_array(apps, _):
    """Create the symbols array for all `TrajectoryData` nodes."""
    import numpy

    DbNode = apps.get_model('db', 'DbNode')
    DbAttribute = apps.get_model('db', 'DbAttribute')

    modifier = ModelModifierV0025(apps, DbAttribute)

    nodes = DbNode.objects.filter(type='node.data.array.trajectory.TrajectoryData.').values_list('id', 'uuid')
    for pk, uuid in nodes:
        symbols = numpy.array(modifier.get_value_for_node(pk, 'symbols'))
        utils.store_numpy_array_in_repository(uuid, 'symbols', symbols)
        modifier.set_value_for_node(DbNode.objects.get(pk=pk), 'array|symbols', list(symbols.shape))
Exemplo n.º 3
0
def downgrade():
    """Migrations for the downgrade."""
    # yapf:disable
    connection = op.get_bind()

    DbNode = table('db_dbnode', column('id', Integer), column('uuid', UUID), column('type', String),
                   column('attributes', JSONB))

    nodes = connection.execute(
        select([DbNode.c.id, DbNode.c.uuid]).where(
            DbNode.c.type == op.inline_literal('node.data.array.trajectory.TrajectoryData.'))).fetchall()

    for pk, uuid in nodes:
        attributes = connection.execute(select([DbNode.c.attributes]).where(DbNode.c.id == pk)).fetchone()
        symbols = numpy.array(attributes['symbols'])
        utils.store_numpy_array_in_repository(uuid, 'symbols', symbols)
        key = op.inline_literal('{"array|symbols"}')
        connection.execute(DbNode.update().where(DbNode.c.id == pk).values(
            attributes=func.jsonb_set(DbNode.c.attributes, key, cast(list(symbols.shape), JSONB))))