Example #1
0
def makeSkyMap(samples, lmax, nside=32, tex=True, psrs=None):
    if tex == True:
        plt.rcParams['text.usetex'] = True

    #nside=32
    npix = hp.nside2npix(nside)   # number of pixels total

    # initialize theta and phi map coordinantes
    skypos=[]
    for ii in range(npix):
        skypos.append(np.array(hp.pix2ang(nside,ii)))
    
    skypos = np.array(skypos)

    harmvals = utils.SetupSkymapPlottingGrid(lmax,skypos)

    if np.atleast_2d(samples).shape[0]>1:
        samples = np.mean(samples, axis=0)
        samples = np.append(2.*np.sqrt(np.pi), samples)

    pwr = utils.GWpower(samples, harmvals)

    ax = plt.subplot(111, projection='astro mollweide')
    ax.grid()
    plot.outline_text(ax)
    plot.healpix_heatmap(pwr[::-1])
    plt.colorbar(orientation='horizontal')
    plt.suptitle(r'$\langle P_{\mathrm{GWB}}(-\hat\Omega)\rangle$', y=0.1)
    #plt.suptitle(r'$P_{\mathrm{GWB}}^{\mathrm{ML}}(-\hat\Omega)$', y=0.1)

    # add pulsars locations
    if psrs is not None:
        ax.plot(psrs[:,0], psrs[:,1], '*', color='w', markersize=6, mew=1, mec='w')
Example #2
0
def makeSkyMap(samples, lmax, nside=16, psrs=None, cmap='YlOrBr'):

    # number of pixels total
    npix = hp.nside2npix(nside)

    # initialize theta and phi map coordinantes
    skypos=[]
    for ii in range(npix):
        skypos.append(np.array(hp.pix2ang(nside,ii)))

    skypos = np.array(skypos)
    harmvals = PALutils.SetupSkymapPlottingGrid(lmax,skypos)

    pwr = []
    for ii in range(len(samples)):
        samples_tot = np.append(2.*np.sqrt(np.pi), samples[ii])
        gwp = PALutils.GWpower(samples_tot, harmvals)
        pwr.append(gwp)

    pwr = np.array(pwr)
    pwr = np.mean(pwr, axis=0)

    ax = plt.subplot(111, projection='astro mollweide')
    ax.grid()
    plot.outline_text(ax)
    plot.healpix_heatmap(pwr, cmap=cmap)
    plt.colorbar(orientation='horizontal')

    # add pulsars locations
    if np.all(psrs):
        ax.plot(psrs[:,0], psrs[:,1], '*', color='w', markersize=6, mew=1, mec='w')

    return pwr
Example #3
0
def plotSkyMap(raSample, decSample, nside=64, contours=None, colorbar=True, \
              inj=None, psrs=None, cmap='YlOrBr', outfile='skymap.pdf'):
    """

    Plot Skymap of chain samples on Mollwiede projection.

    @param raSample: Array of right ascension samples
    @param decSample: Array of declination  samples
    @param nside: Number of pixels across equator [default = 64]
    @param contours: Confidence contours to draw eg. 68%, 95% etc
                     By default this is set to none and no contours
                     will be drawn.
    @param colorbar: Boolean option to draw colorbar [default = True]
    @param inj: list of injected values [ra, dec] in radians to plot
                [default = None]
    @param psrs: Stacked array of pulsar sky locations [ra, dec] in radians
                 [default=None] Will plot as white diamonds

    """

    # clear figures
    plt.clf()

    # create stacked array of ra and dec
    skypos = np.column_stack([raSample, decSample])

    npix = hp.nside2npix(nside)    # number of pixels total


    # initialize theta and phi map coordinantes
    skycarts=[]
    for ii in range(npix):
        skycarts.append(np.array(hp.pix2vec(nside,ii)))

    # get skymap values from greedy binning algorithm
    skymap = greedy_bin_sky(skypos, skycarts)

    # smooth skymap
    skymap = hp.smoothing(skymap, sigma=0.02)

    # make plot
    ax = plt.subplot(111, projection='astro mollweide')

    # Add contours
    if contours is not None:
        for percent in contours:
            indices = np.argsort(-skymap)
            sky = skymap[indices]
            region = np.zeros(skymap.shape)
            ind = np.min(ml.find(np.cumsum(sky) >= 0.01*percent))
            region[indices[0:ind]] = 1.0
            cs = plot.contour(lambda lon, lat: region[hp.ang2pix(nside, 0.5*np.pi - lat, lon)], \
                          colors='k', linewidths=1.0, levels=[0.5])
            #plt.clabel(cs, [0.5], fmt={0.5: '$\mathbf{%d\%%}$' % percent}, fontsize=8, inline=True)

    # plot map
    ax.grid()
    plot.outline_text(ax)
    plot.healpix_heatmap(skymap, cmap=cmap)

    # add injection
    if inj:
        ax.plot(inj[0], inj[1], 'x', color='k', markersize=8, mew=2, mec='k')

    # add pulsars
    if np.all(psrs):
        ax.plot(psrs[:,0], psrs[:,1], '*', color='lime', markersize=8, mew=1, mec='k')

    # add colorbar and title
    if colorbar:
        plt.colorbar(orientation='horizontal')
        plt.suptitle(r'$p(\alpha,\delta|d)$', y=0.1)

    # save skymap
    plt.savefig(outfile, bbox_inches='tight')
