def get_model_radius(model):
    """
    extracts radius for extended source
    :param model: ~gammalib.GModelSky
    :return: radius: float
    """
    try:
        if model.spatial().type() == 'DiffuseMapCube':
            # region not implemented in gammalib, extract manually extent of the map
            # call the energies method to load the cube
            model.spatial().energies()
            # half size along x direction
            slice = model.spatial().cube().extract(0)
            ctr_pix = gammalib.GSkyPixel((slice.nx() - 1) / 2,
                                         (slice.ny() - 1) / 2)
            ctr_dir = slice.pix2dir(ctr_pix)
            bor_pix = gammalib.GSkyPixel(0., (slice.ny() - 1) / 2)
            bor_dir = slice.pix2dir(bor_pix)
            radius = bor_dir.dist_deg(ctr_dir)
        else:
            circle = gammalib.GSkyRegionCircle(model.spatial().region())
            radius = circle.radius()
    except:
        print('Cannot extract radius for model {} with spatial model type {}'.
              format(model.name(),
                     model.spatial().type()))
    return radius
def plot_map(inmap, sub, smooth=0.0):
    """
    Plot Aitoff map

    Parameters
    ----------
    inmap : `~gammalib.GSkyMap()`
        Input sky map
    sub : pyplot
        Frame for map
    smooth : float, optional
        Map smoothing parameter (deg)
    """
    # Optionally smooth map
    if smooth > 0.0:
        map = inmap.copy()
        map.smooth('GAUSSIAN', smooth)
    else:
        map = inmap

    # Create array from skymap
    array = []
    v_max = 0.0
    for iy in range(map.ny()):
        row = []
        for ix in range(map.nx()):
            index = ix + iy * map.nx()
            value = map[index]
            row.append(value)
        array.append(row)

    # Get skymap boundaries
    ra_min = map.pix2dir(gammalib.GSkyPixel(0.0, map.ny() / 2)).ra_deg()
    ra_max = map.pix2dir(gammalib.GSkyPixel(map.nx(), map.ny() / 2)).ra_deg()
    dec_min = map.pix2dir(gammalib.GSkyPixel(map.nx() / 2, 0)).dec_deg()
    dec_max = map.pix2dir(gammalib.GSkyPixel(map.nx() / 2, map.ny())).dec_deg()
    aspect = abs((ra_max - ra_min) / (dec_max - dec_min))
    aspect = 1.0

    # Show Aitoff projection
    c = sub.imshow(array,
                   extent=(ra_min, ra_max, dec_min, dec_max),
                   cmap=plt.get_cmap('jet'),
                   aspect=aspect)
    cbar = plt.colorbar(c, orientation='vertical', shrink=0.9)
    sub.set_xlabel('Right Ascension (deg)', fontsize=14)
    sub.set_ylabel('Declination (deg)', fontsize=14)

    # Set range
    sub.set_xlim([ra_min, ra_max])
    sub.set_ylim([dec_min, dec_max])

    # Return
    return
示例#3
0
def plot_obsdef(obsdef):
    """
    Plot observation definition dictionary

    Parameters
    ----------
    obsdef : list of dict
        List of pointing definitions
    """
    # Create figure
    fig = plt.figure('Map', (20,3))
    fig.subplots_adjust(left=0.05, right=0.98, top=0.98, bottom=0.02)
    sub = plt.subplot()

    # Create map from observation definition dictionary
    map = set_map(obsdef)

    # Create array from skymap
    array = []
    v_max = 0.0
    for iy in range(map.ny()):
        row = []
        for ix in range(map.nx()):
            index = ix+(map.ny()-iy-1)*map.nx()
            value = map[index]
            row.append(value)
        array.append(row)

    # Get skymap boundaries
    lon_min = map.pix2dir(gammalib.GSkyPixel(0.0,map.ny()/2)).l_deg()
    lon_max = map.pix2dir(gammalib.GSkyPixel(map.nx(),map.ny()/2)).l_deg()
    lat_min = map.pix2dir(gammalib.GSkyPixel(map.nx()/2,0)).b_deg()
    lat_max = map.pix2dir(gammalib.GSkyPixel(map.nx()/2,map.ny())).b_deg()
    aspect  = abs((lon_max-lon_min)/(lat_max-lat_min))

    # Show Aitoff projection
    c    = sub.imshow(array, extent=(lon_min,lon_max,lat_min,lat_max),
                      cmap=plt.get_cmap('jet'))
    cbar = plt.colorbar(c, orientation='horizontal', shrink=0.2)
    sub.set_xlabel('Longitude (deg)', fontsize=14)
    sub.set_ylabel('Latitude (deg)', fontsize=14)

    # Show map
    plt.show()

    # Return
    return
