shape2.lat0.fix = True

shape2.radius = 0.63 * u.degree
shape2.radius.fix = True
shape2.radius.max_value = 0.63 * u.degree

lm = Model(source, source2, source3)
bin_list  =  "1c 1d 1e 1f 2c 2d 2e 2f 3c 3d 3e 3f 4c 4d 4e 4f 4g 5e 5f 5g 5h 6e 6f 6g 6h 7f 7g 7h 7i 8g 8h 8i 8j 9g 9h 9i 9j 9k 9l".split()


ra, dec = 307.17, 41.17
#data_radius = 6.0
model_radius = 8.0


fits_roi = HealpixMapROI(ra = ra, dec = dec, model_radius=model_radius, roifile="roi.fits")
hawc = HAL("HAWC", maptree, response,fits_roi)
hawc.set_active_measurements(bin_list=bin_list)
#hawc.display()

# Double check the free parameters
print("Likelihood model:\n")
print(lm)


# Set up the likelihood and run the fit
print("Performing likelihood fit...\n")
datalist = DataList(hawc)
jl = JointLikelihood(lm, datalist, verbose=True)
jl.set_minimizer("ROOT")
param_df, like_df = jl.fit()
Exemple #2
0
def test_healpixRoi(geminga_maptree, geminga_response):

    #test to make sure writing a model with HealpixMapROI works fine
    ra, dec = 101.7, 16.
    data_radius = 9.
    model_radius = 24.

    m = np.zeros(hp.nside2npix(NSIDE))
    vec = Sky2Vec(ra, dec)
    m[hp.query_disc(NSIDE,
                    vec, (data_radius * u.degree).to(u.radian).value,
                    inclusive=False)] = 1

    #hp.fitsfunc.write_map("roitemp.fits" , m, nest=False, coord="C", partial=False, overwrite=True )

    map_roi = HealpixMapROI(data_radius=data_radius,
                            ra=ra,
                            dec=dec,
                            model_radius=model_radius,
                            roimap=m)
    #fits_roi = HealpixMapROI(data_radius=data_radius, ra=ra, dec=dec, model_radius=model_radius, roifile="roitemp.fits")
    hawc = HAL("HAWC", geminga_maptree, geminga_response, map_roi)
    hawc.set_active_measurements(1, 9)
    '''
  Define model: Two sources, 1 point, 1 extended

  Same declination, but offset in RA

  Different spectral idnex, but both power laws
  '''
    pt_shift = 3.0
    ext_shift = 2.0

    # First soource
    spectrum1 = Powerlaw()
    source1 = PointSource("point",
                          ra=ra + pt_shift,
                          dec=dec,
                          spectral_shape=spectrum1)

    spectrum1.K = 1e-12 / (u.TeV * u.cm**2 * u.s)
    spectrum1.piv = 1 * u.TeV
    spectrum1.index = -2.3

    spectrum1.piv.fix = True
    spectrum1.K.fix = True
    spectrum1.index.fix = True

    # Second source
    shape = Gaussian_on_sphere(lon0=ra - ext_shift, lat0=dec, sigma=0.3)
    spectrum2 = Powerlaw()
    source2 = ExtendedSource("extended",
                             spatial_shape=shape,
                             spectral_shape=spectrum2)

    spectrum2.K = 1e-12 / (u.TeV * u.cm**2 * u.s)
    spectrum2.piv = 1 * u.TeV
    spectrum2.index = -2.0

    spectrum2.piv.fix = True
    spectrum2.K.fix = True
    spectrum2.index.fix = True

    shape.lon0.fix = True
    shape.lat0.fix = True
    shape.sigma.fix = True

    model = Model(source1, source2)

    hawc.set_model(model)

    # Write the model map
    model_map_tree = hawc.write_model_map("test.hd5", test_return_map=True)

    # Read the model back
    hawc_model = map_tree_factory('test.hd5', map_roi)

    # Check written model and read model are the same
    check_map_trees(hawc_model, model_map_tree)

    os.remove("test.hd5")
Exemple #3
0
def test_rois():

    #test to make sure ConeROI and MapROI with a simple, circular active region return the same active pixels.

    ra, dec = 100, 30
    data_radius = 10
    model_radius = 15

    cone_roi = HealpixConeROI(data_radius=data_radius,
                              model_radius=model_radius,
                              ra=ra,
                              dec=dec)

    m = np.zeros(hp.nside2npix(NSIDE))
    vec = Sky2Vec(ra, dec)
    m[hp.query_disc(NSIDE,
                    vec, (data_radius * u.degree).to(u.radian).value,
                    inclusive=False)] = 1

    hp.fitsfunc.write_map("roitemp.fits",
                          m,
                          nest=False,
                          coord="C",
                          partial=False,
                          overwrite=True)

    map_roi = HealpixMapROI(data_radius=data_radius,
                            ra=ra,
                            dec=dec,
                            model_radius=model_radius,
                            roimap=m)
    fits_roi = HealpixMapROI(data_radius=data_radius,
                             ra=ra,
                             dec=dec,
                             model_radius=model_radius,
                             roifile="roitemp.fits")

    assert np.all(
        cone_roi.active_pixels(NSIDE) == map_roi.active_pixels(NSIDE))
    assert np.all(
        fits_roi.active_pixels(NSIDE) == map_roi.active_pixels(NSIDE))

    os.remove("roitemp.fits")
    #test that all is still good after saving the ROIs to dictionaries and restoring.
    cone_dict = cone_roi.to_dict()
    map_dict = map_roi.to_dict()
    fits_dict = fits_roi.to_dict()

    cone_roi2 = get_roi_from_dict(cone_dict)
    map_roi2 = get_roi_from_dict(map_dict)
    fits_roi2 = get_roi_from_dict(fits_dict)

    assert np.all(
        cone_roi2.active_pixels(NSIDE) == map_roi.active_pixels(NSIDE))
    assert np.all(
        fits_roi2.active_pixels(NSIDE) == map_roi.active_pixels(NSIDE))
    assert np.all(
        map_roi2.active_pixels(NSIDE) == map_roi.active_pixels(NSIDE))
Exemple #4
0
shape2.lat0.fix = True

shape2.radius = 0.63 * u.degree
shape2.radius.fix = True
shape2.radius.max_value = 0.63 * u.degree

lm = Model(source, source2, source3)
bin_list = "1c 1d 1e 1f 2c 2d 2e 2f 3c 3d 3e 3f 4c 4d 4e 4f 4g 5e 5f 5g 5h 6e 6f 6g 6h 7f 7g 7h 7i 8g 8h 8i 8j 9g 9h 9i 9j 9k 9l".split(
)

ra, dec = 307.17, 41.17
#data_radius = 6.0
model_radius = 8.0

fits_roi = HealpixMapROI(ra=ra,
                         dec=dec,
                         model_radius=model_radius,
                         roifile="roi_6aroundcocoon_nomasking.fits")
hawc = HAL("HAWC", maptree, response, fits_roi)
hawc.set_active_measurements(bin_list=bin_list)
#hawc.display()

# Double check the free parameters
print("Likelihood model:\n")
print(lm)

# Set up the likelihood and run the fit
print("Performing likelihood fit...\n")
datalist = DataList(hawc)
jl = JointLikelihood(lm, datalist, verbose=True)
jl.set_minimizer("ROOT")
param_df, like_df = jl.fit()