def plot_surface_map(ncFile, targetDir, withTemperature=True, withWinds=True, windScaleFactor=50, withMSLP=True): logger = PyPostTools.pyPostLogger() if (withTemperature == False and withWinds == False and withMSLP == False): logger.write("Error in plot_surface_map(): Nothing to do.") return False fig, ax, X, Y = prepare_plot_object(ncFile) st, fh, fh_int = getTimeObjects(ncFile) titleAdd = "" if (withTemperature): T = ncFile["SFC_T"] TF = Conversions.K_to_F(T) clevs = np.arange(-30, 115, 5) contours = plt.contourf(X, Y, TF, clevs, cmap=ColorMaps.temp_colormap, transform=ccrs.PlateCarree()) cbar = plt.colorbar(ax=ax, orientation="horizontal", pad=.05) cbar.set_label("Temperature (F)") titleAdd += "Temperature " if (withMSLP): SLP = to_np(ncFile["MSLP"]) smooth_slp = gaussian_filter(SLP, sigma=3) levs = np.arange(950, 1050, 4) linesC = plt.contour(X, Y, smooth_slp, levs, colors="black", transform=ccrs.PlateCarree(), linewidths=1) plt.clabel(linesC, inline=1, fontsize=10, fmt="%i") titleAdd += "MSLP (mb) " if (withWinds): u = ncFile["SFC_U"] v = ncFile["SFC_V"] uKT = Conversions.ms_to_kts(u) vKT = Conversions.ms_to_kts(v) plt.barbs(to_np(X[::windScaleFactor, ::windScaleFactor]), to_np(Y[::windScaleFactor, ::windScaleFactor]), to_np(uKT[::windScaleFactor, ::windScaleFactor]), to_np(vKT[::windScaleFactor, ::windScaleFactor]), transform=ccrs.PlateCarree(), length=6) titleAdd += "Winds " # Finish things up, for the title crop off the extra comma at the end, add the time text, and save. titleAdd = titleAdd.replace(" ", ", ") titleAdd = titleAdd[:-2] plt.title("Surface Map (" + titleAdd + ")") plt.text(0.02, -0.02, "Forecast Time: " + fh.strftime("%Y-%m-%d %H:%M UTC"), ha='left', va='center', transform=ax.transAxes) plt.text(0.7, -0.02, "Initialized: " + st.strftime("%Y-%m-%d %H:%M UTC"), ha='left', va='center', transform=ax.transAxes) plt.subplots_adjust(bottom=0.1) plt.savefig(targetDir + "/sfcmap_F" + str(fh_int)) plt.close(fig) return True