Skip to content
Snippets Groups Projects
Select Git revision
  • ecb1614f82e237fca0b0b85c7f6350a80beca104
  • master default protected
  • armneon
  • vectorization_sqrt_fix
  • jan_fix
  • mr_parallel_datahandling_fix
  • test_martin
  • jan_test
  • compare_fix
  • target_dh_refactoring
  • philox-simd
  • hyteg
  • const_fix
  • test_martin2
  • improved_comm
  • gpu_liveness_opts
  • release/0.2.15
  • release/0.2.14
  • release/0.2.13
  • release/0.2.12
  • release/0.2.11
  • release/0.2.10
  • release/0.2.9
  • release/0.2.8
  • release/0.2.7
  • release/0.2.6
  • release/0.2.4
  • release/0.2.3
  • release/0.2.2
  • release/0.2.1
30 results

test_plot.py

Blame
  • Forked from pycodegen / pystencils
    968 commits behind the upstream repository.
    test_plot.py 1.72 KiB
    import os
    from tempfile import TemporaryDirectory
    
    import numpy as np
    
    import pystencils.plot as plt
    
    
    def example_scalar_field(t=0):
        x, y = np.meshgrid(np.linspace(0, 2 * np.pi, 100), np.linspace(0, 2 * np.pi, 100))
        z = np.cos(x + 0.1 * t) * np.sin(y + 0.1 * t) + 0.1 * x * y
        return z
    
    
    def example_vector_field(t=0, shape=(40, 40)):
        result = np.empty(shape + (2,))
        x, y = np.meshgrid(np.linspace(0, 2 * np.pi, shape[0]), np.linspace(0, 2 * np.pi, shape[1]))
        result[..., 0] = np.cos(x + 0.1 * t) * np.sin(y + 0.1 * t) + 0.01 * x * y
        result[..., 1] = np.cos(0.001 * y)
        return result
    
    
    def test_animation():
        t = 0
    
        def run_scalar():
            nonlocal t
            t += 1
            return example_scalar_field(t)
    
        def run_vec():
            nonlocal t
            t += 1
            return example_vector_field(t)
    
        plt.clf()
        plt.cla()
    
        with TemporaryDirectory() as tmp_dir:
            ani = plt.vector_field_magnitude_animation(run_vec, interval=1, frames=2)
            ani.save(os.path.join(tmp_dir, "animation1.avi"))
    
            ani = plt.vector_field_animation(run_vec, interval=1, frames=2, rescale=True)
            ani.save(os.path.join(tmp_dir, "animation2.avi"))
    
            ani = plt.vector_field_animation(run_vec, interval=1, frames=2, rescale=False)
            ani.save(os.path.join(tmp_dir, "animation3.avi"))
    
            ani = plt.scalar_field_animation(run_scalar, interval=1, frames=2, rescale=True)
            ani.save(os.path.join(tmp_dir, "animation4.avi"))
    
            ani = plt.scalar_field_animation(run_scalar, interval=1, frames=2, rescale=False)
            ani.save(os.path.join(tmp_dir, "animation5.avi"))
    
            ani = plt.surface_plot_animation(run_scalar, frames=2)
            ani.save(os.path.join(tmp_dir, "animation6.avi"))