def makeMap(lonStart,lonEnd,latStart,latEnd,name,stLon,stLat): plt.figure(figsize=(8,8)) """Get the etopo2 data""" etopo1 = Dataset(etopo1name,'r') lons = etopo1.variables["lon"][:] lats = etopo1.variables["lat"][:] res = findSubsetIndices(latStart-5,latEnd+5,lonStart-40,lonEnd+10,lats,lons) lon,lat=np.meshgrid(lons[res[0]:res[1]],lats[res[2]:res[3]]) print "Extracted data for area %s : (%s,%s) to (%s,%s)"%(name,lon.min(),lat.min(),lon.max(),lat.max()) bathy = etopo1.variables["z"][int(res[2]):int(res[3]),int(res[0]):int(res[1])] bathySmoothed = laplaceFilter.laplace_filter(bathy,M=None) levels=[-6000,-5000,-3000, -2000, -1500, -1000,-500, -400, -300, -250, -200, -150, -100, -75, -65, -50, -35, -25, -15, -10, -5, 0] if lonStart< 0 and lonEnd < 0: lon_0= - (abs(lonEnd)+abs(lonStart))/2.0 else: lon_0=(abs(lonEnd)+abs(lonStart))/2.0 print 'Center longitude ',lon_0 map = Basemap(llcrnrlat=latStart,urcrnrlat=latEnd,\ llcrnrlon=lonStart,urcrnrlon=lonEnd,\ rsphere=(6378137.00,6356752.3142),\ resolution='l',area_thresh=1000.,projection='lcc',\ lat_1=latStart,lon_0=lon_0) x, y = map(lon,lat) map.drawcoastlines() map.drawcountries() map.fillcontinents(color='grey') map.drawmeridians(np.arange(lons.min(),lons.max(),10),labels=[0,0,0,1]) map.drawparallels(np.arange(lats.min(),lats.max(),4),labels=[1,0,0,0]) #map.bluemarble() CS1 = map.contourf(x,y,bathySmoothed,levels, #cmap=mpl_util.LevelColormap(levels,cmap=cm.Blues_r), cmap=cm.Blues_r, extend='upper', alpha=1.0, origin='lower') CS1.axis='tight' """Plot the station as a position dot on the map""" xpt,ypt = map(stLon,stLat) map.plot([xpt],[ypt],'ro', markersize=10) plt.text(xpt+100000,ypt+100000,name) plt.title('Area %s'%(name)) plotfile='map_'+str(name)+'.pdf' plt.savefig(plotfile,dpi=150,orientation='portrait') plt.show()
def makeMap(lonStart=1, lonEnd=5, \ latStart=37, latEnd=47, \ m=None, name='etopo1map', contour=None, cb=None): # Get the etopo1 data etopo1name='/media/SOLabNFS/store/auxdata/dem/ETOPO1/data/bedrock/grid_registered/netcdf/ETOPO1_Bed_g_gmt4.grd' etopo1 = Dataset(etopo1name,'r') lons = etopo1.variables["x"][:] lats = etopo1.variables["y"][:] res = findSubsetIndices(latStart,latEnd,lonStart,lonEnd,lats,lons) lon,lat=np.meshgrid(lons[res[0]:res[1]],lats[res[2]:res[3]]) print "Extracted data for area %s : (%s,%s) to (%s,%s)"%(name,lon.min(),lat.min(),lon.max(),lat.max()) bathy = etopo1.variables["z"][int(res[2]):int(res[3]),int(res[0]):int(res[1])] bathy = laplaceFilter.laplace_filter(bathy,M=None) if lonStart< 0 and lonEnd < 0: lon_0= - (abs(lonEnd)+abs(lonStart))/2.0 else: lon_0=(abs(lonEnd)+abs(lonStart))/2.0 if latStart< 0 and latEnd < 0: lat_0= - (abs(latEnd)+abs(latStart))/2.0 else: lat_0=(abs(latEnd)+abs(latStart))/2.0 print 'Center longitude ', lon_0 print 'Center latitude ', lat_0 if m is None: print ( "Using default NSPER Basemap \n") # m = Basemap(llcrnrlat=latStart,urcrnrlat=latEnd,\ # llcrnrlon=lonStart,urcrnrlon=lonEnd,\ # rsphere=(6378137.00,6356752.3142),\ # resolution='h',area_thresh=1000.,projection='lcc',\ # lat_1=latStart,lon_0=lon_0) m = Basemap(llcrnrlat=latStart,urcrnrlat=latEnd,\ llcrnrlon=lonStart,urcrnrlon=lonEnd,\ satellite_height=798000, \ resolution='h',area_thresh=1000.,projection='nsper',\ lat_1=latStart,lon_0=lon_0,lat_0=lat_0) x, y = m(lon,lat) if contour is None: levels = [-6000,-5000,-3000, -2000, -1500, -1000, -500, \ -400, -300, -250, -200, -150, -100, -75, -65, -50, -35, \ -25, -15, -10, -5, \ 0, 5, 10, 15, 25, 35, 50, 65, 75, 100, \ 150, 200, 250, 300, 400, 500, 1000, \ 2000, 3000, 5000, 6000] cm = gmtColormap(fileName='GMT_globe', \ GMTPath='/home/mag/Documents/repos/solab/PySOL/cmap_data/') cs = m.contourf(x,y,bathy,levels, cmap=LevelColormap(levels,cmap=cm), alpha=1.0, extend='both') cs.axis='tight' # new axis for colorbar. ax = plt.gca() l,b,w,h=ax.get_position().bounds if cb is not None: cax = plt.axes([l-0.25, b+h*0.1, 0.025, h*0.8]) # setup colorbar axes cb = plt.colorbar(cs, cax, orientation='vertical') cb.set_label('Height [m]') # cax = plt.axes([l+w*0.1, b-0.05, w*0.8, 0.025]) # setup colorbar axes # cb = plt.colorbar(cs, cax, orientation='horizontal') plt.axes(ax) # make the original axes current again elif contour is 'land': levels = [0, 5, 10, 15, 25, 35, 50, 65, 75, 100, \ 150, 200, 250, 300, 400, 500, 1000, \ 2000, 3000, 5000, 6000] cm = gmtColormap(fileName='PySOL_land', \ GMTPath='/home/mag/Documents/repos/solab/PySOL/cmap_data/', \ frm='mid') cs = m.contourf(x,y,bathy,levels, cmap=LevelColormap(levels,cmap=cm), alpha=1.0, extend='max') cs.axis='tight' # new axis for colorbar. ax = plt.gca() if cb is not None: l,b,w,h=ax.get_position().bounds cax = plt.axes([l-0.25, b+h*0.1, 0.025, h*0.8]) # setup colorbar axes cb = plt.colorbar(cs, cax, orientation='vertical') cb.set_label('Height [m]') # cax = plt.axes([l+w*0.1, b-0.05, w*0.8, 0.025]) # setup colorbar axes # cb = plt.colorbar(cs, cax, orientation='horizontal') plt.axes(ax) # make the original axes current again # cb.ax.yaxis.set_ylabel_position('left') elif contour is 'ocean': levels = [-6000,-5000,-3000, -2000, -1500, -1000, -500, \ -400, -300, -250, -200, -150, -100, -75, -65, -50, -35, \ -25, -15, -10, -5, 0] levels = [-2000, -1600, -1200, -800, -100] cm = gmtColormap(fileName='GMT_ocean', \ GMTPath='/home/mag/Documents/repos/solab/PySOL/cmap_data/', \ to='mid') cs2 = m.contour(x,y,bathy,levels, cmap=LevelColormap(levels,cmap=cm), alpha=1.0, extend='min') cs2.axis='tight' plt.clabel(cs2, levels, fmt = '%i', colors = 'k', \ manual=0, inline=0) # m.fillcontinents(color='coral',lake_color='aqua') # m.drawmeridians(arange(round(lons.min(),1),round(lons.max(),1), 0.5), \ # labels=[0,0,0,1], color='k') # m.drawparallels(arange(round(lats.min(),1),round(lats.max(),1), 0.5), \ # labels=[1,0,0,0], color='k') m.drawcoastlines(linewidth=1.25,color='k') m.drawcountries(linewidth=1.25,color='k') # maximizing figure mng = plt.get_current_fig_manager() mng.resize(1920,1080) plt.draw() #~ plt.show() #~ ipdb.set_trace() name = name.split(' ')[0] # split the name if it has spaces plotfile='/home/mag/'+str(name)+'_ETOPO1.tiff' plt.savefig(plotfile, facecolor='w', edgecolor='w', \ dpi=300, bbox_inches="tight", pad_inches=0.1)
def makeMap(lonStart, lonEnd, latStart, latEnd, name, stLon, stLat): plt.figure(figsize=(8, 8)) """Get the etopo2 data""" etopo1 = Dataset(etopo1name, 'r') lons = etopo1.variables["lon"][:] lats = etopo1.variables["lat"][:] res = findSubsetIndices(latStart - 5, latEnd + 5, lonStart - 40, lonEnd + 10, lats, lons) lon, lat = np.meshgrid(lons[res[0]:res[1]], lats[res[2]:res[3]]) print "Extracted data for area %s : (%s,%s) to (%s,%s)" % ( name, lon.min(), lat.min(), lon.max(), lat.max()) bathy = etopo1.variables["z"][int(res[2]):int(res[3]), int(res[0]):int(res[1])] bathySmoothed = laplaceFilter.laplace_filter(bathy, M=None) levels = [ -6000, -5000, -3000, -2000, -1500, -1000, -500, -400, -300, -250, -200, -150, -100, -75, -65, -50, -35, -25, -15, -10, -5, 0 ] if lonStart < 0 and lonEnd < 0: lon_0 = -(abs(lonEnd) + abs(lonStart)) / 2.0 else: lon_0 = (abs(lonEnd) + abs(lonStart)) / 2.0 print 'Center longitude ', lon_0 map = Basemap(llcrnrlat=latStart,urcrnrlat=latEnd,\ llcrnrlon=lonStart,urcrnrlon=lonEnd,\ rsphere=(6378137.00,6356752.3142),\ resolution='l',area_thresh=1000.,projection='lcc',\ lat_1=latStart,lon_0=lon_0) x, y = map(lon, lat) map.drawcoastlines() map.drawcountries() map.fillcontinents(color='grey') map.drawmeridians(np.arange(lons.min(), lons.max(), 10), labels=[0, 0, 0, 1]) map.drawparallels(np.arange(lats.min(), lats.max(), 4), labels=[1, 0, 0, 0]) #map.bluemarble() CS1 = map.contourf( x, y, bathySmoothed, levels, #cmap=mpl_util.LevelColormap(levels,cmap=cm.Blues_r), cmap=cm.Blues_r, extend='upper', alpha=1.0, origin='lower') CS1.axis = 'tight' """Plot the station as a position dot on the map""" xpt, ypt = map(stLon, stLat) map.plot([xpt], [ypt], 'ro', markersize=10) plt.text(xpt + 100000, ypt + 100000, name) plt.title('Area %s' % (name)) plotfile = 'map_' + str(name) + '.pdf' plt.savefig(plotfile, dpi=150, orientation='portrait') plt.show()
def makeMap(lonStart,lonEnd,latStart,latEnd,name,stLon,stLat,zoom): fig = plt.figure(figsize=(9,8)) """Get the etopo2 data""" #etopo1name='ETOPO1_Ice_g_gmt4.grd' etopo1name = 'ETOPO1_Bed_g_gmt4.grd' etopo1 = Dataset(etopo1name,'r') lons = etopo1.variables["x"][:] lats = etopo1.variables["y"][:] res = findSubsetIndices(latStart-5,latEnd+5,lonStart-40,lonEnd+10,lats,lons) lon,lat=np.meshgrid(lons[int(res[0]):int(res[1])],lats[int(res[2]):int(res[3])]) print( "Extracted data for area %s : (%s,%s) to (%s,%s)"%(name,lon.min(),lat.min(),lon.max(),lat.max())) bathy = etopo1.variables["z"][int(res[2]):int(res[3]),int(res[0]):int(res[1])] bathySmoothed = laplaceFilter.laplace_filter(bathy,M=None) levels =[3, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1250, 1500,] if lonStart< 0 and lonEnd < 0: lon_0= - (abs(lonEnd)+abs(lonStart))/2.0 else: lon_0=(abs(lonEnd)+abs(lonStart))/2.0 if zoom == 'zoom': resolution = 'i' else: resolution = 'l' map = Basemap(llcrnrlat=latStart,urcrnrlat=latEnd, llcrnrlon=lonStart,urcrnrlon=lonEnd, rsphere=(6378137.00,6356752.3142), resolution=resolution,area_thresh=1000.,projection='lcc', lat_1=latStart,lon_0=lon_0) x, y = map(lon,lat) map.drawcoastlines() map.drawcountries() map.drawmapboundary(fill_color='gainsboro') if zoom != 'zoom': map.drawmeridians(np.arange(lons.min(),lons.max(),10),labels=[0,0,0,1],fontsize=16) map.drawparallels(np.arange(lats.min(),lats.max(),4),labels=[1,0,0,0],fontsize=16) else: map.drawmeridians(np.arange(lons.min(),lons.max(),3),labels=[0,0,0,1],fontsize=16) map.drawparallels(np.arange(lats.min(),lats.max(),2),labels=[1,0,0,0],fontsize=16) #map.etopo() CS1 = map.contourf(x,y,bathySmoothed,levels, # cmap=mpl_util.LevelColormap(levels,cmap=IVTmap), cmap = 'binary', extend='max', alpha=1.0, origin='lower') CS1.axis='tight' """Plot the station as a position dot on the map""" xpt,ypt = map(stLon,stLat) map.plot([xpt],[ypt],'ro', markersize=10) if zoom == 'zoom': dist = 10000 else: dist = 100000 plt.text(xpt+dist,ypt+dist,name,fontsize = 20, fontweight = 'bold', ha='left',va='bottom',color='r') ## model center #longitude_of_central_meridian = 15.0 #latitude_of_projection_origin = 63.0 #"""Plot the MEPS model center as a position dot on the map""" #xpt,ypt = map(longitude_of_central_meridian,latitude_of_projection_origin) #map.plot([xpt],[ypt],color = 'orange', marker = 'o', markersize=10) #plt.text(xpt+100000,ypt+100000,'MEPS center',fontsize = 20, fontweight = 'bold', # ha='left',va='bottom',color='orange') # if zoom != 'zoom': # # ### plot MEPS area # for i in range(0,lato.shape[0],12): # xs, ys = map(lono[i], lato[i]) # map.plot(xs,ys, color = 'orange', marker = 'o', markersize = 10, linestyle = '-', linewidth = 10) # for i in range(0,lato2.shape[0],12): # xs2, ys2 = map(lono2[i], lato2[i]) # map.plot(xs2,ys2, color = 'orange', marker = 'o', markersize = 10, linestyle = '-', linewidth = 10) # # xs, ys = map(lono[739], lato[739]) # map.plot(xs,ys, color = 'orange', marker ='o', markersize = 10, linestyle = '-', linewidth = 10, label = 'MEPS domain') # lgd = plt.legend(loc='lower left',fontsize=18) #plt.title('Area %s'%(name)) #plotfile='figures/map_'+str(name)+'.pdf' #plt.savefig(plotfile,dpi=150,orientation='portrait') #map.drawmapscale(-7., 35.8, -3.25, 39.5, 500, barstyle='fancy') #map.drawmapscale(-0., 35.8, -3.25, 39.5, 500, fontsize = 14) ### Add Colorbar # cbaxes = fig.add_axes([0.14, 0.03, .75, .006] ) #[left, bottom, width, height] cbaxes = fig.add_axes([0.83, 0.15, .035, 0.7] ) #[left, bottom, width, height] cbar = plt.colorbar(CS1,orientation='vertical',cax = cbaxes,ticks=levels[::2])#, cax = cbaxes)#, shrink=0.5) cbar.ax.set_ylabel('elevation [m]',fontsize = 18) cbar.ax.tick_params(labelsize=16)
def makeMapnewArctic(lonStart, lonEnd, latStart, latEnd, lat1, lon1, foutPath, ax): # fig= plt.figure(figsize=(10,8)) """Get the etopo2 data""" # etopo1name='ETOPO1_Ice_g_gmt4.grd' # etopo1name='/home/xuj/work/project/topo/ETOPO1/ETOPO1_Bed_c_gmt4.grd' # etopo1name='/home/xuj/work/project/topo/ETOPO1/barrowStrait.nc' # etopo1name='/home/xuj/work/project/topo/ETOPO1/testnew.nc' etopo1name = '/home/xuj/work/project/whaleDectionRange/bathymetry/topo15_eastNew.nc' etopo1 = Dataset(etopo1name, 'r') lons = etopo1.variables["lon"][:] lats = etopo1.variables["lat"][:] # lons = etopo1.variables["x"][:] # lats = etopo1.variables["y"][:] print "lons:", max(lons), min(lons) print lons print "lats:", max(lats), min(lats) print lats print "lon,lat,start, end:", lonStart, lonEnd, latStart, latEnd print " lat lon start end:", latStart - 2, latEnd + 5, lonStart - 5, lonEnd + 5 res = findSubsetIndices(latStart - 1, latEnd + 1, lonStart - 1, lonEnd + 1, lats, lons) print "res:::", res lon, lat = np.meshgrid(lons[res[0]:res[1]], lats[res[2]:res[3]]) print "shape of lon:", np.shape(lon) print "shape of lat:", np.shape(lat) # exit(1) # print "Extracted data for area %s : (%s,%s) to (%s,%s)"%(name,lon.min(),lat.min(),lon.max(),lat.max()) bathy = etopo1.variables["z"][int(res[2]):int(res[3]), int(res[0]):int(res[1])] etopo1.close() # z0 = etopo1.variables["z"][int(res[0]):int(res[1]),int(res[2]):int(res[3])] # print ma.shape(z0) # z = ma.array().flatten() bathySmoothed = laplaceFilter.laplace_filter(bathy, M=None) y = lons[res[0]:res[1]] x = lats[res[2]:res[3]] # print ma.shape(z),ma.shape(x) # zi = matplotlib.mlab.griddata(x,y,z,lat, lon) # levels=[-5500,-5000,-2500, -2000, -1500, -1000,-500, -400, -300, -250, -200, -150, -100, -75, -65, -50, -35, -25, -15, -10, -5, 0] levels = [ -5000, -4000, -3000, -1000, -500, -400, -300, -250, -200, -150, -100, -50, -20, -5, -1 ] if lonStart < 0 and lonEnd < 0: lon_0 = -(abs(lonEnd) + abs(lonStart)) / 2.0 else: lon_0 = (abs(lonEnd) + abs(lonStart)) / 2.0 print 'Center longitude ', lon_0 map = Basemap(llcrnrlat=latStart,urcrnrlat=latEnd,\ llcrnrlon=lonStart,urcrnrlon=lonEnd,\ rsphere=(6378137.00,6356752.3142),\ resolution='h',area_thresh=1000.,projection='lcc',\ lat_1=latStart,lon_0=lon_0,ax=ax) x, y = map(lon, lat) map.drawcoastlines(linewidth=0.5) map.drawcountries() map.fillcontinents(color='grey') map.drawmeridians(np.arange(int(lons.min()), int(lons.max()), 2), labels=[0, 0, 0, 1], fontsize=10) map.drawparallels(np.arange(int(lats.min()), int(lats.max()), 1), labels=[1, 0, 0, 0], fontsize=10) #map.bluemarble() # CS1 = map.contourf(x,y,bathySmoothed,levels, # cmap=mpl_util.LevelColormap(levels,cmap=cm.Blues_r), # extend='upper', # alpha=1.0, # origin='lower') # CS2 = map.contour(x,y,zi,levels1,linewidths=0.5,colors='k',animated=True) # CS1 = map.contourf(x,y,zi,levels,cmap=mpl_util.LevelColormap(levels,cmap=cm.Blues_r),alpha=1.0) levels1 = [-100] CS2 = map.contour(x, y, bathySmoothed, levels1, linewidths=0.5, colors='y', linestyles='solid', animated=True) plt.clabel(CS2, fontsize=4, inline=True) levels1 = [-200] CS2 = map.contour(x, y, bathySmoothed, levels1, linewidths=0.5, colors='g', linestyles='solid', animated=True) plt.clabel(CS2, fontsize=4, inline=True) # levels1=[-400] # CS2 = map.contour(x,y,bathySmoothed,levels1,linewidths=0.5,colors='r',linestyles='solid',animated=True) # plt.clabel(CS2,fontsize=4,inline=True) # # levels1=[-350] # CS2 = map.contour(x,y,bathySmoothed,levels1,linewidths=0.5,colors='k',linestyles='solid',animated=True) # plt.clabel(CS2,fontsize=4,inline=True) levels1 = [-300] CS2 = map.contour(x, y, bathySmoothed, levels1, linewidths=0.5, colors='c', linestyles='solid', animated=True) plt.clabel(CS2, fontsize=4, inline=True) CS1 = map.contourf(x, y, bathySmoothed, levels, cmap=mpl_util.LevelColormap(levels, cmap=cm.Blues_r), alpha=1.0) # CS1 = map.contourf(x,y,bathySmoothed,levels,cmap=mpl_util.LevelColormap(levels,cmap=cm.ocean),alpha=1.0) # CS1 = map.contourf(x,y,bathySmoothed,levels,cmap=mpl_util.LevelColormap(levels,cmap=cm.jet),alpha=1.0) # # CS1.axis='tight' """Plot the station as a position dot on the map""" # cbar= fig.colorbar(CS1,orientation='horizontal') cb = map.colorbar(CS1, "right", size="2.5%", pad='2%') cb.set_label('Depth (m)', fontsize=10) # map.plot(lon1,lat1,'r*', markersize=6,latlon='true') print type(lon1), type(lat1), np.shape(lon1) # for lon2,lat2 in zip(lon1,lat1): # print lon2,lat2 # print type(lon2) for lon2, lat2 in zip(lon1, lat1): map.plot(float(lon2), float(lat2), 'r.', markersize=2, latlon='true') # lat2 = Lat2[60] # lon2 = Lon2[60] # lat2 = Lat2[-1] # lon2 = Lon2[-1] # map.plot(lon2,lat2,'y*', markersize=1,latlon='true') # g = geodesic.Geodesic.WGS84.Inverse(lat1, lon1, lat2, lon2); # Compute midpoint starting at 1 # l=geodesic.Geodesic.WGS84.Line(g['lat1'],g['lon1'],g['azi1']) # num=50 # print np.shape(lon) # print np.shape(lat) # print np.shape(bathySmoothed) # ## idx,idy = np.where(lon<-87 & lon<-95) # & lat>73 & lat<75 & bitwise operator # idx1,idy1 = np.where((lon<-55) & (lon>-60)) # idx2,idy2 = np.where((lat > 55) & (lat < 58)) # & lat>73 & lat<75 # ## print np.shape(idx1) ## print np.shape(idy1) # # print min(idx2),max(idx2),min(idy1),max(idy1) # print min(idx1),max(idx1),min(idy2),max(idy2) # # xn,yn = np.shape(lon) # # idx1,idx2 = min(idx2),max(idx2) # idy1,idy2 = min(idy1),max(idy1) # idx1,idx2 = 251,551 ## idy1,idy2 = 1201,2201 # # bathySmoothedN = bathySmoothed[idx1:idx2,idy1:idy2] # lonN = lon[idx1:idx2,idy1:idy2] # latN = lat[idx1:idx2,idy1:idy2] # # print np.shape(lonN) # print np.shape(latN) # print np.shape(bathySmoothedN) # # if False: # interpFile = foutPath+'linearInterp.pik' # if os.path.isfile(interpFile): # print "interpolation file is ready, unpacking it...." # with open(interpFile,'rb') as fpik: # finterp=pickle.load(fpik) # f = finterp # else: # # exit(1) # # f = interpolate.interp2d(lonN, latN, bathySmoothedN, kind='cubic') # print "interpolation file is not ready, working on it...." # f = interpolate.interp2d(lonN, latN, bathySmoothedN, kind='linear') # with open(interpFile,'w') as fpik: # pickle.dump(f,fpik) # f = interpolate.griddata(lonN, latN, bathySmoothedN, method='linear') # print "interpolation function is done" # exit(1) # f = interpolate.RectBivariateSpline(lon, lat, bathySmoothed, kx=2, ky=2, s=0) # f = interpolate.Rbf(lonN, latN, bathySmoothedN) # for i in range(num+1): # b=l.Position(i*g['s12']/num) ## print(b['lat2'],b['lon2']) # # if i ==0: # pass # else: # map.plot(b['lon2'],b['lat2'],'ko', markersize=0.5,latlon='true') # # lati = b['lat2'] # loni = b['lon2'] # zi = f(loni, lati) # zi = interpolate.griddata((lonN, latN), bathySmoothedN, (loni, lati),method='linear') # print loni,lati,zi # map.plot(lon2,lat2,'r*', markersize=1,latlon='true') # h1 = geodesic.Geodesic.WGS84.Direct(lat1, lon1, g['azi1'], g['s12']/2); # print(h1['lat2'],h1['lon2']); # Alternatively, compute midpoint starting at 2 # h2 = geodesic.Geodesic.WGS84.Direct(lat2, lon2, g['azi2'], -g['s12']/2); # print(h2['lat2'],h2['lon2']); # p=Geodesic.WGS84.Inverse(40.6, -73.8, 1.4, 104); # for i in ma.arange(len(name)): # # print i , name[i] # xpt,ypt = map(stLon[i*2],stLat[i*2]) # xpt1,ypt1 = map(stLon[i*2+1],stLat[i*2+1]) # # map.plot([xpt],[ypt],'r.', markersize=5) # map.plot([xpt1],[ypt1],'r.', markersize=5) # # plt.text(xpt+10000,ypt+10000,name[i], fontsize=7) # font = {'fontname':'Arial','weight':'bold','size':8} # matplotlib.rc('font', **font) # plt.title('Area %s'%(name)) # plotfile='/home/xuj/work/project/noise/map_nls_north.jpg' # plotfile='/home/xuj/work/codes/barrowStraitSmall.jpg' # plt.show() # plt.close() return map
def makeMap(lonStart=1, lonEnd=5, \ latStart=37, latEnd=47, \ m=None, name='etopo1map', contour=None, cb=None): # Get the etopo1 data etopo1name = '/media/SOLabNFS/store/auxdata/dem/ETOPO1/data/bedrock/grid_registered/netcdf/ETOPO1_Bed_g_gmt4.grd' etopo1 = Dataset(etopo1name, 'r') lons = etopo1.variables["x"][:] lats = etopo1.variables["y"][:] res = findSubsetIndices(latStart, latEnd, lonStart, lonEnd, lats, lons) lon, lat = np.meshgrid(lons[res[0]:res[1]], lats[res[2]:res[3]]) print "Extracted data for area %s : (%s,%s) to (%s,%s)" % ( name, lon.min(), lat.min(), lon.max(), lat.max()) bathy = etopo1.variables["z"][int(res[2]):int(res[3]), int(res[0]):int(res[1])] bathy = laplaceFilter.laplace_filter(bathy, M=None) if lonStart < 0 and lonEnd < 0: lon_0 = -(abs(lonEnd) + abs(lonStart)) / 2.0 else: lon_0 = (abs(lonEnd) + abs(lonStart)) / 2.0 if latStart < 0 and latEnd < 0: lat_0 = -(abs(latEnd) + abs(latStart)) / 2.0 else: lat_0 = (abs(latEnd) + abs(latStart)) / 2.0 print 'Center longitude ', lon_0 print 'Center latitude ', lat_0 if m is None: print("Using default NSPER Basemap \n") # m = Basemap(llcrnrlat=latStart,urcrnrlat=latEnd,\ # llcrnrlon=lonStart,urcrnrlon=lonEnd,\ # rsphere=(6378137.00,6356752.3142),\ # resolution='h',area_thresh=1000.,projection='lcc',\ # lat_1=latStart,lon_0=lon_0) m = Basemap(llcrnrlat=latStart,urcrnrlat=latEnd,\ llcrnrlon=lonStart,urcrnrlon=lonEnd,\ satellite_height=798000, \ resolution='h',area_thresh=1000.,projection='nsper',\ lat_1=latStart,lon_0=lon_0,lat_0=lat_0) x, y = m(lon, lat) if contour is None: levels = [-6000,-5000,-3000, -2000, -1500, -1000, -500, \ -400, -300, -250, -200, -150, -100, -75, -65, -50, -35, \ -25, -15, -10, -5, \ 0, 5, 10, 15, 25, 35, 50, 65, 75, 100, \ 150, 200, 250, 300, 400, 500, 1000, \ 2000, 3000, 5000, 6000] cm = gmtColormap(fileName='GMT_globe', \ GMTPath='/home/mag/Documents/repos/solab/PySOL/cmap_data/') cs = m.contourf(x, y, bathy, levels, cmap=LevelColormap(levels, cmap=cm), alpha=1.0, extend='both') cs.axis = 'tight' # new axis for colorbar. ax = plt.gca() l, b, w, h = ax.get_position().bounds if cb is not None: cax = plt.axes([l - 0.25, b + h * 0.1, 0.025, h * 0.8]) # setup colorbar axes cb = plt.colorbar(cs, cax, orientation='vertical') cb.set_label('Height [m]') # cax = plt.axes([l+w*0.1, b-0.05, w*0.8, 0.025]) # setup colorbar axes # cb = plt.colorbar(cs, cax, orientation='horizontal') plt.axes(ax) # make the original axes current again elif contour is 'land': levels = [0, 5, 10, 15, 25, 35, 50, 65, 75, 100, \ 150, 200, 250, 300, 400, 500, 1000, \ 2000, 3000, 5000, 6000] cm = gmtColormap(fileName='PySOL_land', \ GMTPath='/home/mag/Documents/repos/solab/PySOL/cmap_data/', \ frm='mid') cs = m.contourf(x, y, bathy, levels, cmap=LevelColormap(levels, cmap=cm), alpha=1.0, extend='max') cs.axis = 'tight' # new axis for colorbar. ax = plt.gca() if cb is not None: l, b, w, h = ax.get_position().bounds cax = plt.axes([l - 0.25, b + h * 0.1, 0.025, h * 0.8]) # setup colorbar axes cb = plt.colorbar(cs, cax, orientation='vertical') cb.set_label('Height [m]') # cax = plt.axes([l+w*0.1, b-0.05, w*0.8, 0.025]) # setup colorbar axes # cb = plt.colorbar(cs, cax, orientation='horizontal') plt.axes(ax) # make the original axes current again # cb.ax.yaxis.set_ylabel_position('left') elif contour is 'ocean': levels = [-6000,-5000,-3000, -2000, -1500, -1000, -500, \ -400, -300, -250, -200, -150, -100, -75, -65, -50, -35, \ -25, -15, -10, -5, 0] levels = [-2000, -1600, -1200, -800, -100] cm = gmtColormap(fileName='GMT_ocean', \ GMTPath='/home/mag/Documents/repos/solab/PySOL/cmap_data/', \ to='mid') cs2 = m.contour(x, y, bathy, levels, cmap=LevelColormap(levels, cmap=cm), alpha=1.0, extend='min') cs2.axis = 'tight' plt.clabel(cs2, levels, fmt = '%i', colors = 'k', \ manual=0, inline=0) # m.fillcontinents(color='coral',lake_color='aqua') # m.drawmeridians(arange(round(lons.min(),1),round(lons.max(),1), 0.5), \ # labels=[0,0,0,1], color='k') # m.drawparallels(arange(round(lats.min(),1),round(lats.max(),1), 0.5), \ # labels=[1,0,0,0], color='k') m.drawcoastlines(linewidth=1.25, color='k') m.drawcountries(linewidth=1.25, color='k') # maximizing figure mng = plt.get_current_fig_manager() mng.resize(1920, 1080) plt.draw() #~ plt.show() #~ ipdb.set_trace() name = name.split(' ')[0] # split the name if it has spaces plotfile = '/home/mag/' + str(name) + '_ETOPO1.tiff' plt.savefig(plotfile, facecolor='w', edgecolor='w', \ dpi=300, bbox_inches="tight", pad_inches=0.1)
def makeMap(): figure(figsize=(8, 8)) """Get the etopo1 data""" etopo1name = predir + 'ETOPO1_Ice_g_gmt4.grd' etopo1 = Dataset(etopo1name, 'r') lons = etopo1.variables["x"][:] lats = etopo1.variables["y"][:] res = findSubsetIndices(lat_start - 5, lat_end + 5, lon_start - 40, lon_end + 10, lats, lons) lon, lat = np.meshgrid(lons[int(res[0]):int(res[1])], lats[int(res[2]):int(res[3])]) # print "Extracted data for area %s : (%s,%s) to (%s,%s)"%(name,lon.min(),lat.min(),lon.max(),lat.max()) bathy = etopo1.variables["z"][int(res[2]):int(res[3]), int(res[0]):int(res[1])] bathySmoothed = laplaceFilter.laplace_filter(bathy, M=None) levels = [ -6000, -5000, -3000, -2000, -1500, -1000, -500, -400, -300, -200, -100, -50, 0, 100, 200, 300, 400, 500, 1e3, 2e3 ] if lon_start < 0 and lon_end < 0: lon_0 = -(abs(lon_end) + abs(lon_start)) / 2.0 else: lon_0 = (abs(lon_end) + abs(lon_start)) / 2.0 # print 'Center longitude ',lon_0 map = Basemap(llcrnrlat=lat_start, urcrnrlat=lat_end, llcrnrlon=lon_start, urcrnrlon=lon_end, resolution=None, projection='lcc', lat_1=lat_start, lon_0=lon_0) x, y = map(lon, lat) # map.drawcoastlines() # map.drawcountries() # # map.fillcontinents(color='grey') # map.drawmeridians(np.arange(lons.min(),lons.max(),2),labels=[0,0,0,1]) # map.drawparallels(np.arange(lats.min(),lats.max(),1),labels=[1,0,0,0]) # map.bluemarble() # CS1 = map.contourf(x,y,bathySmoothed,levels, # cmap=cm.Blues_r, # extend='upper', # alpha=1.0, # origin='lower') CS0 = map.contour(x, y, bathySmoothed, levels, colors='k') map.plot(CFlon[:-1], CFlat[:-1], 'ro', markersize=8, latlon=True, label='Cape Farewell Array') map.plot(CFlon[-1], CFlat[-1], 'mo', markersize=8, latlon=True, label='NOC M1') # map.plot(-39.47,59.93,'o',color='orange',markersize=8,latlon=True,label='OOI mooring')#ooi mooring CS0.axis = 'tight'