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

on_pixel_picked function of interactive CameraDisplay gets called for all displays #2355

Closed
kosack opened this issue Jun 19, 2023 · 1 comment · Fixed by #2358
Closed

on_pixel_picked function of interactive CameraDisplay gets called for all displays #2355

kosack opened this issue Jun 19, 2023 · 1 comment · Fixed by #2358
Labels

Comments

@kosack
Copy link
Contributor

kosack commented Jun 19, 2023

Describe the bug

As found by Vincent:

When multiple CameraDisplays are plotted on different Axis objects, each with a registered "pick_event" callback, they all seem to respond to the same "pick_event", so clicking one display moves the selected pixel on the other and the callback is called once per instance.

They should be independent.

To Reproduce

from ctapipe.visualization import CameraDisplay
from ctapipe.instrument import CameraGeometry

import matplotlib.pyplot as plt

class MyCameraDisplay(CameraDisplay):
   def on_pixel_clicked(self, pix_id):
       print(f"MyCamera: {pix_id=} has value {self.image[pix_id]:.2f}")

fig, ax = plt.subplots(2,2)
geom = CameraGeometry.from_name("NectarCam")

disp1 = MyCameraDisplay(geom, ax=ax[0,0])
disp1.enable_pixel_picker()
disp2 = MyCameraDisplay(geom, ax=ax[0,1])
disp2.enable_pixel_picker()

plt.show()

When clicking a pixel in either CameraDisplay, both get updated and the on_pixel_picked() method gets called twice

Expected behavior

Each display can be clicked independently

Supporting information
If applicable, add screenshots, logs, or a traceback to help illustrate the bug.

Additional context

The relevant line is probably:

self.axes.figure.canvas.mpl_connect("pick_event", self._on_pick)

Which should set the callback on this instance, not in general.

@kosack kosack added the bug label Jun 19, 2023
@maxnoe
Copy link
Member

maxnoe commented Jun 19, 2023

I think I already commented somewhere, that we should have enable_pixel_picker take a callback function, not via the currently intended inheritance

This would also solve this issue

@maxnoe maxnoe linked a pull request Jun 20, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants