<commit_before>#!/usr/bin/env python
"""A simple example showing an animation.  The example illustrates a
few things.

 1. You can pass a numpy array of scalars and use it directly with
    tvtk.

 2. The tvtk arrays are views of numpy arrays.  Thus changing the
    array in-place will also change the underlying VTK data.

 3. When changing the numpy data you must call `modified` on a
    relevant tvtk object.

The example is a little contrived since there are better ways of
achieving the same effect but the present form nicely illustrates item
2 mentioned above.

"""
# Author: <NAME> <<EMAIL>>
# Copyright (c) 2004-2007, Enthought, Inc.
# License: BSD Style.

from tvtk.api import tvtk
from tvtk.common import configure_input_data
import numpy
import time

# First create a structured points data set.
sp = tvtk.StructuredPoints(origin=(-10., -10., 0.0),
                           dimensions=(80, 80, 1),
                           spacing=(0.25, 0.25, 0.0))

# Create some nice data at these points.
x = numpy.arange(-10., 10., 0.25)
y = x
r = numpy.sqrt(x[:,None]**2+y**2)
# We need the transpose so the data is as per VTK's expected format
# where X coords vary fastest, Y next and then Z.
try:
    import scipy.special
    z = numpy.reshape(numpy.transpose(5.0*scipy.special.j0(r)), (-1,) )
except ImportError:
    z = numpy.reshape(numpy.transpose(5.0*numpy.sin(r)/r), (-1,) )

# Now set the scalar data for the StructuredPoints object.  The
# scalars of the structured points object will be a view into our
# Numeric array.  Thus, if we change `z` in-place, the changes will
# automatically affect the VTK arrays.
sp.point_data.scalars = z

# Convert this to a PolyData object.
geom_filter = tvtk.ImageDataGeometryFilter()
configure_input_data(geom_filter, sp)

# Now warp this using the scalar value to generate a carpet plot.
warp = tvtk.WarpScalar()
configure_input_data(warp, geom_filter.output)

# Smooth the resulting data so it looks good.
normals = tvtk.PolyDataNormals()
configure_input_data(normals, warp.output)

# The rest of the VTK pipeline.
m = tvtk.PolyDataMapper(scalar_range=(min(z), max(z)))
configure_input_data(m, normals.output)

a = tvtk.Actor(mapper=m)<commit_msg>Fix tvtk example array_animation.py.<commit_after>#!/usr/bin/env python
"""A simple example showing an animation.  The example illustrates a
few things.

 1. You can pass a numpy array of scalars and use it directly with
    tvtk.

 2. The tvtk arrays are views of numpy arrays.  Thus changing the
    array in-place will also change the underlying VTK data.

 3. When changing the numpy data you must call `modified` on a
    relevant tvtk object.

The example is a little contrived since there are better ways of
achieving the same effect but the present form nicely illustrates item
2 mentioned above.

"""
# Author: <NAME> <<EMAIL>>
# Copyright (c) 2004-2007, Enthought, Inc.
# License: BSD Style.

from tvtk.api import tvtk
from tvtk.common import configure_input
import numpy
import time

# First create a structured points data set.
sp = tvtk.StructuredPoints(origin=(-10., -10., 0.0),
                           dimensions=(80, 80, 1),
                           spacing=(0.25, 0.25, 0.0))

# Create some nice data at these points.
x = numpy.arange(-10., 10., 0.25)
y = x
r = numpy.sqrt(x[:,None]**2+y**2)
# We need the transpose so the data is as per VTK's expected format
# where X coords vary fastest, Y next and then Z.
try:
    import scipy.special
    z = numpy.reshape(numpy.transpose(5.0*scipy.special.j0(r)), (-1,) )
except ImportError:
    z = numpy.reshape(numpy.transpose(5.0*numpy.sin(r)/r), (-1,) )

# Now set the scalar data for the StructuredPoints object.  The
# scalars of the structured points object will be a view into our
# Numeric array.  Thus, if we change `z` in-place, the changes will
# automatically affect the VTK arrays.
sp.point_data.scalars = z

# Convert this to a PolyData object.
geom_filter = tvtk.ImageDataGeometryFilter()
configure_input(geom_filter, sp)

# Now warp this using the scalar value to generate a carpet plot.
warp = tvtk.WarpScalar()
configure_input(warp, geom_filter)

# Smooth the resulting data so it looks good.
normals = tvtk.PolyDataNormals()
configure_input(normals, warp)

# The rest of the VTK pipeline.
m = tvtk.PolyDataMapper(scalar_range=(min(z), max(z)))
configure_input(m, normals)

a = tvtk.Actor(mapper=m)
{'fraction_non_alphanumeric': 0.09787816563997262, 'fraction_numerical': 0.021446497832534793, 'mean_word_length': 3.678762006403415, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4604005', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1375, 'n_words': 544}