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 TablePSF and Fermi PSF #84

Merged
merged 23 commits into from May 26, 2014

Conversation

Projects
None yet
3 participants
@cdeil
Member

cdeil commented Mar 16, 2014

@adonath The Fermi PSF is given as a 1-dim radial density distribution P(r) where r is the offset to the center.

Is there a utility function to turn this into a 2-dim astropy kernel and / or model, so that it can be used for convolution / fitting?

If not, can you write it or do you have any pointers how I could implement this?

cc @ellisowen (needs convolution with the Fermi PSF to compute model images)

@cdeil cdeil added this to the 0.1 milestone Feb 20, 2014

@cdeil cdeil added feature labels Feb 20, 2014

@adonath

This comment has been minimized.

Show comment
Hide comment
@adonath

adonath Feb 21, 2014

Member

@ellisowen
There is no explicit utility function for this, but it can be done,
with a bit more effort, as following (See "Example Convolution II") :

http://nbviewer.ipython.org/github/adonath/gamma_astropy_talk/blob/master/gamma_astropy_talk.ipynb?create=1

But this is only possible for the convolution kernels. If you want to
fit the model, it is more complicated,
because you still can't add or combine models. I think the only way is,
to implement the model yourself from the scratch,
because there is no custom_model_2d decorator also.
Here is a tutorial for 1D models (Section "A step by step definition of
a 1D Gaussian model")

http://astropy.readthedocs.org/en/latest/modeling/new.html

For 2D models it works the same, except that you derive from
"Parametric2DModel". There are a lot of examples in the source code.
If you have the model ready, you can use "Model2DKernel" to derive a
kernel for convolution from it.

Am Do 20 Feb 2014 23:19:52 CET schrieb Christoph Deil:

@adonath https://github.com/adonath The Fermi PSF
https://gammapy.readthedocs.org/en/latest/api/gammapy.morphology.fermi_psf.FermiPSF.html
is given as a 1-dim radial density distribution |P(r)| where |r| is
the offset to the center.

Is there a utility function to turn this into a 2-dim astropy kernel
and / or model, so that it can be used for convolution / fitting?

If not, can you write it or do you have any pointers how I could
implement this?

cc @ellisowen https://github.com/ellisowen (needs convolution with
the Fermi PSF to compute model images)


Reply to this email directly or view it on GitHub
#84.

Member

adonath commented Feb 21, 2014

@ellisowen
There is no explicit utility function for this, but it can be done,
with a bit more effort, as following (See "Example Convolution II") :

http://nbviewer.ipython.org/github/adonath/gamma_astropy_talk/blob/master/gamma_astropy_talk.ipynb?create=1

But this is only possible for the convolution kernels. If you want to
fit the model, it is more complicated,
because you still can't add or combine models. I think the only way is,
to implement the model yourself from the scratch,
because there is no custom_model_2d decorator also.
Here is a tutorial for 1D models (Section "A step by step definition of
a 1D Gaussian model")

http://astropy.readthedocs.org/en/latest/modeling/new.html

For 2D models it works the same, except that you derive from
"Parametric2DModel". There are a lot of examples in the source code.
If you have the model ready, you can use "Model2DKernel" to derive a
kernel for convolution from it.

Am Do 20 Feb 2014 23:19:52 CET schrieb Christoph Deil:

@adonath https://github.com/adonath The Fermi PSF
https://gammapy.readthedocs.org/en/latest/api/gammapy.morphology.fermi_psf.FermiPSF.html
is given as a 1-dim radial density distribution |P(r)| where |r| is
the offset to the center.

Is there a utility function to turn this into a 2-dim astropy kernel
and / or model, so that it can be used for convolution / fitting?

If not, can you write it or do you have any pointers how I could
implement this?

cc @ellisowen https://github.com/ellisowen (needs convolution with
the Fermi PSF to compute model images)


Reply to this email directly or view it on GitHub
#84.

@cdeil

This comment has been minimized.

Show comment
Hide comment
@cdeil

cdeil Feb 21, 2014

Member

Let's forget about fitting for the moment, what we really need at the moment is a 2D Kernel so that we can compute PSF-convolved model images.

Just to make sure I understand correctly ... given a 1-dim function

def f(r):
    return (some function of r)

I first have to create a Parametric2DModel calling f(r) for f = sqrt(x^2 + y^2) and then I can pass that to the Model2DKernel constructor.

It seems there should be a utility function or class (e.g. CustomRadialKernel) that does this, no?
@adonath Can you quickly write this or should I just do this for this specific case as described above today?

Member

cdeil commented Feb 21, 2014

Let's forget about fitting for the moment, what we really need at the moment is a 2D Kernel so that we can compute PSF-convolved model images.

Just to make sure I understand correctly ... given a 1-dim function

def f(r):
    return (some function of r)

I first have to create a Parametric2DModel calling f(r) for f = sqrt(x^2 + y^2) and then I can pass that to the Model2DKernel constructor.

