Esempio n. 1
0
    def configure(self):
        # copy inps to self object
        inps = cmd_line_parse(self.iargs)
        for key, value in inps.__dict__.items():
            setattr(self, key, value)

        # copy inps from view.py to self object
        view_cmd = get_view_cmd(self.iargs)
        self.data_img, atr, inps_view = view.prep_slice(view_cmd)
        for key, value in inps_view.__dict__.items():
            setattr(self, key, value)

        self.offset *= self.disp_scale  # due to unit change from view.prep_slice()

        # do not update the following setting from view.py
        self.file = inps.file
        self.dset = inps.dset
        self.fig_size = inps.fig_size

        # auto figure size
        if not self.fig_size:
            length, width = int(self.atr['LENGTH']), int(self.atr['WIDTH'])
            fig_size = pp.auto_figure_size((length, width), disp_cbar=True)
            self.fig_size = [fig_size[0] + fig_size[1], fig_size[1]]
        return
Esempio n. 2
0
    def plot(self):
        # Figure 1
        self.fig = plt.figure(self.figname, figsize=self.fig_size)
        # Axes 1 - Image
        self.ax_img = self.fig.add_axes([0.05, 0.1, 0.4, 0.8])
        view_cmd = self.view_cmd.format(self.img_file)
        d_img, atr, inps_img = view.prep_slice(view_cmd)
        if all(i is not None for i in self.yx):
            inps_img.pts_marker = 'r^'
            inps_img.pts_yx = np.array(self.yx).reshape(-1, 2)
            # point yx --> lalo for geocoded product
            if 'Y_FIRST' in atr.keys():
                coord = ut.coordinate(atr)
                inps_img.pts_lalo = np.array(coord.radar2geo(self.yx[0], self.yx[1])[0:2]).reshape(-1,2)
        inps_img.print_msg = self.print_msg
        self.ax_img = view.plot_slice(self.ax_img, d_img, atr, inps_img)[0]

        # coordinate info
        self.coord = ut.coordinate(atr)
        self.fig_coord = inps_img.fig_coord

        # Axes 2 - coherence matrix
        self.ax_mat = self.fig.add_axes([0.55, 0.125, 0.40, 0.75])
        self.colormap = pp.ColormapExt(self.cmap_name, vlist=self.cmap_vlist).colormap
        if all(i is not None for i in self.yx):
            self.plot_coherence_matrix4pixel(self.yx)

        # Link the canvas to the plots.
        self.cid = self.fig.canvas.mpl_connect('button_press_event', self.update_coherence_matrix)
        if self.disp_fig:
            plt.show()
        return
Esempio n. 3
0
    def plot(self):
        # Figure 1
        self.fig = plt.figure(self.figname, figsize=self.fig_size)
        # Axes 1 - Image
        self.ax_img = self.fig.add_axes([0.05, 0.1, 0.4, 0.8])
        view_cmd = self.view_cmd.format(self.img_file)
        d_img, atr, inps_img = view.prep_slice(view_cmd)
        if self.yx:
            inps_img.pts_yx = np.array(self.yx).reshape(-1, 2)
            inps_img.pts_marker = 'r^'
        inps_img.print_msg = self.print_msg
        self.ax_img = view.plot_slice(self.ax_img, d_img, atr, inps_img)[0]

        # coordinate info
        self.coord = ut.coordinate(atr)
        self.fig_coord = inps_img.fig_coord

        # Axes 2 - coherence matrix
        self.ax_mat = self.fig.add_axes([0.55, 0.125, 0.40, 0.75])
        self.colormap = pp.ColormapExt(self.cmap_name,
                                       vlist=self.cmap_vlist).colormap
        if self.yx:
            self.plot_coherence_matrix4pixel(self.yx)

        # Link the canvas to the plots.
        self.cid = self.fig.canvas.mpl_connect('button_press_event',
                                               self.update_coherence_matrix)
        if self.disp_fig:
            plt.show()
        return
