def plotWindVectorsOnMap(date, showIt=True): from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import wUUtils as Util # setup Lambert Conformal basemap. m = Basemap(width=3200000,height=2500000,projection='lcc', resolution='i',lat_1=45.,lat_0=43.6,lon_0=-80.) # draw coastlines. m.drawcoastlines() m.drawcountries() m.drawstates() # draw a boundary around the map, fill the background. # this background will end up being the ocean color, since # the continents will be drawn on top. m.drawmapboundary(fill_color='aqua') # fill continents, set lake color same as ocean color. m.fillcontinents(color='wheat',lake_color='aqua') # get city locations (Toronto, Montreal, Detroit) cityName = Util.getStationList() lon, lat = Util.getStationLonLat(cityName) # convert to map projection coords. # Note that lon,lat can be scalars, lists or numpy arrays. xpt,ypt = m(lon,lat) m.plot(xpt,ypt,'bo') # plot a blue dot there # compute wind vectors windX = Util.loadDailyVariable(cityName, date, 'WindMeanX') windY = Util.loadDailyVariable(cityName, date, 'WindMeanY') for icity in range(len(cityName)): stretch = 20000 dx, dy = stretch*windX[icity], stretch*windY[icity] plt.arrow(xpt[icity],ypt[icity],dx,dy,color='r',width=12000,head_length=40000,head_width=40000) plt.text(xpt[icity]+30000,ypt[icity]+20000,cityName[icity], size='large') plt.title("Daily-mean wind: " + date) if showIt: plt.show()
def contourPlotVarOnMapFrame(variable, date, \ contours, npts = 20, \ figname='figure', frameNum=0, \ title='Data', units='units', \ width_fac = 16, height_fac = 12): import wUUtils as Util stations = Util.getStationList() data = Util.loadDailyVariable(stations, date, variable) contourPlotDataOnMapFrame(data, contours, npts, \ figname, frameNum, title, \ units, width_fac, height_fac)
def contourPlotVarOnMap(variable, date, npts = 20, ncntrs = 10, \ width_fac = 16, height_fac = 12): import numpy as np import wUUtils as Util import matplotlib.pyplot as plt import scipy.interpolate from mpl_toolkits.basemap import Basemap # open new figure window plt.figure() # setup Lambert Conformal basemap. m = Basemap(width=width_fac*100000,height=height_fac*100000, \ projection='lcc', resolution='i', \ lat_1=45.,lat_0=43.6,lon_0=-82.) # draw coastlines. m.drawcoastlines() m.drawcountries() m.drawstates() # draw a boundary around the map, fill the background. # this background will end up being the ocean color, since # the continents/data will be drawn on top. m.drawmapboundary(fill_color='aqua') # load data stations = Util.getStationList() lon, lat = Util.getStationLonLat(stations) data = Util.loadDailyVariable(stations, date, variable) # print(zip(stations,data)) # convert data to arrays: x, y, z = np.array(lon), np.array(lat), np.array(data) # map data points to projection coordinates xmap, ymap = m(x,y) # Set up a regular grid of interpolation points xi, yi = np.linspace(x.min(), x.max(), npts), \ np.linspace(y.min(), y.max(), npts) # map regular lon-lat grid to projection coordinates xi, yi = m(*np.meshgrid(xi,yi)) # Interpolate data to projected regular grid # function is one of 'linear', 'multiquadric', 'gaussian', # 'inverse', 'cubic', 'quintic', 'thin_plate' rbf = scipy.interpolate.Rbf(xmap, ymap, z, \ function='linear') zi = rbf(xi, yi) # draw filled contours cs = m.contourf(xi,yi,zi,ncntrs,cmap=plt.cm.jet) # plot circles at original (projected) data points m.scatter(xmap,ymap,c=z) # add colorbar. cbar = m.colorbar(cs,location='bottom',pad="5%") cbar.set_label(variable) plt.title(variable + " -- " + date) # display plot plt.show()