Exemple #1
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
Exemple #2
0
    def plot_init_image(self, img_data):
        """Plot the initial 2D image."""
        # prepare data
        if self.wrap:
            if self.disp_unit_img == 'radian':
                img_data *= self.range2phase
            img_data = ut.wrap(img_data, wrap_range=self.wrap_range)

        # Title and Axis Label
        self.disp_date_format = ptime.get_compact_isoformat(self.date_list[0])
        disp_date = self.dates[self.idx].strftime(self.disp_date_format)
        self.fig_title = 'N = {}, Time = {}'.format(self.idx, disp_date)

        # Initial Pixel of interest
        self.pts_yx = None
        self.pts_lalo = None
        if self.yx and self.yx != self.ref_yx:
            self.pts_yx = np.array(self.yx).reshape(-1, 2)
            if self.lalo:
                self.pts_lalo = np.array(self.lalo).reshape(-1, 2)

        # call view.py to plot
        self.img, self.cbar_img = view.plot_slice(self.ax_img, img_data,
                                                  self.atr, self)[2:4]
        self.fig_img.canvas.set_window_title(self.figname_img)
        self.fig_img.tight_layout(rect=(0, 0, 1, 0.97))

        return self.img, self.cbar_img
    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
    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
Exemple #5
0
    def plot(self):
        # Read data for transection
        self.data_list = []
        self.atr_list = []
        for fname in self.file:
            data, atr = readfile.read(fname, datasetName=self.dset)
            data = pp.scale_data2disp_unit(data,
                                           metadata=atr,
                                           disp_unit=self.disp_unit)[0]
            self.data_list.append(data)
            self.atr_list.append(atr)

        # Figure
        self.fig, (self.ax_img,
                   self.ax_txn) = plt.subplots(1,
                                               2,
                                               num=self.figname,
                                               figsize=self.fig_size)

        # Axes 1 - map with view.prep/plot_slice()
        self.ax_img = view.plot_slice(self.ax_img, self.data_img, self.atr,
                                      self)[0]

        # Axes 2 - transection
        self.ax_txn.yaxis.tick_right()
        self.ax_txn.yaxis.set_label_position("right")

        # plot initial input transect
        if self.start_yx and self.end_yx:
            self.draw_line(self.start_yx, self.end_yx)
            self.draw_transection(self.start_yx, self.end_yx, self.start_lalo,
                                  self.end_lalo)

        self.fig.subplots_adjust(left=0.05, wspace=0.25)

        # save
        if self.save_fig:
            outfile = '{}.pdf'.format(self.outfile_base)
            self.fig.savefig(outfile,
                             bbox_inches='tight',
                             transparent=True,
                             dpi=self.fig_dpi)
            vprint('saved transect to', outfile)

        self.cid = self.fig.canvas.mpl_connect('button_release_event',
                                               self.select_point)

        if self.disp_fig:
            vprint('showing ...')
            plt.show()
        return
Exemple #6
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
Exemple #7
0
    def plot_init_image(self, img_data):
        # prepare data
        if self.wrap:
            if self.disp_unit_img == 'radian':
                img_data *= self.range2phase
            img_data = ut.wrap(img_data, wrap_range=self.wrap_range)

        # Title and Axis Label
        disp_date = self.dates[self.idx].strftime('%Y-%m-%d')
        self.fig_title = 'N = {}, Time = {}'.format(self.idx, disp_date)

        # Initial Pixel of interest
        self.pts_yx = None
        self.pts_lalo = None
        if self.yx and self.yx != self.ref_yx:
            self.pts_yx = np.array(self.yx).reshape(-1, 2)
            if self.lalo:
                self.pts_lalo = np.array(self.lalo).reshape(-1, 2)

        # call view.py to plot
        self.img, self.cbar_img = view.plot_slice(self.ax_img, img_data, self.atr, self)[2:4]
        return self.img, self.cbar_img
Exemple #8
0
        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,
                              top=True,