示例#1
0
    def plotInversionResults(self):
        """
        Plotting inversion results to plot folder
        """
        try:
            _dsretc = "dsretc"
            self.log.info('Plotting inversion results...\n')

            self.log.info('Plotting stream waveforms...\n')
            plot.streams(self.station_list, self.dir.streams,
                         self.dir.allstreams)

            self.log.info('Plotting inversions...\n')
            _depth, _corr, _dc, _bballs =  plot.mt_list2data(self.mt_list)
            plot.correlation(_depth, _corr, _dc, _bballs, self.dir.inversions)

            self.log.info('Plotting misfits...\n')
            # find best mt depth folder
            _depth_folder = os.path.join(self.dir.inversion,
                                         str(self.origin.mt.cent_depth))
            plot.misfit(self.tl, self.station_list,
                        _depth_folder, self.dir.misfit)

            self.log.info('Plotting correlations...\n')
            _time_list, _depth_list, _dc_list, _corr_list, _bball_list = \
                                        plot.corr_file2data(self.dir.corr)
            plot.contour(_time_list, _depth_list, _dc_list, _corr_list,
                         _bball_list, self.dir.correlation)

            self.log.info('Plotting focal mechanism...\n')
            plot.beachBall(self.origin.mt.strike,
                           self.origin.mt.dip,
                           self.origin.mt.rake,
			   self.origin.mt.mrr,
			   self.origin.mt.mtt,
			   self.origin.mt.mpp,
			   self.origin.mt.mrt,
			   self.origin.mt.mrp,
			   self.origin.mt.mtp,
                           self.dir.beachball)

            self.log.info('Plotting map...\n')
            plot.maps(self.station_list, self.origin,
                      self.origin.mt.strike,
                      self.origin.mt.dip,
                      self.origin.mt.rake,
                      self.dir.map)

            self.log.info('Plotting text results...\n')

            _dsretc_path = os.path.join(self.settings.isola_path, _dsretc)
            plot.results2text(self.station_list, self.origin,
                              self.settings, self.dir.result,
                              _dsretc_path, self.f1, self.f2, self.f3,
                              self.f4, self.dir.text)

        except:
            self.log.info('Error occurred in plotting inversion results...\n')
            raise
示例#2
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')
import matplotlib as mpl
import matplotlib.pyplot as plt

# -----------------------------------------------------------------------------
if __name__ == "__main__":

    n = 32
    X, Z = np.meshgrid(
        np.linspace(-0.5 + 0.5 / n, +0.5 - 0.5 / n, n),
        np.linspace(-0.5 + 0.5 / n, +0.5 - 0.5 / n, n),
    )
    Y = 0.75 * np.exp(-10 * (X**2 + Z**2))

    def f(x, y):
        return (1 - x / 2 + x**5 + y**3) * np.exp(-(x**2) - y**2)

    n = 100
    x = np.linspace(-3, 3, n)
    y = np.linspace(-3, 3, n)
    X, Y = np.meshgrid(x, y)
    Z = 0.5 * f(X, Y)

    fig = plt.figure(figsize=(6, 6))
    ax = fig.add_axes([0, 0, 1, 1])

    camera = glm.camera(25, 45, 1, "perspective")
    plot.axis(ax, camera)
    plot.contour(ax, camera, Z)

plt.show()
示例#4
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')