Пример #1
0
def make_3im_png(data3, pngfile, cmap, title3, vmin=None, vmax=None, cbar=True):
    """
    Make png with 3 images for comparison.
    data3 and title3 must be list with 3 elements.
    cmap can be 'insar'. To wrap data, np.angle(np.exp(1j*x/cycle)*cycle)
    """
    ### Plot setting
    if cmap=='insar':
        cdict = tools_lib.cmap_insar()
        plt.register_cmap(name='insar',data=cdict)

    length, width = data3[0].shape
    figsizex = 12
    xmergin = 4 if cbar else 0
    figsizey = int((figsizex-xmergin)/3*length/width)+2
    
    fig = plt.figure(figsize = (figsizex, figsizey))

    for i in range(3):
        ax = fig.add_subplot(1, 3, i+1) #index start from 1
        im = ax.imshow(data3[i], vmin=vmin, vmax=vmax, cmap=cmap)
        ax.set_title(title3[i])
        ax.set_xticklabels([])
        ax.set_yticklabels([])
        if cbar: fig.colorbar(im, ax=ax)

    plt.tight_layout()
    plt.savefig(pngfile)
    plt.close()
   
    return 
Пример #2
0
def make_im_png(data, pngfile, cmap, title, vmin=None, vmax=None, cbar=True):
    """
    Make png image.
    cmap can be 'insar'. To wrap data, np.angle(np.exp(1j*x/cycle)*cycle)
    """

    if cmap=='insar':
        cdict = tools_lib.cmap_insar()
        plt.register_cmap(name='insar',data=cdict)
    
    length, width = data.shape
    figsizex = 8
    xmergin = 2 if cbar else 0
    figsizey = int((figsizex-xmergin)*(length/width))+1
    
    ### Plot
    fig, ax = plt.subplots(1, 1, figsize=(figsizex, figsizey))
    plt.tight_layout()
    
    im = ax.imshow(data, vmin=vmin, vmax=vmax, cmap=cmap)
    ax.set_xticklabels([])
    ax.set_yticklabels([])
    ax.set_title(title)
    if cbar: fig.colorbar(im)

    plt.savefig(pngfile)
    plt.close()
    
    return
Пример #3
0
def make_loop_png(ifgd12, ifgd23, ifgd13, unw12, unw23, unw13, loop_ph,
                  loop_pngdir):
    ### Load color map for InSAR
    cdict = tools_lib.cmap_insar()
    plt.register_cmap(name='insar', data=cdict)

    rms = np.sqrt(np.nanmean(loop_ph**2))

    ### Settings
    imd1 = ifgd12[:8]
    imd2 = ifgd23[:8]
    imd3 = ifgd23[-8:]
    pngname = os.path.join(loop_pngdir,
                           imd1 + '_' + imd2 + '_' + imd3 + '_loop.png')
    cycle = 3  # 2pi*3/cycle
    titles = [ifgd12, ifgd23, ifgd13]
    data = [unw12, unw23, unw13]

    length, width = unw12.shape
    if length > width:
        figsize_y = 10
        figsize_x = int((figsize_y - 1) * width / length)
        if figsize_x < 5: figsize_x = 5
    else:
        figsize_x = 10
        figsize_y = int(figsize_x * length / width + 1)
        if figsize_y < 3: figsize_y = 3

    ### Plot
    fig = plt.figure(figsize=(figsize_x, figsize_y))

    ## 3 ifgs
    for i in range(3):
        data_wrapped = np.angle(np.exp(1j * (data[i] / cycle)) * cycle)
        ax = fig.add_subplot(2, 2, i + 1)  #index start from 1
        ax.imshow(data_wrapped, vmin=-np.pi, vmax=+np.pi, cmap='insar')
        ax.set_title('{}'.format(titles[i]))
        ax.set_xticklabels([])
        ax.set_yticklabels([])

    ## loop phase
    ax = fig.add_subplot(2, 2, 4)  #index start from 1
    ax.imshow(loop_ph, vmin=-np.pi, vmax=+np.pi, cmap=SCM.vik)
    ax.set_title('Loop phase (RMS={:.2f}rad)'.format(rms))
    ax.set_xticklabels([])
    ax.set_yticklabels([])

    plt.tight_layout()
    plt.savefig(pngname)
    plt.close()
Пример #4
0
def make_loop_png(unw12, unw23, unw13, loop_ph, png, titles4, cycle):
    ### Load color map for InSAR
    cdict = tools_lib.cmap_insar()
    plt.register_cmap(cmap=mpl.colors.LinearSegmentedColormap('insar', cdict))
    plt.rcParams['axes.titlesize'] = 10

    ### Settings
    data = [unw12, unw23, unw13]

    length, width = unw12.shape
    if length > width:
        figsize_y = 10
        figsize_x = int((figsize_y - 1) * width / length)
        if figsize_x < 5: figsize_x = 5
    else:
        figsize_x = 10
        figsize_y = int(figsize_x * length / width + 1)
        if figsize_y < 3: figsize_y = 3

    ### Plot
    fig = plt.figure(figsize=(figsize_x, figsize_y))

    ## 3 ifgs
    for i in range(3):
        data_wrapped = np.angle(np.exp(1j * (data[i] / cycle)) * cycle)
        ax = fig.add_subplot(2, 2, i + 1)  #index start from 1
        ax.imshow(data_wrapped,
                  vmin=-np.pi,
                  vmax=+np.pi,
                  cmap='insar',
                  interpolation='nearest')
        ax.set_title('{}'.format(titles4[i]))
        ax.set_xticklabels([])
        ax.set_yticklabels([])

    ## loop phase
    ax = fig.add_subplot(2, 2, 4)  #index start from 1
    ax.imshow(loop_ph,
              vmin=-np.pi,
              vmax=+np.pi,
              cmap=SCM.vik,
              interpolation='nearest')
    ax.set_title('{}'.format(titles4[3]))
    ax.set_xticklabels([])
    ax.set_yticklabels([])

    plt.tight_layout()
    plt.savefig(png)
    plt.close()
Пример #5
0
            raise Usage('No {} exists!'.format(infile))

    except Usage as err:
        print("\nERROR:", file=sys.stderr, end='')
        print("  " + str(err.msg), file=sys.stderr)
        print("\nFor help, use -h or --help.\n", file=sys.stderr)
        sys.exit(2)

    #%% Set cmap if SCM
    if cmap_name.startswith('SCM'):
        if cmap_name.endswith('_r'):
            exec("cmap = {}.reversed()".format(cmap_name[:-2]))
        else:
            exec("cmap = {}".format(cmap_name))
    elif cmap_name == 'insar':
        cdict = tools_lib.cmap_insar()
        plt.register_cmap(
            cmap=mpl.colors.LinearSegmentedColormap('insar', cdict))
        cmap = 'insar'
    else:
        cmap = cmap_name

    #%% Get info and Read data
    if gdal.IdentifyDriver(infile):  ## If Geotiff or grd
        geotiff = gdal.Open(infile)
        data = geotiff.ReadAsArray()
        if data.ndim > 2:
            print('\nERROR: {} has multiple bands and cannot be displayed.\n'.
                  format(infile),
                  file=sys.stderr)
            sys.exit(2)