Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyplotImageViewer delays Experiment execution #402

Open
MarcusZuber opened this issue Apr 27, 2017 · 1 comment
Open

PyplotImageViewer delays Experiment execution #402

MarcusZuber opened this issue Apr 27, 2017 · 1 comment
Assignees

Comments

@MarcusZuber
Copy link
Member

When a PyPlotImageViewer is attached to an experiment the frame-rate drops. As far as I understood, the PyplotImageViewer should drop frames when the drawing of an old frame is not yet finished.

Example:

from concert.experiments.base import Acquisition, Experiment
from concert.experiments.addons import Consumer
from concert.devices.cameras.dummy import Camera
from concert.ext.viewers import PyplotImageViewer
from concert.quantities import q

class MyExp(Experiment):
   def __init__(self):
      from concert.experiments.base import Acquisition, Experiment
      acq = Acquisition("img", self.take_frames)
      Experiment.__init__(self, [acq])

   def take_frames(self):
      import numpy as np
      from time import time
      start = time()
      for i in range(100):
         yield np.zeros((2048, 2048))
      print time()-start

exp = MyExp()
viewer = PyplotImageViewer()
live_view = Consumer(exp.acquisitions,viewer)

Running exp.run() like this gives me 1.24s. If I detatch the live_view I get 0.0125s.
I tested it on my local machine (no ssh x-forwarding).

Can I somehow make the PyplotImageViewer less blocking? Also the asyncronous ImageWriter delays the acquisition (until now usually less than a frame with 15fps and 2k x 2k pixels). Is it possible to speed up the whole addon-consumer-pipeline?

@tfarago I thinkt this is also related to the delay that we had (have) with the pco.4000

@tfarago
Copy link
Contributor

tfarago commented Apr 28, 2017

I have very inconsistent results with np.zeros. To me it seems that sometimes python optimizes that just for array reservation and sometimes it really allocates zeros. Try the following:

class MyExp(Experiment):
   def __init__(self, num_iterations=30, create_new=True):
      acq = Acquisition("img", self.take_frames)
      Experiment.__init__(self, [acq])
      self.num_iterations = num_iterations
      self.create_new = create_new

   def take_frames(self):
      start = time()
      create_duration = 0
      im = np.zeros((2048, 2048))

      for i in range(self.num_iterations):
        create_st = time()
        if self.create_new:
            im = np.random.normal(size=(2048, 2048))
        create_duration += time() - create_st
        yield im

      print 'Creation duration:', create_duration
      print ' Overall duration:', time() - start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants