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

Change API of ImageCleaner to be __call__(self, event: ArrayEvent) #2015

Closed
maxnoe opened this issue Jul 14, 2022 · 8 comments · Fixed by #2511
Closed

Change API of ImageCleaner to be __call__(self, event: ArrayEvent) #2015

maxnoe opened this issue Jul 14, 2022 · 8 comments · Fixed by #2511

Comments

@maxnoe
Copy link
Member

maxnoe commented Jul 14, 2022

Please describe the use case that requires this feature.
Currently, the ImageCleaner has the API of __call__(self, tel_id, image, peak_time).
For more advanced cleaning methods that e.g. require monitoring information about the current NSB / pedestal variation, it is impossible to use this information.

Describe the solution you'd like

Also switch to __call__(self, event) so the cleaning algorithms can access all relevant information.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context

E.g. LSTs cleaning is using a factor of the pedestal standard deviation as a lower bound for the cleaning threshold.

@maxnoe
Copy link
Member Author

maxnoe commented Jul 14, 2022

Side note, I think this shows again that we should Invert the in memory container hierarchy as discussed in #1165 to have

ArrayEvent
    TelescopeEvent
         r1
         dl1
         dl2
         mon

Instead of telescope maps for each data level.

@kosack
Copy link
Contributor

kosack commented Oct 19, 2022

I don't really like passing too much info to low-level algorithms as it makes it hard to follow what they actually use, and the code becomes needsly confusing (this was one of the "lessons learned" we tried to avoid in ctapipe). Since I think pedestal variances are clearly useful for image cleaning, I would prefer just to pass those to all image cleaners explicitly in ImageProcessor.

for the discussion about the array structure, see #1165

@maxnoe
Copy link
Member Author

maxnoe commented May 16, 2023

I think it is important here to make a difference between low-level code in small, self-contained functions with well-defined inputs and outputs and processing components that need to be flexible to allow access to more information that might be needed and which we currently do not anticipate.

E.g. the low-level tail_cuts_clean function would stay as it is, but the Component should get the ArrayEvent (or TelescopeEvent once we implement what is proposed in CEP 2 / #1165) so that the levels can be adapted to the monitoring info before passing to the tailcuts clean.

We have seen time and again, that more information becomes useful or is needed and expanding the API every time that happens is I think worse than just providing the high level API with the full event container.

@maxnoe
Copy link
Member Author

maxnoe commented May 16, 2023

See also comment in this issue which I closed as duplicate of this one:
#2331 (comment)

@kosack
Copy link
Contributor

kosack commented May 22, 2023

There was a reason it was implemented this way: reusability. The idea was that you might have an ImageCleaner component in multiple places, for example inside the TwoPassImageExtractor, inside the DataVolumeReducer and later (as now) inside the ImageProcessor. Each would get it's image and peak time from a different place, so it was cleaner (no pun intended) to not hard-code that in the __call__ method.

You can of course still use low-level versions of those in each place, but having a configurable algorithm has advantanges: e.g. we could study which cleaning method works best for DVR without having to change the code, or even use different methods for different cameras/telescopes

@maxnoe
Copy link
Member Author

maxnoe commented May 23, 2023

You are now arguing some hypothetical use cases against a real one that was brought up multiple times.

A usecase that is so important to e.g. the analysis of LST commissioning data, that lack of support for it prevents moving to using the ctapipe tools for the analysis.

We need to enable this.

Since the components can be configured, I don't see a reason why we can't add the needed configuration options needed for the use cases you mentioned even if we change to the more general API.

Another possibility would be to have two public methods in ImageCleaner: __call__(self, ArrayEvent) and a lower-level clean(tel_id, image, peak_time).

@HealthyPear
Copy link
Member

Regarding #2331, would it be possible to temporarily add a MAGICCleaner under ctapipe/image/cleaning.py which does not inherit from ImageCleaner and gets called with the event container?

In this way, we ensure that the current structure of ctapipe cleaning API does not get modified yet, but we allow MAGIC people to update their code bases with more recent versions of ctapipe (I guess we can assume that a hypothetical MAGICCleaner is used only by MAGIC-related projects for now).

Then when this issue gets closed you would only need to change the class parent (I am assuming very lightly).

@aleberti
Copy link

Any update on this? Now magic-cta-pipe moved to ctapipe v0.19, and I would really like to be able to move to use ctapipe tools for the pipeline, at least at the low level. Right now I am still stuck because I cannot implement the MAGIC cleaning inheriting directly from ImageCleaner. If there is another solution, of course let me know.

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

Successfully merging a pull request may close this issue.

4 participants