Esempio n. 4
0
    def plot(self):
        # Figure 1
        self.fig = plt.figure(self.figname, figsize=self.fig_size)
        # Axes 1 - Image
        self.ax_img = self.fig.add_axes([0.05, 0.1, 0.4, 0.8])
        view_cmd = self.view_cmd.format(self.img_file)
        d_img, atr, inps_img = view.prep_slice(view_cmd)
        if self.yx:
            inps_img.pts_yx = np.array(self.yx).reshape(-1, 2)
            inps_img.pts_marker = 'r^'
        inps_img.print_msg = self.print_msg
        self.ax_img = view.plot_slice(self.ax_img, d_img, atr, inps_img)[0]

        # coordinate info
        self.coord = ut.coordinate(atr)
        self.fig_coord = inps_img.fig_coord

        # Axes 2 - coherence matrix
        self.ax_mat = self.fig.add_axes([0.55, 0.125, 0.40, 0.75])
        if self.yx:
            self.plot_coherence_matrix4pixel(self.yx)

        # Link the canvas to the plots.
        self.cid = self.fig.canvas.mpl_connect('button_press_event', self.update_coherence_matrix)
        if self.disp_fig:
            plt.show()
        return
Esempio n. 5
0
def get_poly_mask(fname, datasetName, print_msg=True):
    """Get mask of pixels within polygon from interactive selection
    Parameters: data : 2D np.array in size of (length, width)
    Returns:    mask : 2D np.arrat in size of (length, width) in np.bool_ format
    """
    # option 1 - Advanced plot using view.prep/plot_slice()
    cmd = 'view.py {} '.format(fname)
    if datasetName:
        cmd += ' {} '.format(datasetName)
    ## Customized setting for plotting (temporarily for advanced users)
    #cmd += ' --dem ./inputs/geometryGeo.h5 --contour-step 100 --contour-smooth 0.0 '
    #cmd += ' -u cm -v -6 6 '

    d_v, atr, inps = view.prep_slice(cmd)
    ax = plt.subplots(figsize=inps.fig_size)[1]
    inps.fig_coord = 'radar'  #selector works for radar coord plot only
    ax, inps, im = view.plot_slice(ax, d_v, atr, inps)[0:3]

    ## Option 2 - Simple plot with matplotlib
    #from mintpy.utils import readfile
    #data = readfile.read(fname, datasetName)[0]
    #vlim = np.nanmax(np.abs(data))
    #vmin, vmax = -vlim, vlim
    ## for dataset with non-negative values such as elevation
    #if np.nanmin(data) > 0:
    #    vmin = np.nanmin(data)
    ## plot
    #fig, ax = plt.subplots()
    #im = ax.imshow(data, cmap='jet', vmin=vmin, vmax=vmax)
    #fig.colorbar(im)

    selector = SelectFromCollection(ax, im)
    plt.show()
    selector.disconnect()

    if hasattr(selector, 'mask'):
        mask = selector.mask
        if print_msg:
            print('selected polygon: {}'.format(selector.poly_path))
    else:
        mask = None
        if print_msg:
            print('no polygon selected.\n')
    return mask
Esempio n. 6
0
            pass

        if save_fig:
            fig, ax = plt.subplots(nrows=1, ncols=2, figsize=[8, 3])

            # read vel data
            cmd = 'view.py {} velocity --mask {} '.format(vel_file, mask_file)
            cmd += ' --sub-lon {w} {e} --sub-lat {s} {n} '.format(w=geo_box[0],
                                                                  n=geo_box[1],
                                                                  e=geo_box[2],
                                                                  s=geo_box[3])
            cmd += ' -c bwr_r -v -1.0 1.0 --cbar-loc bottom --cbar-nbins 5 --cbar-ext both --cbar-size 5% '
            cmd += ' --dem {} --dem-nocontour '.format(dem_file)
            cmd += ' --lalo-step 0.2 --lalo-loc 1 0 1 0 --scalebar 0.3 0.80 0.05 --notitle --fontsize 12 '
            cmd += ' --noverbose'
            d_v, atr, inps = view.prep_slice(cmd)
            ax[0], inps, im, cbar = view.plot_slice(ax[0], d_v, atr, inps)

            ax[0].plot(lon, lat, "k^", mfc='none', mew=1.,
                       ms=6)  # point of interest
            cbar.set_label("LOS Velocity [cm/yr]", fontsize=font_size)

            ax[1].scatter(dates, d_ts, marker='o', s=4**2)  # , color='k')
            pp.auto_adjust_xaxis_date(ax[1], obj.yearList, fontsize=font_size)
            ax[1].set_xlabel('Time [years]', fontsize=font_size)
            ax[1].set_ylabel('LOS Displacement [cm]', fontsize=font_size)
            ax[1].yaxis.set_minor_locator(ticker.AutoMinorLocator())
            ax[1].tick_params(which='both',
                              direction='in',
                              labelsize=font_size,
                              bottom=True,