def plot_ts(x, y, title='', savefig=None): x_pol, y_pol = util.poly_fit(x, y, order=3) x_lin, y_lin = linear_fit(x, y) m, c = linear_fit(x, y, return_coef=True) fig = plt.figure(figsize=(10,3)) ax = fig.add_subplot((111)) x = x.round(2) n = y_lin[0] # reference to zero plt.plot(x, y-n, linewidth=3) #plt.plot(x_pol, y_pol-n) plt.plot(x_lin, y_lin-n, 'r') viz.add_inner_title(ax, 'dh/dt = %.1f cm/yr' % (m*100), loc=4) viz.add_inner_title(ax, title, loc=2) #plt.ylim(-0.1, 0.1) plt.xlim(2003.5, 2009.6) #plt.xlabel('time') plt.ylabel('dh (m)') #fig.autofmt_xdate() if savefig is not None: plt.savefig(savefig) plt.show() return fig
def plot_ts(x, y, title='', savefig=None): x_pol, y_pol = util.poly_fit(x, y, order=3) x_lin, y_lin = linear_fit(x, y) m, c = linear_fit(x, y, return_coef=True) fig = plt.figure(figsize=(10, 3)) ax = fig.add_subplot((111)) x = x.round(2) #n = y_lin[0] # zero at the begining n = y_lin[0] + (y_lin[-1] - y_lin[0]) / 2. # zero at the middle plt.plot(x, y - n, linewidth=3) #plt.plot(x_pol, y_pol-n) plt.plot(x_lin, y_lin - n, 'r') viz.add_inner_title(ax, 'dh/dt = %.1f cm/yr' % (m * 100), loc=1) viz.add_inner_title(ax, title, loc=2) plt.ylim(-.3, .3) plt.xlim(2003.5, 2010.1) #plt.xlabel('years') plt.ylabel('Elevation change (m)') #fig.autofmt_xdate() if savefig is not None: pass #plt.savefig(savefig+'_ts.png') #np.savetxt(savefig+'_ts.txt', np.column_stack((x, y))) return fig
def plot_ts(ax, x, y, dtime, title='', savefig=None, linewidth=None, color=None, alpha=None, label=True): #x_pol, y_pol = util.poly_fit(x, y, order=3) x_lin, y_lin = linear_fit(x, y) m, c = linear_fit(x, y, return_coef=True) x = x.round(2) #n = y_lin[0] # zero at the begining n = y_lin[0] + (y_lin[-1] - y_lin[0])/2. # zero at the middle x_dt = fy2dt(x) ax.plot(x, y-n, linewidth=linewidth, color=color, alpha=alpha) #plt.plot(x_pol, y_pol-n, **kw) x_lin_dt = np.sort(fy2dt(x_lin)) ax.plot(x_lin, y_lin-n, linewidth=linewidth-1, color=color, alpha=alpha) if label: viz.add_inner_title(ax, 'dh/dt = %.1f cm/yr' % (m*100), loc=1) viz.add_inner_title(ax, title, loc=2) plt.ylim(-.28, .28) plt.xlim(2003.5, 2010.1) #plt.xlabel('years') plt.ylabel('Elevation change (m)') if savefig is not None: pass #plt.savefig(savefig+'_ts.png') #np.savetxt(savefig+'_ts.txt', np.column_stack((x, y))) return ax
def plot_ts(x, y, title='', savefig=None): x_pol, y_pol = util.poly_fit(x, y, order=3) x_lin, y_lin = linear_fit(x, y) m, c = linear_fit(x, y, return_coef=True) fig = plt.figure(figsize=(10,3)) ax = fig.add_subplot((111)) x = x.round(2) #n = y_lin[0] # zero at the begining n = y_lin[0] + (y_lin[-1] - y_lin[0])/2. # zero at the middle plt.plot(x, y-n, linewidth=3) #plt.plot(x_pol, y_pol-n) plt.plot(x_lin, y_lin-n, 'r') viz.add_inner_title(ax, 'dh/dt = %.1f cm/yr' % (m*100), loc=1) viz.add_inner_title(ax, title, loc=2) plt.ylim(-.3, .3) plt.xlim(2003.5, 2010.1) #plt.xlabel('years') plt.ylabel('Elevation change (m)') #fig.autofmt_xdate() if savefig is not None: pass #plt.savefig(savefig+'_ts.png') #np.savetxt(savefig+'_ts.txt', np.column_stack((x, y))) return fig
def plot_ts(x, y, title='', savefig=None): x_pol, y_pol = util.poly_fit(x, y, order=3) x_lin, y_lin = linear_fit(x, y) m, c = linear_fit(x, y, return_coef=True) fig = plt.figure(figsize=(10, 3)) ax = fig.add_subplot((111)) x = x.round(2) #n = y_lin[0] # reference to zero nmin = y_lin.min() # reference to center nmax = y_lin.max() n = nmin + (nmax - nmin) / 2. plt.plot(x, y - n, linewidth=3) plt.plot(x_pol, y_pol - n) plt.plot(x_lin, y_lin - n) viz.add_inner_title(ax, 'dh/dt = %.1f cm/yr' % (m * 100), loc=4) #viz.add_inner_title(ax, 'dAGC/dt = %.1f dB/yr' % (m*100), loc=4) viz.add_inner_title(ax, title, loc=1) #plt.ylim(-3.5, 3.5) plt.xlim(1992, 2012.7) ax.xaxis.set_ticks(range(1992, 2013, 2)) #plt.xlabel('time') plt.ylabel('dh [m]') #plt.ylabel('dAGC [dB]') fig.autofmt_xdate() if savefig is not None: plt.savefig(savefig) plt.show() return fig
def plot_ts(x, y, title='', savefig=None): x_pol, y_pol = util.poly_fit(x, y, order=3) x_lin, y_lin = linear_fit(x, y) m, c = linear_fit(x, y, return_coef=True) fig = plt.figure(figsize=(10,3)) ax = fig.add_subplot((111)) x = x.round(2) #n = y_lin[0] # reference to zero nmin = y_lin.min() # reference to center nmax = y_lin.max() n = nmin + (nmax - nmin)/2. plt.plot(x, y-n, linewidth=3) plt.plot(x_pol, y_pol-n) plt.plot(x_lin, y_lin-n) viz.add_inner_title(ax, 'dh/dt = %.1f cm/yr' % (m*100), loc=4) #viz.add_inner_title(ax, 'dAGC/dt = %.1f dB/yr' % (m*100), loc=4) viz.add_inner_title(ax, title, loc=1) #plt.ylim(-3.5, 3.5) plt.xlim(1992, 2012.7) ax.xaxis.set_ticks(range(1992, 2013, 2)) #plt.xlabel('time') plt.ylabel('dh [m]') #plt.ylabel('dAGC [dB]') fig.autofmt_xdate() if savefig is not None: plt.savefig(savefig) plt.show() return fig
def plot_ts(ax, x, y, num=1): x_pol, y_pol = util.poly_fit(x, y, order=3) x_lin, y_lin = linear_fit(x, y) m, c = linear_fit(x, y, return_coef=True) x = x.round(2) n = y_lin[0] # reference to zero ax.plot(x, y-n, linewidth=2.5) #ax.plot(x_pol, y_pol-n) ax.plot(x_lin, y_lin-n, 'r') if num != 7: viz.add_inner_title(ax, '(%d)' % num, loc=2) viz.add_inner_title(ax, 'trend = %.1f cm/yr' % (m*100), loc=3) return ax
def plot_ts(x, y): x_pol, y_pol = util.poly_fit(x, y, order=3) x_lin, y_lin = linear_fit(x, y) m, c = linear_fit(x, y, return_coef=True) fig = plt.figure() ax = fig.add_subplot((111)) x = x.round(2) n = y_lin[0] # reference to zero plt.plot(x, y-n, linewidth=2) plt.plot(x_pol, y_pol-n) plt.plot(x_lin, y_lin-n) viz.add_inner_title(ax, 'linear trend = %.1f cm/yr' % (m*100), loc=2) #plt.ylim(-0.8, 0.8) plt.xlabel('time') plt.ylabel('dh (m)') plt.show() return fig
def plot_ts(x, y): x_pol, y_pol = util.poly_fit(x, y, order=3) x_lin, y_lin = linear_fit(x, y) m, c = linear_fit(x, y, return_coef=True) fig = plt.figure() ax = fig.add_subplot((111)) x = x.round(2) n = y_lin[0] # reference to zero plt.plot(x, y - n, linewidth=2) plt.plot(x_pol, y_pol - n) plt.plot(x_lin, y_lin - n) viz.add_inner_title(ax, 'linear trend = %.1f cm/yr' % (m * 100), loc=2) #plt.ylim(-0.8, 0.8) plt.xlabel('time') plt.ylabel('dh (m)') plt.show() return fig
def plot_tseries(time2, lon, lat, dh_mean_corr, dh_mean, dg_mean, R, S, term='mix'): #time2 = y2dt(time2) R = np.mean(R) S = np.mean(S) if not np.alltrue(np.isnan(dh_mean[1:])): # use only non-null and non-zero entries for correlation ind, = np.where((~np.isnan(dh_mean)) & (~np.isnan(dg_mean)) & \ (dh_mean!=0) & (dg_mean!=0)) t = np.arange(len(dh_mean)) x, y = linear_fit(dg_mean[ind], dh_mean[ind]) x2, y2 = linear_fit_robust(dg_mean[ind], dh_mean[ind]) fig = plt.figure() ax = fig.add_subplot((111)) plt.plot(dg_mean[ind], dh_mean[ind], 'o') plt.plot(x, y, linewidth=2, label='lstsq fit') plt.plot(x2, y2, linewidth=2, label='robust fit') plt.legend(loc=2).draw_frame(False) if term == 'mix': plt.xlabel('dAGC (dB)') plt.ylabel('dh (m)') plt.title('Mix-term sensitivity (S = corr grad)') elif term == 'short': plt.xlabel('$\Delta$dAGC (dB)') plt.ylabel('$\Delta$dh (m)') plt.title('Short-term sensitivity (S = corr grad)') ax = viz.add_inner_title(ax, 'R = %.2f, S = %.2f' % (R, S), 4) #----------------- fig = plt.figure() plt.subplot((211)) plt.plot(time2, dg_mean, linewidth=2, label='backscatter') plt.legend().draw_frame(False) plt.ylabel('dAGC (dB)') plt.title('lon = %.2f, lat = %.2f' % (lon, lat)) #plt.gca().xaxis.set_major_formatter(plt.FormatStrFormatter('%d')) plt.subplot((212)) plt.plot(time2, dh_mean, 'g', linewidth=2, label='dh_uncorr') plt.plot(time2, dh_mean_corr, 'r', linewidth=2, label='dh_corr') plt.legend().draw_frame(False) plt.ylabel('dh (m)') #plt.gca().xaxis.set_major_formatter(plt.FormatStrFormatter('%d')) fig.autofmt_xdate() return fig
def plot_ts_mean(t, Y): y = np.ma.masked_invalid(Y) ts = np.mean(np.mean(y, axis=1), axis=1) #x_pol, y_pol = spline_interp(t, ts, smooth=0.1) x_pol, y_pol = util.poly_fit(t, ts, order=3) x_lin, y_lin = linear_fit(t, ts) m, c = linear_fit(t, ts, return_coef=True) fig = plt.figure() ax = fig.add_subplot((111)) n = y_lin[0] # shift plt.plot(t, ts - n, linewidth=2) plt.plot(x_pol, y_pol - n) plt.plot(x_lin, y_lin - n) viz.add_inner_title(ax, 'linear trend = %.1f cm/yr' % (m * 100), loc=2) #plt.ylim(ts.min(), ts.max()) plt.xlabel('time') plt.ylabel('dh (m)') plt.title('Mean TS') plt.show() return fig
def plot_ts_mean(t, Y): y = np.ma.masked_invalid(Y) ts = np.mean(np.mean(y, axis=1), axis=1) #x_pol, y_pol = spline_interp(t, ts, smooth=0.1) x_pol, y_pol = util.poly_fit(t, ts, order=3) x_lin, y_lin = linear_fit(t, ts) m, c = linear_fit(t, ts, return_coef=True) fig = plt.figure() ax = fig.add_subplot((111)) n = y_lin[0] # shift plt.plot(t, ts-n, linewidth=2) plt.plot(x_pol, y_pol-n) plt.plot(x_lin, y_lin-n) viz.add_inner_title(ax, 'linear trend = %.1f cm/yr' % (m*100), loc=2) #plt.ylim(ts.min(), ts.max()) plt.xlabel('time') plt.ylabel('dh (m)') plt.title('Mean TS') plt.show() return fig
ts = mean_t + mean_xy[i,j] + Y[:,i,j] #x_pol, y_pol = spline_interp(t, ts, smooth=0.1) x_pol, y_pol = util.poly_fit(t, ts, order=3) x_lin, y_lin = linear_fit(t, ts) m, c = linear_fit(t, ts, return_coef=True) fig = plt.figure() ax = fig.add_subplot((111)) n = y_lin[0] # shift plt.plot(t, ts-n, linewidth=2) plt.plot(x_pol, y_pol-n) plt.plot(x_lin, y_lin-n) viz.add_inner_title(ax, 'linear trend = %.1f cm/yr' % (m*100), loc=2) #plt.ylim(ts.min(), ts.max()) plt.xlabel('time') plt.ylabel('dh (m)') plt.title('Mean TS') plt.show() return fig def plot_grid_and_ts(lon, lat, dhdt, t, dh, (i,j), **kw): cell = (lon[j], lon[j+1], lat[i], lat[i+1]) plot_grid(lon, lat, dhdt, cell, **kw) plt.show() def plot_map(lon, lat, grid, bbox, mfile, mres=1, **kw):
def plot_ts(time2, lon, lat, dh_mean_cor, dh_mean, dg_mean, R, S, diff=True): if np.alltrue(np.isnan(dh_mean[1:])): return None #time2 = y2dt(time2) R = np.mean(R) S = np.mean(S) # use only non-null and non-zero entries for correlation ind, = np.where((~np.isnan(dh_mean)) & (~np.isnan(dg_mean)) & \ (dh_mean!=0) & (dg_mean!=0)) t = np.arange(len(dh_mean)) if not diff: x, y = ap.linear_fit(dg_mean[ind], dh_mean[ind]) x2, y2 = ap.linear_fit_robust(dg_mean[ind], dh_mean[ind]) fig = plt.figure() ax = fig.add_subplot((111)) plt.plot(dg_mean[ind], dh_mean[ind], 'o') plt.plot(x, y, linewidth=2, label='lstsq fit') plt.plot(x2, y2, linewidth=2, label='robust fit') plt.legend(loc=2).draw_frame(False) plt.xlabel('dAGC (dB)') plt.ylabel('dh (m)') plt.title('Mixed-term sensitivity') else: dh_mean2 = np.diff(dh_mean) dg_mean2 = np.diff(dg_mean) dh_mean2 = np.append(dh_mean2, np.nan) dg_mean2 = np.append(dg_mean2, np.nan) x, y = ap.linear_fit(dg_mean2[ind], dh_mean2[ind]) x2, y2 = ap.linear_fit_robust(dg_mean2[ind], dh_mean2[ind]) fig = plt.figure() ax = fig.add_subplot((111)) plt.plot(dg_mean2[ind], dh_mean2[ind], 'o') plt.plot(x, y, linewidth=2, label='lstsq fit') plt.plot(x2, y2, linewidth=2, label='robust fit') plt.legend(loc=2).draw_frame(False) plt.xlabel('$\Delta$dAGC (dB)') plt.ylabel('$\Delta$dh (m)') plt.title('Short-term sensitivity') ax1 = viz.add_inner_title(ax, 'corrcoef: R = %.2f' % R, 3) ax1 = viz.add_inner_title(ax, 'slope: S = %.2f' % S, 4) plt.savefig('corr.png') #----------------- if not diff: fig = plt.figure() ax2 = plt.subplot((211)) plt.plot(time2, dh_mean, 'b', linewidth=2, label='dh') plt.plot(time2, dh_mean_cor, 'r', linewidth=2, label='dh$_{COR}$') #plt.legend().draw_frame(False) viz.add_inner_title(ax2, 'dh', 2) viz.add_inner_title(ax2, 'dh$_{COR}$', 3) plt.title('lon = %.2f, lat = %.2f' % (lon, lat)) plt.ylabel('m') #plt.xlim(1992, 2012.1) #plt.gca().xaxis.set_major_formatter(plt.FormatStrFormatter('%d')) ax3 = plt.subplot((212)) plt.plot(time2, dg_mean, 'g', linewidth=2, label='dAGC') #plt.legend().draw_frame(False) viz.add_inner_title(ax3, 'dAGC', 3) plt.ylabel('dB') #plt.xlim(1992, 2012.1) #plt.gca().xaxis.set_major_formatter(plt.FormatStrFormatter('%d')) else: fig = plt.figure() ax2 = plt.subplot((311)) plt.plot(time2, dh_mean, 'b', linewidth=2, label='dh') plt.plot(time2, dh_mean_cor, 'r', linewidth=2, label='dh$_{COR}$') #plt.legend().draw_frame(False) viz.add_inner_title(ax2, 'dh', 2) viz.add_inner_title(ax2, 'dh$_{COR}$', 3) plt.title('lon = %.2f, lat = %.2f' % (lon, lat)) plt.ylabel('m') #plt.xlim(1992, 2012.1) #plt.gca().xaxis.set_major_formatter(plt.FormatStrFormatter('%d')) ax3 = plt.subplot((312)) plt.plot(time2, dh_mean2, 'm', linewidth=2, label='$\Delta$dh') #plt.legend().draw_frame(False) viz.add_inner_title(ax3, '$\Delta$dh', 3) plt.ylabel('m') #plt.xlim(1992, 2012.1) #plt.gca().xaxis.set_major_formatter(plt.FormatStrFormatter('%d')) ax4 = plt.subplot((313)) plt.plot(time2, dg_mean2, 'c', linewidth=2, label='$\Delta$dAGC') #plt.legend().draw_frame(False) viz.add_inner_title(ax4, '$\Delta$dAGC', 3) plt.ylabel('dB') #plt.xlim(1992, 2012.1) #plt.gca().xaxis.set_major_formatter(plt.FormatStrFormatter('%d')) fig.autofmt_xdate() plt.savefig('ts.png') return fig
ts = mean_t + mean_xy[i, j] + Y[:, i, j] #x_pol, y_pol = spline_interp(t, ts, smooth=0.1) x_pol, y_pol = util.poly_fit(t, ts, order=3) x_lin, y_lin = linear_fit(t, ts) m, c = linear_fit(t, ts, return_coef=True) fig = plt.figure() ax = fig.add_subplot((111)) n = y_lin[0] # shift plt.plot(t, ts - n, linewidth=2) plt.plot(x_pol, y_pol - n) plt.plot(x_lin, y_lin - n) viz.add_inner_title(ax, 'linear trend = %.1f cm/yr' % (m * 100), loc=2) #plt.ylim(ts.min(), ts.max()) plt.xlabel('time') plt.ylabel('dh (m)') plt.title('Mean TS') plt.show() return fig def plot_grid_and_ts(lon, lat, dhdt, t, dh, (i, j), **kw): cell = (lon[j], lon[j + 1], lat[i], lat[i + 1]) plot_grid(lon, lat, dhdt, cell, **kw) plt.show() def plot_map(lon, lat, grid, bbox, mfile, mres=1, **kw):