コード例 #1
0
ファイル: plotting.py プロジェクト: rexjoe/atrain_match
def imshow_lwps(amsr_lwp, cpp_lwp, time_diff, sea, title=None, lwp_max=None):
    """
    Show *amsr_lwp* and *cpp_lwp* side by side. *sea* is used to draw a
    background, and mask out any pixels which are not sea.
    
    """
    import matplotlib.pyplot as plt

    from utility_functions import broken_cmap_r
    from matplotlib.colors import ListedColormap

    #Comment: utility_functions is a separate package, created by J.Malm,
    #but which we can not find. If we want to run this part of the code, it
    #might be changed to something from matplotlib instead.
    #By calling amsr_avhrr_match without '-p', this part of the code is not
    #executed.
    #Sara Hornquist 2015-03-12

    # Use average of all AVHRR pixels in AMSR footprint
    if len(cpp_lwp) == 3:
        cpp_lwp = cpp_lwp.mean(axis=-1)

    fig = plt.figure()

    vmin, vmax, break_value = limits([amsr_lwp, cpp_lwp], lwp_max)
    cmap = broken_cmap_r(np.array([vmin, vmax]), break_value=break_value)
    ground_sea_cmap = ListedColormap(['g', 'b'], name="ground/sea map")
    sea_map = np.ma.array(sea, mask=sea.mask + sea)

    ax = fig.add_subplot(131)
    ax.imshow(sea_map, cmap=ground_sea_cmap)
    im = ax.imshow(np.ma.array(amsr_lwp, mask=~sea),
                   vmin=vmin,
                   vmax=vmax,
                   cmap=cmap)
    cbar = fig.colorbar(im)
    cbar.set_label('g m**-2')
    ax.set_title('AMSR-E lwp')

    ax = fig.add_subplot(132, sharex=ax, sharey=ax)
    ax.imshow(sea_map, cmap=ground_sea_cmap)
    im = ax.imshow(np.ma.array(cpp_lwp, mask=~sea),
                   vmin=vmin,
                   vmax=vmax,
                   cmap=cmap)
    cbar = fig.colorbar(im)
    cbar.set_label('g m**-2')
    ax.set_title('PPS CPP cwp')

    ax = fig.add_subplot(133, sharex=ax, sharey=ax)
    im = ax.imshow(time_diff)
    cbar = fig.colorbar(im)
    cbar.set_label('s')
    ax.set_title('Time difference')

    if title:
        fig.suptitle(title)

    return fig
コード例 #2
0
ファイル: plotting.py プロジェクト: mitkin/atrain_match
def plot_fields(fields, break_value=None):
    """
    Plot *fields*. Each element in *fields* should be a `Field` instance.
    
    Plots on orthogonal projection, with lon_0, lat_0 taken from mean of lon,
    lat of first element in *fields*.
    
    """
    from mpl_toolkits.basemap import Basemap
    from matplotlib import pyplot as pl
    from utility_functions import broken_cmap_r
    
    #Comment: utility_functions is a separate package, created by J.Malm,
    #but which we can not find. If we want to run this part of the code, it
    #might be changed to something from matplotlib instead.
    #broken_cmap_r is supposed to create a colormap with a gradient on one side
    #of a threshold, and another gradient on the other side, and a unique
    #colour on the theshold it self.
    #Sara Hornquist 2015-03-12

    
    lon_0 = fields[0].lon.mean()
    lat_0 = fields[0].lat.mean()
    
    vmin, vmax, break_value = limits([f.data for f in fields], break_value)
    cmap = broken_cmap_r(vmin=vmin, vmax=vmax, break_value=break_value)
    
    fig = pl.figure()
    ax = None
    for ix, f in enumerate(fields):
        ax = fig.add_subplot(len(fields) % 2 + 1, len(fields) // 2 + 1, ix + 1,
                             sharex=ax, sharey=ax)
        m = Basemap(projection='ortho', lon_0=lon_0, lat_0=lat_0, lat_ts=0,
                    resolution='c', ax=ax)
        m.drawcoastlines(linewidth=.5, color='g')
        
        step = (f.data.shape[1] // 256) or 1 # don't use full gigantic arrays
        _slice = (slice(None, None, step),) * 2
        x, y = m(f.lon[_slice], f.lat[_slice])
        # Mask out pixels outside projection limb
        #on_map = (x < 1e20) | (y < 1e20)
        #data = np.ma.array(f.data[_slice], mask=~on_map)
        data = f.data[_slice]
        logger.debug("data.shape = %r" % (data.shape,))
        #mesh = m.pcolor(x, y, data, vmin=vmin, vmax=vmax, cmap=cmap)
        # pcolormesh is much faster, but I can't get rid of off-projection drawing
        mesh = m.pcolormesh(x, y, data, vmin=vmin, vmax=vmax, cmap=cmap)
        fig.colorbar(mesh)
        ax.set_title(f.desc)
        
        m.drawmeridians(range(0, 360, 20), linewidth=.5)
        m.drawparallels(range(-80, 90, 10), linewidth=.5)
        # Mark 70 deg latitudes (cut off for validation)
        m.drawparallels([-70, 70], color='r', dashes=[1, 0], latmax=70)
    
    return fig