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

Add iterative tailcuts cleaning variant #2329

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

clara-escanuela
Copy link
Contributor

This would be my approach for Issue #2326

@clara-escanuela clara-escanuela changed the title Issue #2326 Proposing a small change to tailcuts cleaning May 11, 2023
@kosack
Copy link
Contributor

kosack commented May 11, 2023

I'd suggest making this a separate cleaning function, rather than modifying TailCuts (which has already been modified so many times that it hardly looks simple anymore). Since tailcuts is the default algorithm, it's best to keep it simple. Another possibility is to make this algorithm call the tailcuts function, rather than modify it. That might require a small modification, but better than adding a loop to tailcuts_clean where there wasn't one before.

You will also need to add a new ImageCleaner subclass.

@Hckjs
Copy link
Contributor

Hckjs commented May 15, 2023

Maybe also have a look at this part of the VolumeReducer, i think its quite similar. Maybe you can write a function used in both classes?

@clara-escanuela
Copy link
Contributor Author

Maybe also have a look at this part of the VolumeReducer, i think its quite similar. Maybe you can write a function used in both classes?

That would make sense I think. Or can we somehow alter the "dilate" function so that it has the option to only dilate pixels above certain threshold?

@clara-escanuela
Copy link
Contributor Author

I think it is better to just add it as an extra cleaning method, otherwise dilate would not be so general and more input parameters would be required

@clara-escanuela
Copy link
Contributor Author

By the way, what is the reason for CI / docs to fail? The error message is not so clear to me and I am curious as this is also happening in my other PR

@maxnoe maxnoe changed the title Proposing a small change to tailcuts cleaning Add iterative tailcuts cleaning variant Sep 27, 2023
ctapipe/image/cleaning.py Outdated Show resolved Hide resolved
ctapipe/image/cleaning.py Outdated Show resolved Hide resolved
ctapipe/image/cleaning.py Outdated Show resolved Hide resolved
# AND have any neighbor that is in the picture
pixels_above_boundary = image >= boundary_thresh

for count in range(max_iter):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we both complained that this is a new cleaning method, not just tailcuts,but in the end the code is nearly 99% copied from tailcuts. So maybe:

  1. we reconsider and just add an iteration option to tailcuts_clean (even if it's a bit ugly and probably breaks processing all events at once)
  2. factor out the common code in both functions to a separate function that can be called by tailcuts_clean and tailcuts_hysteresis_clean
  3. keep as is, but have lots of code duplication and the very real posisbility of forgetting to fix bugs in multiple places.

@maxnoe what do you think?

pixels_above_boundary & pixels_with_picture_neighbors
) | pixels_in_picture
else:
pixels_with_boundary_neighbors = geom.neighbor_matrix_sparse.dot(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move this out of the loop because it is a constant

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this will gain you a bit of speed as well, since pixels_above_boundary is not changing, there is no need to do the dot-product each time

Copy link

codecov bot commented Jan 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8d61c03) 92.47% compared to head (0fa134b) 92.49%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2329      +/-   ##
==========================================
+ Coverage   92.47%   92.49%   +0.02%     
==========================================
  Files         234      234              
  Lines       19965    20020      +55     
==========================================
+ Hits        18462    18517      +55     
  Misses       1503     1503              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Successfully merging this pull request may close these issues.

5 participants