<commit_before>import inspect
import sys
import os
import time

import vtki
import numpy as np

# get location of this folder and the example files
dir_path = os.path.dirname(os.path.realpath(__file__))
antfile = os.path.join(dir_path, 'ant.ply')
planefile = os.path.join(dir_path, 'airplane.ply')
hexbeamfile = os.path.join(dir_path, 'hexbeam.vtk')
spherefile = os.path.join(dir_path, 'sphere.ply')
uniformfile = os.path.join(dir_path, 'uniform.vtk')
rectfile = os.path.join(dir_path, 'rectilinear.vtk')


# get location of this folder
dir_path = os.path.dirname(os.path.realpath(__file__))


def load_ant():
    """ Load ply ant mesh """
    return vtki.PolyData(antfile)


def load_airplane():
    """ Load ply airplane mesh """
    return vtki.PolyData(planefile)


def load_sphere():
    """ Loads sphere ply mesh """
    return vtki.PolyData(spherefile)


def load_uniform():
    """ Loads a sample uniform grid """
    return vtki.UniformGrid(uniformfile)


def load_rectilinear():
    """ Loads a sample uniform grid """
    return vtki.RectilinearGrid(rectfile)

def load_hexbean():
    """ Loads a sample UnstructuredGrid """
    return vtki.UnstructuredGrid(hexbeamfile)


def plot_ants_plane(off_screen=False):
    """
    Demonstrate how to create a plot class to plot multiple meshes while
    adding scalars and text.

    Plot two ants and airplane
    """

    # load and shrink airplane
    airplane = vtki.PolyData(planefile)
    airplane.points /= 10
    # pts = airplane.points # gets pointer to array
    # pts /= 10  # shrink

    # rotate and translate ant so it is on the plane
    ant = vtki.PolyData(antfile)
    ant.rotate_x(90)
    ant.translate([90, 60, 15])

    # Make a copy and add another ant
    ant_copy = ant.copy()
    ant_copy.translate([30, 0, -10])

    # Create plotting object
    plotter = vtki.Plotter(off_screen=off_screen)
    plotter.add_mesh(ant, 'r')
    plotter.add_mesh(ant_copy, 'b')

    # Add airplane mesh and make the color equal to the Y position
    plane_scalars = airplane.points[:, 1]
    plotter.add_mesh(airplane, scalars=plane_scalars, stitle='Plane Y\nLocation')
    plotter.add_text('Ants and Plane Example')
    plotter.plot()


def beam_example(off_screen=False):
    # Load module and example file
    hexfile = hexbeamfile

    # Load Grid
    grid = vtki.UnstructuredGrid(hexfile)

    # Create fiticious displacements as a function of Z location
    d = grid.points[:, 2]**3/250
    grid.points[:, 1] += d

    # Camera position
    cpos = [(11.915126303095157, 6.11392754955802, 3.6124956735471914),
            (0.0, 0.375, 2.0),
            (-0.42546442225230097, 0.9024244135964158, -0.06789847673314177)]

    try:
        import matplotlib
        colormap = 'bwr'
    except ImportError:
        colormap = None

    # plot this displaced beam
    plotter = vtki.Plotter(off_screen=off_screen)
    plotter.add_mesh(grid, scalars=d, stitle='Y Displacement',
                     rng=[-d.max(), d.max()], colormap=colormap)
    plotter.camera_position = cpos
    plotter.add_text('Static Beam Example')
    cpos = plotter.plot(autoclose=False)  # store camera position
    # plotter.TakeScreenShot('beam.png')
    plotter.close()


