示例#1
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')
示例#2
0
def makeSkyMap(samples,
               lmax,
               nside=32,
               cmap=None,
               strain=None,
               tex=True,
               psrs=None,
               axis=None):

    if tex == True:
        plt.rcParams['text.usetex'] = True

    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:
        if strain is None:
            samples = np.mean(samples, axis=0)
            samples = np.append(2. * np.sqrt(np.pi), samples)
        elif strain is not None:
            samples = np.mean((samples.T * 10**(2.0 * strain)).T, axis=0)
            samples = np.append(
                np.mean(10**(2.0 * strain) * (2.0 * np.sqrt(np.pi))), samples)
    else:
        #### !!!!!
        samples = np.append(2. * np.sqrt(np.pi), samples)

    pwr = utils.GWpower(samples, harmvals)
    print pwr, samples

    if axis is None:
        ax = plt.subplot(111, projection='astro mollweide')
        ax.grid()
        plot.outline_text(ax)
        if cmap is not None:
            if strain is None:
                plot.healpix_heatmap(pwr, cmap=cmap)
            elif strain is not None:
                plot.healpix_heatmap(pwr, cmap=cmap)
        else:
            plot.healpix_heatmap(pwr)
        plt.colorbar(orientation='horizontal')
        if strain is None:
            plt.suptitle(r'$\langle P_{\mathrm{GWB}}(\hat\Omega)\rangle$',
                         y=0.1)
        elif strain is not None:
            plt.suptitle(
                r'$\langle A_h^2 P_{\mathrm{GWB}}(\hat\Omega)\rangle$', y=0.1)

        # add pulsars locations
        if psrs is not None:
            ax.plot(psrs[:, 0],
                    np.pi / 2. - psrs[:, 1],
                    '*',
                    color='w',
                    markersize=15,
                    mew=1,
                    mec='k')
    elif axis is not None:
        axis.grid()
        plot.outline_text(axis)
        if cmap is not None:
            plot.healpix_heatmap(pwr, cmap=cmap)
        else:
            plot.healpix_heatmap(pwr)

        # add pulsars locations
        if psrs is not None:
            axis.plot(psrs[:, 0],
                      np.pi / 2. - psrs[:, 1],
                      '*',
                      color='w',
                      markersize=6,
                      mew=1,
                      mec='w')
示例#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')
示例#4
0
def makeSkyMap(samples, lmax, nside=32, cmap=None, strain=None, tex=True,
               psrs=None, axis=None):

    if tex == True:
        plt.rcParams['text.usetex'] = True

    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:
        if strain is None:
            samples = np.mean(samples, axis=0)
            samples = np.append(2.*np.sqrt(np.pi), samples)
        elif strain is not None:
            samples = np.mean((samples.T * 10**(2.0*strain)).T, axis=0)
            samples = np.append(np.mean(10**(2.0*strain) * (2.0*np.sqrt(np.pi))), samples)
    else:
        #### !!!!!
        samples = np.append(2.*np.sqrt(np.pi), samples)
            
    pwr = utils.GWpower(samples, harmvals)
    print pwr, samples

    if axis is None:
        ax = plt.subplot(111, projection='astro mollweide')
        ax.grid()
        plot.outline_text(ax)
        if cmap is not None:
            if strain is None:
                plot.healpix_heatmap(pwr,cmap=cmap)
            elif strain is not None:
                plot.healpix_heatmap(pwr,cmap=cmap)
        else:
            plot.healpix_heatmap(pwr)
        plt.colorbar(orientation='horizontal')
        if strain is None:
            plt.suptitle(r'$\langle P_{\mathrm{GWB}}(\hat\Omega)\rangle$', y=0.1)
        elif strain is not None:
            plt.suptitle(r'$\langle A_h^2 P_{\mathrm{GWB}}(\hat\Omega)\rangle$', y=0.1)

        # add pulsars locations
        if psrs is not None:
            ax.plot(psrs[:,0], np.pi/2. - psrs[:,1], '*', color='w',
                    markersize=15, mew=1, mec='k')
    elif axis is not None:
        axis.grid()
        plot.outline_text(axis)
        if cmap is not None:
            plot.healpix_heatmap(pwr,cmap=cmap)
        else:
            plot.healpix_heatmap(pwr)

        # add pulsars locations
        if psrs is not None:
            axis.plot(psrs[:,0], np.pi/2. - psrs[:,1], '*', color='w',
                      markersize=6, mew=1, mec='w')
示例#5
0
                                   kind='cubic')
            result_ds = round(float(conf_interp(result_strain)), 4)

            ax = plt.subplot(111, projection="astro mollweide")
            ax.grid()
            plot.outline_text(ax)

            #TODO this is just temporary
            def find_nearest(array, value):
                idx = (np.abs(array - value)).argmin()
                return array[idx]

            closest_freq = find_nearest(freq_array, orbital_f)
            closest_conf = find_nearest(confidence_array, result_ds)
            plot.healpix_heatmap(np.log10(
                freqdict[closest_freq].map_dictionary[closest_conf]),
                                 cmap='viridis_r')
            #---------------------------
            ax.scatter(math.radians(input_phi),
                       math.radians(input_theta),
                       marker='o',
                       s=40,
                       color='orangered',
                       linewidths=1.0,
                       edgecolors='k',
                       zorder=8)
            #TOD make colorbar an axes
            cb = plt.colorbar(orientation='horizontal')
            cb.ax.tick_params(labelcolor='w', color='w')
            plt.suptitle(
                '{0}% Characteristic Strain Upper Limit at {1}Hz, '.format(