-
Notifications
You must be signed in to change notification settings - Fork 0
/
scenario_line_vague.py
102 lines (85 loc) · 3.92 KB
/
scenario_line_vague.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
# -*- coding: utf8 -*-
import elasticite as el
import numpy as np
def make_vague(impulse=False):
name = 'waves'
import os
import numpy as np
import MotionClouds as mc
mc.N_X, mc.N_Y, mc.N_frame = 128, 32, 512
fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame)
theta, B_theta, B_wave = 0., np.pi/8., .1
alpha, sf_0, B_sf, B_V = 2., .25, .3, 2.
alpha, sf_0, B_sf, B_V = 1., .1, .3, 2.
seed = 1234565
V_X, V_Y, g = .5, 0., .1
V_X, V_Y, g = .5, 0., 2
loggabor=True
B_v = .025
def envelope_gravity(fx, fy, ft, B_wave, g=.1):
"""
Gravitational envelope:
selects the plane corresponding to the speed (V_X, V_Y) with some thickness B_V
"""
k = fx*V_X+fy*V_Y
env = np.exp(-.5*(((ft/.5)**2-g*np.sqrt(((k/.5)**2)))**2/(B_wave*mc.frequency_radius(fx, fy, ft, ft_0=np.inf))**2))
env *= (ft*k) < 0
return env
def envelope_gabor_wave(fx, fy, ft, B_wave, V_X=mc.V_X, V_Y=mc.V_Y,
B_V=mc.B_V, B_v=1., sf_0=mc.sf_0, B_sf=mc.B_sf, loggabor=mc.loggabor,
theta=mc.theta, B_theta=mc.B_theta, alpha=mc.alpha):
"""
Returns the Motion Cloud kernel
"""
envelope = mc.envelope_gabor(fx, fy, ft, V_X=V_X, V_Y=V_Y,
B_V=B_V, sf_0=sf_0, B_sf=B_sf, loggabor=loggabor,
theta=theta, B_theta=B_theta, alpha=alpha)
envelope *= envelope_gravity(fx, fy, ft, B_wave=B_wave)
return envelope
B_v_low, B_v_high = .025, .1
mc_vague = envelope_gabor_wave(fx, fy, ft, V_X=1., V_Y=0., B_wave=B_v_low, B_V=B_V, theta=theta, B_theta=B_theta, sf_0=sf_0, B_sf=B_sf, alpha=alpha)
return mc.rectif(mc.random_cloud(mc_vague, seed=seed, impulse=impulse))
class EdgeGrid(el.EdgeGrid):
def __init__(self, vague, x_offset=0, y_offset=0, t_offset=0, N_steps = 256, 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]
surface = np.convolve(surface, np.arange(5), mode='same')
dsurface = np.gradient(surface)
dsurface *= np.bartlett(N_lame)
#print(dsurface.mean(), dsurface.max(), damp(self.t))
dsurface /= np.abs(dsurface).max()
dsurface *= np.tan(np.pi/32) # maximum angle achieved
self.lames[2, :N_lame] = np.arctan(dsurface)*damp(self.t)
if __name__ == "__main__":
import sys
if len(sys.argv)>1: mode = sys.argv[1]
else: mode = 'both'
vague_dense = make_vague(impulse=False)
period = 512./30
e = EdgeGrid(N_lame=25, grid_type='line', mode=mode,
verb=False, period=period, filename='mat/line_vague_dense.npy',
vague = vague_dense,
x_offset=0, y_offset=0, t_offset=0, N_steps=512)
# running the code
el.main(e)