def get_model_dir(model):
    """
    extracts sky direction for either analytical model or DiffuseMap
    :param model: ~gammalib.GModelSky
    :return: src_dir: ~gammalib.GSkyDir
    """
    if model.spatial().type() == 'DiffuseMap':
        # retrieve direction from map
        src_dir = model.spatial().region().centre()
    elif model.spatial().type() == 'DiffuseMapCube':
        # region does not work, extract manually from the map
        # call the energies method to load the cube
        model.spatial().energies()
        # assume it is center of the map
        sl = model.spatial().cube().extract(0)
        ctr_pix = gammalib.GSkyPixel((sl.nx() - 1) / 2, (sl.ny() - 1) / 2)
        src_dir = sl.pix2dir(ctr_pix)
    else:
        # retrieve direction from analytical model
        src_dir = model.spatial().dir()
    return src_dir
示例#5
0
def plot_map(inmap, sub, smooth=0.0):
    """
    Plot sky map

    Parameters
    ----------
    inmap : `~gammalib.GSkyMap()`
        Input sky map
    sub : pyplot
        Frame for map
    smooth : float, optional
        Map smoothing parameter (degrees)
    """
    # Optionally smooth map
    if smooth > 0.0:
        map = inmap.copy()
        map.smooth('GAUSSIAN', smooth)
    else:
        map = inmap

    # Create array from skymap
    array = []
    v_max = 0.0
    for iy in range(map.ny()):
        row = []
        for ix in range(map.nx()):
            index = ix + (map.ny() - iy - 1) * map.nx()
            value = map[index] - 10
            if value < 0:
                value = 0
            row.append(value)
        array.append(row)

    # Get skymap boundaries
    ra_min = map.pix2dir(gammalib.GSkyPixel(0.0, map.ny() / 2)).ra_deg()
    ra_max = map.pix2dir(gammalib.GSkyPixel(map.nx(), map.ny() / 2)).ra_deg()
    dec_min = map.pix2dir(gammalib.GSkyPixel(map.nx() / 2, 0)).dec_deg()
    dec_max = map.pix2dir(gammalib.GSkyPixel(map.nx() / 2, map.ny())).dec_deg()
    ra_min -= 83.63
    ra_max -= 83.63
    dec_min -= 22.015
    dec_max -= 22.015
    aspect = abs((ra_max - ra_min) / (dec_max - dec_min))

    # Show Aitoff projection
    c = sub.imshow(array,
                   extent=(ra_min, ra_max, dec_min, dec_max),
                   cmap=plt.get_cmap('jet'),
                   aspect=aspect)
    sub.set_xlim([ra_min, ra_max])
    sub.set_ylim([dec_min, dec_max])
    sub.set_xlabel('Right Ascension + 83.63 (deg)', fontsize=14)
    sub.set_ylabel('Declination + 22.015 (deg)', fontsize=14)

    # Set ticks
    for tick in sub.xaxis.get_major_ticks():
        tick.label.set_fontsize(14)
    for tick in sub.yaxis.get_major_ticks():
        tick.label.set_fontsize(14)
    sub.xaxis.set_ticks_position('both')
    sub.yaxis.set_ticks_position('both')

    # Return
    return