Skip to content

Commit

Permalink
Remove old moviepy animation code
Browse files Browse the repository at this point in the history
  • Loading branch information
jdmonaco committed Nov 19, 2020
1 parent ad52242 commit f330f6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 40 deletions.
6 changes: 3 additions & 3 deletions neuroswarms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
Requirements: numpy, scipy, matplotlib, pytables, pillow.
Related paper:
Related paper:
Monaco, J.D., Hwang, G.M., Schultz, K.M. et al. Cognitive swarming in complex
environments with attractor dynamics and oscillatory computing. Biol Cybern
114, 269–284 (2020). https://doi.org/10.1007/s00422-020-00823-z
This software is provided AS IS under the terms of the Open Source MIT License.
This software is provided AS IS under the terms of the Open Source MIT License.
See http://www.opensource.org/licenses/mit-license.ph
"""

Expand Down Expand Up @@ -45,4 +45,4 @@
MAPDIR = os.path.join(os.path.dirname(REPOPATH), 'mapdata')
PROJDIR = os.path.join(HOME, NAME)
RUNDIR = os.path.join(PROJDIR, 'output')
DATADIR = os.path.join(PROJDIR, 'data')
DATADIR = os.path.join(PROJDIR, 'data')
48 changes: 11 additions & 37 deletions neuroswarms/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
Created: 2019-05-12
Updated: 2020-11-16
Related paper:
Related paper:
Monaco, J.D., Hwang, G.M., Schultz, K.M. et al. Cognitive swarming in complex
environments with attractor dynamics and oscillatory computing. Biol Cybern
114, 269–284 (2020). https://doi.org/10.1007/s00422-020-00823-z
This software is provided AS IS under the terms of the Open Source MIT License.
This software is provided AS IS under the terms of the Open Source MIT License.
See http://www.opensource.org/licenses/mit-license.ph
"""

Expand All @@ -28,13 +28,6 @@
log1p, sqrt, nextafter, any)
from numpy.random import seed, rand, randn, randint

# from moviepy.editor import VideoClip
# from moviepy.video.io.bindings import mplfig_to_npimage
#
# Set the environment variable to tell moviepy where ffmpeg is
# if platform.system() == 'Windows':
# os.environ['FFMPEG_BINARY'] = r"C:\Program Files (x86)\ffmpeg\ffmpeg.exe"

from matplotlib import pyplot as plt
from matplotlib.colors import colorConverter
from matplotlib.animation import FuncAnimation
Expand Down Expand Up @@ -141,8 +134,8 @@ def set_parameters(self, pfile=None, **params):
logstr = f' * {name} = {val} [default: {dflt}]'
self.out(logstr, hideprefix=True)

# Import environmental geometry into the global scope, into the
# persistent key-value store, and as instance attributes of the
# Import environmental geometry into the global scope, into the
# persistent key-value store, and as instance attributes of the
# simulation object
global E
self.hline()
Expand Down Expand Up @@ -182,10 +175,10 @@ def simulate(self, tag=None, paramfile=None, **params):
---------
tag : string tag to be added to the output movie file
paramfile : absolute path or filename for a parameter fille; for a
paramfile : absolute path or filename for a parameter fille; for a
filename, the project and run directories will be searched
Keyword arguments provide parameter values that supercede those found
Keyword arguments provide parameter values that supercede those found
in a `paramfile`.
"""
self.set_parameters(paramfile, **params)
Expand Down Expand Up @@ -333,17 +326,6 @@ def init():

return self.artists

# Update loop function - MoviePy version
# n = -1
# def update(t):
# For moviepy, the floating-point time is provided to the update function,
# so we will instead keep track of our own frame count and simply return
# the static _fig in case the callback goes over frame count
# nonlocal n
# n += 1
# if n > _nframes - 1:
# return mplfig_to_npimage(_fig)

#
# Update loop for Matplotlib figure animation
#
Expand Down Expand Up @@ -410,9 +392,9 @@ def update(n):
W_R[:] += V_Delta*V_R*dt*eta_R*p*(r - p*W_R)
W_S[:] += V_Delta*V_S*dt*eta_S*p*(q - p*W_S)

# For precision and masking, convert non-zero weights to distances
# via log1p (thus requiring subtraction of 1, since we are not
# using expm1 to create weights because we do not want learning to
# For precision and masking, convert non-zero weights to distances
# via log1p (thus requiring subtraction of 1, since we are not
# using expm1 to create weights because we do not want learning to
# operate on negative weights). Eqns. 15-16.
W_R.clip(0, ONEMEPS, out=W_R)
W_S.clip(0, ONEMEPS, out=W_S)
Expand Down Expand Up @@ -519,12 +501,6 @@ def update(n):
# For matplolib.animation.FuncAnimation:
return self.artists

# For moviepy.editor.VideoClip:
# return mplfig_to_npimage(_fig)

# For moviepy, we need to manually initialize the figure
# init()

# Create the Matplotlib figure animation object
anim = FuncAnimation(fig=_fig, func=update, frames=range(_nframes),
init_func=init, interval=10, repeat=False, blit=True)
Expand All @@ -533,8 +509,6 @@ def update(n):
if tag: fn = '{}+{}.mp4'.format(self._name, tag)
else: fn = '{}.mp4'.format(self._name)
self.savepath = self.path(fn)
# animation = VideoClip(update, duration=duration)
# animation.write_videofile(temppath, fps=_nframes/duration)
anim.save(self.savepath, fps=MOVIE_FPS, dpi=MOVIE_DPI)
self.hline()
plt.close(_fig)
Expand All @@ -558,7 +532,7 @@ def play_movie(self, movie_path):
Note: This code will call the command-line movie player `mpv` if it is
installed and available on the local search path. On macOS systems, it
can be installed with homebrew via `brew install mpv`. On linux,
can be installed with homebrew via `brew install mpv`. On linux,
it can be installed in standard ways, such as `sudo apt install mpv`.
"""
dv = subprocess.DEVNULL
Expand All @@ -570,4 +544,4 @@ def play_movie(self, movie_path):

mpv_cmd = ['mpv', '--loop=yes', '--ontop=yes']
mpv_cmd.append(movie_path)
subprocess.run(mpv_cmd, **devnull)
subprocess.run(mpv_cmd, **devnull)

0 comments on commit f330f6f

Please sign in to comment.