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

fwhm, rise/fall time #2151

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

Conversation

clara-escanuela
Copy link
Contributor

No description provided.

@clara-escanuela clara-escanuela linked an issue Dec 5, 2022 that may be closed by this pull request
ctapipe/image/extractor.py Outdated Show resolved Hide resolved
ctapipe/image/extractor.py Outdated Show resolved Hide resolved
ctapipe/image/extractor.py Outdated Show resolved Hide resolved
@kosack
Copy link
Contributor

kosack commented Dec 6, 2022

a good unit test here might be to cross-check with scipy.signal.peak_widths (which I think only works for 1D signals and is not very fast):

width, width_height, l_ips, r_ips = peak_widths(
    signal,
    peaks=[peak,],
    rel_height=0.5,
)

Just a quick test on some waveforms shows the scipy function works reasonably well, as long as the peak is not at the edges:
image

@clara-escanuela
Copy link
Contributor Author

Alternatively to this implementation for fwhm, one could do the same as for time over threshold with a slightly worst result but quicker and maybe interpolate before.

@clara-escanuela clara-escanuela marked this pull request as ready for review May 19, 2023 21:15
ctapipe/image/extractor.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 15, 2024

Codecov Report

Attention: 46 lines in your changes are missing coverage. Please review.

Comparison is base (017aec3) 92.55% compared to head (766d061) 92.32%.
Report is 1 commits behind head on main.

Files Patch % Lines
ctapipe/image/extractor.py 8.00% 46 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2151      +/-   ##
==========================================
- Coverage   92.55%   92.32%   -0.23%     
==========================================
  Files         234      234              
  Lines       20006    20073      +67     
==========================================
+ Hits        18516    18532      +16     
- Misses       1490     1541      +51     

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

kosack
kosack previously approved these changes Jan 18, 2024
Copy link
Contributor

@kosack kosack left a comment

Choose a reason for hiding this comment

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

Looks fine. In a future PR, we can add it perhaps as an optional output of the ImageExtractors, so if enabled, you get images of t_rise, t_fall, and t_over_threshold.

ctapipe/image/extractor.py Outdated Show resolved Hide resolved
@clara-escanuela
Copy link
Contributor Author

Do you know why some tests, unrelated to the implementation, are failing?

@kosack
Copy link
Contributor

kosack commented Jan 22, 2024

Do you know why some tests, unrelated to the implementation, are failing?

Yes, it's due to a change in scikit learn that causes a problem with astropy. @maxnoe opened a PR to fix it, so shortly you should be able to just merge or rebase the main branch and your tests should pass again. #2496 Feel free to review it! We need a second reviewer to commit (and it's a minimal change)...

nopython=True,
cache=True,
)
def time_parameters(waveform, fwhm_arr, rise_time_arr, fall_time_arr):
Copy link
Member

Choose a reason for hiding this comment

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

I think this new method is missing in __all__ at the top.


"""
peak_index = np.argmax(waveform)
amplitude = np.max(waveform)
Copy link
Member

Choose a reason for hiding this comment

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

This is wasteful, you don't need to find the maximum again, just do amplitude = waveform[peak_index]

rt_10 = ti - (ampl_10percent - yi) / (yj - yi)

fwhm = 0.0
if None not in (fwhm_right, fwhm_left):
Copy link
Member

Choose a reason for hiding this comment

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

You initialize these two with np.nan above, so None will never be in (fwhm_right, fwhm_left).

I think you can just subtract the two anyways, and the result will be nan if either is nan. Check if there is a warning and maybe silence it in case we don't want to have a warning like "invalid valid encountered in subtract".

fwhm = fwhm_right - fwhm_left

rise_time = 0.0
if None not in (rt_90, rt_10):
Copy link
Member

Choose a reason for hiding this comment

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

Same as above with the other if

rise_time = rt_90 - rt_10

fall_time = 0.0
if None not in (ft_90, ft_10):
Copy link
Member

Choose a reason for hiding this comment

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

Same as above with the other if

fall_time_arr[0] = fall_time


def time_over_threshold(waveforms, thr):
Copy link
Member

Choose a reason for hiding this comment

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

Technically, this is "samples above threshold", for "time over threshold you would have to divide by the sampling frequency.

Copy link
Member

@maxnoe maxnoe left a comment

Choose a reason for hiding this comment

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

See inline comments

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.

FWHM
4 participants