It seems there should be a utility function or class (e.g. CustomRadialKernel) that does this, no?
@adonath Can you quickly write this or should I just do this for this specific case as described above today?

@adonath

This comment has been minimized.

Show comment
Hide comment
@adonath

adonath Feb 21, 2014

Member

Yes, that's correct. But I think much more useful than a CustomRadialKernel would be to have the custom_model_2d decorator. Which would solve both problems (see astropy/astropy#1763). The difference is just one line of code: Defining the astropy.model.

If you just want the Fermi PSF you can take the example from the notebook I linked above.
It works, because you can add kernels, but not models. Or is the PSF model different?

# Lets try to model the Fermi PSF with astropy
from numpy import pi
from astropy.modeling.models import Beta2D
from astropy.convolution import Model2DKernel

# Define core and tail parameters
# Values are taken from: 
# http://fermi.gsfc.nasa.gov/ssc/data/analysis/documentation/Cicerone/Cicerone_LAT_IRFs/IRF_PSF.html
f_core = 0.05
sigma_core, sigma_tail = 0.5399, 1.063
gamma_core, gamma_tail = 2.651, 2.932

A_core = 1 / (2 * pi * sigma_core ** 2) * (1 - 1 / gamma_core)
A_tail = 1 / (2 * pi * sigma_tail ** 2) * (1 - 1 / gamma_tail)
psf_core = Beta2D(A_core, 0, 0, 2 * gamma_core * sigma_core ** 2, gamma_core)
psf_tail = Beta2D(A_tail, 0, 0, 2 * gamma_tail * sigma_tail ** 2, gamma_tail)

# Define PSF kernel
psf_kernel = f_core * Model2DKernel(psf_core, x_size=91) + (1 - f_core) * Model2DKernel(psf_tail, x_size=91)
Member

adonath commented Feb 21, 2014

Yes, that's correct. But I think much more useful than a CustomRadialKernel would be to have the custom_model_2d decorator. Which would solve both problems (see astropy/astropy#1763). The difference is just one line of code: Defining the astropy.model.

If you just want the Fermi PSF you can take the example from the notebook I linked above.
It works, because you can add kernels, but not models. Or is the PSF model different?

# Lets try to model the Fermi PSF with astropy
from numpy import pi
from astropy.modeling.models import Beta2D
from astropy.convolution import Model2DKernel

# Define core and tail parameters
# Values are taken from: 
# http://fermi.gsfc.nasa.gov/ssc/data/analysis/documentation/Cicerone/Cicerone_LAT_IRFs/IRF_PSF.html
f_core = 0.05
sigma_core, sigma_tail = 0.5399, 1.063
gamma_core, gamma_tail = 2.651, 2.932

A_core = 1 / (2 * pi * sigma_core ** 2) * (1 - 1 / gamma_core)
A_tail = 1 / (2 * pi * sigma_tail ** 2) * (1 - 1 / gamma_tail)
psf_core = Beta2D(A_core, 0, 0, 2 * gamma_core * sigma_core ** 2, gamma_core)
psf_tail = Beta2D(A_tail, 0, 0, 2 * gamma_tail * sigma_tail ** 2, gamma_tail)

# Define PSF kernel
psf_kernel = f_core * Model2DKernel(psf_core, x_size=91) + (1 - f_core) * Model2DKernel(psf_tail, x_size=91)
@cdeil

This comment has been minimized.

Show comment
Hide comment
@cdeil

cdeil Feb 21, 2014

Member

@adonath No, this Fermi PSF model is not exactly what we need.

I think I can implement what we need tomorrow ... will ask again if I don't understand something about astropy kernels.

Member

cdeil commented Feb 21, 2014

@adonath No, this Fermi PSF model is not exactly what we need.

I think I can implement what we need tomorrow ... will ask again if I don't understand something about astropy kernels.

@cdeil cdeil added the easy label Feb 25, 2014

@cdeil cdeil assigned ellisowen and unassigned ellisowen May 2, 2014

@cdeil cdeil self-assigned this May 26, 2014

@cdeil cdeil removed easy labels May 26, 2014

@cdeil cdeil changed the title from Compute 2-dim kernel image for 1-dim radial distribution to Implement TablePSF and Fermi PSF May 26, 2014

cdeil added a commit that referenced this pull request May 26, 2014

Merge pull request #84 from cdeil/fermi_psf
Implement TablePSF and Fermi PSF

@cdeil cdeil merged commit 6f5ba1e into gammapy:master May 26, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details

@cdeil cdeil deleted the cdeil:fermi_psf branch May 26, 2014

cdeil pushed a commit to cdeil/gammapy that referenced this pull request Jul 18, 2014

@cdeil cdeil changed the title from Implement TablePSF and Fermi PSF to Add TablePSF and Fermi PSF Apr 8, 2015

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