Example #4
0
def plotSkyMap(raSample, decSample, nside=16, contours=None, colorbar=True, \
              inj=None, psrs=None, smooth=True, smoothsigma=0.1, cmap='YlOrBr',
               outfile='skymap.pdf', color='k'):
    """

    Plot Skymap of chain samples on Mollwiede projection.

    @param raSample: Array of right ascension samples
    @param decSample: Array of declination  samples
    @param nside: Number of pixels across equator [default = 64]
    @param contours: Confidence contours to draw eg. 68%, 95% etc
                     By default this is set to none and no contours
                     will be drawn.
    @param colorbar: Boolean option to draw colorbar [default = True]
    @param inj: list of injected values [ra, dec] in radians to plot
                [default = None]
    @param psrs: Stacked array of pulsar sky locations [ra, dec] in radians
                 [default=None] Will plot as white diamonds

    """

    # clear figures
    #plt.clf()

    # create stacked array of ra and dec
    skypos = np.column_stack([raSample, decSample])

    npix = hp.nside2npix(nside)    # number of pixels total


    # initialize theta and phi map coordinantes
    skycarts=[]
    for ii in range(npix):
        skycarts.append(np.array(hp.pix2vec(nside,ii)))

    # get skymap values from greedy binning algorithm
    skymap = greedy_bin_sky(skypos, skycarts)

    # smooth skymap
    if smooth:
        skymap = hp.smoothing(skymap, sigma=smoothsigma)

    # make plot
    ax = plt.subplot(111, projection='astro mollweide')

    # Add contours
    if contours is not None:
        for percent in contours:
            indices = np.argsort(-skymap)
            sky = skymap[indices]
            region = np.zeros(skymap.shape)
            ind = np.min(ml.find(np.cumsum(sky) >= 0.01*percent))
            region[indices[0:ind]] = 1.0
            cs = plot.contour(lambda lon, lat: region[hp.ang2pix(nside, 0.5*np.pi - lat, lon)], \
                          colors=color, linewidths=1.0, levels=[0.5])
            #plt.clabel(cs, [0.5], fmt={0.5: '$\mathbf{%d\%%}$' % percent}, fontsize=8, inline=True)

    # plot map
    ax.grid()
    plot.outline_text(ax)
    if cmap is not None:
        plot.healpix_heatmap(skymap, cmap=cmap)

    # add injection
    if inj:
        ax.plot(inj[0], inj[1], 'x', color='k', markersize=8, mew=2, mec='k')

    # add pulsars
    if np.all(psrs):
        ax.plot(psrs[:,0], psrs[:,1], '*', color='lime', markersize=8, mew=1, mec='k')

    # add colorbar and title
    if colorbar:
        plt.colorbar(orientation='horizontal')
        plt.suptitle(r'$p(\alpha,\delta|d)$', y=0.1)

    # save skymap
    plt.savefig(outfile, bbox_inches='tight')