<jupyter_start><jupyter_text>InforAlso exemplify 2d animation, 3d and interactive plot<jupyter_code>import numpy as np
from detection2d import detect_single
from wave2d import LinearRandomWave2D
import matplotlib.pyplot as plt

from ipywidgets import interactive
from celluloid import Camera
import matplotlib
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.colors import LightSource
plt.rcParams.update({'font.size': 16})<jupyter_output><empty_output><jupyter_text>Get(load) the wave<jupyter_code>t_series = np.arange(0,100,5)
seed = 2
wave2d = LinearRandomWave2D()
wave2d.prepare_wave(seed)

#mesh, elev_series = wave2d.generate_wave(t_series=t_series)
#mesh, env_series = wave2d.generate_envelope(t_series=t_series)

mesh = np.load('data/mesh.npy')
elev_series = np.load('data/elev_series.npy')
env_series = np.load('data/env_series.npy')

levels = np.arange(-12, 12.1, 2)<jupyter_output><empty_output><jupyter_text>Plot the wave<jupyter_code># 2d animation
%matplotlib notebook  

fig = plt.figure(figsize=(6,5))
camera = Camera(fig)
for i in range(len(elev_series)):
    plt.contourf(mesh[0], mesh[1], elev_series[i])
    plt.contour(mesh[0], mesh[1], env_series[i], levels=levels)
    plt.xlabel('x')
    plt.ylabel('y')
    camera.snap()
plt.tight_layout()
animation = camera.animate()
animation.save('plots/animation_2d.gif')
# 2d interactive plot
%matplotlib inline

def f(i):
    plt.figure(figsize=(6,5))
    plt.contourf(mesh[0], mesh[1], elev_series[i])
    plt.contour(mesh[0], mesh[1], env_series[i], levels=levels)
    plt.xlabel('x')
    plt.ylabel('y')
    plt.show()
    
interactive_plot = interactive(f, i=(0, 19))
output = interactive_plot.children[-1]
output.layout.height = '350px'
interactive_plot
# generate 3d snapshot
%matplotlib notebook

blue_rgb = matplotlib.colors.ColorConverter().to_rgb('tab:blue')
colors = np.array([[blue_rgb for i in range(256)] for j in range(256)])

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ls = LightSource(90, 0)
rgb = ls.shade_rgb(colors, elev_series[0], blend_mode = 'soft')
ax.plot_surface(mesh[0], mesh[1], elev_series[0], shade=False, facecolors=rgb, 
                         rstride=1, cstride=1, linewidth=0, antialiased=False)
ax.set_xlabel('$x$')
ax.set_ylabel('$y$')
# scale of different directions
ax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([1.25, 1.25, 0.2, 1]))
# the display view 
# view_init(elev=None, azim=None)
plt.savefig('plots/snap_3d.pdf')
plt.show()
# generate 3d animation (a little bit slow)
%matplotlib notebook

blue_rgb = matplotlib.colors.ColorConverter().to_rgb('tab:blue')
colors = np.array([[blue_rgb for i in range(256)] for j in range(256)])

fig = plt.figure()
camera = Camera(fig)
ax = fig.add_subplot(111, projection='3d')
ls = LightSource(90, 0)
for i in range(len(elev_series)):
    rgb = ls.shade_rgb(colors, elev_series[i], blend_mode = 'soft')
    surf = x.plot_surface(mesh[0], mesh[1], elev_series[0], shade=False, facecolors=rgb, 
                         rstride=1, cstride=1, linewidth=0, antialiased=False)
    ax.set_xlabel('$x$')
    ax.set_ylabel('$y$')
    # scale of different directions
    ax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([1.25, 1.25, 0.2, 1]))
    # the display view 
    # view_init(elev=None, azim=None)
    camera.snap()
animation = camera.animate()
animation.save('plots/animatioin_3d.gif')<jupyter_output><empty_output><jupyter_text>Generate wave detection contourf: elevation  contour: envelope  red dots: detected group centers<jupyter_code>detect_single(2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14557138865604918, 'fraction_numerical': 0.03129365744621403, 'mean_word_length': 5.556776556776557, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '191062', 'license': 'MIT', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1340, 'n_words': 264, 'path': 'wavefinder/demonstration2d.ipynb', 'repo_name': 'umbrellagong/wavefinder', 'size': '3579'}