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 PSFMap class #1432

Merged
merged 22 commits into from Jul 10, 2018

Conversation

2 participants
@registerrier
Contributor

registerrier commented Jun 18, 2018

This PR adds a function to project a gammapy.irf.PSF3D on a gammapy.map.
It also adds a class to work with the resulting Map to extract an gammapy.irf.EnergyDependentTablePSF at any position or to produce a PSF kernel following the implementation of PR #1388.
The complete computation of a PSFMap for a collection of observation has to be performed on a higher level maker class. This will be added in a coming PR.

@registerrier registerrier self-assigned this Jun 18, 2018

@registerrier registerrier added this to To do in Map analysis via automation Jun 18, 2018

@registerrier registerrier added this to the 0.8 milestone Jun 18, 2018

@registerrier registerrier requested review from cdeil and adonath Jun 18, 2018

@cdeil cdeil referenced this pull request Jun 19, 2018

Closed

Add a PSF map kernel class #1388

@cdeil

@registerrier - Thanks!

I've left some inline comments.

More generally, I think extending the class-level docstring a bit to describe what this is would be useful.
An example code snippet how to make one of those things in an Examples section is always gold for users and developers, because then they can just copy & paste that and start to learn / try out a new class in ipython / Jupyter. In this case it could be possible to read a CTA PSF IRF and make such a map with ~ 5 lines?

The other main comment I have is the name. You called the class PSFMap. But is is not a map. It has a map. Looking at how this is used then from callers, you get code like in your test:

pmap = PSFMap(psfmap)

It's easy to be confused in calling code what the "psf_map" and the "pmap" are, no?
As you've probably seen in
https://github.com/gammapy/gammapy/pull/1388/files#diff-cde80870ee7dc037d5c9a8863a870762R15
I put "kernel" in the class name, because for me a fundamental difference wrt the IRF classes is that those represent probability density functions, but this is a discretised probability mass function, i.e. what is commonly called a "kernel".
Suggest to avoid the use of "Map" in the class name here to avoid confusion.

@@ -0,0 +1,189 @@
import numpy as np

This comment has been minimized.

@cdeil

cdeil Jun 19, 2018

Member

For new files, always add the two boilerplate lines at the top: license and future inits (copy from any other file).
Same for the new test file you're adding here.

@cdeil

cdeil Jun 19, 2018

Member

For new files, always add the two boilerplate lines at the top: license and future inits (copy from any other file).
Same for the new test file you're adding here.

This comment has been minimized.

@registerrier

registerrier Jun 19, 2018

Contributor

Done

@registerrier

registerrier Jun 19, 2018

Contributor

Done

Show outdated Hide outdated gammapy/cube/psf_map.py
Show outdated Hide outdated gammapy/cube/psf_map.py
Show outdated Hide outdated gammapy/cube/psf_map.py
Show outdated Hide outdated gammapy/cube/psf_map.py
Show outdated Hide outdated gammapy/cube/psf_map.py
Show outdated Hide outdated gammapy/cube/psf_map.py
Parameters
----------
fraction : float
the containment fraction (a positive number <=1). Default 0.68.

This comment has been minimized.

@cdeil

cdeil Jun 19, 2018

Member

Add empty line before Returns section.

@cdeil

cdeil Jun 19, 2018

Member

Add empty line before Returns section.

This comment has been minimized.

@registerrier

registerrier Jul 4, 2018

Contributor

Done

@registerrier

registerrier Jul 4, 2018

Contributor

Done

Show outdated Hide outdated gammapy/cube/tests/test_psf_map.py
Show outdated Hide outdated gammapy/cube/psf_map.py
@registerrier

This comment has been minimized.

Show comment
Hide comment
@registerrier

registerrier Jun 19, 2018

Contributor

Regarding the name, indeed PSFMapis not very satisfactory since it is not a Map. Yet the only thing it contains is a Map. The class mostly provides convenience methods to interact with the map of PSFs, such as the extraction of an EnergyDependentTablePSFat any position. A possibility could be to have only functions taking the actual Map as argument. But this seemed an easier solution for users.

Making an inheritance on Map did not seem like a good idea since the Map could be an WcsNDMapor an HpxNDMap and it is expected to have specific axes.

This object does not contain kernels a priori, but can be used to create them. It could be called PSFKernelMaker or PSFKernelFactory or?

What we are doing here is really to create and handle maps of IRFs (here PSF but the approach would be nearly identical for Edisp). So PSFMapHandler could be a better name?

Contributor

registerrier commented Jun 19, 2018

Regarding the name, indeed PSFMapis not very satisfactory since it is not a Map. Yet the only thing it contains is a Map. The class mostly provides convenience methods to interact with the map of PSFs, such as the extraction of an EnergyDependentTablePSFat any position. A possibility could be to have only functions taking the actual Map as argument. But this seemed an easier solution for users.

Making an inheritance on Map did not seem like a good idea since the Map could be an WcsNDMapor an HpxNDMap and it is expected to have specific axes.

This object does not contain kernels a priori, but can be used to create them. It could be called PSFKernelMaker or PSFKernelFactory or?

What we are doing here is really to create and handle maps of IRFs (here PSF but the approach would be nearly identical for Edisp). So PSFMapHandler could be a better name?

@cdeil

This comment has been minimized.

Show comment
Hide comment
@cdeil

cdeil Jun 19, 2018

Member

@registerrier - You're right. I was confusing this PSFMap object with what I started to implement in #1388, a real PSF kernel array where I also used a Map object to hold it.

I'm afraid I'm out of good ideas concerning the name. Maybe leave as-is? I certainly didn't want to suggest changing to subclassing or something like that, I was just confused about what this is and was thinking if there is a better name.

Member

cdeil commented Jun 19, 2018

@registerrier - You're right. I was confusing this PSFMap object with what I started to implement in #1388, a real PSF kernel array where I also used a Map object to hold it.

I'm afraid I'm out of good ideas concerning the name. Maybe leave as-is? I certainly didn't want to suggest changing to subclassing or something like that, I was just confused about what this is and was thinking if there is a better name.

@registerrier registerrier moved this from To do to In progress in Map analysis Jun 20, 2018

@cdeil

Some quick comments inline.
I'll try this out locally now ...

Show outdated Hide outdated gammapy/cube/tests/test_psf_map.py
Show outdated Hide outdated gammapy/cube/psf_map.py

@cdeil cdeil assigned cdeil and unassigned registerrier Jul 10, 2018

@cdeil

cdeil approved these changes Jul 10, 2018

@cdeil

This comment has been minimized.

Show comment
Hide comment
@cdeil

cdeil Jul 10, 2018

Member

@registerrier - Thanks!

Member

cdeil commented Jul 10, 2018

@registerrier - Thanks!

@cdeil cdeil merged commit 2f9afdf into gammapy:master Jul 10, 2018

0 of 2 checks passed

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details

Map analysis automation moved this from In progress to Done Jul 10, 2018

@cdeil cdeil changed the title from Add functions and class to work with PSFs with gammapy.maps to Add PSFMap class Aug 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment