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

PSF model #2643

Merged
merged 36 commits into from
Feb 6, 2025
Merged

PSF model #2643

merged 36 commits into from
Feb 6, 2025

Conversation

ctoennis
Copy link
Contributor

I am adding PSF models to ctapipe.image.psf_model. I made a parent class called PSFModel and a PSF model based on pure coma abberation called ComaModel.

This will be used in the pointing calculation using star tracking and PSF fitting using stars.

@ctoennis ctoennis added enhancement module:calib issues related to ctapipe.calib new functionality labels Nov 10, 2024
@ctoennis ctoennis self-assigned this Nov 10, 2024
@ctoennis ctoennis requested review from maxnoe and kosack November 10, 2024 13:01
@kosack
Copy link
Contributor

kosack commented Nov 11, 2024

Quick question: are these models applicable for both gamma-ray and optical PSF? If not, maybe call it OpticalPSFModel to be more clear where it should be used.

@maxnoe
Copy link
Member

maxnoe commented Nov 11, 2024

I think this is purely optical, not IRF. Also, I think the appropriate place would be in ctapipe.instrument.optics

@ctoennis
Copy link
Contributor Author

Quick question: are these models applicable for both gamma-ray and optical PSF? If not, maybe call it OpticalPSFModel to be more clear where it should be used.

The model accounts for coma abbarations and the default parameters i have would be for photons in the optical range. With different parameters this should work with gamma photons, but i am not sure. I could call the ComeModel OpticalComaModel and keep the parent class as is. Then later models specifically for gamma photons can be added.

@ctoennis
Copy link
Contributor Author

I think this is purely optical, not IRF. Also, I think the appropriate place would be in ctapipe.instrument.optics

Makes sense. I will move it to optics.

@kosack
Copy link
Contributor

kosack commented Nov 11, 2024

Side note: we should check with what is used in SimPipe's instrument model, to ensure what is output here is compatible with what the simulations expect.

@maxnoe
Copy link
Member

maxnoe commented Nov 11, 2024

Side note: we should check with what is used in SimPipe's instrument model, to ensure what is output here is compatible with what the simulations expect.

I don't think there is a model like this in SimPipe, but @orelgueta or @GernotMaier can confirm. Rather coma is naturally resulting from the definition of the mirror facets.

@kosack
Copy link
Contributor

kosack commented Nov 11, 2024

I think the appropriate place would be in ctapipe.instrument.optics

The instrument module is where we define the InstrumentDescription model (which currently is collected under SubarrayDescription class here in ctapipe). Would be useful then to integrate it with the rest of the model, i.e. add a place for it in OpticsDescription, and add serialization so that it can be written and read. A collection of these could be serialized to a new table (one row per telescope), as we do with other OpticsDescription parts (SubarrayDescription.to_table(kind="optical_psf"), or else just in OpticsDescription... ) . That could be in another PR if you like, but in that case we should open an issue to make sure this new part of the model is properly integrated

Edit: to be more clear, I would expect something like this to work:

psf : Optional[PSFModel]  = subarray.tel[tel_id].optics.psf

if psf: 
     plot_psf(psf)  # some general function that plots any PSFModel

@ctoennis
Copy link
Contributor Author

I think the appropriate place would be in ctapipe.instrument.optics

The instrument module is where we define the InstrumentDescription model (which currently is collected under SubarrayDescription class here in ctapipe). Would be useful then to integrate it with the rest of the model, i.e. add a place for it in OpticsDescription, and add serialization so that it can be written and read. A collection of these could be serialized to a new table (one row per telescope), as we do with other OpticsDescription parts (SubarrayDescription.to_table(kind="optical_psf"), or else just in OpticsDescription... ) . That could be in another PR if you like, but in that case we should open an issue to make sure this new part of the model is properly integrated

Edit: to be more clear, I would expect something like this to work:

psf : Optional[PSFModel]  = subarray.tel[tel_id].optics.psf

if psf: 
     plot_psf(psf)  # some general function that plots any PSFModel

if it is okay then i will open an issue for this

@ctoennis
Copy link
Contributor Author

I think the appropriate place would be in ctapipe.instrument.optics

