def doWindfieldPlotting(configFile): """ Plot the wind field on a map. :param str configFile: Path to the configuration file. :Note: the file name is assumed to be 'gust.interp.nc' """ from netCDF4 import Dataset import numpy as np config = ConfigParser() config.read(configFile) outputPath = config.get('Output', 'Path') windfieldPath = pjoin(outputPath, 'windfield') inputFile = config.get('DataProcess', 'InputFile') if inputFile.endswith(".nc"): # We have a netcdf track file. Work under the assumption it is # drawn directly from TCRM. trackFile = os.path.basename(inputFile) trackId = trackFile.split('.')[1] gustFile = 'gust.{0}.nc'.format(trackId) outputWindFile = pjoin(windfieldPath, gustFile) else: # Note the assumption about the file name! outputWindFile = pjoin(windfieldPath, 'gust.001-00001.nc') plotPath = pjoin(outputPath, 'plots', 'maxwind.png') f = Dataset(outputWindFile, 'r') xdata = f.variables['lon'][:] ydata = f.variables['lat'][:] vdata = f.variables['vmax'][:] gridLimit = None if config.has_option('Region', 'gridLimit'): gridLimit = config.geteval('Region', 'gridLimit') ii = np.where((xdata >= gridLimit['xMin']) & (xdata <= gridLimit['xMax'])) jj = np.where((ydata >= gridLimit['yMin']) & (ydata <= gridLimit['yMax'])) [xgrid, ygrid] = np.meshgrid(xdata[ii], ydata[jj]) ig, jg = np.meshgrid(ii, jj) vdata = vdata[jg, ig] else: [xgrid, ygrid] = np.meshgrid(xdata, ydata) map_kwargs = dict(llcrnrlon=xgrid.min(), llcrnrlat=ygrid.min(), urcrnrlon=xgrid.max(), urcrnrlat=ygrid.max(), projection='merc', resolution='i') title = "Maximum wind speed" cbarlabel = "Wind speed ({0})".format(f.variables['vmax'].units) levels = np.arange(30, 101., 5.) saveWindfieldMap(vdata, xgrid, ygrid, title, levels, cbarlabel, map_kwargs, plotPath)
def doWindfieldPlotting(configFile): """ Plot the wind field on a map. :param str configFile: Path to the configuration file. :Note: the file name is assumed to be 'gust.interp.nc' """ from netCDF4 import Dataset import numpy as np config = ConfigParser() config.read(configFile) outputPath = config.get('Output', 'Path') windfieldPath = pjoin(outputPath, 'windfield') # Note the assumption about the file name! outputWindFile = pjoin(windfieldPath, 'gust.interp.nc') plotPath = pjoin(outputPath, 'plots', 'maxwind.png') f = Dataset(outputWindFile, 'r') xdata = f.variables['lon'][:] ydata = f.variables['lat'][:] vdata = f.variables['vmax'][:] gridLimit = None if config.has_option('Region','gridLimit'): gridLimit = config.geteval('Region', 'gridLimit') ii = np.where((xdata >= gridLimit['xMin']) & (xdata <= gridLimit['xMax'])) jj = np.where((ydata >= gridLimit['yMin']) & (ydata <= gridLimit['yMax'])) [xgrid, ygrid] = np.meshgrid(xdata[ii], ydata[jj]) ig, jg = np.meshgrid(ii, jj) vdata = vdata[jg, ig] else: [xgrid, ygrid] = np.meshgrid(xdata, ydata) map_kwargs = dict(llcrnrlon=xgrid.min(), llcrnrlat=ygrid.min(), urcrnrlon=xgrid.max(), urcrnrlat=ygrid.max(), projection='merc', resolution='i') title = "Maximum wind speed" cbarlabel = "Wind speed ({0})".format(f.variables['vmax'].units) levels = np.arange(30, 101., 5.) saveWindfieldMap(vdata, xgrid, ygrid, title, levels, cbarlabel, map_kwargs, plotPath)
def plotGustToFile(self, result, filename): """ Plot the wind field on a map """ lat, lon, speed, Vx, Vy, P = result mapkwargs = dict(llcrnrlon=self.gridLimit['xMin'], llcrnrlat=self.gridLimit['yMin'], urcrnrlon=self.gridLimit['xMax'], urcrnrlat=self.gridLimit['yMax'], resolution='i', projection='merc') levels = np.arange(20., 100.1, 5.) cbarlabel = 'Wind speed (m/s)' [gx, gy] = np.meshgrid(lon, lat) title = 'TC wind field' saveWindfieldMap(speed, gx, gy, title, levels, cbarlabel, mapkwargs, filename)