def main(argv): #default settings markerSize=16 markerSize2=16 markerColor='g' markerColor2='red' lineWidth=2 fontSize=16 unit='cm' Save_timeseries='no' dispTsFig='yes' dispVelFig='yes' dispContour='only' contour_step=200 smoothContour='no' radius=0; edgeWidth=1.5 fig_dpi=300 if len(sys.argv)>2: try: opts, args = getopt.getopt(argv,"f:F:v:a:b:s:m:c:w:u:l:h:S:D:C:V:t:T:d:r:x:y:P:p:") except getopt.GetoptError: Usage() ; sys.exit(1) for opt,arg in opts: if opt == '-f': timeSeriesFile = arg elif opt == '-F': timeSeriesFile_2 = arg elif opt == '-v': velocityFile = arg elif opt == '-a': vmin = float(arg) elif opt == '-b': vmax = float(arg) elif opt == '-s': fontSize = int(arg) elif opt == '-m': markerSize=int(arg); markerSize2=int(arg) elif opt == '-S': Save_timeseries=arg elif opt == '-c': markerColor=arg elif opt == '-w': lineWidth=int(arg) elif opt == '-u': unit=arg elif opt == '-l': lbound=float(arg) elif opt == '-h': hbound=float(arg) elif opt == '-D': demFile=arg elif opt == '-C': dispContour=arg elif opt == '-V': contour_step=float(arg) elif opt == '-t': minDate=arg elif opt == '-T': maxDate=arg elif opt == '-d': datesNot2show = arg.split() elif opt == '-r': radius=abs(int(arg)) elif opt == '-x': xsub = [int(i) for i in arg.split(':')]; xsub.sort(); dispVelFig='no' elif opt == '-y': ysub = [int(i) for i in arg.split(':')]; ysub.sort(); dispVelFig='no' elif opt == '-P': dispTsFig=arg elif opt == '-p': dispVelFig=arg elif len(sys.argv)==2: if argv[0]=='-h': Usage(); sys.exit(1) elif os.path.isfile(argv[0]): timeSeriesFile = argv[0] h5timeseries = h5py.File(timeSeriesFile) if not 'timeseries' in h5timeseries.keys(): print 'ERROR' Usage(); sys.exit(1) else: Usage(); sys.exit(1) elif len(sys.argv)<2: Usage(); sys.exit(1) if unit in ('m','M'): unitFac=1 elif unit in ('cm','Cm','CM'): unitFac=100 elif unit in ('mm','Mm','MM','mM'): unitFac=1000 else: print 'Warning:' print 'wrong unit input!' print 'cm is considered to display the displacement' ############################################################## # Read time series file info if not os.path.isfile(timeSeriesFile): Usage();sys.exit(1) h5timeseries = h5py.File(timeSeriesFile) if not 'timeseries' in h5timeseries.keys(): Usage(); sys.exit(1) dateList1 = h5timeseries['timeseries'].keys() ############################################################## # Dates to show time series plot import matplotlib.dates as mdates years = mdates.YearLocator() # every year months = mdates.MonthLocator() # every month yearsFmt = mdates.DateFormatter('%Y') print '*******************' print 'All dates existed:' print dateList1 print '*******************' try: datesNot2show print 'dates not to show: '+str(datesNot2show) except: datesNot2show=[] try: minDate minDateyy=yyyymmdd2years(minDate) print 'minimum date: '+minDate for date in dateList1: yy=yyyymmdd2years(date) if yy < minDateyy: datesNot2show.append(date) except: pass try: maxDate maxDateyy=yyyymmdd2years(maxDate) print 'maximum date: '+maxDate for date in dateList1: yy=yyyymmdd2years(date) if yy > maxDateyy: datesNot2show.append(date) except: pass try: dateList=[] for date in dateList1: if date not in datesNot2show: dateList.append(date) print '--------------------------------------------' print 'dates used to show time series displacements:' print dateList print '--------------------------------------------' except: dateList=dateList1 print 'using all dates to show time series displacement' ################################################################### # Date info dateIndex={} for ni in range(len(dateList)): dateIndex[dateList[ni]]=ni tbase=[] d1 = datetime.datetime(*time.strptime(dateList[0],"%Y%m%d")[0:5]) for ni in range(len(dateList)): d2 = datetime.datetime(*time.strptime(dateList[ni],"%Y%m%d")[0:5]) diff = d2-d1 tbase.append(diff.days) dates=[] for ni in range(len(dateList)): d = datetime.datetime(*time.strptime(dateList[ni],"%Y%m%d")[0:5]) dates.append(d) datevector=[] for i in range(len(dates)): datevector.append(np.float(dates[i].year) + np.float(dates[i].month-1)/12 + np.float(dates[i].day-1)/365) datevector2=[round(i,2) for i in datevector] ########################################### # Plot Fig 1 - Velocity / last epoch of time series / DEM import matplotlib.pyplot as plt if dispVelFig in ('yes','Yes','y','Y','YES'): fig = plt.figure() ax=fig.add_subplot(111) try: velocityFile h5file=h5py.File(velocityFile,'r') k=h5file.keys() dset= h5file[k[0]].get(k[0]) print 'display: ' + k[0] except: dset = h5timeseries['timeseries'].get(h5timeseries['timeseries'].keys()[-1]) print 'display: last epoch of timeseries' #DEM/contour option try: demFile import _readfile as readfile if os.path.basename(demFile).split('.')[1]=='hgt': amp,dem,demRsc = readfile.read_float32(demFile) elif os.path.basename(demFile).split('.')[1]=='dem': dem,demRsc = readfile.read_dem(demFile) if dispContour in ('no','No','n','N','NO','yes','Yes','y','Y','YES'): print 'show DEM as basemap' cmap_dem=plt.get_cmap('gray') import _pysar_utilities as ut plt.imshow(ut.hillshade(dem,50.0),cmap=cmap_dem) if dispContour in ('only','Only','o','O','ONLY','yes','Yes','y','Y','YES'): print 'show contour' if smoothContour in ('yes','Yes','y','Y','YES'): import scipy.ndimage as ndimage dem=ndimage.gaussian_filter(dem,sigma=10.0,order=0) contour_sequence=np.arange(-6000,9000,contour_step) plt.contour(dem,contour_sequence,origin='lower',colors='black',alpha=0.5) except: print 'No DEM file' try: img=ax.imshow(dset,vmin=vmin,vmax=vmax) except: img=ax.imshow(dset) import matplotlib.patches as patches # need for draw rectangle of points selected on VelFig ########################################## # Plot Fig 2 - Time series plot import scipy.stats as stats fig2 = plt.figure(2) ax2=fig2.add_subplot(111) try: timeSeriesFile_2 h5timeseries_2=h5py.File(timeSeriesFile_2) print 'plot 2nd time series' except: pass ########### Plot Time Series with x/y ########## try: xsub ysub try: xmin=xsub[0]; xmax=xsub[1]+1; print 'x='+str(xsub[0])+':'+str(xsub[1]) except: xmin=xsub[0]-radius; xmax=xsub[0]+radius+1; print 'x='+str(xsub[0])+'+/-'+str(radius) try: ymin=ysub[0]; ymax=ysub[1]+1; print 'y='+str(ysub[0])+':'+str(ysub[1]) except: ymin=ysub[0]-radius; ymax=ysub[0]+radius+1; print 'y='+str(ysub[0])+'+/-'+str(radius) try: fig rectSelect=patches.Rectangle((xmin,ymin),radius*2+1,radius*2+1,fill=False,lw=edgeWidth) ax.add_patch(rectSelect) except: pass Dis=[] for date in dateList: Dis.append(h5timeseries['timeseries'].get(date)[ymin:ymax,xmin:xmax]) Dis0=array(Dis) dis=Dis0*unitFac dis=reshape(dis,(len(dateList),-1)) dis_mean=stats.nanmean(dis,1) if (xmax-xmin)*(ymax-ymin)==1: dis_std=[0]*len(dateList) else: dis_std=stats.nanstd(dis,1) (_, caps, _)=ax2.errorbar(dates,dis_mean,yerr=dis_std,fmt='-ko',\ ms=markerSize, lw=lineWidth, alpha=1, mfc=markerColor,\ elinewidth=edgeWidth,ecolor='black',capsize=markerSize*0.5) for cap in caps: cap.set_markeredgewidth(edgeWidth) print dis_mean # x axis format ax2.fmt_xdata = DateFormatter('%Y-%m-%d %H:%M:%S') if unitFac==100: ax2.set_ylabel('Displacement [cm]',fontsize=fontSize) elif unitFac==1000: ax2.set_ylabel('Displacement [mm]',fontsize=fontSize) else: ax2.set_ylabel('Displacement [m]' ,fontsize=fontSize) ax2.set_xlabel('Time [years]',fontsize=fontSize) ax2.set_title('x='+str(xmin)+':'+str(xmax-1)+', y='+str(ymin)+':'+str(ymax-1)) ax2.xaxis.set_major_locator(years) ax2.xaxis.set_major_formatter(yearsFmt) ax2.xaxis.set_minor_locator(months) datemin = datetime.date(int(datevector[0]),1,1) datemax = datetime.date(int(datevector[-1])+1,1,1) ax2.set_xlim(datemin, datemax) # y axis format try: lbound hbound ax2.set_ylim(lbound,hbound) except: ax2.set_ylim(nanmin(dis_mean-dis_std)-0.4*abs(nanmin(dis_mean)),\ nanmax(dis_mean+dis_std)+0.4*abs(nanmax(dis_mean))) for tick in ax2.xaxis.get_major_ticks(): tick.label.set_fontsize(fontSize) for tick in ax2.yaxis.get_major_ticks(): tick.label.set_fontsize(fontSize) #fig2.autofmt_xdate() #adjust x overlap by rorating, may enble again if Save_timeseries in ('yes','Yes','Y','y','YES'): import scipy.io as sio Delay={} Delay['displacement']=Dis0 Delay['unit']='m' Delay['time']=datevector tsNameBase='ts_x'+str(xmin)+'_'+str(xmax-1)+'y'+str(ymin)+'_'+str(ymax-1) sio.savemat(tsNameBase+'.mat', {'displacement': Delay}) print 'saved data to '+tsNameBase+'.mat' plt.savefig(tsNameBase+'.pdf',dpi=fig_dpi) print 'saved plot to '+tsNameBase+'.pdf'
def main(argv): color_map='jet' disp_opposite='no' try: opts, args = getopt.getopt(argv,"h:f:d:o:x:y:m:M:i:c:") except getopt.GetoptError: Usage() ; sys.exit(1) if opts==[]: Usage() ; sys.exit(1) for opt,arg in opts: if opt in ("-h","--help"): Usage(); sys.exit() elif opt == '-f': File = arg elif opt == '-d': demFile=arg elif opt == '-m': Vmin=float(arg) elif opt == '-M': Vmax=float(arg) elif opt == '-x': winx=arg.split(':') elif opt == '-y': winy = arg.split(':') elif opt == '-o': outName = arg elif opt == '-i': disp_opposite = arg elif opt == '-c': color_map=arg h5file=h5py.File(File,'r') k=h5file.keys() print k[0] #ccmap=plt.get_cmap(color_map) ################################################ cdict1 = {'red': ((0.0, 0.0, 0.0), (0.5, 0.0, 0.0), (0.6, 1.0, 1.0), (0.8, 1.0, 1.0), (1.0, 0.5, 0.5)), 'green': ((0.0, 0.0, 0.0), (0.2, 0.0, 0.0), (0.4, 1.0, 1.0), (0.6, 1.0, 1.0), (0.8, 0.0, 0.0), (1.0, 0.0, 0.0)), 'blue': ((0.0, 0.5, .5), (0.2, 1.0, 1.0), (0.4, 1.0, 1.0), (0.5, 0.0, 0.0), (1.0, 0.0, 0.0),) } if color_map =='pysar_hsv': ccmap = LinearSegmentedColormap('BlueRed1', cdict1) else: ccmap=plt.get_cmap(color_map) print 'colormap is : '+ color_map ################################################ dset = h5file[k[0]].get(k[0]) data=dset[0:dset.shape[0],0:dset.shape[1]] if disp_opposite in('yes','Yes','Y','y','YES'): data=-1*data try: xref=h5file[k[0]].attrs['ref_x'] yref=h5file[k[0]].attrs['ref_y'] except: print 'No reference point' try: ullon=float(h5file[k[0]].attrs['X_FIRST']) ullat=float(h5file[k[0]].attrs['Y_FIRST']) lon_step=float(h5file[k[0]].attrs['X_STEP']) lat_step=float(h5file[k[0]].attrs['Y_STEP']) lon_unit=h5file[k[0]].attrs['Y_UNIT'] lat_unit=h5file[k[0]].attrs['X_UNIT'] llcrnrlon=ullon llcrnrlat=ullat+lat_step*data.shape[0] urcrnrlon=ullon+lon_step*data.shape[1] urcrnrlat=ullat geocoord='yes' print 'Input file is Geocoded' except: geocoord='no' fig = plt.figure() ax = fig.add_axes([0.1,0.1,0.8,0.8]) m = Basemap(llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat, urcrnrlon=urcrnrlon, urcrnrlat=urcrnrlat, resolution='l', area_thresh=1., projection='cyl',suppress_ticks=False,ax=ax) print demFile demFile if os.path.basename(demFile).split('.')[1]=='hgt': amp,dem,demRsc = readfile.read_float32(demFile) elif os.path.basename(demFile).split('.')[1]=='dem': dem,demRsc = readfile.read_real_int16(demFile) ################################################################# try: winx wx=[int(i) for i in win_x.split()] dem=dem[:,wx[0]:wx[1]] data=data[:,wx[0]:wx[1]] ullon=float(h5file[k[0]].attrs['X_FIRST'])+wx[0] llcrnrlon=ullon urcrnrlon=ullon+lon_step*data.shape[1] except: print '' try: winy wy=[int(i) for i in winy.split()] dem=dem[wy[0]:wy[1],:] data=data[wy[0]:wy[1],:] except: print '' ################################################################ fig = plt.figure() ax = fig.add_axes([0.1,0.1,0.8,0.8]) m = Basemap(llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat, urcrnrlon=urcrnrlon, urcrnrlat=urcrnrlat, resolution='l', area_thresh=1., projection='cyl',suppress_ticks=False,ax=ax) cmap_dem=plt.get_cmap('gray') m.imshow(ut.hillshade(np.flipud(dem),50.0),cmap=cmap_dem) try: im=m.imshow(np.flipud(data),vmin=Vmin,vmax=Vmax,cmap=ccmap) # cb = m.colorbar(im,"right", size="5%", pad='2%') except: im=m.imshow(np.flipud(data)) try: figName = outName except: outName=os.path.basename(File).replace('.h5','') figName = outName + '.png' plt.savefig(figName,pad_inches=0.0) #plt.show() h5file.close()
def main(argv): color_map='jet' disp_opposite='no' try: opts, args = getopt.getopt(argv,"h:f:d:o:x:y:m:M:i:c:") except getopt.GetoptError: Usage() ; sys.exit(1) if opts==[]: Usage() ; sys.exit(1) for opt,arg in opts: if opt in ("-h","--help"): Usage() sys.exit() elif opt == '-f': File = arg elif opt == '-d': demFile=arg elif opt=='-m': Vmin=float(arg) elif opt=='-M': Vmax=float(arg) elif opt == '-x': winx=arg.split(':') elif opt == '-y': winy = arg.split(':') elif opt == '-o': outName = arg elif opt == '-i': disp_opposite = arg elif opt == '-c': color_map=arg h5file=h5py.File(File,'r') k=h5file.keys() print k[0] # ccmap=plt.get_cmap(color_map) ################################################ cdict1 = {'red': ((0.0, 0.0, 0.0), (0.5, 0.0, 0.0), (0.6, 1.0, 1.0), (0.8, 1.0, 1.0), (1.0, 0.5, 0.5)), 'green': ((0.0, 0.0, 0.0), (0.2, 0.0, 0.0), (0.4, 1.0, 1.0), (0.6, 1.0, 1.0), (0.8, 0.0, 0.0), (1.0, 0.0, 0.0)), 'blue': ((0.0, 0.5, .5), (0.2, 1.0, 1.0), (0.4, 1.0, 1.0), (0.5, 0.0, 0.0), (1.0, 0.0, 0.0),) } if color_map =='pysar_hsv': ccmap = LinearSegmentedColormap('BlueRed1', cdict1) else: ccmap=plt.get_cmap(color_map) print 'colormap is : '+ color_map ################################################ dset = h5file[k[0]].get(k[0]) data=dset[0:dset.shape[0],0:dset.shape[1]] if disp_opposite in('yes','Yes','Y','y','YES'): data=-1*data try: xref=h5file[k[0]].attrs['ref_x'] yref=h5file[k[0]].attrs['ref_y'] except: print 'No reference point' try: ullon=float(h5file[k[0]].attrs['X_FIRST']) ullat=float(h5file[k[0]].attrs['Y_FIRST']) lon_step=float(h5file[k[0]].attrs['X_STEP']) lat_step=float(h5file[k[0]].attrs['Y_STEP']) lon_unit=h5file[k[0]].attrs['Y_UNIT'] lat_unit=h5file[k[0]].attrs['X_UNIT'] llcrnrlon=ullon llcrnrlat=ullat+lat_step*data.shape[0] urcrnrlon=ullon+lon_step*data.shape[1] urcrnrlat=ullat geocoord='yes' print 'Input file is Geocoded' except: geocoord='no' fig = plt.figure() ax = fig.add_axes([0.1,0.1,0.8,0.8]) m = Basemap(llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat, urcrnrlon=urcrnrlon, urcrnrlat=urcrnrlat, resolution='l', area_thresh=1., projection='cyl',suppress_ticks=False,ax=ax) print demFile demFile if os.path.basename(demFile).split('.')[1]=='hgt': amp,dem,demRsc = readfile.read_float32(demFile) elif os.path.basename(demFile).split('.')[1]=='dem': dem,demRsc = readfile.read_dem(demFile) ################################################################# try: winx wx=[int(i) for i in win_x.split()] dem=dem[:,wx[0]:wx[1]] data=data[:,wx[0]:wx[1]] ullon=float(h5file[k[0]].attrs['X_FIRST'])+wx[0] llcrnrlon=ullon urcrnrlon=ullon+lon_step*data.shape[1] except: print '' try: winy wy=[int(i) for i in winy.split()] dem=dem[wy[0]:wy[1],:] data=data[wy[0]:wy[1],:] except: print '' ################################################################ fig = plt.figure() ax = fig.add_axes([0.1,0.1,0.8,0.8]) m = Basemap(llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat, urcrnrlon=urcrnrlon, urcrnrlat=urcrnrlat, resolution='l', area_thresh=1., projection='cyl',suppress_ticks=False,ax=ax) cmap_dem=plt.get_cmap('gray') m.imshow(ut.hillshade(np.flipud(dem),50.0),cmap=cmap_dem) try: im=m.imshow(np.flipud(data),vmin=Vmin,vmax=Vmax,cmap=ccmap) # cb = m.colorbar(im,"right", size="5%", pad='2%') except: im=m.imshow(np.flipud(data)) # cb = m.colorbar(im,"right", size="5%", pad='2%') # m.bluemarble() # cb = m.colorbar(im,"right", size="5%", pad='2%') # parallels = np.arange(31.,34,0.5) # m.drawparallels(parallels,labels=[1,0,0,1],linewidth=0.0) # meridians = np.arange(-115.,-112.,0.5) # m.drawmeridians(meridians,labels=[1,0,0,1],linewidth=0.0) # m.drawmapscale() # m = Basemap(llcrnrlon=-110.,llcrnrlat=0.,urcrnrlon=-20.,urcrnrlat=57., # projection='lcc',lat_1=20.,lat_2=40.,lon_0=-60., # resolution ='l',area_thresh=1000.) # m.drawcoastlines() # m.drawcountries() # m.drawmapboundary(fill_color='#99ffff') # m.fillcontinents(color='#cc9966',lake_color='#99ffff') # m.drawparallels(np.arange(10,70,20),labels=[1,1,0,0]) # m.drawmeridians(np.arange(-100,0,20),labels=[0,0,0,1]) # plt.title('Atlantic Hurricane Tracks (Storms Reaching Category 4, 1851-2004)') try: figName = outName except: outName=os.path.basename(File).replace('.h5','') figName = outName + '.png' plt.savefig(figName,pad_inches=0.0) # plt.show() h5file.close()
def main(argv): try: opts, args = getopt.getopt(argv,"h:D:O:G:S:f:m:M:l:u:s:c:e:d:r:p:w:i:j:t:R:a:b:k:x:y:") except getopt.GetoptError: Usage() ; sys.exit(1) flip_lr='no' flip_ud='no' disp_geo = 'no' font_size=8 color_map='jet' figs_rows=5 figs_cols=8 rewrapping='yes' allData2display='yes' Wspace = 0.1 Hspace = 0.1 title = 'out' # title = 'None' showRef = 'yes' ref_color='k' ref_symbol='s' ref_size =10 dip_opposite = 'no' saveFig='no' if opts==[]: Usage() ; sys.exit(1) for opt,arg in opts: if opt in ("-h","--help"): Usage() sys.exit() elif opt == '-f': File = arg elif opt == '-D': demFile=arg elif opt == '-m': min = float(arg) elif opt == '-M': max = float(arg) elif opt == '-l': flip_lr = arg elif opt == '-u': flip_ud = arg elif opt == '-s': font_size = int(arg) elif opt == '-c': color_map = arg elif opt == '-e': epoch_number = int(arg) allData2display='no' elif opt == '-d': epoch_date = arg allData2display='no' elif opt == '-r': figs_rows = int(arg) elif opt == '-p': figs_cols = int(arg) elif opt == '-w': rewrapping = arg elif opt == '-i': Wspace = float(arg) elif opt == '-j': Hspace = float(arg) elif opt == '-t': title = arg elif opt == '-R': showRef = arg elif opt == '-a': ref_color = arg elif opt == '-b': ref_symbol = arg elif opt == 'k': ref_size=int(arg) elif opt == '-x': win_x = arg elif opt == '-y': win_y = arg elif opt == '-G': disp_geo = arg elif opt == '-O': dip_opposite=arg elif opt=='-S': saveFig=arg h5file=h5py.File(File,'r') k=h5file.keys() print k if color_map == 'hsv': ################################################ cdict1 = {'red': ((0.0, 0.0, 0.0), (0.5, 0.0, 0.0), (0.6, 1.0, 1.0), (0.8, 1.0, 1.0), (1.0, 0.5, 0.5)), 'green': ((0.0, 0.0, 0.0), (0.2, 0.0, 0.0), (0.4, 1.0, 1.0), (0.6, 1.0, 1.0), (0.8, 0.0, 0.0), (1.0, 0.0, 0.0)), 'blue': ((0.0, 0.5, .5), (0.2, 1.0, 1.0), (0.4, 1.0, 1.0), (0.5, 0.0, 0.0), (1.0, 0.0, 0.0),) } ccmap = LinearSegmentedColormap('BlueRed1', cdict1) ################################################ else: ccmap=plt.get_cmap(color_map) #################################################################### #################################################################### # if k[0]=='velocity' or k[0]=='temporal_coherence' or k[0]=='rmse': if len(k)==1 and k[0] in ('dem','velocity','mask','temporal_coherence','rmse'): dset = h5file[k[0]].get(k[0]) data=dset[0:dset.shape[0],0:dset.shape[1]] if dip_opposite in('yes','Yes','Y','y','YES'): data=-1*data try: xref=h5file[k[0]].attrs['ref_x'] yref=h5file[k[0]].attrs['ref_y'] except: print 'No reference point' # Yunjun, Mar 2015 try: xref=xref-h5file[k[0]].attrs['subset_x0'] yref=yref-h5file[k[0]].attrs['subset_y0'] except: print 'No subset' try: ullon=float(h5file[k[0]].attrs['X_FIRST']) ullat=float(h5file[k[0]].attrs['Y_FIRST']) lon_step=float(h5file[k[0]].attrs['X_STEP']) lat_step=float(h5file[k[0]].attrs['Y_STEP']) lon_unit=h5file[k[0]].attrs['Y_UNIT'] lat_unit=h5file[k[0]].attrs['X_UNIT'] llcrnrlon=ullon llcrnrlat=ullat+lat_step*data.shape[0] urcrnrlon=ullon+lon_step*data.shape[1] urcrnrlat=ullat geocoord='yes' print 'Input file is Geocoded' except: geocoord='no' try: win_x wx=[int(i) for i in win_x.split()] data=data[:,wx[0]:wx[1]] xref = xref-wx[0] except: print 'No subste in x direction' try: win_y wy=[int(i) for i in win_y.split()] data=data[wy[0]:wy[1],:] yref = yref-wy[0] except: print 'No subset in y direction' try: min except: min=np.nanmin(data) try: max except: max=np.nanmax(data) if flip_lr=='yes': data=np.fliplr(data) xref=np.shape(data)[1]-xref-1 if flip_ud=='yes': data=np.flipud(data) yref=np.shape(data)[0]-yref-1 try: demFile # amp,dem,demRsc = readfile.read_float32(demFile) if os.path.basename(demFile).split('.')[1]=='hgt': amp,dem,demRsc = readfile.read_float32(demFile) elif os.path.basename(demFile).split('.')[1]=='dem': dem,demRsc = readfile.read_dem(demFile) try: win_x wx=[int(i) for i in win_x.split()] dem=dem[:,wx[0]:wx[1]] except: print '' try: win_y wy=[int(i) for i in win_y.split()] dem=dem[wy[0]:wy[1],:] except: print '' if flip_lr=='yes': dem=np.fliplr(dem) if flip_ud=='yes': dem=np.flipud(dem) cmap_dem=plt.get_cmap('gray') if disp_geo in ('yes','Yes','Y','y','YES') and geocoord in ('yes','Yes','Y','y','YES'): print 'display geo' # from mpl_toolkits.basemap import Basemap # m = Basemap(llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat, urcrnrlon=urcrnrlon, urcrnrlat=urcrnrlat,resolution='f', area_thresh=1., projection='cyl') # m.imshow(ut.hillshade(dem,50.0), interpolation='nearest', origin='upper') # m.drawcoastlines(color='w',linewidth=0.8) # m.drawmapboundary() # draw a line around the map region # m.drawrivers() # m.drawparallels(numpy.arange(int(d1.min()), int(d1.max()), 1),linewidth=0.2,labels=[1,0,0,0]) # m.drawmeridians(numpy.arange(int(d0.min()), int(d0.max()), 1),linewidth=0.2,labels=[0,0,0,1]) else: print 'Not GEO' plt.imshow(ut.hillshade(dem,50.0),cmap=cmap_dem) except: print 'No DEM file' plt.imshow(data,cmap=ccmap, vmin=min, vmax=max) plt.colorbar() if k[0]=='velocity': plt.title('Velocity (m/yr)',fontsize=font_size) figName='velocity.pdf' elif k[0]=='temporal_coherence': plt.title('Temporal coherence',fontsize=font_size) figName='temporal_coherence.pdf' elif k[0]=='dem': plt.title('DEM error',fontsize=font_size) figName='DEM_error.pdf' elif k[0]=='rmse': plt.title('RMSE (m/yr)',fontsize=font_size) figName='rmse.pdf' elif k[0]=='mask': plt.title('Pixels with no valid value.',fontsize=font_size) figName='mask.pdf' if showRef=='yes': try: refPoint=ref_color+ref_symbol plt.plot(xref,yref,refPoint,ms=ref_size) except: print 'No reference point' plt.xlim(0,np.shape(data)[1]) plt.ylim(np.shape(data)[0],0) if saveFig=='yes': plt.savefig(figName) plt.show() # plt.savefig('fig.pdf') # fig = plt.figure() # ax.imshow(data,vmin=min, vmax=max) # ax.xaxis.label.set_fontsize(40) #################################################################### #################################################################### if 'timeseries' in k and allData2display=='yes': if rewrapping=='yes': print 'rewrapping' dateList=h5file['timeseries'].keys() nfigs=figs_rows*figs_cols ligram = len(dateList) range2phase=4*np.pi/float(h5file['timeseries'].attrs['WAVELENGTH']) # range2phase=4*np.pi/0.056 print 'number of timeseries epochs to display:'+ str(ligram) kk=int(ligram/nfigs)+1 ii=0 for j in range(1,kk): fig = plt.figure(j) ii=(j-1)*nfigs+1 for i in range(ii,ii+nfigs): ax = fig.add_subplot(figs_rows,figs_cols,i-ii+1) dset=h5file['timeseries'].get(dateList[i-1]) data = dset[0:dset.shape[0],0:dset.shape[1]] data=range2phase*data # data=np.angle(np.exp(1j*data)) data=rewrap(data) ax.imshow(data,cmap=ccmap) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title=='out': ax.set_title(dateList[i-1],fontsize=font_size) elif title=='in': add_inner_title(ax, dateList[i-1], loc=1) fig.subplots_adjust(wspace=Wspace,hspace=Hspace) figName=k[0]+'_'+str(j)+'.pdf' if saveFig in ['yes','Yes','y','YES']: plt.savefig(figName) fig = plt.figure(kk) ii=(kk-1)*nfigs+1 for i in range(ii,ligram+1): ax = fig.add_subplot(figs_rows,figs_cols,i-ii+1) dset=h5file['timeseries'].get(dateList[i-1]) data = dset[0:dset.shape[0],0:dset.shape[1]] data=range2phase*data # data=np.angle(np.exp(1j*data)) data=rewrap(data) ax.imshow(data,cmap=ccmap) ax.xaxis.label.set_fontsize(20) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title=='out': ax.set_title(dateList[i-1],fontsize=font_size) elif title =='in': add_inner_title(ax, dateList[i-1], loc=1) fig.subplots_adjust(wspace=Wspace,hspace=Hspace) figName=k[0]+'_'+str(kk)+'.pdf' if saveFig in ['yes','Yes','y','YES']: plt.savefig(figName) plt.show() else: print 'No rewrapping' dateList=h5file['timeseries'].keys() nfigs=figs_rows*figs_cols ligram = len(dateList) print 'number of timeseries epochs to display:'+ str(ligram) kk=int(ligram/nfigs)+1 ii=0 for j in range(1,kk): fig = plt.figure(j) ii=(j-1)*nfigs+1 for i in range(ii,ii+nfigs): ax = fig.add_subplot(figs_rows,figs_cols,i-ii+1) data=h5file['timeseries'].get(dateList[i-1]) try: im=ax.imshow(data,cmap=ccmap,vmin=min,vmax=max) # print 'here' except: im=ax.imshow(data,cmap=ccmap) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title=='out': ax.set_title(dateList[i-1],fontsize=font_size) elif title=='in': add_inner_title(ax, dateList[i-1], loc=1) fig.subplots_adjust(wspace=Wspace,hspace=Hspace) fig = plt.figure(kk) ii=(kk-1)*nfigs+1 for i in range(ii,ligram+1): ax = fig.add_subplot(figs_rows,figs_cols,i-ii+1) data=h5file['timeseries'].get(dateList[i-1]) try: im=ax.imshow(data,cmap=ccmap,vmin=min,vmax=max) except: im=ax.imshow(data,cmap=ccmap) ax.xaxis.label.set_fontsize(20) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title=='out': ax.set_title(dateList[i-1],fontsize=font_size) if title=='in': add_inner_title(ax, dateList[i-1], loc=1) fig.subplots_adjust(wspace=Wspace,hspace=Hspace) plt.show() #################################################################### #################################################################### elif 'timeseries' in k and allData2display=='no': dateList=h5file['timeseries'].keys() try: epoch_number except: epoch_number=dateList.index(epoch_date) range2phase=4*np.pi/float(h5file['timeseries'].attrs['WAVELENGTH']) # range2phase=4*np.pi/0.056 dset=h5file['timeseries'].get(dateList[epoch_number]) data = dset[0:dset.shape[0],0:dset.shape[1]] if rewrapping=='yes': data=range2phase*data # data=np.angle(np.exp(1j*data)) data=rewrap(data) try: min except: min=np.nanmin(data) try: max except: max=np.nanmax(data) plt.imshow(data,cmap=ccmap,vmin=min,vmax=max) plt.colorbar() plt.show() ################################################################ ################################################################ if k[0]in('interferograms','coherence','wrapped') and allData2display=='yes': if k[0] in ('coherence','wrapped'): rewrapping='no' # color_map = 'gray' # ccmap=plt.get_cmap(color_map) if rewrapping=='yes': ifgramList=h5file[k[0]].keys() nfigs=figs_rows*figs_cols ligram = len(ifgramList) print 'number of '+k[0]+' to display:'+ str(ligram) kk=int(ligram/nfigs)+1 ii=0 for j in range(1,kk): fig = plt.figure(j) ii=(j-1)*nfigs+1 for i in range(ii,ii+nfigs): ax = fig.add_subplot(figs_rows,figs_cols,i-ii+1) dset = h5file[k[0]][ifgramList[i-1]].get(ifgramList[i-1]) data = dset[0:dset.shape[0],0:dset.shape[1]] data=np.angle(np.exp(1j*data)) ax.imshow(data,cmap=ccmap) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title=='out': ax.set_title(h5file[k[0]][ifgramList[i-1]].attrs['DATE12'],fontsize=font_size) elif title=='in': add_inner_title(ax, h5file[k[0]][ifgramList[i-1]].attrs['DATE12'], loc=1) fig.subplots_adjust(wspace=Wspace,hspace=Hspace) fig = plt.figure(kk) ii=(kk-1)*nfigs+1 for i in range(ii,ligram+1): ax = fig.add_subplot(figs_rows,figs_cols,i-ii+1) dset = h5file[k[0]][ifgramList[i-1]].get(ifgramList[i-1]) data = dset[0:dset.shape[0],0:dset.shape[1]] data=np.angle(np.exp(1j*data)) ax.imshow(data,cmap=ccmap) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title=='out': ax.set_title(h5file[k[0]][ifgramList[i-1]].attrs['DATE12'],fontsize=font_size) elif title=='in': add_inner_title(ax, h5file[k[0]][ifgramList[i-1]].attrs['DATE12'], loc=1) fig.subplots_adjust(wspace=Wspace,hspace=Hspace) plt.show() else: ifgramList=h5file[k[0]].keys() nfigs=figs_rows*figs_cols ligram = len(ifgramList) print 'number of '+k[0]+' to display:'+ str(ligram) kk=int(ligram/nfigs)+1 ii=0 for j in range(1,kk): fig = plt.figure(j) ii=(j-1)*nfigs+1 for i in range(ii,ii+nfigs): ax = fig.add_subplot(figs_rows,figs_cols,i-ii+1) print 'loading '+ifgramList[i-1] dset = h5file[k[0]][ifgramList[i-1]].get(ifgramList[i-1]) data = dset[0:dset.shape[0],0:dset.shape[1]] try: ax.imshow(data,vmin=min,vmax=max,cmap=ccmap) except: ax.imshow(data,cmap=ccmap) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title=='out': ax.set_title(h5file[k[0]][ifgramList[i-1]].attrs['DATE12'],fontsize=font_size) elif title=='in': add_inner_title(ax, h5file[k[0]][ifgramList[i-1]].attrs['DATE12'], loc=1) fig.subplots_adjust(wspace=Wspace,hspace=Hspace) fig = plt.figure(kk) ii=(kk-1)*nfigs+1 for i in range(ii,ligram+1): ax = fig.add_subplot(figs_rows,figs_cols,i-ii+1) print 'loading '+ifgramList[i-1] dset = h5file[k[0]][ifgramList[i-1]].get(ifgramList[i-1]) data = dset[0:dset.shape[0],0:dset.shape[1]] #data = h5file[k[0]][ifgramList[i-1]].get(ifgramList[i-1]) try: ax.imshow(data,vmin=min,vmax=max,cmap=ccmap) except: ax.imshow(data,cmap=ccmap) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title=='out': ax.set_title(h5file[k[0]][ifgramList[i-1]].attrs['DATE12'],fontsize=font_size) elif title=='in': add_inner_title(ax, h5file[k[0]][ifgramList[i-1]].attrs['DATE12'], loc=1) fig.subplots_adjust(wspace=Wspace,hspace=Hspace) plt.show() #################################################################### #################################################################### elif k[0]in('interferograms','coherence','wrapped') and allData2display=='no': if k[0] in ('coherence','wrapped'): rewrapping=='no' ifgramList=h5file[k[0]].keys() try: epoch_number except: for i in range(len(ifgramList)): if epoch_date in ifgramList[i]: epoch_number = i dset = h5file[k[0]][ifgramList[epoch_number]].get(ifgramList[epoch_number]) data = dset[0:dset.shape[0],0:dset.shape[1]] if rewrapping=='yes': data=np.angle(np.exp(1j*data)) if dip_opposite in('yes','Yes','Y','y','YES'): data=-1*data #DEM basemap try: demFile if os.path.basename(demFile).split('.')[1]=='hgt': amp,dem,demRsc = readfile.read_float32(demFile) elif os.path.basename(demFile).split('.')[1]=='dem': dem,demRsc = readfile.read_dem(demFile) try: win_x wx=[int(i) for i in win_x.split()] dem=dem[:,wx[0]:wx[1]] except: print '' try: win_y wy=[int(i) for i in win_y.split()] dem=dem[wy[0]:wy[1],:] except: print '' if flip_lr=='yes': dem=np.fliplr(dem) if flip_ud=='yes': dem=np.flipud(dem) cmap_dem=plt.get_cmap('gray') if disp_geo in ('yes','Yes','Y','y','YES') and geocoord in ('yes','Yes','Y','y','YES'): print 'display geo' else: print 'Not GEO' plt.imshow(ut.hillshade(dem,50.0),cmap=cmap_dem) except: print 'No DEM file' try: plt.imshow(data,cmap=ccmap,vmin=min,vmax=max) except: plt.imshow(data,cmap=ccmap) plt.colorbar() # plt.title(h5file[k[0]][ifgramList[epoch_number]].attrs['DATE12'],fontsize=font_size) plt.title(ifgramList[epoch_number],fontsize=font_size) plt.show() ################################################################ ################################################################ h5file.close()
def main(argv): try: opts, args = getopt.getopt( argv, "h:D:O:G:S:f:m:M:l:u:s:c:e:d:r:p:w:i:j:t:R:a:b:k:x:y:") except getopt.GetoptError: Usage() sys.exit(1) flip_lr = 'no' flip_ud = 'no' disp_geo = 'no' font_size = 8 color_map = 'jet' figs_rows = 5 figs_cols = 8 rewrapping = 'yes' allData2display = 'yes' Wspace = 0.1 Hspace = 0.1 title = 'out' # title = 'None' showRef = 'yes' ref_color = 'k' ref_symbol = 's' ref_size = 10 dip_opposite = 'no' saveFig = 'no' if opts == []: Usage() sys.exit(1) for opt, arg in opts: if opt in ("-h", "--help"): Usage() sys.exit() elif opt == '-f': File = arg elif opt == '-D': demFile = arg elif opt == '-m': min = float(arg) elif opt == '-M': max = float(arg) elif opt == '-l': flip_lr = arg elif opt == '-u': flip_ud = arg elif opt == '-s': font_size = int(arg) elif opt == '-c': color_map = arg elif opt == '-e': epoch_number = int(arg) allData2display = 'no' elif opt == '-d': epoch_date = arg allData2display = 'no' elif opt == '-r': figs_rows = int(arg) elif opt == '-p': figs_cols = int(arg) elif opt == '-w': rewrapping = arg elif opt == '-i': Wspace = float(arg) elif opt == '-j': Hspace = float(arg) elif opt == '-t': title = arg elif opt == '-R': showRef = arg elif opt == '-a': ref_color = arg elif opt == '-b': ref_symbol = arg elif opt == 'k': ref_size = int(arg) elif opt == '-x': win_x = arg elif opt == '-y': win_y = arg elif opt == '-G': disp_geo = arg elif opt == '-O': dip_opposite = arg elif opt == '-S': saveFig = arg h5file = h5py.File(File, 'r') k = h5file.keys() print k if color_map == 'hsv': ################################################ cdict1 = { 'red': ((0.0, 0.0, 0.0), (0.5, 0.0, 0.0), (0.6, 1.0, 1.0), (0.8, 1.0, 1.0), (1.0, 0.5, 0.5)), 'green': ((0.0, 0.0, 0.0), (0.2, 0.0, 0.0), (0.4, 1.0, 1.0), (0.6, 1.0, 1.0), (0.8, 0.0, 0.0), (1.0, 0.0, 0.0)), 'blue': ( (0.0, 0.5, .5), (0.2, 1.0, 1.0), (0.4, 1.0, 1.0), (0.5, 0.0, 0.0), (1.0, 0.0, 0.0), ) } ccmap = LinearSegmentedColormap('BlueRed1', cdict1) ################################################ else: ccmap = plt.get_cmap(color_map) #################################################################### #################################################################### # if k[0]=='velocity' or k[0]=='temporal_coherence' or k[0]=='rmse': if len(k) == 1 and k[0] in ('dem', 'velocity', 'mask', 'temporal_coherence', 'rmse'): dset = h5file[k[0]].get(k[0]) data = dset[0:dset.shape[0], 0:dset.shape[1]] if dip_opposite in ('yes', 'Yes', 'Y', 'y', 'YES'): data = -1 * data try: xref = h5file[k[0]].attrs['ref_x'] yref = h5file[k[0]].attrs['ref_y'] except: print 'No reference point' # Yunjun, Mar 2015 try: xref = xref - h5file[k[0]].attrs['subset_x0'] yref = yref - h5file[k[0]].attrs['subset_y0'] except: print 'No subset' try: ullon = float(h5file[k[0]].attrs['X_FIRST']) ullat = float(h5file[k[0]].attrs['Y_FIRST']) lon_step = float(h5file[k[0]].attrs['X_STEP']) lat_step = float(h5file[k[0]].attrs['Y_STEP']) lon_unit = h5file[k[0]].attrs['Y_UNIT'] lat_unit = h5file[k[0]].attrs['X_UNIT'] llcrnrlon = ullon llcrnrlat = ullat + lat_step * data.shape[0] urcrnrlon = ullon + lon_step * data.shape[1] urcrnrlat = ullat geocoord = 'yes' print 'Input file is Geocoded' except: geocoord = 'no' try: win_x wx = [int(i) for i in win_x.split()] data = data[:, wx[0]:wx[1]] xref = xref - wx[0] except: print 'No subste in x direction' try: win_y wy = [int(i) for i in win_y.split()] data = data[wy[0]:wy[1], :] yref = yref - wy[0] except: print 'No subset in y direction' try: min except: min = np.nanmin(data) try: max except: max = np.nanmax(data) if flip_lr == 'yes': data = np.fliplr(data) xref = np.shape(data)[1] - xref - 1 if flip_ud == 'yes': data = np.flipud(data) yref = np.shape(data)[0] - yref - 1 try: demFile # amp,dem,demRsc = readfile.read_float32(demFile) if os.path.basename(demFile).split('.')[1] == 'hgt': amp, dem, demRsc = readfile.read_float32(demFile) elif os.path.basename(demFile).split('.')[1] == 'dem': dem, demRsc = readfile.read_dem(demFile) try: win_x wx = [int(i) for i in win_x.split()] dem = dem[:, wx[0]:wx[1]] except: print '' try: win_y wy = [int(i) for i in win_y.split()] dem = dem[wy[0]:wy[1], :] except: print '' if flip_lr == 'yes': dem = np.fliplr(dem) if flip_ud == 'yes': dem = np.flipud(dem) cmap_dem = plt.get_cmap('gray') if disp_geo in ('yes', 'Yes', 'Y', 'y', 'YES') and geocoord in ('yes', 'Yes', 'Y', 'y', 'YES'): print 'display geo' # from mpl_toolkits.basemap import Basemap # m = Basemap(llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat, urcrnrlon=urcrnrlon, urcrnrlat=urcrnrlat,resolution='f', area_thresh=1., projection='cyl') # m.imshow(ut.hillshade(dem,50.0), interpolation='nearest', origin='upper') # m.drawcoastlines(color='w',linewidth=0.8) # m.drawmapboundary() # draw a line around the map region # m.drawrivers() # m.drawparallels(numpy.arange(int(d1.min()), int(d1.max()), 1),linewidth=0.2,labels=[1,0,0,0]) # m.drawmeridians(numpy.arange(int(d0.min()), int(d0.max()), 1),linewidth=0.2,labels=[0,0,0,1]) else: print 'Not GEO' plt.imshow(ut.hillshade(dem, 50.0), cmap=cmap_dem) except: print 'No DEM file' plt.imshow(data, cmap=ccmap, vmin=min, vmax=max) plt.colorbar() if k[0] == 'velocity': plt.title('Velocity (m/yr)', fontsize=font_size) figName = 'velocity.pdf' elif k[0] == 'temporal_coherence': plt.title('Temporal coherence', fontsize=font_size) figName = 'temporal_coherence.pdf' elif k[0] == 'dem': plt.title('DEM error', fontsize=font_size) figName = 'DEM_error.pdf' elif k[0] == 'rmse': plt.title('RMSE (m/yr)', fontsize=font_size) figName = 'rmse.pdf' elif k[0] == 'mask': plt.title('Pixels with no valid value.', fontsize=font_size) figName = 'mask.pdf' if showRef == 'yes': try: refPoint = ref_color + ref_symbol plt.plot(xref, yref, refPoint, ms=ref_size) except: print 'No reference point' plt.xlim(0, np.shape(data)[1]) plt.ylim(np.shape(data)[0], 0) if saveFig == 'yes': plt.savefig(figName) plt.show() # plt.savefig('fig.pdf') # fig = plt.figure() # ax.imshow(data,vmin=min, vmax=max) # ax.xaxis.label.set_fontsize(40) #################################################################### #################################################################### if 'timeseries' in k and allData2display == 'yes': if rewrapping == 'yes': print 'rewrapping' dateList = h5file['timeseries'].keys() nfigs = figs_rows * figs_cols ligram = len(dateList) range2phase = 4 * np.pi / float( h5file['timeseries'].attrs['WAVELENGTH']) # range2phase=4*np.pi/0.056 print 'number of timeseries epochs to display:' + str(ligram) kk = int(ligram / nfigs) + 1 ii = 0 for j in range(1, kk): fig = plt.figure(j) ii = (j - 1) * nfigs + 1 for i in range(ii, ii + nfigs): ax = fig.add_subplot(figs_rows, figs_cols, i - ii + 1) dset = h5file['timeseries'].get(dateList[i - 1]) data = dset[0:dset.shape[0], 0:dset.shape[1]] data = range2phase * data # data=np.angle(np.exp(1j*data)) data = rewrap(data) ax.imshow(data, cmap=ccmap) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title == 'out': ax.set_title(dateList[i - 1], fontsize=font_size) elif title == 'in': add_inner_title(ax, dateList[i - 1], loc=1) fig.subplots_adjust(wspace=Wspace, hspace=Hspace) figName = k[0] + '_' + str(j) + '.pdf' if saveFig in ['yes', 'Yes', 'y', 'YES']: plt.savefig(figName) fig = plt.figure(kk) ii = (kk - 1) * nfigs + 1 for i in range(ii, ligram + 1): ax = fig.add_subplot(figs_rows, figs_cols, i - ii + 1) dset = h5file['timeseries'].get(dateList[i - 1]) data = dset[0:dset.shape[0], 0:dset.shape[1]] data = range2phase * data # data=np.angle(np.exp(1j*data)) data = rewrap(data) ax.imshow(data, cmap=ccmap) ax.xaxis.label.set_fontsize(20) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title == 'out': ax.set_title(dateList[i - 1], fontsize=font_size) elif title == 'in': add_inner_title(ax, dateList[i - 1], loc=1) fig.subplots_adjust(wspace=Wspace, hspace=Hspace) figName = k[0] + '_' + str(kk) + '.pdf' if saveFig in ['yes', 'Yes', 'y', 'YES']: plt.savefig(figName) plt.show() else: print 'No rewrapping' dateList = h5file['timeseries'].keys() nfigs = figs_rows * figs_cols ligram = len(dateList) print 'number of timeseries epochs to display:' + str(ligram) kk = int(ligram / nfigs) + 1 ii = 0 for j in range(1, kk): fig = plt.figure(j) ii = (j - 1) * nfigs + 1 for i in range(ii, ii + nfigs): ax = fig.add_subplot(figs_rows, figs_cols, i - ii + 1) data = h5file['timeseries'].get(dateList[i - 1]) try: im = ax.imshow(data, cmap=ccmap, vmin=min, vmax=max) # print 'here' except: im = ax.imshow(data, cmap=ccmap) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title == 'out': ax.set_title(dateList[i - 1], fontsize=font_size) elif title == 'in': add_inner_title(ax, dateList[i - 1], loc=1) fig.subplots_adjust(wspace=Wspace, hspace=Hspace) fig = plt.figure(kk) ii = (kk - 1) * nfigs + 1 for i in range(ii, ligram + 1): ax = fig.add_subplot(figs_rows, figs_cols, i - ii + 1) data = h5file['timeseries'].get(dateList[i - 1]) try: im = ax.imshow(data, cmap=ccmap, vmin=min, vmax=max) except: im = ax.imshow(data, cmap=ccmap) ax.xaxis.label.set_fontsize(20) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title == 'out': ax.set_title(dateList[i - 1], fontsize=font_size) if title == 'in': add_inner_title(ax, dateList[i - 1], loc=1) fig.subplots_adjust(wspace=Wspace, hspace=Hspace) plt.show() #################################################################### #################################################################### elif 'timeseries' in k and allData2display == 'no': dateList = h5file['timeseries'].keys() try: epoch_number except: epoch_number = dateList.index(epoch_date) range2phase = 4 * np.pi / float( h5file['timeseries'].attrs['WAVELENGTH']) # range2phase=4*np.pi/0.056 dset = h5file['timeseries'].get(dateList[epoch_number]) data = dset[0:dset.shape[0], 0:dset.shape[1]] if rewrapping == 'yes': data = range2phase * data # data=np.angle(np.exp(1j*data)) data = rewrap(data) try: min except: min = np.nanmin(data) try: max except: max = np.nanmax(data) plt.imshow(data, cmap=ccmap, vmin=min, vmax=max) plt.colorbar() plt.show() ################################################################ ################################################################ if k[0] in ('interferograms', 'coherence', 'wrapped') and allData2display == 'yes': if k[0] in ('coherence', 'wrapped'): rewrapping = 'no' # color_map = 'gray' # ccmap=plt.get_cmap(color_map) if rewrapping == 'yes': ifgramList = h5file[k[0]].keys() nfigs = figs_rows * figs_cols ligram = len(ifgramList) print 'number of ' + k[0] + ' to display:' + str(ligram) kk = int(ligram / nfigs) + 1 ii = 0 for j in range(1, kk): fig = plt.figure(j) ii = (j - 1) * nfigs + 1 for i in range(ii, ii + nfigs): ax = fig.add_subplot(figs_rows, figs_cols, i - ii + 1) dset = h5file[k[0]][ifgramList[i - 1]].get(ifgramList[i - 1]) data = dset[0:dset.shape[0], 0:dset.shape[1]] data = np.angle(np.exp(1j * data)) ax.imshow(data, cmap=ccmap) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title == 'out': ax.set_title( h5file[k[0]][ifgramList[i - 1]].attrs['DATE12'], fontsize=font_size) elif title == 'in': add_inner_title( ax, h5file[k[0]][ifgramList[i - 1]].attrs['DATE12'], loc=1) fig.subplots_adjust(wspace=Wspace, hspace=Hspace) fig = plt.figure(kk) ii = (kk - 1) * nfigs + 1 for i in range(ii, ligram + 1): ax = fig.add_subplot(figs_rows, figs_cols, i - ii + 1) dset = h5file[k[0]][ifgramList[i - 1]].get(ifgramList[i - 1]) data = dset[0:dset.shape[0], 0:dset.shape[1]] data = np.angle(np.exp(1j * data)) ax.imshow(data, cmap=ccmap) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title == 'out': ax.set_title(h5file[k[0]][ifgramList[i - 1]].attrs['DATE12'], fontsize=font_size) elif title == 'in': add_inner_title( ax, h5file[k[0]][ifgramList[i - 1]].attrs['DATE12'], loc=1) fig.subplots_adjust(wspace=Wspace, hspace=Hspace) plt.show() else: ifgramList = h5file[k[0]].keys() nfigs = figs_rows * figs_cols ligram = len(ifgramList) print 'number of ' + k[0] + ' to display:' + str(ligram) kk = int(ligram / nfigs) + 1 ii = 0 for j in range(1, kk): fig = plt.figure(j) ii = (j - 1) * nfigs + 1 for i in range(ii, ii + nfigs): ax = fig.add_subplot(figs_rows, figs_cols, i - ii + 1) print 'loading ' + ifgramList[i - 1] dset = h5file[k[0]][ifgramList[i - 1]].get(ifgramList[i - 1]) data = dset[0:dset.shape[0], 0:dset.shape[1]] try: ax.imshow(data, vmin=min, vmax=max, cmap=ccmap) except: ax.imshow(data, cmap=ccmap) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title == 'out': ax.set_title( h5file[k[0]][ifgramList[i - 1]].attrs['DATE12'], fontsize=font_size) elif title == 'in': add_inner_title( ax, h5file[k[0]][ifgramList[i - 1]].attrs['DATE12'], loc=1) fig.subplots_adjust(wspace=Wspace, hspace=Hspace) fig = plt.figure(kk) ii = (kk - 1) * nfigs + 1 for i in range(ii, ligram + 1): ax = fig.add_subplot(figs_rows, figs_cols, i - ii + 1) print 'loading ' + ifgramList[i - 1] dset = h5file[k[0]][ifgramList[i - 1]].get(ifgramList[i - 1]) data = dset[0:dset.shape[0], 0:dset.shape[1]] #data = h5file[k[0]][ifgramList[i-1]].get(ifgramList[i-1]) try: ax.imshow(data, vmin=min, vmax=max, cmap=ccmap) except: ax.imshow(data, cmap=ccmap) ax.set_yticklabels([]) ax.set_xticklabels([]) ax.set_xticks([]) ax.set_yticks([]) if title == 'out': ax.set_title(h5file[k[0]][ifgramList[i - 1]].attrs['DATE12'], fontsize=font_size) elif title == 'in': add_inner_title( ax, h5file[k[0]][ifgramList[i - 1]].attrs['DATE12'], loc=1) fig.subplots_adjust(wspace=Wspace, hspace=Hspace) plt.show() #################################################################### #################################################################### elif k[0] in ('interferograms', 'coherence', 'wrapped') and allData2display == 'no': if k[0] in ('coherence', 'wrapped'): rewrapping == 'no' ifgramList = h5file[k[0]].keys() try: epoch_number except: for i in range(len(ifgramList)): if epoch_date in ifgramList[i]: epoch_number = i dset = h5file[k[0]][ifgramList[epoch_number]].get( ifgramList[epoch_number]) data = dset[0:dset.shape[0], 0:dset.shape[1]] if rewrapping == 'yes': data = np.angle(np.exp(1j * data)) if dip_opposite in ('yes', 'Yes', 'Y', 'y', 'YES'): data = -1 * data #DEM basemap try: demFile if os.path.basename(demFile).split('.')[1] == 'hgt': amp, dem, demRsc = readfile.read_float32(demFile) elif os.path.basename(demFile).split('.')[1] == 'dem': dem, demRsc = readfile.read_dem(demFile) try: win_x wx = [int(i) for i in win_x.split()] dem = dem[:, wx[0]:wx[1]] except: print '' try: win_y wy = [int(i) for i in win_y.split()] dem = dem[wy[0]:wy[1], :] except: print '' if flip_lr == 'yes': dem = np.fliplr(dem) if flip_ud == 'yes': dem = np.flipud(dem) cmap_dem = plt.get_cmap('gray') if disp_geo in ('yes', 'Yes', 'Y', 'y', 'YES') and geocoord in ('yes', 'Yes', 'Y', 'y', 'YES'): print 'display geo' else: print 'Not GEO' plt.imshow(ut.hillshade(dem, 50.0), cmap=cmap_dem) except: print 'No DEM file' try: plt.imshow(data, cmap=ccmap, vmin=min, vmax=max) except: plt.imshow(data, cmap=ccmap) plt.colorbar() # plt.title(h5file[k[0]][ifgramList[epoch_number]].attrs['DATE12'],fontsize=font_size) plt.title(ifgramList[epoch_number], fontsize=font_size) plt.show() ################################################################ ################################################################ h5file.close()
def main(argv): color_map = 'jet' disp_opposite = 'no' try: opts, args = getopt.getopt(argv, "h:f:d:o:x:y:m:M:i:c:") except getopt.GetoptError: Usage() sys.exit(1) if opts == []: Usage() sys.exit(1) for opt, arg in opts: if opt in ("-h", "--help"): Usage() sys.exit() elif opt == '-f': File = arg elif opt == '-d': demFile = arg elif opt == '-m': Vmin = float(arg) elif opt == '-M': Vmax = float(arg) elif opt == '-x': winx = arg.split(':') elif opt == '-y': winy = arg.split(':') elif opt == '-o': outName = arg elif opt == '-i': disp_opposite = arg elif opt == '-c': color_map = arg h5file = h5py.File(File, 'r') k = h5file.keys() print k[0] # ccmap=plt.get_cmap(color_map) ################################################ cdict1 = { 'red': ((0.0, 0.0, 0.0), (0.5, 0.0, 0.0), (0.6, 1.0, 1.0), (0.8, 1.0, 1.0), (1.0, 0.5, 0.5)), 'green': ((0.0, 0.0, 0.0), (0.2, 0.0, 0.0), (0.4, 1.0, 1.0), (0.6, 1.0, 1.0), (0.8, 0.0, 0.0), (1.0, 0.0, 0.0)), 'blue': ( (0.0, 0.5, .5), (0.2, 1.0, 1.0), (0.4, 1.0, 1.0), (0.5, 0.0, 0.0), (1.0, 0.0, 0.0), ) } if color_map == 'pysar_hsv': ccmap = LinearSegmentedColormap('BlueRed1', cdict1) else: ccmap = plt.get_cmap(color_map) print 'colormap is : ' + color_map ################################################ dset = h5file[k[0]].get(k[0]) data = dset[0:dset.shape[0], 0:dset.shape[1]] if disp_opposite in ('yes', 'Yes', 'Y', 'y', 'YES'): data = -1 * data try: xref = h5file[k[0]].attrs['ref_x'] yref = h5file[k[0]].attrs['ref_y'] except: print 'No reference point' try: ullon = float(h5file[k[0]].attrs['X_FIRST']) ullat = float(h5file[k[0]].attrs['Y_FIRST']) lon_step = float(h5file[k[0]].attrs['X_STEP']) lat_step = float(h5file[k[0]].attrs['Y_STEP']) lon_unit = h5file[k[0]].attrs['Y_UNIT'] lat_unit = h5file[k[0]].attrs['X_UNIT'] llcrnrlon = ullon llcrnrlat = ullat + lat_step * data.shape[0] urcrnrlon = ullon + lon_step * data.shape[1] urcrnrlat = ullat geocoord = 'yes' print 'Input file is Geocoded' except: geocoord = 'no' fig = plt.figure() ax = fig.add_axes([0.1, 0.1, 0.8, 0.8]) m = Basemap(llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat, urcrnrlon=urcrnrlon, urcrnrlat=urcrnrlat, resolution='l', area_thresh=1., projection='cyl', suppress_ticks=False, ax=ax) print demFile demFile if os.path.basename(demFile).split('.')[1] == 'hgt': amp, dem, demRsc = readfile.read_float32(demFile) elif os.path.basename(demFile).split('.')[1] == 'dem': dem, demRsc = readfile.read_dem(demFile) ################################################################# try: winx wx = [int(i) for i in win_x.split()] dem = dem[:, wx[0]:wx[1]] data = data[:, wx[0]:wx[1]] ullon = float(h5file[k[0]].attrs['X_FIRST']) + wx[0] llcrnrlon = ullon urcrnrlon = ullon + lon_step * data.shape[1] except: print '' try: winy wy = [int(i) for i in winy.split()] dem = dem[wy[0]:wy[1], :] data = data[wy[0]:wy[1], :] except: print '' ################################################################ fig = plt.figure() ax = fig.add_axes([0.1, 0.1, 0.8, 0.8]) m = Basemap(llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat, urcrnrlon=urcrnrlon, urcrnrlat=urcrnrlat, resolution='l', area_thresh=1., projection='cyl', suppress_ticks=False, ax=ax) cmap_dem = plt.get_cmap('gray') m.imshow(ut.hillshade(np.flipud(dem), 50.0), cmap=cmap_dem) try: im = m.imshow(np.flipud(data), vmin=Vmin, vmax=Vmax, cmap=ccmap) # cb = m.colorbar(im,"right", size="5%", pad='2%') except: im = m.imshow(np.flipud(data)) # cb = m.colorbar(im,"right", size="5%", pad='2%') # m.bluemarble() # cb = m.colorbar(im,"right", size="5%", pad='2%') # parallels = np.arange(31.,34,0.5) # m.drawparallels(parallels,labels=[1,0,0,1],linewidth=0.0) # meridians = np.arange(-115.,-112.,0.5) # m.drawmeridians(meridians,labels=[1,0,0,1],linewidth=0.0) # m.drawmapscale() # m = Basemap(llcrnrlon=-110.,llcrnrlat=0.,urcrnrlon=-20.,urcrnrlat=57., # projection='lcc',lat_1=20.,lat_2=40.,lon_0=-60., # resolution ='l',area_thresh=1000.) # m.drawcoastlines() # m.drawcountries() # m.drawmapboundary(fill_color='#99ffff') # m.fillcontinents(color='#cc9966',lake_color='#99ffff') # m.drawparallels(np.arange(10,70,20),labels=[1,1,0,0]) # m.drawmeridians(np.arange(-100,0,20),labels=[0,0,0,1]) # plt.title('Atlantic Hurricane Tracks (Storms Reaching Category 4, 1851-2004)') try: figName = outName except: outName = os.path.basename(File).replace('.h5', '') figName = outName + '.png' plt.savefig(figName, pad_inches=0.0) # plt.show() h5file.close()