-
Notifications
You must be signed in to change notification settings - Fork 77
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
Add a display module to save images and video of events #726
base: main
Are you sure you want to change the base?
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Codecov Report
@@ Coverage Diff @@
## master #726 +/- ##
==========================================
+ Coverage 85.75% 85.88% +0.13%
==========================================
Files 78 78
Lines 6619 6645 +26
==========================================
+ Hits 5676 5707 +31
+ Misses 943 938 -5
Continue to review full report at Codecov.
|
Hi, Is this the code to create the videos send around by @moralejo? If yes, great job! Looking at the code, I think this needs a lot of cleanup though, to be useful for inclusion in lstchain. To be included in the library for example means that we cannot just change the script to change input values. We need to use the configuration system for this, and for example give input / output files on the command line or as configuration. Also, matplotlib can be more efficient and directly store videos, when you use the Here is a script I wrote a while ago for creating a video of a single event using the ctapipe configuration system (a from ctapipe.visualization import CameraDisplay
from ctapipe.coordinates import TelescopeFrame
from ctapipe.io import EventSource
from ctapipe.calib import CameraCalibrator
from ctapipe.core import Tool
from ctapipe.core.traits import Float, Path, Int
import matplotlib.pyplot as plt
import astropy.units as u
import numpy as np
from matplotlib.animation import FuncAnimation
from tqdm import tqdm
class ShowerAnimation(Tool):
tel_id = Int(default_value=1, help="Telescope to show").tag(config=True)
output = Path(help="Output file").tag(config=True)
fps = Float(default_value=10, help="FPS for the final video").tag(config=True)
aliases = {
('i', 'input'): 'EventSource.input_url',
('o', 'output'): 'ShowerAnimation.output',
}
def setup(self):
self.source = EventSource(
parent=self,
allowed_tels={self.tel_id, }
)
self.subarray = self.source.subarray
self.cam = self.subarray.tel[self.tel_id].camera.geometry
# self.calib = CameraCalibrator(self.subarray)
self.event = next(iter(self.source))
self.r1 = self.event.r1.tel[self.tel_id].waveform
self.frames = self.r1.shape[1]
# figsize / dpi will make FullHD video
self.fig = plt.figure(figsize=(19.2, 10.8), dpi=100)
self.ax = self.fig.add_axes([0, 0, 1, 1])
self.ax.set_axis_off()
self.disp = CameraDisplay(self.cam, cmap='inferno')
self.disp.add_colorbar()
self.progress = tqdm(total=self.frames)
def init_ani(self):
self.disp.image = self.r1[:, 0]
self.disp.set_limits_minmax(self.r1.min(), self.r1.max())
return self.disp.pixels,
def update_ani(self, frame):
self.progress.update(1)
self.disp.image = self.r1[:, frame]
return self.disp.pixels,
def start(self):
ani = FuncAnimation(
fig=self.fig,
func=self.update_ani,
init_func=self.init_ani,
frames=self.frames,
interval=1000 / self.fps,
)
ani.save(self.output, fps=self.fps, dpi=100)
# plt.show()
if __name__ == '__main__':
ShowerAnimation().run() You can find more about how the config system and the tools work here: |
Thanks for the feedback @maxnoe. Certainly the code can be simplified and improved. About matplotlib's FuncAnimation, @maxnoe what do you mean? The class is being used already, right? |
Sorry, didn't see it. I ony saw the different |
Hi @moralejo , @maxnoe, thanks for the suggestions. Also if is there something at the code to be optimised always it could be changed, the parts at the code are separated and commented. |
A module (
event_displayer.py
) to filter events, and calibrate and save images and video of the events. There is also a notebook (example_event_displayer.ipynb
) with an explanation and examples of how it works.