def plot_wave(fps=30, frequency=1, wavetime=3, interactive=False,
              off_screen=False):
    """
    Plot a 3D moving wave in a render window.

    Parameters
    ----------
    fps : int, optional
        Maximum frames per second to display.  Defaults to 30.

    frequency: float, optional
        Wave cycles per second.  Defaults to 1

    wavetime : float, optional
        The desired total display time in seconds.  Defaults to 3 seconds.

    interactive: bool, optional
        Allows the user to set the camera position before the start of the
        wave movement.  Default False.

    off_screen : bool, optional
        Enables off screen rendering when True.  Used for automated testing.
        Disabled by default.

    Returns
    -------
    points : np.ndarray
        Position of points at last frame.

    """
    # camera position
    cpos = [(6.879481857604187, -32.143727535933195, 23.05622921691103),
            (-0.2336056403734026, -0.6960083534590372, -0.7226721553894022),
            (-0.008900669873416645, 0.6018246347860926, 0.7985786667826725)]

    # Make data
    X = np.arange(-10, 10, 0.25)
    Y = np.arange(-10, 10, 0.25)
    X, Y = np.meshgrid(X, Y)
    R = np.sqrt(X**2 + Y**2)
    Z = np.sin(R)

    # Create and plot structured grid
    sgrid = vtki.StructuredGrid(X, Y, Z)

    # Get pointer to points
    points = sgrid.points.copy()

    # Start a plotter object and set the scalars to the Z height
    plotter = vtki.Plotter(off_screen=off_screen)
    plotter.add_mesh(sgrid, scalars=Z.ravel())
    plotter.camera_position = cpos
    plotter.plot(title='Wave Example', window_size=[800, 600],
                 # autoclose=False, interactive=interactive)
                 autoclose=False, interactive_update=True)

    # Update Z and display a frame for each updated position
    tdelay = 1. / fps
    tlast = time.time()
    tstart = time.time()
    while time.time() - tstart < wavetime:
        # get phase from start
        telap = time.time() - tstart
        phase = telap * 2 * np.pi * frequency
        Z = np.sin(R + phase)
        points[:, -1] = Z.ravel()

        # update plotting object, but don't automatically render
        plotter.update_coordinates(points, render=False)
        plotter.update_scalars(Z.ravel(), render=False)

        # Render and get time to render
        rstart = time.time()
        plotter.update()
        # plotter.render()
        rstop = time.time()

        # time delay
        tpast = time.time() - tlast
        if tpast < tdelay and tpast >= 0:
            time.sleep(tdelay - tpast)

        # get render time and actual FPS
        rtime = rstop - rstart
        act_fps = 1 / (time.time() - tlast + 1E-10)
        tlast = time.time()

    # Close movie and delete object
    plotter.close()

    return points
<commit_msg>load_hexbean -> load_hexbeam<commit_after>import inspect
import sys
import os
import time

import vtki
import numpy as np

# get location of this folder and the example files
dir_path = os.path.dirname(os.path.realpath(__file__))
antfile = os.path.join(dir_path, 'ant.ply')
planefile = os.path.join(dir_path, 'airplane.ply')
hexbeamfile = os.path.join(dir_path, 'hexbeam.vtk')
spherefile = os.path.join(dir_path, 'sphere.ply')
uniformfile = os.path.join(dir_path, 'uniform.vtk')
rectfile = os.path.join(dir_path, 'rectilinear.vtk')


# get location of this folder
dir_path = os.path.dirname(os.path.realpath(__file__))


def load_ant():
    """ Load ply ant mesh """
    return vtki.PolyData(antfile)


def load_airplane():
    """ Load ply airplane mesh """
    return vtki.PolyData(planefile)


def load_sphere():
    """ Loads sphere ply mesh """
    return vtki.PolyData(spherefile)


def load_uniform():
    """ Loads a sample uniform grid """
    return vtki.UniformGrid(uniformfile)


def load_rectilinear():
    """ Loads a sample uniform grid """
    return vtki.RectilinearGrid(rectfile)

def load_hexbeam():
    """ Loads a sample UnstructuredGrid """
    return vtki.UnstructuredGrid(hexbeamfile)


def plot_ants_plane(off_screen=False):
    """
    Demonstrate how to create a plot class to plot multiple meshes while
    adding scalars and text.

    Plot two ants and airplane
    """

    # load and shrink airplane
    airplane = vtki.PolyData(planefile)
    airplane.points /= 10
    # pts = airplane.points # gets pointer to array
    # pts /= 10  # shrink

    # rotate and translate ant so it is on the plane
    ant = vtki.PolyData(antfile)
    ant.rotate_x(90)
    ant.translate([90, 60, 15])

    # Make a copy and add another ant
    ant_copy = ant.copy()
    ant_copy.translate([30, 0, -10])

    # Create plotting object
    plotter = vtki.Plotter(off_screen=off_screen)
    plotter.add_mesh(ant, 'r')
    plotter.add_mesh(ant_copy, 'b')

    # Add airplane mesh and make the color equal to the Y position
    plane_scalars = airplane.points[:, 1]
    plotter.add_mesh(airplane, scalars=plane_scalars, stitle='Plane Y\nLocation')
    plotter.add_text('Ants and Plane Example')
    plotter.plot()


