Exemplo n.º 1
0
def check_integrals():
    """Check that Sherpa normed models integrate to 1."""
    from sherpa.astro import ui
    from sherpa.astro.ui import normgauss2d
    from models import normdisk2d, normshell2d
    
    ui.clean()
    
    g = normgauss2d('g')
    g.xpos, g.ypos, g.ampl, g.fwhm = 100, 100, 42, 5
    
    d = normdisk2d('d')
    d.xpos, d.ypos, d.ampl, d.r0 = 100, 100, 42, 50
    
    s = normshell2d('s')
    s.xpos, s.ypos, s.ampl, s.r0, s.width = 100, 100, 42, 30, 20
    
    models = [g, d, s]
    
    ui.dataspace2d((200, 200))
    for model in models:
        ui.set_model(model)
        # In sherpa normed model values are flux per pixel area.
        # So to get the total flux (represented by the `ampl` parameter)
        # one can simply sum over all pixels, because a pixel has area 1 pix^2.
        # :-) 
        integral = ui.get_model_image().y.sum()
        print model.name, integral
Exemplo n.º 2
0
def check_integrals():
    """Check that Sherpa normed models integrate to 1."""
    from sherpa.astro import ui
    from sherpa.astro.ui import normgauss2d
    from models import normdisk2d, normshell2d

    ui.clean()

    g = normgauss2d('g')
    g.xpos, g.ypos, g.ampl, g.fwhm = 100, 100, 42, 5

    d = normdisk2d('d')
    d.xpos, d.ypos, d.ampl, d.r0 = 100, 100, 42, 50

    s = normshell2d('s')
    s.xpos, s.ypos, s.ampl, s.r0, s.width = 100, 100, 42, 30, 20

    models = [g, d, s]

    ui.dataspace2d((200, 200))
    for model in models:
        ui.set_model(model)
        # In sherpa normed model values are flux per pixel area.
        # So to get the total flux (represented by the `ampl` parameter)
        # one can simply sum over all pixels, because a pixel has area 1 pix^2.
        # :-)
        integral = ui.get_model_image().y.sum()
        print model.name, integral
Exemplo n.º 3
0
# In principle one might first want to fit the background amplitude. However the background estimation method already yields the correct normalization, so we freeze the background amplitude to unity instead of adjusting it. The (smoothed) residuals from this background model are then computed and shown.

# In[ ]:


sh.set_full_model(bkg)
bkg.ampl = 1
sh.freeze(bkg)


# In[ ]:


resid = Map.read("analysis_3d/counts_2D.fits")
resid.data = sh.get_data_image().y - sh.get_model_image().y
resid_smooth = resid.smooth(width=4)
resid_smooth.plot(add_cbar=True);


# ### Find and fit the brightest source
# We then find the position of the maximum in the (smoothed) residuals map, and fit a (symmetrical) Gaussian source with that initial position:

# In[ ]:


yp, xp = np.unravel_index(
    np.nanargmax(resid_smooth.data), resid_smooth.data.shape
)
ampl = resid_smooth.get_by_pix((xp, yp))[0]
Exemplo n.º 4
0
sh.set_stat("cash")
sh.set_method("simplex")
sh.load_image('../datasets/images/MSH15-52_counts.fits.gz')
sh.set_coord("logical")

sh.load_table_model("expo", "../datasets/images/MSH15-52_exposure.fits.gz")
sh.load_table_model("bkg", "../datasets/images/MSH15-52_background.fits.gz")
sh.load_psf("psf", "../datasets/images/MSH15-52_psf.fits.gz")

# In[54]:

sh.set_full_model(bkg)
bkg.ampl = 1
sh.freeze(bkg)

data = sh.get_data_image().y - sh.get_model_image().y
resid = SkyImage(data=data, wcs=ref_image.wcs)

resid_table = []  #Keep residual images in a list to show them later
resid_smo6 = resid.smooth(radius=6)
resid_smo6.plot(vmax=5, add_cbar=True)
resid_table.append(resid_smo6)

# In[55]:

maxcoord = resid_smo6.lookup_max()
maxpix = resid_smo6.wcs_skycoord_to_pixel(maxcoord[0])
print(maxcoord)
print(maxpix)
sh.set_full_model(
    bkg + psf(sh.gauss2d.g0) * expo)  # creates g0 as a gauss2d instance
Exemplo n.º 5
0
sh.load_table_model("expo", "G300-0_test_exposure.fits")
sh.load_table_model("bkg", "G300-0_test_background.fits")
sh.load_psf("psf", "G300-0_test_psf.fits")


# In principle one might first want to fit the background amplitude. However the background estimation method already yields the correct normalization, so we freeze the background amplitude to unity instead of adjusting it. The (smoothed) residuals from this background model are then computed and shown.

# In[3]:


sh.set_full_model(bkg)
bkg.ampl = 1
sh.freeze(bkg)

data = sh.get_data_image().y -  sh.get_model_image().y
resid = SkyImage(data=data, wcs=wcs)

resid_table = []  # Keep residual images in a list to show them later
resid_smo6 = resid.smooth(radius = 6)
resid_smo6.plot()
resid_table.append(resid_smo6)


# ### Find and fit the brightest source
# We then find the position of the maximum in the (smoothed) residuals map, and fit a (symmetrical) Gaussian source with that initial position:

# In[4]:


maxcoord = resid_smo6.lookup_max()