Skip to content

Muon fit chord length fix#2803

Merged
maxnoe merged 32 commits into
mainfrom
muon_fit_chord_length_fix
Aug 15, 2025
Merged

Muon fit chord length fix#2803
maxnoe merged 32 commits into
mainfrom
muon_fit_chord_length_fix

Conversation

@burmist-git
Copy link
Copy Markdown
Member

Modified the chord_length function to fix a bug. It now filters out non-physical solutions for chodr vs phi.
Updated the test for chord_length calculation in the muon intensity fitter. It now checks that no non-physical solutions are returned (more details in here : issue #2760).

…itter. It now checks that no non-physical solutions are returned.
@burmist-git
Copy link
Copy Markdown
Member Author

#2760 (comment)

@ctao-dpps-sonarqube

This comment has been minimized.

1 similar comment
@ctao-dpps-sonarqube

This comment has been minimized.

Comment thread docs/changes/2803.bugfix.rst Outdated
rho = 3
phi = np.deg2rad(180)
length = chord_length(radius, rho, phi)
assert np.isclose(length, 0, atol=1e-15)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

according to sonar, these two lines are not covered by tests:

        if np.abs(phi) < np.arcsin(1.0 / rho):
            chord = 2 * radius * np.sqrt(chord)

Please check and ensure this is covered by proper tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These two lines are fully covered by this test. If you remove this check, the test will fail. Please have a look—I removed this check, and the test failed on my laptop.
image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

your test verifies the part when condition np.abs(phi) < np.arcsin(1.0 / rho) is not met, but looks like it doesn't check when it is met.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Okay, values where rho is greater than 1 and phi is 0 can be included

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You have four cases in the function: no chord, a muon outside of the circle, and two cases for muon inside the circle. All of them have to be tested. Also, border cases (e.g. a hit straight in the center) and at the tangentially with φ=π/2 could be interesting to test. as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes and now we have 4 tests :
image

Two inside and two outside

Comment thread src/ctapipe/image/muon/intensity_fitter.py
@ctao-dpps-sonarqube

This comment has been minimized.

@ctao-dpps-sonarqube

This comment has been minimized.

@ctao-dpps-sonarqube

This comment has been minimized.

@ctao-dpps-sonarqube

This comment has been minimized.

@ctao-dpps-sonarqube

This comment has been minimized.

@ctao-dpps-sonarqube

This comment has been minimized.

Comment thread src/ctapipe/image/muon/intensity_fitter.py
@ctao-dpps-sonarqube

This comment has been minimized.

@ctao-dpps-sonarqube

This comment has been minimized.

@mexanick
Copy link
Copy Markdown
Contributor

I'm not sure why the sonar coverage is ill-computed... @kosack @maxnoe any idea? Could it be a consequence of a transfer to the new sonar instance?

@burmist-git I compiled the documentation and discovered that no sphinx doc is produced for the the module-level functions in the ctapipe.image.muon.intensity_fitter module. Please fix this by:

  • add in __all__ all the functions that aren't private
  • Update module-level docstring (I believe it is outdated)
  • perhaps something else I missed - please verify that the doc assembles correctly

Also I noticed the a couple of warnings like the following one, all in the ctapipe.image.muon.ring_fitter module:

UserWarning: potentially wrong underline length... 
Returns 
-------- in 
Perform a circle fit to ``image`` with the chosen ``fit_method``.
... in the docstring of __call__ in /ctapipe/src/ctapipe/image/muon/ring_fitter.py.

Please fix them too.

@ctao-dpps-sonarqube

This comment has been minimized.

@mexanick mexanick requested review from maxnoe and mexanick August 14, 2025 12:19
@ctao-dpps-sonarqube

This comment has been minimized.

mexanick
mexanick previously approved these changes Aug 14, 2025
@maxnoe
Copy link
Copy Markdown
Member

maxnoe commented Aug 15, 2025

@burmist-git sorry, I discussed with @mexanick offline and we agreed that the docs should stay and it's the correct workaround for an issue with numba: numba/numba#5755

Could you revert the last two commits? This will also fix the ci

@burmist-git
Copy link
Copy Markdown
Member Author

@maxnoe Sure, I can do that. The only remaining question is the directory of chord_length.rst. It was here: docs/api-reference/image/chord_length.rst, but it probably should be here: docs/api-reference/image/muon/chord_length.rst.

@maxnoe
Copy link
Copy Markdown
Member

maxnoe commented Aug 15, 2025

The only remaining question is the directory

There currently is no muon subdirectory in the documentation, everything is flat in image in files, so it's fine. Maybe call the file muon_chord_length.rst to make it clearer.

@ctao-dpps-sonarqube

This comment has been minimized.

mexanick
mexanick previously approved these changes Aug 15, 2025
@maxnoe
Copy link
Copy Markdown
Member

maxnoe commented Aug 15, 2025

Ah, sorry, misread the commits.

@maxnoe
Copy link
Copy Markdown
Member

maxnoe commented Aug 15, 2025

You need to change the entry in the toc in docs/api-reference/image/muon.rst to take the changed name into account.

Edit: done now

Comment thread docs/api-reference/image/muon.rst Outdated
Copy link
Copy Markdown
Member Author

@burmist-git burmist-git left a comment

Choose a reason for hiding this comment

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

change the name of the rts file

@burmist-git
Copy link
Copy Markdown
Member Author

burmist-git commented Aug 15, 2025

@maxnoe The only valid option for me was to review changes, could not apply them.
All is done than :
image

@ctao-dpps-sonarqube
Copy link
Copy Markdown

Failed

  • 53.30% Coverage on New Code (is less than 80.00%)

Analysis Details

0 Issues

  • Bug 0 Bugs
  • Vulnerability 0 Vulnerabilities
  • Code Smell 0 Code Smells

Coverage and Duplications

  • Coverage 53.30% Coverage (94.30% Estimated after merge)
  • Duplications 0.00% Duplicated Code (0.70% Estimated after merge)

Project ID: cta-observatory_ctapipe_AY52EYhuvuGcMFidNyUs

View in SonarQube

@maxnoe maxnoe merged commit cc9c770 into main Aug 15, 2025
12 of 13 checks passed
@burmist-git burmist-git deleted the muon_fit_chord_length_fix branch August 16, 2025 09:11
@maxnoe maxnoe mentioned this pull request Oct 24, 2025
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.

4 participants