def beam_example(off_screen=False):
    # Load module and example file
    hexfile = hexbeamfile

    # Load Grid
    grid = vtki.UnstructuredGrid(hexfile)

    # Create fiticious displacements as a function of Z location
    d = grid.points[:, 2]**3/250
    grid.points[:, 1] += d

    # Camera position
    cpos = [(11.915126303095157, 6.11392754955802, 3.6124956735471914),
            (0.0, 0.375, 2.0),
            (-0.42546442225230097, 0.9024244135964158, -0.06789847673314177)]

    try:
        import matplotlib
        colormap = 'bwr'
    except ImportError:
        colormap = None

    # plot this displaced beam
    plotter = vtki.Plotter(off_screen=off_screen)
    plotter.add_mesh(grid, scalars=d, stitle='Y Displacement',
                     rng=[-d.max(), d.max()], colormap=colormap)
    plotter.camera_position = cpos
    plotter.add_text('Static Beam Example')
    cpos = plotter.plot(autoclose=False)  # store camera position
    # plotter.TakeScreenShot('beam.png')
    plotter.close()


def plot_wave(fps=30, frequency=1, wavetime=3, interactive=False,
              off_screen=False):
    """
    Plot a 3D moving wave in a render window.

    Parameters
    ----------
    fps : int, optional
        Maximum frames per second to display.  Defaults to 30.

    frequency: float, optional
        Wave cycles per second.  Defaults to 1

    wavetime : float, optional
        The desired total display time in seconds.  Defaults to 3 seconds.

    interactive: bool, optional
        Allows the user to set the camera position before the start of the
        wave movement.  Default False.

    off_screen : bool, optional
        Enables off screen rendering when True.  Used for automated testing.
        Disabled by default.

    Returns
    -------
    points : np.ndarray
        Position of points at last frame.

    """
    # camera position
    cpos = [(6.879481857604187, -32.143727535933195, 23.05622921691103),
            (-0.2336056403734026, -0.6960083534590372, -0.7226721553894022),
            (-0.008900669873416645, 0.6018246347860926, 0.7985786667826725)]

    # Make data
    X = np.arange(-10, 10, 0.25)
    Y = np.arange(-10, 10, 0.25)
    X, Y = np.meshgrid(X, Y)
    R = np.sqrt(X**2 + Y**2)
    Z = np.sin(R)

    # Create and plot structured grid
    sgrid = vtki.StructuredGrid(X, Y, Z)

    # Get pointer to points
    points = sgrid.points.copy()

    # Start a plotter object and set the scalars to the Z height
    plotter = vtki.Plotter(off_screen=off_screen)
    plotter.add_mesh(sgrid, scalars=Z.ravel())
    plotter.camera_position = cpos
    plotter.plot(title='Wave Example', window_size=[800, 600],
                 # autoclose=False, interactive=interactive)
                 autoclose=False, interactive_update=True)

    # Update Z and display a frame for each updated position
    tdelay = 1. / fps
    tlast = time.time()
    tstart = time.time()
    while time.time() - tstart < wavetime:
        # get phase from start
        telap = time.time() - tstart
        phase = telap * 2 * np.pi * frequency
        Z = np.sin(R + phase)
        points[:, -1] = Z.ravel()

        # update plotting object, but don't automatically render
        plotter.update_coordinates(points, render=False)
        plotter.update_scalars(Z.ravel(), render=False)

        # Render and get time to render
        rstart = time.time()
        plotter.update()
        # plotter.render()
        rstop = time.time()

        # time delay
        tpast = time.time() - tlast
        if tpast < tdelay and tpast >= 0:
            time.sleep(tdelay - tpast)

        # get render time and actual FPS
        rtime = rstop - rstart
        act_fps = 1 / (time.time() - tlast + 1E-10)
        tlast = time.time()

    # Close movie and delete object
    plotter.close()

    return points

{'fraction_non_alphanumeric': 0.10717529518619437, 'fraction_numerical': 0.053835356287672366, 'mean_word_length': 2.674757281553398, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, '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': '7429394', 'n_tokens_mistral': 4491, 'n_tokens_neox': 3932, 'n_words': 1087}