élasticité - scénario onde

L'installation Elasticité dynamique agit comme un filtre et génère de nouveaux espaces démultipliés, comme un empilement quasi infini d'horizons. Par principe de réflexion, la pièce absorbe l'image de l'environnement et accumule les points de vue ; le mouvement permanent requalifie continuellement ce qui est regardé et entendu.

Ce post crée des ondes se propageant sur la série de lames.

In [1]:
%load_ext autoreload
%autoreload 2
In [2]:
import matplotlib
#matplotlib.use('nbagg')
matplotlib.rcParams['figure.max_open_warning'] = 400
%matplotlib inline
%config InlineBackend.figure_format='retina'
import matplotlib.pyplot as plt
#%config InlineBackend.figure_format = 'svg'
#import mpld3
#mpld3.enable_notebook()

vague simple

In [3]:
!rm  ../files/onde*
In [4]:
name = 'onde'
vext = '.mp4'
import os
import numpy as np
import MotionClouds as mc
mc.figpath = '../files/2015-10-14_elasticite/'
mc.N_X, mc.N_Y, mc.N_frame = 50, 2, 2048
fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame)
theta, B_theta = 0., np.pi/8.
alpha, sf_0, B_sf, B_V = 1., .02, .1, .05
seed = 1234565
V_X, V_Y = .05, 0.
mc_wave = mc.envelope_gabor(fx, fy, ft, V_X=V_X, V_Y=V_Y, B_V=B_V, 
                            theta=theta, B_theta=B_theta, sf_0=sf_0, B_sf=B_sf, alpha=alpha)
mc.figures(mc_wave, name, vext=vext, seed=seed, do_figs=False)
mc.in_show_video(name)
Saving sequence ../files/onde as a .mp4 format

Saving the corrresponding cloud as a nd.array:

In [5]:
vague_dense = mc.rectif(mc.random_cloud(mc_wave), contrast=1)
print(vague_dense.shape)
(50, 2, 2048)
In [6]:
plt.matshow(vague_dense[:, 0, :])
Out[6]:
<matplotlib.image.AxesImage at 0x1063ca5f8>
No description has been provided for this image
In [7]:
mc.figures(mc_wave, name + '_impulse', seed=seed, impulse=True, do_figs=False)
mc.in_show_video(name + '_impulse')
Saving sequence ../files/2015-10-14_elasticite/onde_impulse as a .mp4 format
In [8]:
vague_solo = mc.rectif(mc.random_cloud(mc_wave, seed=seed, impulse=True), contrast=1)
print(vague_solo.shape, vague_solo.min(), vague_solo.mean(), vague_solo.max())
(50, 2, 2048) 0.368487487441 0.5 1.0
In [9]:
plt.matshow(vague_solo[:, 0, :])
Out[9]:
<matplotlib.image.AxesImage at 0x106be09b0>
No description has been provided for this image

transforme la vague 2D sur les lames

In [10]:
def vague_animate(z, x_offset=0, y_offset=0, N_lame = 25, t_offset=0, N_steps = 2048):
    import matplotlib.pyplot as plt
    import matplotlib.animation as animation
    from IPython.display import HTML

    fig, ax = plt.subplots(figsize=(15, 3))

    x = np.arange(0, N_lame)        # x-array

    def vague(i):
        return z[x_offset:(x_offset+N_lame), y_offset, t_offset+i]

    def animate(i):
        line.set_ydata(vague(i))  # update the data
        return line,

    #Init only required for blitting to give a clean slate.
    def init():
        line.set_ydata(np.ma.array(x, mask=True))
        return line,

    line,  = ax.plot(x, vague(0))
    ax.set_xlim([0, N_lame-1])
    ax.set_ylim([0, 1])

    anim = animation.FuncAnimation(fig, animate, np.arange(1, N_steps), init_func=init,
        interval=25, blit=True)

    return HTML(anim.to_html5_video())
    
