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

Directly return peak position from neighbor average waveform #1914

Merged
merged 1 commit into from
May 24, 2022

Conversation

maxnoe
Copy link
Member

@maxnoe maxnoe commented May 23, 2022

This is a small change to not compute the full array of average neighbor waveforms for each pixel and then in a separate numpy call calculate the peak position but do it directly in the same numba function.

This reduces memory usage and call overhead, runtime is divided in half from 800 to 400 µs for this test case:

import numpy as np
from ctapipe.instrument import TelescopeDescription, SubarrayDescription
import astropy.units as u
from ctapipe.image.extractor import NeighborPeakWindowSum
from timeit import repeat


tel = TelescopeDescription.from_name('LST', 'LSTCam')
geom = tel.camera.geometry
subarray = SubarrayDescription(
    'perf',
    tel_positions={1: [0, 0, 0] * u.m},
    tel_descriptions={1: tel},
)


extractor = NeighborPeakWindowSum(subarray)

waveforms = np.random.normal(size=(geom.n_pixels, 40)).astype('float32')
selected_gain_channels = np.zeros(geom.n_pixels, dtype=int)


# number_of_islands(geom, mask)
code = '''
extractor(waveforms, 1, selected_gain_channels)
'''

exec(code)

N = 200
times = np.array(repeat(code, number=N, repeat=10, globals=globals()))
print(f'{np.mean(times / N) * 1e6:.2f} ± {np.std(times / N) * 1e6:.2f} µs')

@maxnoe maxnoe linked an issue May 23, 2022 that may be closed by this pull request
@codecov
Copy link

codecov bot commented May 23, 2022

Codecov Report

Merging #1914 (c733f01) into master (b11ce6c) will increase coverage by 0.04%.
The diff coverage is 66.66%.

@@            Coverage Diff             @@
##           master    #1914      +/-   ##
==========================================
+ Coverage   92.05%   92.09%   +0.04%     
==========================================
  Files         189      189              
  Lines       14872    14872              
==========================================
+ Hits        13691    13697       +6     
+ Misses       1181     1175       -6     
Impacted Files Coverage Δ
ctapipe/image/__init__.py 100.00% <ø> (ø)
ctapipe/image/extractor.py 83.39% <28.57%> (+0.25%) ⬆️
ctapipe/image/tests/test_extractor.py 100.00% <100.00%> (ø)
ctapipe/conftest.py 94.23% <0.00%> (ø)
ctapipe/io/tests/conftest.py 100.00% <0.00%> (ø)
ctapipe/io/tests/test_prod2.py 100.00% <0.00%> (ø)
ctapipe/tools/tests/test_tools.py 100.00% <0.00%> (ø)
ctapipe/io/tests/test_datawriter.py 100.00% <0.00%> (ø)
ctapipe/tools/tests/test_process.py 95.27% <0.00%> (ø)
ctapipe/io/tests/test_eventseeker.py 98.11% <0.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b11ce6c...c733f01. Read the comment docs.

@maxnoe maxnoe requested a review from LukasNickel May 24, 2022 10:17
@maxnoe maxnoe merged commit 2bb0950 into master May 24, 2022
@maxnoe maxnoe deleted the neighbor_perf branch May 24, 2022 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SImplify neighbor extractor by directly calculating peak position
3 participants