makeVideo

Asked by Paolo

Hello everyone!

I'm trying to understand how the makeVideo command works. I just copied and paste the code "3d postprocessing" explained here:

https://yade-dem.org/doc/tutorial-examples.html

However, my code instead of stopping at iterPeriod=20000 continues going on, giving error but continuing saving the snapshots and not making the video. It is as if the finish() function is not correctly read. The error is something like :

OSError Traceback (most recent call last)
/usr/bin/yade in <module>()

/usr/bin/yade in finish()
     41 # snapshot is label of qt.SnapshotEngine
     42 # the 'snapshots' attribute contains list of all saved files
---> 43 makeVideo(snapshot.snapshots,'3d.mpeg',fps=10,bps=10000)
     44 O.pause()
     45
.....................(continues).......................

I'm executing the code inside a folder that is on the desktop. I don't know if the problem could be related to the directory.

I have another issue. I'm wondering if it is possible to make snapshots and videos of a graph plotted with the command plot.addData. I'd like to have two different evolving videos, a first one from the simulation and a second one from the graph.
I'm not very practical about YADE so, please, I'd glad if you give me a very understandable answer. =)

Thank you!

Paolo

Question information

Language:
English Edit question
Status:
Expired
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#1

Hi,

 > I'm wondering if it is possible to make snapshots and videos of a graph plotted with the command plot.addData

Behind addData is just matplotlib, so you can just use standard 'save' functions from there. Something like
plt.savefig("snapshot"+str(O.iter)+".png")

Bruno

Revision history for this message
Jan Stránský (honzik) said :
#2

Hello,

> The error is something like :

please always provide as specific information as possible, not "something like", but the complete error [1].
I have tried the code, and the error says that the problem is at makeVideo function. The error message is a bit cryptic, but says something about mencoder (a linux external program). It was not installed on my system.
After
sudo apt install mencoder
the example works as expected

> It is as if the finish() function is not correctly read

is is read correctly, but the error is inside the function, so it exits at makeVideo, before executing O.pause()

> I'm wondering if it is possible to make snapshots and videos of a graph

For sure it is possible somehow, but **personally** I would do this in the post-processing stage.
One option is to use yade :-) loading the data in a cycle, in each cycle deleting the unwanted part, plot the desired data and save the figure.
Having series of pictures, making movie should be trivial.
(**personally** I would do also the graphics postprocessing externally in Paraview)

cheers
Jan

[1] https://www.yade-dem.org/wiki/Howtoask

Revision history for this message
Paolo (p4olo) said :
#3

Thank you guys, I'm making progress. I succeeded in collecting snapshots both from the simulation and the addData graph. I eventually downloaded mencoder and now everything works well.

Just one last thing. It happens that sometimes, during the simulation, the following error appears and stops the evolution of the plotted graph. The simulation goes on and I can collect the snapshots from it correctly, but the graph remains stuck. I cannot understand what it means.

In [1]: Unhandled exception in thread started by <function liveUpdate at 0x7f785b36e5d0>
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/usr/lib/x86_64-linux-gnu/yade/py/yade/plot.py in liveUpdate(timestamp)
    506 for ax in axes:
    507 try:
--> 508 ax.relim() # recompute axes limits
    509 ax.autoscale_view()
    510 except RuntimeError: pass # happens if data are being updated and have not the same dimension at the very moment

/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in relim(self, visible_only)
   1936 for line in self.lines:
   1937 if not visible_only or line.get_visible():
-> 1938 self._update_line_limits(line)
   1939
   1940 for p in self.patches:

/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.pyc in _update_line_limits(self, line)
   1799 Figures out the data limit of the given line, updating self.dataLim.
   1800 """
-> 1801 path = line.get_path()
   1802 if path.vertices.size == 0:
   1803 return

/usr/lib/python2.7/dist-packages/matplotlib/lines.pyc in get_path(self)
    955 """
    956 if self._invalidy or self._invalidx:
--> 957 self.recache()
    958 return self._path
    959

/usr/lib/python2.7/dist-packages/matplotlib/lines.pyc in recache(self, always)
    665 y = self._y
    666
--> 667 self._xy = np.column_stack(np.broadcast_arrays(x, y)).astype(float)
    668 self._x, self._y = self._xy.T # views
    669

/usr/lib/python2.7/dist-packages/numpy/lib/stride_tricks.pyc in broadcast_arrays(*args, **kwargs)
    247 args = [np.array(_m, copy=False, subok=subok) for _m in args]
    248
--> 249 shape = _broadcast_shape(*args)
    250
    251 if all(array.shape == shape for array in args):

/usr/lib/python2.7/dist-packages/numpy/lib/stride_tricks.pyc in _broadcast_shape(*args)
    182 # use the old-iterator because np.nditer does not handle size 0 arrays
    183 # consistently
--> 184 b = np.broadcast(*args[:32])
    185 # unfortunately, it cannot handle 32 or more arguments directly
    186 for pos in range(32, len(args), 31):

ValueError: shape mismatch: objects cannot be broadcast to a single shape

Thanks for helping me!
Cheers
Paolo

Revision history for this message
Launchpad Janitor (janitor) said :
#4

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Jan Stránský (honzik) said :
#5

it is some internal matplotlib error..
consider an "external" solution (e.g. gnuplot) for this purpose.
cheers
Jan