{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# More fun with gravity waves\n", "\n", "[Motion Clouds](https://neuralensemble.github.io/MotionClouds) were defined in the origin to provide a simple parameterization for \n", "textures. Thus we used a simple unimodal, normal distribution (on the log-radial frequency space to be more precise). But the larger set of Random Phase Textures may provide some interesting examples, some of them can even be fun! This is the case of this simulation of the waves you may observe on the surface on the ocean. \n", "\n", "Main features of gravitational waves are:\n", "\n", "1. longer waves travel faster (tsunami are fast and global, ripples are slow and local) - speed is *linearly proportional* to wavelength\n", "2. phase speed (following a wave's crest) is **twice** as fast as group speed (following a group of waves).\n", "\n", "More info about deep water waves : http://farside.ph.utexas.edu/teaching/336L/Fluidhtml/node122.html\n", "\n", "" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import os\n", "import numpy as np\n", "import MotionClouds as mc\n", "fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame)\n", "mc.figpath = '../files/2016-04-24_a-wave-going-backwards'\n", "if not(os.path.isdir(mc.figpath)): os.mkdir(mc.figpath)\n", "\n", "def envelope_gravity(fx, fy, ft, B_wave, V_X, V_Y, g=.1):\n", " \"\"\"\n", " Gravitational envelope:\n", " selects the manifold corresponding to the speed (V_X, V_Y) with some thickness B_V\n", "\n", " \"\"\"\n", " k = fx*V_X+fy*V_Y\n", " env = np.exp(-.5*(((ft/.5)**2-g*np.sqrt(((k/.5)**2)))**2/(B_wave*mc.frequency_radius(fx, fy, ft, clean_division=True))**2))\n", " env *= (ft*k) < 0\n", " return env\n", "\n", "def envelope_gabor_wave(fx, fy, ft, B_wave, V_X, V_Y,\n", " B_V=mc.B_V, B_v=1., sf_0=mc.sf_0, B_sf=mc.B_sf, loggabor=mc.loggabor,\n", " theta=mc.theta, B_theta=mc.B_theta, alpha=mc.alpha):\n", " \"\"\"\n", " Returns the Motion Cloud kernel\n", "\n", " \"\"\"\n", " envelope = mc.envelope_gabor(fx, fy, ft, V_X, V_Y,\n", " B_V=B_V, sf_0=sf_0, B_sf=B_sf, loggabor=loggabor,\n", " theta=theta, B_theta=B_theta, alpha=alpha)\n", " envelope *= envelope_gravity(fx, fy, ft, B_wave=B_wave, V_X=V_X, V_Y=V_Y)\n", " return envelope" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.6/site-packages/vispy/visuals/isocurve.py:22: UserWarning: VisPy is not yet compatible with matplotlib 2.2+\n", " warnings.warn(\"VisPy is not yet compatible with matplotlib 2.2+\")\n" ] }, { "data": { "text/html": [ "\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "  " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "name = 'wave2'\n", "theta, B_theta, B_wave = 0., np.pi/12., .02\n", "alpha, sf_0, B_sf, B_V = 1., .2, .4, 2.\n", "recompute = True\n", "env = envelope_gabor_wave(fx, fy, ft, V_X=1.5, V_Y=0., B_wave=B_wave, B_V=B_V, \n", " theta=theta, B_theta=B_theta, sf_0=sf_0, B_sf=B_sf, alpha=alpha)\n", "mc.figures(env, name, recompute=recompute, figpath=mc.figpath)\n", "mc.in_show_video(name, figpath=mc.figpath)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "name = 'wave2_back'\n", "im = mc.rectif(mc.random_cloud(env))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
 \n", "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "im_back = im.copy()\n", "for i in range(mc.N_frame):\n", " im_back[:, :, i] = np.roll(im[:, :, i], -i, axis=0)\n", "mc.anim_save(im_back, os.path.join(mc.figpath, name))\n", "mc.in_show_video(name, figpath=mc.figpath)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Post-prod" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " % Total % Received % Xferd Average Speed Time Time Time Current\n", " Dload Upload Total Spent Left Speed\n", "100 38858 100 38858 0 0 221k 0 --:--:-- --:--:-- --:--:-- 220k\n" ] } ], "source": [ "!curl https://upload.wikimedia.org/wikipedia/commons/thumb/4/4f/Paperboat.svg/1000px-Paperboat.svg.png -o /tmp/Paperboat.png" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "pygame 1.9.4\n", "Hello from the pygame community. https://www.pygame.org/contribute.html\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|█████████▉| 256/257 [00:00<00:00, 943.70it/s]\n" ] }, { "data": { "text/html": [ "