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 function to compute bias and resolution from energy dispersion #144

Merged
merged 1 commit into from Apr 26, 2021

Conversation

maxnoe
Copy link
Member

@maxnoe maxnoe commented Mar 23, 2021

No description provided.

@codecov
Copy link

codecov bot commented Mar 23, 2021

Codecov Report

Merging #144 (6d9da0e) into master (aa63141) will decrease coverage by 2.39%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #144      +/-   ##
==========================================
- Coverage   87.35%   84.95%   -2.40%     
==========================================
  Files          38       38              
  Lines        1329     1363      +34     
==========================================
- Hits         1161     1158       -3     
- Misses        168      205      +37     
Impacted Files Coverage Δ
pyirf/benchmarks/__init__.py 100.00% <100.00%> (ø)
pyirf/benchmarks/energy_bias_resolution.py 50.00% <100.00%> (-43.11%) ⬇️
pyirf/benchmarks/tests/test_bias_resolution.py 58.69% <100.00%> (-41.31%) ⬇️

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 aa63141...6d9da0e. Read the comment docs.

Copy link
Member

@HealthyPear HealthyPear left a comment

Choose a reason for hiding this comment

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

for the on-axis case we shouldn't expect big differences

I think doing this from the IRF instead of from the events themselves is more general and the energy benchmarks (meaning res and bias) would get the validation from the IRF indirectly

perhaps (apart from the ED comparison) we could think of dump the old function in favor of this one

pyirf/benchmarks/energy_bias_resolution.py Show resolved Hide resolved
@maxnoe
Copy link
Member Author

maxnoe commented Mar 29, 2021

@HealthyPear I don't really see a reason to dump the old function, both are fine and needed I'd say.

@HealthyPear HealthyPear added benchmarking Content related to internal or external benchmarking enhancement New feature or request labels Apr 9, 2021
@HealthyPear HealthyPear added this to In progress in Next release via automation Apr 9, 2021
Next release automation moved this from In progress to Reviewer approved Apr 16, 2021
bias = np.zeros((n_energy_bins, n_fov_bins))
resolution = np.zeros((n_energy_bins, n_fov_bins))

for energy_bin in range(n_energy_bins):
Copy link

@adonath adonath Apr 16, 2021

Choose a reason for hiding this comment

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

The only way I have found in Gammapy to avoid the loop is the "brute-force" approach of finding the closest corresponding value: compute the cdf and setup an ND interpolator, evaluate the cdf on a finer grid, with the precision you require and then use np.argmin(cdf_fine - value, axis=) to find the closest value along the given axis. The resulting ND implementation uses a lot numpy broadcasting, see https://github.com/gammapy/gammapy/blob/master/gammapy/irf/psf/core.py#L53, for a similar problem. I'm not sure whether it is more efficient in the end, but the solution is at least ND and does not rely on the hard-coded loops over the other dimensions. Not sure I would recommend it though...

Copy link

Choose a reason for hiding this comment

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

I just remember @registerrier implemented an ND solution, based on np.nditer() for a similar problem to avoid the hard-coded Python loops here: https://github.com/gammapy/gammapy/blob/master/gammapy/stats/counts_statistic.py#L42 Might be useful as well..

Copy link

@adonath adonath Apr 16, 2021

Choose a reason for hiding this comment

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

The advantage of the first solution is that it fully supports numpy broadcasting. So something like this:

containment = np.array([0.68, 80, 90])
energy_true = [1, 3, 10, 30, 100] * u.TeV
offset = [0.5, 1] * u.deg

psf.containment_radius(
    containment=containment.reshape((-1, 1, 1)),
    energy_true=energy_true.reshape((1, -1, 1)),
    offset=offset.reshape((1, 1,- 1))
)

Returns the expected broad-casted result. Not sure it's needed here but in general it's nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

@adonath Thanks a lot!

@maxnoe maxnoe merged commit 0cb53db into master Apr 26, 2021
Next release automation moved this from Reviewer approved to Done Apr 26, 2021
@maxnoe maxnoe deleted the bias_resolution_from_irf branch April 26, 2021 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
benchmarking Content related to internal or external benchmarking enhancement New feature or request
Projects
Next release
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants