def print_cape_for_timestamp(wrf_data, timestamp, filepath): slp = pressure_lib.get_sea_level_pressure(wrf_data) cinfo = getvar(wrf_data, "cape_2d", missing=0.0) cape = cinfo[0, :, :].fillna(0) lat, lon = latlon_coords(slp) lat_normal = to_np(lat) lon_normal = to_np(lon) # rain sum cape_res = get_pyngl(cinfo) cape_res.nglDraw = False # don't draw plot cape_res.nglFrame = False # don't advance frame cape_res.cnFillOn = True # turn on contour fill cape_res.cnLinesOn = False # turn off contour lines cape_res.cnLineLabelsOn = False # turn off line labels cape_res.cnFillMode = "RasterFill" # These two resources cape_res.cnLevelSelectionMode = "ExplicitLevels" cape_res.cnFillColors = numpy.array([ [255,255,255], [ 0,255, 0], [ 0,128, 0], \ [240,230,140], [255,255, 0], [255,140, 0], \ [255, 0, 0], [139, 0, 0], [186, 85,211],\ [153, 50,204], [139, 0,139], ],'f') / 255. cape_res.cnLevels = numpy.array( [.1, 500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500]) cape_res = geography_lib.initialize_geography(cape_res, "gray50") cape_res.lbTitleString = "Convective available potential energy [CAPE] in (J/kg)" cape_res.lbOrientation = "horizontal" cape_res.lbTitleFontHeightF = 0.015 cape_res.lbLabelFontHeightF = 0.015 cape_res.tiMainString = "Thunderstorm probability (%s)" % timestamp.strftime( "%b %d %Y %HUTC") cape_res.trGridType = "TriangularMesh" # can speed up plotting. cape_res.tfDoNDCOverlay = True # required for native projection # pressure p_res = pressure_lib.get_pressure_resource(lat_normal, lon_normal) wk_res = Ngl.Resources() wk_res.wkWidth = 2500 wk_res.wkHeight = 2500 output_path = "%scape_%s" % (filepath, timestamp.strftime("%Y_%m_%d_%H")) wks_comp = Ngl.open_wks("png", output_path, wk_res) # creating plots for the measurands capeplot = Ngl.contour_map(wks_comp, cape, cape_res) pplot = Ngl.contour(wks_comp, slp, p_res) Ngl.overlay(capeplot, pplot) Ngl.maximize_plot(wks_comp, capeplot) Ngl.draw(capeplot) Ngl.frame(wks_comp) Ngl.delete_wks(wks_comp) # delete currently used workstation
def get_3h_rainsum(previous_data, current_data, timestamp, filepath): slp = pressure_lib.get_sea_level_pressure(current_data) previous_sum, rain_con = get_cumulated_rain_sum(previous_data) current_sum, rain_con = get_cumulated_rain_sum(current_data) rain_sum = current_sum - previous_sum lat, lon = latlon_coords(rain_con) lat_normal = to_np(lat) lon_normal = to_np(lon) # rain sum rr_res = initialize_rain_resource(rain_con) rr_res.lbTitleString = "3h rainsum in (mm)" rr_res.lbOrientation = "horizontal" rr_res.lbTitleFontHeightF = 0.015 rr_res.lbLabelFontHeightF = 0.015 rr_res.tiMainString = "3h rainsum (%s)" % timestamp.strftime( "%b %d %Y %HUTC") rr_res.trGridType = "TriangularMesh" # can speed up plotting. rr_res.tfDoNDCOverlay = True # required for native projection # pressure p_res = pressure_lib.get_pressure_resource(lat_normal, lon_normal) wk_res = Ngl.Resources() wk_res.wkWidth = 2500 wk_res.wkHeight = 2500 output_path = "%srain_3h_%s" % (filepath, timestamp.strftime("%Y_%m_%d_%H")) wks_comp = Ngl.open_wks("png", output_path, wk_res) # creating plots for the measurands rrplot = Ngl.contour_map(wks_comp, rain_sum, rr_res) pplot = Ngl.contour(wks_comp, slp, p_res) Ngl.overlay(rrplot, pplot) Ngl.maximize_plot(wks_comp, rrplot) Ngl.draw(rrplot) Ngl.frame(wks_comp) Ngl.delete_wks(wks_comp) # delete currently used workstation
#-- draw polygons polyg = Ngl.add_polygon(wks1,map,x1d,y1d,pgres) #-- add polygons to map #-- labelbar resources lbres = Ngl.Resources() lbres.vpWidthF = 0.85 #-- labelbar width lbres.vpHeightF = 0.15 #-- labelbar height lbres.lbOrientation = "Horizontal" #-- labelbar orientation lbres.lbFillPattern = "SolidFill" #-- labelbar box fill style lbres.lbMonoFillPattern = 21 #-- labelbar box fill pattern lbres.lbMonoFillColor = False #-- use multiple colors lbres.lbFillColors = colors #-- set color array lbres.lbLabelFontHeightF = 0.014 #-- labelbar label font size lbres.lbLabelAlignment = "InteriorEdges" #-- draw labels between boxes #-- add labelbar to workstation lb = Ngl.labelbar_ndc(wks1,nlevels,labels,0.1,0.2,lbres) #-- maximize and draw the plot, and advance the frame Ngl.maximize_plot(wks1, map) Ngl.draw(map) Ngl.frame(wks1) #-- get wallclock time t2 = time.time() print "Wallclock time: %0.3f seconds" % (t2-t1) print "" Ngl.end()
res.mpNationalLineThicknessF = 1.5 res.mpGeophysicalLineColor = "gray40" res.mpGeophysicalLineThicknessF = 1.5 res.cnMonoLineColor = True res.cnLevelSelectionMode = "ManualLevels" res.cnMinLevelValF = 1000.0 res.cnMaxLevelValF = 6000.0 res.cnLevelSpacingF = 250.0 res.cnLineThicknessF = 2.5 # create PWAT plot for analysis data MD_plot = ngl.contour_map(wks,MD,res) ngl.maximize_plot(wks, MD_plot) ngl.draw(MD_plot) ngl.frame(wks) ngl.destroy(wks) del res del MD #del CIN ################################################################################################### # open forecast file f_fili = "GFS_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri+f_fili)
res.mpNationalLineThicknessF = 1.5 res.mpGeophysicalLineColor = "gray40" res.mpGeophysicalLineThicknessF = 1.5 res.cnMonoLineColor = True res.cnLevelSelectionMode = "ManualLevels" res.cnMinLevelValF = 0.0 res.cnMaxLevelValF = 65.0 res.cnLevelSpacingF = 2.5 res.cnLineThicknessF = 2.5 # create PWAT plot for analysis data PWAT_plot = ngl.contour_map(wks, PWAT, res) ngl.maximize_plot(wks, PWAT_plot) ngl.draw(PWAT_plot) ngl.frame(wks) ngl.destroy(wks) del res del PWAT #del CIN ################################################################################################### # open forecast file f_fili = "GFS_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri + f_fili)
vcres.vcRefAnnoFontHeightF = 0.005 vcres.vcLineArrowThicknessF = 2.0 # create vector plot for analysis data and overlay on colour contours level 1 uv_plot1 = ngl.vector(wks,u_1,v_1,vcres) # create vector plot for analysis data and overlay on colour contours level2 vcres.vcLineArrowColor = "Red" uv_plot2 = ngl.vector(wks,u_2,v_2,vcres) ngl.overlay(shear_plot,uv_plot1) ngl.overlay(shear_plot,uv_plot2) ngl.maximize_plot(wks, shear_plot) ngl.draw(shear_plot) ngl.frame(wks) ngl.destroy(wks) del res del vcres ################################################################################################### # open forecast file f_fili = "GFS_48h_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri+f_fili)
res.cnLineThicknessF = 5.0 res.cnLineColor = "steelblue1" res.cnLevelSelectionMode = "ManualLevels" res.cnMinLevelValF = -85.0 res.cnMaxLevelValF = 115.0 res.cnLevelSpacingF = 100.0 # plot ITD and overlay on colour contours ws_plot2 = ngl.contour(wks, ws, res) ngl.overlay(ws_plot, ws_plot2) ngl.overlay(ws_plot, uv_plot) ngl.maximize_plot(wks, ws_plot) ngl.draw(ws_plot) ngl.frame(wks) ngl.destroy(wks) del res del vcres ################################################################################################### # open forecast file f_fili = "GFS_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri + f_fili) # loop through forecast times
res.cnLineThicknessF = 2.5 res.cnInfoLabelOn = True res.cnInfoLabelString = "CIN Contours at -50, -100 and -250 J/Kg" res.cnInfoLabelOrthogonalPosF = -0.06 res.cnInfoLabelParallelPosF = 0.505 res.cnLevelSelectionMode = "ExplicitLevels" res.cnLevels = [-250.0, -100.0, -50.0] # plot CIN and overlay on colour contours CIN_plot = ngl.contour(wks,CIN,res) ngl.overlay(CAPE_plot,CIN_plot) ngl.maximize_plot(wks, CAPE_plot) ngl.draw(CAPE_plot) ngl.frame(wks) ngl.destroy(wks) del res del CAPE del CIN ################################################################################################### # open forecast file f_fili = "GFS_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri+f_fili)
res.mpGridAndLimbOn = True res.pmTickMarkDisplayMode = "Never" res.mpProjection = "CylindricalEquidistant" res.mpLimitMode = "LatLon" # Limit the map view. res.mpMinLonF = lontr res.mpMaxLonF = lonbl res.mpMinLatF = lattr res.mpMaxLatF = latbl res.mpOutlineBoundarySets = "AllBoundaries" res.mpNationalLineColor = colour res.mpNationalLineThicknessF = 2.0 res.mpGeophysicalLineColor = colour res.mpGeophysicalLineThicknessF = 2.0 res.mpGridLatSpacingF = 5.0 res.mpGridLonSpacingF = 5.0 res.mpGridLineThicknessF = 2.0 res.cnMonoLineColor = True map_plot = ngl.map(wks,res) ngl.maximize_plot(wks, map_plot) ngl.draw(map_plot) ngl.frame(wks) ngl.destroy(wks) del res os.system('mogrify -trim map_'+colour+'_'+region+'.png') # os.system('mogrify -resize 1350x900 map_'+colour+'_'+region+'.png')
res.cnMonoLineColor = True max_cont = 0.0001 min_cont = -0.0001 res.cnLevelSelectionMode = "ManualLevels" res.cnMinLevelValF = min_cont res.cnMaxLevelValF = max_cont res.cnLevelSpacingF = (max_cont - min_cont) / 15.0 res.cnLineThicknessF = 2.5 # create convergence plot for analysis data conv_plot = ngl.contour_map(wks, conv, res) ngl.maximize_plot(wks, conv_plot) ngl.draw(conv_plot) ngl.frame(wks) ngl.destroy(wks) del res ################################################################################################### # open forecast file f_fili = "GFS_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri + f_fili) # loop through forecast times for i in range(0, len(fore)):
min_cont = -0.25 if float(lev_hPa) >=700: max_cont = 0.1 min_cont = -0.1 res.cnLevelSelectionMode = "ManualLevels" res.cnMinLevelValF = min_cont res.cnMaxLevelValF = max_cont res.cnLevelSpacingF = (max_cont-min_cont)/20.0 res.cnLineThicknessF = 2.5 # create pv plot for analysis data pv_plot = ngl.contour_map(wks,pv,res) ngl.maximize_plot(wks, pv_plot) ngl.draw(pv_plot) ngl.frame(wks) ngl.destroy(wks) del res ################################################################################################### # open forecast file f_fili = "GFS_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri+f_fili) # loop through forecast times for i in range(0, len(fore)):
if float(lev_hPa) >= 700: max_cont = 305.0 min_cont = 265.0 lev_space = 2.0 res.cnLevelSelectionMode = "ManualLevels" res.cnMinLevelValF = min_cont res.cnMaxLevelValF = max_cont res.cnLevelSpacingF = lev_space res.cnLineThicknessF = 2.5 # create plot for analysis data temp_plot = ngl.contour_map(wks, temp, res) ngl.maximize_plot(wks, temp_plot) ngl.draw(temp_plot) ngl.frame(wks) ngl.destroy(wks) del res ################################################################################################### # open forecast file f_fili = "GFS_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri + f_fili) # loop through forecast times
res.cnMonoLineColor = True max_cont = (2.0 * round(np.max(mslp / 2.0), 0)) + 10.0 min_cont = (2.0 * round(np.min(mslp / 2.0), 0)) - 10.0 res.cnLevelSelectionMode = "ManualLevels" res.cnMinLevelValF = min_cont res.cnMaxLevelValF = max_cont res.cnLevelSpacingF = 2. res.cnLineThicknessF = 2.5 # create plot for analysis data mslp_plot = ngl.contour_map(wks, mslp, res) ngl.maximize_plot(wks, mslp_plot) ngl.draw(mslp_plot) ngl.frame(wks) ngl.destroy(wks) del res ################################################################################################### # open forecast file f_fili = "GFS_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri + f_fili) # loop through forecast times
res.cnMonoLineColor = True max_cont = 0.00025 min_cont = -0.00025 res.cnLevelSelectionMode = "ManualLevels" res.cnMinLevelValF = min_cont res.cnMaxLevelValF = max_cont res.cnLevelSpacingF = 0.000025 res.cnLineThicknessF = 2.5 # create plot for analysis data vort_plot = ngl.contour_map(wks, vort, res) ngl.maximize_plot(wks, vort_plot) ngl.draw(vort_plot) ngl.frame(wks) ngl.destroy(wks) del res ################################################################################################### # open forecast file f_fili = "GFS_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri + f_fili) # loop through forecast times
res.cnMonoLineColor = True max_cont = (2.0 * round(np.max(geopot / 2.0), 0)) + 10.0 min_cont = (2.0 * round(np.min(geopot / 2.0), 0)) - 10.0 res.cnLevelSelectionMode = "ManualLevels" res.cnMinLevelValF = min_cont res.cnMaxLevelValF = max_cont res.cnLevelSpacingF = 2. res.cnLineThicknessF = 2.5 # create plot for analysis data geo_plot = ngl.contour_map(wks, geopot, res) ngl.maximize_plot(wks, geo_plot) ngl.draw(geo_plot) ngl.frame(wks) ngl.destroy(wks) del res ################################################################################################### # open forecast file f_fili = "GFS_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri + f_fili) # loop through forecast times
res.cnLineDashPattern = 11 res.cnLineThicknessF = 5.0 res.cnLineColor = "purple" res.cnLevelSelectionMode = "ManualLevels" res.cnMinLevelValF = -85.0 res.cnMaxLevelValF = 115.0 res.cnLevelSpacingF = 100.0 # plot ITD and overlay on colour contours dp_plot2 = ngl.contour(wks, dewpoint, res) ngl.overlay(dp_plot, dp_plot2) ngl.maximize_plot(wks, dp_plot) ngl.draw(dp_plot) ngl.frame(wks) ngl.destroy(wks) del res del dewpoint ################################################################################################### # open forecast file f_fili = "GFS_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri + f_fili) # loop through forecast times
vcres.vcRefMagnitudeF = 30.0 # define vector ref mag vcres.vcRefLengthF = 0.03 # define length of vec ref vcres.vcMinFracLengthF = 0.3 vcres.vcMinDistanceF = 0.02 vcres.vcRefAnnoOrthogonalPosF = -0.20 vcres.vcRefAnnoFontHeightF = 0.005 vcres.vcLineArrowThicknessF = 2.0 # create vector plot for analysis data and overlay on colour contours uv_plot1 = ngl.vector(wks, max_shear_u2_u1, max_shear_v2_v1, vcres) # create vector plot for analysis data and overlay on colour contours level2 ngl.overlay(PRATE_plot, uv_plot1) ngl.maximize_plot(wks, PRATE_plot) ngl.draw(PRATE_plot) ngl.frame(wks) ngl.destroy(wks) del res.mpProjection del res.mpLimitMode del res.mpMinLonF del res.mpMaxLonF del res.mpMinLatF del res.mpMaxLatF # del res.mpPerimOn del res.mpOutlineBoundarySets del res.mpNationalLineColor del res.mpNationalLineThicknessF
vcres.vcFillArrowsOn = True vcres.vcRefMagnitudeF = 30.0 # define vector ref mag vcres.vcRefLengthF = 0.02 # define length of vec ref vcres.vcMinFracLengthF = 0.3 vcres.vcMinDistanceF = 0.02 vcres.vcRefAnnoOrthogonalPosF = -0.20 vcres.vcRefAnnoFontHeightF = 0.005 cnres.tiMainString = "Fully opaque filled vectors over filled contours" #---Draw fully opaque vectors uv_plot = Ngl.vector(wks,u,v,vcres) spd_plot = Ngl.contour_map(wks,spd,cnres) Ngl.overlay(spd_plot,uv_plot) Ngl.maximize_plot(wks, spd_plot) Ngl.draw(spd_plot) Ngl.frame(wks) #---This time make vectors partially transparent vcres.vcGlyphOpacityF = 0.3 cnres.tiMainString = "Partially transparent vectors over filled contours" uv_plot = Ngl.vector(wks,u,v,vcres) spd_plot = Ngl.contour_map(wks,spd,cnres) Ngl.overlay(spd_plot,uv_plot) Ngl.maximize_plot(wks, spd_plot) Ngl.draw(spd_plot) Ngl.frame(wks)
lbres.lbTitleOffsetF = 0.00 #---Create the labelbar labels = ["0","1","2","3"] lbid = Ngl.labelbar_ndc (wks,len(labels),labels,0.0,0.,lbres) # # Create some annotation resources indicating how we want to # attach the labelbar to the plot. The default is the center # of the plot. Below amOrthogonalPosF is set to move the # labelbar down and outside the plot. # amres = Ngl.Resources() amres.amOrthogonalPosF = 0.7 annoid = Ngl.add_annotation(plot,lbid,amres) txres = Ngl.Resources() txres.txFontHeightF = 0.01 txres.txJust = "TopRight" txres.txPerimOn = True txid = Ngl.add_text(wks,plot,flnm,res.mpMaxLonF,res.mpMaxLatF,txres) #---This will resize plot so it and the labelbar fit in the frame. Ngl.maximize_plot(wks, plot) #---Drawing the original map also draws the attached labelbar. Ngl.draw(plot) Ngl.frame(wks) Ngl.end()
def draw_gh_500hPa(sel_year, sel_month): print("darwing 500hPa gh plot for " + str(sel_month).zfill(2) + " " + str(sel_year)) files_cli = sorted( glob.glob( os.path.join( '/home/alley/work/Dong/mongo/seasonal_analysis/data/data/download_from_mongo/cli/', 'gh_500_*.grb'))) f_cli = xr.open_mfdataset(files_cli, concat_dim="time", combine="nested", engine="cfgrib", parallel=True) h = f_cli["z"] h = h.mean(dim="time") h_cli = h / 98 lat = f_cli["latitude"].values lon = f_cli["longitude"].values file_cur = "/home/alley/work/Dong/mongo/seasonal_analysis/data/data/download_from_mongo/cur/gh_500_" + str( sel_year) + str(sel_month).zfill(2) + ".grb" # print(file_cur) f_cur = xr.open_mfdataset(file_cur, engine="cfgrib", parallel=True) h_cur = f_cur["z"] / 98 h_ano = h_cur - h_cli leftString = "500hPa Height & Anomaly for " + str(sel_month) + str( sel_year) rightString = "dagpm" wks_type = 'png' wks = Ngl.open_wks( wks_type, '/home/alley/work/Dong/mongo/seasonal_analysis/images/gh_500hPa_' + str(sel_year) + str(sel_month).zfill(2) + '.png') res = Ngl.Resources() res.nglFrame = False res.nglDraw = False res.mpLimitMode = "LatLon" res.mpMinLonF = 60 res.mpMaxLonF = 180 res.mpMinLatF = 0 res.mpMaxLatF = 60 plot_map = Ngl.map(wks, res) fres = Ngl.Resources() fres.nglFrame = False fres.nglDraw = False fres.cnFillOn = True fres.sfXArray = lon fres.sfYArray = lat fres.lbOrientation = "Horizontal" # horizontal labelbar fres.cnLinesOn = False fres.cnLineLabelsOn = False fres.cnLevelSelectionMode = "ExplicitLevels" fres.cnFillPalette = "BlueDarkRed18" fres.cnLevels = np.arange(-5, 6, 1) plot_cn = Ngl.contour(wks, h_ano, fres) cnres = Ngl.Resources() cnres.nglDraw = False cnres.nglFrame = False cnres.cnFillOn = False cnres.cnLinesOn = True cnres.cnLineLabelsOn = True cnres.cnInfoLabelOn = False cnres.sfXArray = lon cnres.sfYArray = lat cnres.cnLevelSelectionMode = "ExplicitLevels" cnres.cnLevels = np.arange(500, 600, 4) cnres.cnLineColor = "black" cnres.cnLineThicknessF = 5 plot2 = Ngl.contour(wks, h_cur, cnres) Ngl.overlay(plot_map, plot_cn) Ngl.overlay(plot_map, plot2) # txres = Ngl.Resources() txres.txFontHeightF = 0.024 # Ngl.text_ndc(wks, leftString, 0.3, 0.83, txres) Ngl.text_ndc(wks, rightString, 0.85, 0.83, txres) # Ngl.maximize_plot(wks, plot_map) Ngl.draw(plot_map) Ngl.frame(wks) Ngl.end() print("Finish darwing 500hPa gh plot plot for " + str(sel_month).zfill(2) + " " + str(sel_year))
bres.tmXBLabelFontHeightF = 0.015 # Make labels smaller. This # will affect Y labels too. #---Set the values and labels for the Y axis of blank plot. bres.tmYLMode = "Explicit" bres.tmYLValues = lat_values bres.tmYLLabels = lat_labels #---Align four corners of both plots, that is, don't do data transformation bres.tfDoNDCOverlay = True #---Create the blank plot. blank = Ngl.blank_plot(wks,bres) #---Draw blank plot for debugging purposes. #Ngl.draw(blank) #Ngl.frame(wks) #---Overlay blank plot on existing map plot. Ngl.overlay(map.base,blank) #---Resize map so it fits within frame Ngl.maximize_plot(wks, map) #---Drawing the original map also draws the overlaid blank plot Ngl.draw(map) Ngl.frame(wks) Ngl.end()
res.mpNationalLineThicknessF = 1.5 res.mpGeophysicalLineColor = "gray40" res.mpGeophysicalLineThicknessF = 1.5 res.cnMonoLineColor = True res.cnLevelSelectionMode = "ManualLevels" res.cnMinLevelValF = -20.0 res.cnMaxLevelValF = 40.0 res.cnLevelSpacingF = 2.0 res.cnLineThicknessF = 2.5 # create DPTMP2 plot for analysis data DPTMP2_plot = ngl.contour_map(wks, DPTMP2, res) ngl.maximize_plot(wks, DPTMP2_plot) ngl.draw(DPTMP2_plot) ngl.frame(wks) ngl.destroy(wks) del res del DPTMP2 #del CIN ################################################################################################### # open forecast file f_fili = "GFS_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri + f_fili)
res.cnMonoLineColor = True max_cont = 100.0 min_cont = 0.0 res.cnLevelSelectionMode = "ManualLevels" res.cnMinLevelValF = min_cont res.cnMaxLevelValF = max_cont res.cnLevelSpacingF = 2.5 res.cnLineThicknessF = 2.5 # create relative humidity plot for analysis data rh_plot = ngl.contour_map(wks, rh, res) ngl.maximize_plot(wks, rh_plot) ngl.draw(rh_plot) ngl.frame(wks) ngl.destroy(wks) del res ################################################################################################### # open forecast file f_fili = "GFS_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri + f_fili) # loop through forecast times
vcres.vcMinFracLengthF = 0.3 vcres.vcMinDistanceF = 0.02 vcres.vcRefAnnoOrthogonalPosF = -0.20 vcres.vcRefAnnoFontHeightF = 0.005 vcres.vcLineArrowThicknessF = 2.0 # create vector plot for analysis data and overlay on colour contours level 1 uv_plot1 = ngl.vector(wks, max_shear_u2_u1, max_shear_v2_v1, vcres) PWAT_plot = ngl.contour(wks, PWAT, res) ngl.overlay(LI_plot, uv_plot1) ngl.overlay(LI_plot, PWAT_plot) ngl.maximize_plot(wks, LI_plot) ngl.draw(LI_plot) ngl.frame(wks) ngl.destroy(wks) del res del LI del PWAT del vcres del u1 del v1 del u2 del v2 del shear del max_shear del max_shear_u2_u1
res.mpMinLatF = lattr res.mpMaxLatF = latbl res.mpOutlineBoundarySets = "AllBoundaries" res.mpNationalLineColor = -1 res.mpNationalLineThicknessF = 2.0 res.mpGeophysicalLineColor = -1 res.mpGeophysicalLineThicknessF = 2.0 res.mpGridLatSpacingF = 5.0 res.mpGridLonSpacingF = 5.0 res.mpGridLineThicknessF = 2.0 res.mpGridLineColor = colour res.cnMonoLineColor = True grid_plot = ngl.map(wks, res) ngl.maximize_plot(wks, grid_plot) ngl.draw(grid_plot) ngl.frame(wks) ngl.destroy(wks) del res os.system('mogrify -trim grid_' + colour + '_' + region + '.png') # if region == "WA" or region == "unknownWA": # os.system('mogrify -trim grid_'+colour+'_'+region+'.png') # os.system('mogrify -resize 886x600 grid_'+colour+'_'+region+'.png') # elif region == "EA" or region == "unknownEA": # os.system('mogrify -trim grid_'+colour+'_'+region+'.png') # os.system('mogrify -resize 600x733 grid_'+colour+'_'+region+'.png')
res.cnMonoLineColor = True max_cont = (2.0*round(np.max(theta/2.0),0))+10.0 min_cont = (2.0*round(np.min(theta/2.0),0))-10.0 res.cnLevelSelectionMode = "ManualLevels" res.cnMinLevelValF = 290.0 #min_cont res.cnMaxLevelValF = 355.0 #max_cont res.cnLevelSpacingF = 2.5 res.cnLineThicknessF = 2.5 # create plot for analysis data theta_plot = ngl.contour_map(wks,theta,res) ngl.maximize_plot(wks, theta_plot) ngl.draw(theta_plot) ngl.frame(wks) ngl.destroy(wks) del res ################################################################################################### # open forecast file f_fili = "GFS_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri+f_fili) # loop through forecast times
res.tiMainFontColor = "Navy" res.tiMainOffsetYF = 0.02 res.tiMainFontHeightF = 0.035 res.tiYAxisString = "Left Y axis string" res.stMonoLineColor = False # Use multiple colors for streamlines. res.stLineThicknessF = 2.0 # Twice as thick res.lbOrientation = "Horizontal" res.pmLabelBarOrthogonalPosF = -0.02 res.pmLabelBarHeightF = 0.1 res.pmLabelBarWidthF = 0.6 plot = Ngl.streamline_scalar(wks, u, v, spd, res) # Create streamline plot. txres = Ngl.Resources() # Text resources desired txres.txFontColor = "OrangeRed" subtitles(wks, plot, "Left string", "Center string", "Right string", txres) del txres.txFontColor # Go back to foreground color (black) txres.txFontHeightF = 0.029 right_axis(wks, plot, "Right Y axis string", txres) Ngl.maximize_plot(wks, plot) Ngl.draw(plot) # Drawing the plot will draw the three subtitles attached. Ngl.frame(wks) Ngl.end()
res.cnMonoLineColor = True max_cont = 0.00005 min_cont = -0.00005 res.cnLevelSelectionMode = "ManualLevels" res.cnMinLevelValF = min_cont res.cnMaxLevelValF = max_cont res.cnLevelSpacingF = (max_cont - min_cont) / 20.0 res.cnLineThicknessF = 2.5 # create divergence plot for analysis data div_plot = ngl.contour_map(wks, div, res) ngl.maximize_plot(wks, div_plot) ngl.draw(div_plot) ngl.frame(wks) ngl.destroy(wks) del res ################################################################################################### # open forecast file f_fili = "GFS_forecast_%s_%s.nc" % (init_dt[:8], init_dt[8:10]) forecast = nio.open_file(diri + f_fili) # loop through forecast times for i in range(0, len(fore)):
Ngl.overlay(map_plot,fill_contour_plot) Ngl.overlay(map_plot,line_contour_plot) Ngl.overlay(map_plot,vector_plot) # # Change the title. # srlist = Ngl.Resources() srlist.tiMainString = "vectors, line, and filled contours" Ngl.set_values(map_plot,srlist) # # Draw the map plot, which now contains the vectors and # filled/line contours. # Ngl.maximize_plot(wks,map_plot) # Maximize size of plot in frame. Ngl.draw(map_plot) Ngl.frame(wks) # # Change the title. # srlist.tiMainString = "line and filled contours" Ngl.set_values(map_plot,srlist) # # Remove the vector plot and redraw. We should now # just see the line contours and filled contours. # Ngl.remove_overlay(map_plot,vector_plot,0) Ngl.draw(map_plot)
def print_comp_for_timestamp(wrf_data, timestamp, filepath): slp = pressure_lib.get_sea_level_pressure(wrf_data) temperature = getvar(wrf_data,"tc") u = get_latitude_wind(wrf_data) v = get_longitude_wind(wrf_data) lat, lon = latlon_coords(temperature) lat_normal = to_np(lat) lon_normal = to_np(lon) # temperature t_res = get_pyngl(temperature) t_res.nglDraw = False # don't draw plot t_res.nglFrame = False # don't advance frame t_res.cnFillOn = True # turn on contour fill t_res.cnLinesOn = False # turn off contour lines t_res.cnLineLabelsOn = False # turn off line labels t_res.cnFillMode = "RasterFill" # These two resources t_res.cnFillPalette = "BlAqGrYeOrReVi200" t_res.cnLevelSelectionMode = "ManualLevels" t_res.cnMinLevelValF = -25.0 # min. temperature for composite t_res.cnMaxLevelValF = 45.0 # max. temperature for composite t_res.cnLevelSpacingF = 1 # increment t_res = geography_lib.initialize_geography(t_res, "gray25") t_res.lbTitleString = "%s in (%s)" % (temperature.description,temperature.units) t_res.lbOrientation = "horizontal" t_res.lbTitleFontHeightF = 0.015 t_res.lbLabelFontHeightF = 0.015 t_res.tiMainString = "Composite (%s)" % timestamp.strftime("%b %d %Y %HUTC") t_res.trGridType = "TriangularMesh" # can speed up plotting. t_res.tfDoNDCOverlay = True # required for native projection # pressure p_res = pressure_lib.get_pressure_resource(lat_normal, lon_normal) # wind uv_res = Ngl.Resources() uv_res.nglDraw = False # don't draw plot uv_res.nglFrame = False # don't advance frame uv_res.vcFillArrowsOn = True uv_res.vcRefMagnitudeF = 15.0 uv_res.vcRefLengthF = 0.03 uv_res.vcMinDistanceF = 0.02 uv_res.vcRefAnnoFontHeightF = 0.01 uv_res.vcRefAnnoString1 = "$VMG$ m/s" uv_res.vcRefAnnoString2 = "ground windspeed (m/s) reference" uv_res.vfXArray = lon_normal uv_res.vfYArray = lat_normal wk_res = Ngl.Resources() wk_res.wkWidth = 2500 wk_res.wkHeight = 2500 output_path = "%scomp_%s" % (filepath, timestamp.strftime("%Y_%m_%d_%H")) wks_comp = Ngl.open_wks("png", output_path, wk_res) # creating plots for the measurands tplot = Ngl.contour_map(wks_comp,temperature[0,:,:],t_res) pplot = Ngl.contour(wks_comp,slp,p_res) vector = Ngl.vector(wks_comp,u,v,uv_res) Ngl.overlay(tplot, vector) Ngl.overlay(tplot, pplot) Ngl.maximize_plot(wks_comp, tplot) Ngl.draw(tplot) Ngl.frame(wks_comp) Ngl.delete_wks(wks_comp) # delete currently used workstation