The instrument module is where we define the InstrumentDescription model (which currently is collected under SubarrayDescription class here in ctapipe). Would be useful then to integrate it with the rest of the model, i.e. add a place for it in OpticsDescription, and add serialization so that it can be written and read. A collection of these could be serialized to a new table (one row per telescope), as we do with other OpticsDescription parts (SubarrayDescription.to_table(kind="optical_psf"), or else just in OpticsDescription... ) . That could be in another PR if you like, but in that case we should open an issue to make sure this new part of the model is properly integrated
Edit: to be more clear, I would expect something like this to work:

psf : Optional[PSFModel]  = subarray.tel[tel_id].optics.psf

if psf: 
     plot_psf(psf)  # some general function that plots any PSFModel

if it is okay then i will open an issue for this

Here it is: #2647

@ctoennis ctoennis requested a review from kosack November 12, 2024 13:05
src/ctapipe/instrument/optics.py Outdated Show resolved Hide resolved
src/ctapipe/instrument/optics.py Outdated Show resolved Hide resolved
src/ctapipe/instrument/optics.py Outdated Show resolved Hide resolved
src/ctapipe/instrument/optics.py Outdated Show resolved Hide resolved
src/ctapipe/instrument/optics.py Outdated Show resolved Hide resolved
@mexanick
Copy link
Contributor

mexanick commented Feb 4, 2025

@maxnoe , continuing the discussion started in #2689 :

The parametrization in polar coordinates works well under assumption that the radial and polar components are independent, i.e. $\vec{r}\perp\vec{\phi}$. This breaks at low radii, that's why some workarounds were introduced. However, with the Cherenkov camera we are not that much interested in the stars images that close to the center of the camera (we need a lever arm and a larger light spread to obtain reasonable precision), that's why no particular attention was given to this kind of edge cases before. I agree that it looks a bit ugly, and a better parametrization can be considered, but I would propose to move on for the moment with this and add other parameterizations in the future as needed (there'll be need to do this anyway for double-mirror telescopes).

@maxnoe
Copy link
Member

maxnoe commented Feb 4, 2025

When evaluating at 0,0 I got a warning:

/home/maxnoe/Uni/CTA/ctapipe/src/ctapipe/instrument/optics.py:430: RuntimeWarning: invalid value encountered in scalar divide
  dphi = np.arcsin(chord_length / (2 * r0))

otherwise looks good

This comment has been minimized.

@maxnoe
Copy link
Member

maxnoe commented Feb 4, 2025

This comment has been minimized.

@mexanick
Copy link
Contributor

mexanick commented Feb 4, 2025

The math does not render properly: https://ctapipe--2643.org.readthedocs.build/en/2643/api/ctapipe.instrument.ComaPSFModel.html#ctapipe.instrument.ComaPSFModel

this is fixed now. The only thing, is that there's an autosummary for the attributes, so the documentation for them is basically repeated twice. Also, the init docstring is ignored. Any suggestion on what to do with this? Shall I remove the Attributes summary from the class-level docstring and add there what's in the init's one?

This comment has been minimized.

@maxnoe
Copy link
Member

maxnoe commented Feb 4, 2025

Also, the init docstring is ignored

Yes, documentation should be in the class docstring, not __init__. Add the Parameters section to the class docstring

This comment has been minimized.

maxnoe
maxnoe previously approved these changes Feb 4, 2025
@mexanick
Copy link
Contributor

mexanick commented Feb 6, 2025

@kosack can you please take a look? I shouldn't participate in the review any further as I've contributed to the code.

src/ctapipe/instrument/optics.py Outdated Show resolved Hide resolved
src/ctapipe/instrument/optics.py Outdated Show resolved Hide resolved
src/ctapipe/instrument/optics.py Outdated Show resolved Hide resolved

This comment has been minimized.

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.

Copy link

Passed

Analysis Details

0 Issues

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

Coverage and Duplications

  • Coverage 98.80% Coverage (94.20% 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 717699c into main Feb 6, 2025
13 checks passed
@maxnoe maxnoe deleted the PSFModel branch February 6, 2025 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants