Animations in EinsteinPy

Importing required modules

In [1]:
import numpy as np

from einsteinpy.geodesic import Timelike
from einsteinpy.plotting import StaticGeodesicPlotter
Matplotlib is building the font cache; this may take a moment.

Defining various parameters

  • Initial position & momentum of the test partcle
  • Spin of the Kerr Black Hole in metric_params
  • Other solver parameters

    Note that, we are working in M-Units ($G = c = M = 1$).

In [2]:
# Constant Radius Orbit
position = [4, np.pi / 3, 0.]
momentum = [0., 0.767851, 2.]
a = 0.99
steps = 400.
delta = 0.5

Calculating geodesic

In [3]:
geod = Timelike(
    metric="Kerr",
    metric_params=(a,),
    position=position,
    momentum=momentum,
    steps=steps,
    delta=delta,
    return_cartesian=True
)

Animating

In [4]:
%matplotlib nbagg
sgpl = StaticGeodesicPlotter()
sgpl.animate(geod, interval=1)
sgpl.show()

Saving animation as .gif

In [5]:
sgpl.ani.save('animation.gif', writer='imagemagick', fps=60)
MovieWriter stderr:
convert-im6.q16: no images defined `animation.gif' @ error/convert.c/ConvertImageCommand/3258.

---------------------------------------------------------------------------
BrokenPipeError                           Traceback (most recent call last)
~/Softwares/miniconda3/envs/einsteinpy3.8/lib/python3.8/site-packages/matplotlib/animation.py in saving(self, fig, outfile, dpi, *args, **kwargs)
    235         try:
--> 236             yield self
    237         finally:

~/Softwares/miniconda3/envs/einsteinpy3.8/lib/python3.8/site-packages/matplotlib/animation.py in save(self, filename, writer, fps, dpi, codec, bitrate, extra_args, metadata, extra_anim, savefig_kwargs, progress_callback)
   1176                         frame_number += 1
-> 1177                 writer.grab_frame(**savefig_kwargs)
   1178 

~/Softwares/miniconda3/envs/einsteinpy3.8/lib/python3.8/site-packages/matplotlib/animation.py in grab_frame(self, **savefig_kwargs)
    355         # Save the figure data to the sink, using the frame format and dpi.
--> 356         self.fig.savefig(self._proc.stdin, format=self.frame_format,
    357                          dpi=self.dpi, **savefig_kwargs)

~/Softwares/miniconda3/envs/einsteinpy3.8/lib/python3.8/site-packages/matplotlib/figure.py in savefig(self, fname, transparent, **kwargs)
   2961 
-> 2962         self.canvas.print_figure(fname, **kwargs)
   2963 

~/Softwares/miniconda3/envs/einsteinpy3.8/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2254                 with cbook._setattr_cm(self.figure, dpi=dpi):
-> 2255                     result = print_method(
   2256                         filename,

~/Softwares/miniconda3/envs/einsteinpy3.8/lib/python3.8/site-packages/matplotlib/backend_bases.py in wrapper(*args, **kwargs)
   1668 
-> 1669         return func(*args, **kwargs)
   1670 

~/Softwares/miniconda3/envs/einsteinpy3.8/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in print_raw(self, filename_or_obj, *args)
    454         with cbook.open_file_cm(filename_or_obj, "wb") as fh:
--> 455             fh.write(renderer.buffer_rgba())
    456 

BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

CalledProcessError                        Traceback (most recent call last)
<ipython-input-5-35b43486ec2f> in <module>
----> 1 sgpl.ani.save('animation.gif', writer='imagemagick', fps=60)

~/Softwares/miniconda3/envs/einsteinpy3.8/lib/python3.8/site-packages/matplotlib/animation.py in save(self, filename, writer, fps, dpi, codec, bitrate, extra_args, metadata, extra_anim, savefig_kwargs, progress_callback)
   1175                         progress_callback(frame_number, total_frames)
   1176                         frame_number += 1
-> 1177                 writer.grab_frame(**savefig_kwargs)
   1178 
   1179     def _step(self, *args):

~/Softwares/miniconda3/envs/einsteinpy3.8/lib/python3.8/contextlib.py in __exit__(self, type, value, traceback)
    129                 value = type()
    130             try:
--> 131                 self.gen.throw(type, value, traceback)
    132             except StopIteration as exc:
    133                 # Suppress StopIteration *unless* it's the same exception that

~/Softwares/miniconda3/envs/einsteinpy3.8/lib/python3.8/site-packages/matplotlib/animation.py in saving(self, fig, outfile, dpi, *args, **kwargs)
    236             yield self
    237         finally:
--> 238             self.finish()
    239 
    240 

~/Softwares/miniconda3/envs/einsteinpy3.8/lib/python3.8/site-packages/matplotlib/animation.py in finish(self)
    345             overridden_cleanup()
    346         else:
--> 347             self._cleanup()  # Inline _cleanup() once cleanup() is removed.
    348 
    349     def grab_frame(self, **savefig_kwargs):

~/Softwares/miniconda3/envs/einsteinpy3.8/lib/python3.8/site-packages/matplotlib/animation.py in _cleanup(self)
    376                 "MovieWriter stderr:\n%s", err)
    377         if self._proc.returncode:
--> 378             raise subprocess.CalledProcessError(
    379                 self._proc.returncode, self._proc.args, out, err)
    380 

CalledProcessError: Command '['convert', '-size', '750x750', '-depth', '8', '-delay', '1.6666666666666667', '-loop', '0', 'rgba:-', 'animation.gif']' returned non-zero exit status 1.