In [11]:
vague_animate(vague_dense[::2, :, :])
Out[11]:
No description has been provided for this image
In [12]:
vague_animate(vague_solo, x_offset=vague_solo.shape[0]//2-25//2, y_offset=vague_solo.shape[1]//2, t_offset=0, N_steps = vague_solo.shape[-1])
Out[12]:
No description has been provided for this image
In [13]:
vague_animate(vague_solo, x_offset=vague_solo.shape[0]//2-25//2, y_offset=vague_solo.shape[1]//2, t_offset=vague_solo.shape[-1]//4, N_steps=vague_solo.shape[-1]//2)
Out[13]:
No description has been provided for this image
In [14]:
vague_animate(vague_solo, x_offset=vague_solo.shape[0]//2-25//2, y_offset=vague_solo.shape[1]//2, 
              t_offset=vague_solo.shape[-1]*3//8, N_steps=vague_solo.shape[-1]//4)
Out[14]:
No description has been provided for this image

Saving as a scenario

In [15]:
%%writefile ../scenario_line_onde.py
#!/usr/bin/env python
# -*- coding: utf8 -*-

import elasticite as el
import numpy as np

def make_vague(impulse=False):
    import os
    import numpy as np
    import MotionClouds as mc

    mc.N_X, mc.N_Y, mc.N_frame = 50, 2, 2048
    fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame)
    theta, B_theta = 0., np.pi/8.
    alpha, sf_0, B_sf, B_V = 1., .02, .1, .1
    seed = 1234565
    V_X, V_Y = .1, 0.
    mc_wave = mc.envelope_gabor(fx, fy, ft, V_X=V_X, V_Y=V_Y, B_V=B_V, 
                                theta=theta, B_theta=B_theta, sf_0=sf_0, B_sf=B_sf, alpha=alpha)

    wave = mc.random_cloud(mc_wave, seed=seed, impulse=impulse)
    
    wave -= wave.mean()
    wave /= np.abs(wave).max()
    return wave

class EdgeGrid(el.EdgeGrid):
    def __init__(self, vague, x_offset=0, y_offset=0, t_offset=0, N_steps = 2048, damp_tau=5., **kwargs):
        #super(el.EdgeGrid.__init__(self))
        #super(el.EdgeGrid, self).__init__(**kwargs)
        el.EdgeGrid.__init__(self, **kwargs)
        #print (self.verb, kwargs)
        self.vague = vague
        self.x_offset = x_offset
        self.y_offset = y_offset
        self.t_offset = t_offset
        self.N_steps = N_steps
        #print(self.x_offset, self.y_offset, self.t_offset)
        #print(self.z.shape)
        self.damp_tau = damp_tau
        
        
    def update(self):
        if self.structure: N_lame = self.N_lame-self.struct_N
        else: N_lame = self.N_lame
        damp = lambda t: 1. - np.exp(-np.abs(np.mod(t+self.period/2, self.period)-self.period/2)/self.damp_tau)

        N_periods = 1
        i = np.mod(np.int(self.t/self.period * self.vague.shape[2] / N_periods), self.vague.shape[2])
        surface = np.zeros_like(self.lames[2, :N_lame])
        #for k, amp in zip([-2, -1, 0, 1, 2], [.125, .25, .5, .25, .125]):
        #    surface += amp * self.vague[self.x_offset:(self.x_offset+N_lame), self.y_offset, self.t_offset+i+k]
        surface = self.vague[self.x_offset:(self.x_offset+N_lame), self.y_offset, self.t_offset+i].ravel()
        #surface = np.convolve(surface, np.arange(5), mode='same')
        #dsurface = np.gradient(surface)
        #dsurface = np.roll(surface, 1) - surface
        #dsurface *= np.bartlett(N_lame)
        # print(dsurface.mean(), np.abs(dsurface).max(), damp(self.t))
        #dsurface /= np.abs(dsurface).max()
        surface *= np.tan(np.pi/12)*damp(self.t) # maximum angle achieved
        #print(surface.min(), surface.mean(), np.abs(surface).max(), damp(self.t))
        self.lames[2, :N_lame] = np.arctan(surface)
        
if __name__ == "__main__":
    import sys
    if len(sys.argv)>1: mode = sys.argv[1]
    else: mode = 'both'
        
    vague_dense = make_vague(impulse=False)
    print (np.abs(vague_dense).max())

    period = 2048./30
    e = EdgeGrid(N_lame=25, grid_type='line', mode=mode,
                 verb=False, period=period, filename='mat/line_onde_dense.npy', 
                 vague = vague_dense,
                 x_offset=0, y_offset=0, t_offset=0, N_steps=2048)

    # running the code
    el.main(e)
Overwriting ../scenario_line_onde.py
In [16]:
%cd ..
!rm mat/line_onde_dense.npy
%run  scenario_line_onde.py writer
%cd posts
/Users/laurentperrinet/cloud_nas/science/elasticte
Could not load pyglet
1.0
/Users/laurentperrinet/cloud_nas/science/elasticte/posts
In [17]:
z = np.load('../mat/line_onde_dense.npy')
el.check(e, z)
print(z.shape)
fig, ax = plt.subplots(figsize=(15, 3))
#_ = ax.plot(z[:, 0])
_ = ax.plot(z[:, 0], z[:, 1:])
(2048, 26)
No description has been provided for this image
In [18]:
%%writefile ../scenario_line_onde_solo.py
#!/usr/bin/env python
# -*- coding: utf8 -*-

import elasticite as el
import numpy as np

from scenario_line_onde import make_vague, EdgeGrid

if __name__ == "__main__":
    import sys
    if len(sys.argv)>1: mode = sys.argv[1]
    else: mode = 'both'
    period = 2048./30
    vague_solo = make_vague(impulse=True)
    e_solo = EdgeGrid(N_lame=25, grid_type='line', mode=mode,
                 verb=False, period=period, filename='mat/line_onde_solo.npy', 
                 vague = vague_solo,
                 x_offset=vague_solo.shape[0]//2-25//2, y_offset=vague_solo.shape[1]//2, 
                 t_offset=0, N_steps=512)#t_offset=vague_solo.shape[-1]*3//8, N_steps=vague_solo.shape[-1]//4)

    # running the code
    el.main(e_solo)
Overwriting ../scenario_line_onde_solo.py
In [19]:
%cd ..
!rm mat/line_onde_solo.npy
%run  scenario_line_onde_solo.py writer
%cd posts
/Users/laurentperrinet/cloud_nas/science/elasticte
/Users/laurentperrinet/cloud_nas/science/elasticte/posts
In [20]:
z = np.load('../mat/line_onde_solo.npy')
el.check(e, z)
fig, ax = plt.subplots(figsize=(15, 3))
#_ = ax.plot(z[:, 0])
_ = ax.plot(z[:, 0], z[:, 1:])
No description has been provided for this image

git

In [21]:
!git pull
Already up-to-date.
In [22]:
!git add ../mat/line_onde_* ../scenario_line_onde*
!git s
M  ../mat/line_onde_solo.npy
 M "2015-10-14 \303\251lasticit\303\251, Fresnel.ipynb"
 M "2015-11-17 \303\251lasticit\303\251 expansion en miroir - dynamique d'un point focal.ipynb"
 M "2015-11-26 \303\251lasticit\303\251 - sc\303\251nario montage.ipynb"
 M "2015-11-29 \303\251lasticit\303\251 - sc\303\251nario onde.ipynb"
In [23]:
!git commit -am' scenario onde '
[master 760a1f8]  scenario onde
 5 files changed, 17457 insertions(+), 13743 deletions(-)
 rewrite mat/line_onde_solo.npy (94%)
 rewrite "posts/2015-11-26 \303\251lasticit\303\251 - sc\303\251nario montage.ipynb" (96%)
In [24]:
! git push
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 17.04 MiB | 5.75 MiB/s, done.
Total 9 (delta 5), reused 0 (delta 0)
To git@git.framasoft.org:laurentperrinet/elasticte.git
   e65defe..760a1f8  master -> master