cfres.cnLinesOn = False #-- don't draw contour lines cfres.cnLineLabelsOn = False #-- turn off contour line labels cfres.lbOrientation = "horizontal" cfres.mpGridAndLimbOn = False # Turn off grid and limb lines. pmres.gsMarkerSizeF = 0.0015 pmres.gsMarkerThicknessF = 0.1 pmres.gsMarkerOpacityF = 1 txres = Ngl.Resources() txres.txJust = "BottomCenter" txres.txFontHeightF = 0.025 title = 'Time of emergegence of FWI>p95 frequency~C~1-sigma above all forcing '+str(pyear0[base_pp])+'-'+str(pyear1[base_pp]) diff_cyc, lon_cyc = Ngl.add_cyclic(toe_diff_median_masked,lon) cfres.sfXArray = lon_cyc cfres.tiMainString = sf_list[ss] plot = Ngl.contour_map(wks,diff_cyc,cfres) pmres.gsMarkerColor = colors[np.int(ncolors/4),:] pmres.gsMarkerIndex = 1 marker_all = Ngl.add_polymarker(wks,plot,lon_1d_all,lat_1d_all,pmres) pmres.gsMarkerColor = colors[np.int(ncolors/4)*3,:] pmres.gsMarkerIndex = 1 marker_sf = Ngl.add_polymarker(wks,plot,lon_1d_sf,lat_1d_sf,pmres) Ngl.draw(plot) Ngl.text_ndc(wks,title,0.5,0.87,txres) Ngl.frame(wks)
# Main code #---------------------------------------------------------------------- # Open file and get variable. The lat/lon variables will be # generated using fspan. This data came from another dataset # that had lat/lon on the file, but lat/lon was nothing more # than equally-spaced values which we can regenerate exactly. # f = Nio.open_file(os.path.join(Ngl.pynglpath("data"), "cdf", "hgt.nc"), "r") hgt = f.variables["HGT"][:, :, :] lat = Ngl.fspan(-90, 90, 73) lon = Ngl.fspan(0, 357.5, 144) # Add a cyclic point in the longitude dimension. hgt0, lon = Ngl.add_cyclic(hgt[0, :, :], lon) # # Start graphics. # wks_type = "png" wks = Ngl.open_wks(wks_type, "spaghetti") Ngl.define_colormap(wks, "default") # Change color map. mpres = Ngl.Resources() mpres.nglDraw = False # Do not draw until the end. mpres.nglFrame = False # Do not automatically advance frame. # # Set contour resources first, because we'll make a copy of them
ffile)) print("You can get the files from the NCL website at:") print("http://www.ncl.ucar.edu/Document/Manuals/NCL_User_Guide/Data/") sys.exit() minval = 250. #-- minimum contour level maxval = 315 #-- maximum contour level inc = 5. #-- contour level spacing #-- open file and read variables f = Nio.open_file(ffile, "r") #-- open data file temp = f.variables["tsurf"][0, :, :] #-- first time step lat = f.variables["lat"][:] #-- all latitudes lon = f.variables["lon"][:] #-- all longitudes tempac, lon = Ngl.add_cyclic(temp, lon) #-- open a workstation wkres = Ngl.Resources() #-- generate an res object wks_type = "png" #-- output type wks_name = os.path.basename(__file__).split(".")[0] wks = Ngl.open_wks(wks_type, wks_name, wkres) #-- set resources res = Ngl.Resources() #-- generate an resource object for plot if hasattr(f.variables["tsurf"], "long_name") and hasattr( f.variables["tsurf"], "units"): res.tiMainString = "{} ({})".format( f.variables["tsurf"].long_name, f.variables["tsurf"].units) #-- set main title
# # Add a text string explaining the lines. # text_res = Ngl.Resources() # text resources text_res.txFontHeightF = 0.03 # font height text_res.txFontColor = "Red" Ngl.text_ndc(wks,"dashed red line shows area with no data",0.5,0.17,text_res) Ngl.frame(wks) # Now advance frame. # # Add cyclic points. Since lat2d/lon2d are 2D arrays, make them # cyclic the same way you do the 2D data array. # u = Ngl.add_cyclic(urot) v = Ngl.add_cyclic(vrot) lon = Ngl.add_cyclic(lon2d) lat = Ngl.add_cyclic(lat2d) # # Specify new coordinate arrays for data. # resources.vfXArray = lon resources.vfYArray = lat resources.tiMainString = "Streamline plot with cyclic point added" plot = Ngl.streamline_map(wks,u,v,resources) #
pres.nglPanelLabelBar = True #False pres.nglPanelTop = 0.88 res.cnMinLevelValF = 1996 #-- contour min. value res.cnMaxLevelValF = 2080 #-- contour max. value res.cnLevelSpacingF = 4 #-- contour interval colors00 = Ngl.read_colormap_file("MPL_YlOrRd") ncolors00= colors00.shape[0] colors0 = colors00[np.linspace(2,ncolors00-1,int((res.cnMaxLevelValF-res.cnMinLevelValF)/res.cnLevelSpacingF),dtype=int),:] grey_color = np.expand_dims(np.array([0.85, 0.85, 0.85, 1]), axis=0) colors = np.append(grey_color,colors0[::-1,:],axis=0) res.cnFillPalette = colors #BlWhRe' #'MPL_YlOrRd' #-- choose color map plot = [] title = 'Time of Emergence ~C~1 standard deviation ~C~ FWI > p95 Frequency' toe_cyc, lon_cyc = Ngl.add_cyclic(toe_all_ens_agree_masked,lon) res.sfXArray = lon_cyc res.tiMainString = 'all forcing' p = Ngl.contour_map(wks,toe_cyc,res) plot.append(p) Ngl.panel(wks,plot,[1,1],pres) Ngl.text_ndc(wks,title,0.5,0.85,txres) Ngl.frame(wks) Ngl.delete_wks(wks)
print("You do not have the necessary file (%s) to run this example." % (diri+fname)) print("You can get the files from the NCL website at:") print("http://www.ncl.ucar.edu/Document/Manuals/NCL_User_Guide/Data/") sys.exit() minval = 250. #-- minimum contour level maxval = 315 #-- maximum contour level inc = 5. #-- contour level spacing #-- open file and read variables f = Nio.open_file(diri + fname,"r") #-- open data file temp = f.variables["tsurf"][0,:,:] #-- first time step lat = f.variables["lat"][:] #-- all latitudes lon = f.variables["lon"][:] #-- all longitudes tempac,lon = Ngl.add_cyclic(temp,lon) #-- open a workstation wks_type = "png" #-- graphics output type wkres = Ngl.Resources() #-- generate an res object #-- for workstation wkres.wkWidth = 2500 #-- plot res 2500 pixel width wkres.wkHeight = 2500 #-- plot resolution 2500 wks = Ngl.open_wks(wks_type,"plot_contour_ngl",wkres) #-- open workstation #-- set resources res = Ngl.Resources() #-- generate an resource object for plot if hasattr(f.variables["tsurf"],"long_name"): res.tiMainString = f.variables["tsurf"].long_name #-- set main title
filea = "ice5g_21k_1deg.nc" fileb = "sstanom.robinsonproj.nc" a = Nio.open_file(os.path.join(dirc,"cdf",filea)) b = Nio.open_file(os.path.join(dirc,"cdf",fileb)) topo = a.variables["Topo"][:,:] Lat = a.variables["Lat"][:] Lon = a.variables["Lon"][:] icem = a.variables["Icemask"][:,:] # Keep topo where icem.eq.1 topo = numpy.ma.where(icem == 1, topo,1e20) # Add longitude cyclic point topo,Lon = Ngl.add_cyclic(topo,Lon) sst = b.variables["SST"][:,:] lat = b.variables["lat"][:] lon = b.variables["lon"][:] sst,lon = Ngl.add_cyclic(sst,lon) # # Start the graphics # wks_type = "ps" wks = Ngl.open_wks(wks_type,"multi_plot") Ngl.merge_colormaps(wks,"BlWhRe","default") #==========================================================================
if (not os.path.exists(diri + fname)): print("You do not have the necessary file (%s) to run this example." % (diri + fname)) print("You can get the files from the NCL website at:") print("http://www.ncl.ucar.edu/Document/Manuals/NCL_User_Guide/Data/") sys.exit() #-- open file and read variables f = Nio.open_file(diri + fname, "r") #-- open data file t = f.variables["t"] #-- get whole "t" variable t26 = t[0, :, 26, :] #-- variable at lat index 26 lev = f.variables["lev"][:] * 0.01 #-- all levels, convert to hPa lat = f.variables["lat"][:] #-- reverse latitudes lon = f.variables["lon"][:] #-- all longitudes t26, lon = Ngl.add_cyclic(t26, lon) strlat26 = lat[26] #-- retrieve data of lat index 26 #-- get the minimum and maximum of the data minval = int(np.amin(t[:])) #-- minimum value maxval = int(np.amax(t[:])) #-- maximum value inc = 5 #-- contour level spacing #-- values on which to place tickmarks on X and Y axis lons = np.arange(-180, 240, 60) levs = [1000, 700, 500, 400, 300, 200, 150, 100, 70, 50, 30, 10] wks = Ngl.open_wks("png", "plot_rectilinear_slice_ngl") #-- open workstation #-- set resources
#-- define variables diri = "$HOME/NCL/general/data/new_data/" #-- data directory fname = "rectilinear_grid_2D.nc" #-- data file name minval = 250. #-- minimum contour level maxval = 315 #-- maximum contour level inc = 5. #-- contour level spacing ncn = (maxval - minval) / inc + 1 #-- number of contour levels. #-- open file and read variables f = Nio.open_file(diri + fname, "r") #-- open data file temp = f.variables["tsurf"][0, ::-1, :] #-- first time step, reverse latitude lat = f.variables["lat"][::-1] #-- reverse latitudes lon = f.variables["lon"][:] #-- all longitudes tempac = Ngl.add_cyclic(temp[:, :]) #-- open a workstation wkres = Ngl.Resources() #-- generate an res object for workstation wkres.wkColorMap = "rainbow" #-- choose colormap wks_type = "x11" #-- graphics output type wks = Ngl.open_wks(wks_type, "plot_contour_PyNGL", wkres) #-- open workstation #-- set resources res = Ngl.Resources() #-- generate an resource object for plot if hasattr(f.variables["tsurf"], "long_name"): res.tiMainString = f.variables["tsurf"].long_name #-- set main title res.vpXF = 0.1 #-- start x-position of viewport res.vpYF = 0.9 #-- start y-position of viewport
colors00 = Ngl.read_colormap_file("MPL_RdBu") ncolors00 = colors00.shape[0] colors0 = colors00[np.linspace(2, ncolors00 - 1, int((res.cnMaxLevelValF - res.cnMinLevelValF) / res.cnLevelSpacingF), dtype=int), :] grey_color = np.expand_dims(np.array([0.85, 0.85, 0.85, 1]), axis=0) colors = np.append(grey_color, colors0[::-1, :], axis=0) res.cnFillPalette = colors #'BlWhRe' #'MPL_YlOrRd' #-- choose color map plot = [] title = 'CESM all forcing vs all forcing without ' + sf + ' effect ~C~FWI >= p' + str( pxx) + ' risk ratio' for pp in range(5, nperiods, 1): for vv in range(0, n_vars, 1): print('period ' + str(pp + 1)) # res.tiMainString = var[vv]+' '+str(pyear0[pp])+'-'+str(pyear1[pp]) res.tiMainString = '' riskratio_cyc, lon_cyc = Ngl.add_cyclic( riskratio_ens_agree_masked[vv, pp, :, :], lon) res.sfXArray = lon_cyc p = Ngl.contour_map(wks, riskratio_cyc, res) plot.append(p) Ngl.panel(wks, plot, [n_vars, 1], pres) #Ngl.text_ndc(wks,title,0.5,0.92,txres) Ngl.frame(wks) Ngl.delete_wks(wks)
def ngl_plot(wks,data2d,lon,lat,title,longname,units, projection,clev,cmap,scrip_file): cellbounds=False if os.path.isfile(scrip_file): infile = Nio.open_file(scrip_file,"r") clat = infile.variables["grid_corner_lat"][:,:] clon = infile.variables["grid_corner_lon"][:,:] if clon.shape[0] == len(lat): cellbounds=True res = Ngl.Resources() if cmap!=None: res.cnFillPalette = cmap if len(clev)==1: res.cnLevelSelectionMode = "AutomaticLevels" res.cnMaxLevelCount = clev[0] else: res.cnLevelSelectionMode = "ManualLevels" res.cnMinLevelValF=clev[0] res.cnMaxLevelValF=clev[1] res.cnLevelSpacingF=clev[2] # defaults. some projection options might change: res.cnFillOn = True # Turn on contour fill. res.cnLinesOn = False # Turn off contour lines res.cnLineLabelsOn = False # Turn off line labels. res.cnInfoLabelOn = False # Turn off info label. res.mpOutlineOn = True res.mpFillOn = False res.mpGridAndLimbOn = False # dont draw grid lines #res.mpShapeMode = "FreeAspect" if projection == "latlon" : res.mpProjection = "CylindricalEquidistant" res.mpLimitMode = "MaximalArea" # res.mpMinLatF = -90. # res.mpMaxLatF = 90. # res.mpMinLonF = -180. # res.mpMaxLonF = 180. elif projection == "US1": res.mpProjection = "CylindricalEquidistant" res.mpLimitMode = "LatLon" res.mpMinLatF = -30 res.mpMaxLatF = 75 res.mpMinLonF = -180 res.mpMaxLonF = 0 elif projection == "andes": res.mpProjection = "CylindricalEquidistant" res.mpLimitMode = "LatLon" res.mpMinLatF = -40. res.mpMaxLatF = 15. res.mpMinLonF = -100. res.mpMaxLonF = -40. elif projection == "andes2": res.mpProjection = "CylindricalEquidistant" res.mpLimitMode = "LatLon" res.mpMinLatF = -17. res.mpMaxLatF = 3. res.mpMinLonF = -85. res.mpMaxLonF = -65. elif projection == "himalaya": res.mpProjection = "CylindricalEquidistant" res.mpLimitMode = "LatLon" res.mpMinLatF = 0. res.mpMaxLatF = 60. res.mpMinLonF = 50. res.mpMaxLonF = 110. elif projection == "oro": res.mpProjection = "Orthographic" res.mpCenterLatF = 45. res.mpCenterLonF = -45. elif projection == "oro-debug1": res.mpProjection = "Orthographic" res.mpLimitMode="Angles" hdeg=10 res.mpLeftAngleF=hdeg res.mpRightAngleF=hdeg res.mpBottomAngleF=hdeg res.mpTopAngleF=hdeg elif projection == "debug1": res.mpProjection = "CylindricalEquidistant" res.mpLimitMode = "LatLon" res.mpMinLatF = 30. res.mpMaxLatF = 50. res.mpMinLonF = 85. res.mpMaxLonF = 105. elif projection == "debug2": res.mpProjection = "CylindricalEquidistant" res.mpLimitMode = "LatLon" res.mpMinLatF = -10. res.mpMaxLatF = 75. res.mpMinLonF = 45. res.mpMaxLonF = 175. elif projection == "baroclinic": res.mpProjection = "CylindricalEquidistant" res.mpLimitMode = "LatLon" res.mpCenterLonF = 100. res.mpMinLatF = 25. res.mpMaxLatF = 75. res.mpMinLonF = 25. res.mpMaxLonF = 175. res.cnLinesOn = True # Turn off contour lines res.mpOutlineOn = False else: print("Bad projection argument: ",projection) sys.exit(3) res.nglFrame = False # Don't advance frame. #res.tiXAxisString = "~F25~longitude" #res.tiYAxisString = "~F25~latitude" res.nglPointTickmarksOutward = True if cellbounds: res.cnFillMode = 'CellFill' res.sfXCellBounds = clon res.sfYCellBounds = clat else: #res.cnFillMode = "AreaFill" res.cnFillMode = "RasterFill" res.cnRasterSmoothingOn = True res.sfXArray = lon[:] res.sfYArray = lat[:] #res.sfCopyData = False # "not a valid resource in contour at this time... # if wks_type == "pdf": # res.gsnMaximize = True # res.gsnPaperOrientation = "portrait" res.lbLabelAutoStride = True # Clean up labelbar labels. #res.lbAutoManage = True #res.lbLabelStride = 10 res.lbBoxLinesOn = False # Turn of labelbar box lines. res.lbOrientation = "horizontal" res.tiMainString = title print("Title: ",res.tiMainString) print("data min/max=",numpy.amin(data2d),numpy.amax(data2d)) if res.cnLevelSelectionMode == "ManualLevels": nlevels=(res.cnMaxLevelValF-res.cnMinLevelValF)/res.cnLevelSpacingF print("contour levels: manual [",res.cnMinLevelValF,",",\ res.cnMaxLevelValF,"] spacing=",res.cnLevelSpacingF) print("number of contour levels:",nlevels) else: print("contour levels: auto. number of levels:",res.cnMaxLevelCount) nlevels=res.cnMaxLevelCount if nlevels>20: res.lbLabelStride = nlevels/8 # for lat/lon plots, add cyclic point: res2=res if hasattr(res,"sfXArray"): if len(res.sfXArray)*len(res.sfYArray) == numpy.prod(data2d.shape): print("NGL structured data plot. Adding cyclic point") data2d,lon2= Ngl.add_cyclic(data2d[:,:],res.sfXArray[:]) res2.sfXArray=lon2 else: print("NGL unstructered plot with internal triangulation") elif hasattr(res,"sfXCellBounds"): print("NGL unstructered plot with cell bounds") else: print("Error with resource coordinate data") # plot: map = Ngl.contour_map(wks,data2d,res2) print("Contour done.") del res2 #-- write variable long_name and units to the plot txres = Ngl.Resources() txres.txFontHeightF = 0.016 Ngl.text_ndc(wks,longname,0.14,0.82,txres) Ngl.text_ndc(wks,units, 0.95,0.82,txres) del txres Ngl.frame(wks) # advance frame return map
# # Send graphics to PNG # wks_type = "png" wks = Ngl.open_wks(wks_type, "vector_pop") # # Get the u/v and lat/lon variables. # urot = file.variables["urot"] vrot = file.variables["vrot"] lat2d = file.variables["lat2d"] lon2d = file.variables["lon2d"] t = file.variables["t"] u = Ngl.add_cyclic(urot[290:]) v = Ngl.add_cyclic(vrot[290:]) lon = Ngl.add_cyclic(lon2d[290:]) lat = Ngl.add_cyclic(lat2d[290:]) temp = Ngl.add_cyclic(t[290:]) # # Set up resource list. # # First we're going to draw a contour plot with the grid cells outlined # so you can see what the POP grid looks like. # cnres = Ngl.Resources() cnres.nglFrame = False #
# wks_type = "png" wks = Ngl.open_wks(wks_type,"ngl11p") dirc = Ngl.pynglpath("data") data = Ngl.asciiread(os.path.join(dirc, "asc", "u.cocos"), (39,14), "float") pressure = data[:,0] # First column of data is pressure (mb). height = data[:,1] # Second column is height (km). u = data[:,2:14] # Rest of columns are climatological zonal winds # (u: m/s) unew = Ngl.add_cyclic(u) # Add cyclic points to u. #----------- Begin first plot ----------------------------------------- resources = Ngl.Resources() resources.tiMainString = "~F26~Cocos Island" # Main title. resources.tiYAxisString = "~F25~Pressure (mb)" # Y axes label. resources.sfYCStartV = float(max(pressure)) # Indicate start and end of left resources.sfYCEndV = float(min(pressure)) # Y axes values. resources.trYReverse = True # Reverse the Y values. resources.trYLog = True # Use log scale. resources.tmXBMode = "Explicit" # Define your own tick mark labels.
FileMA['QFLX'] / rhow) # convert from m/s to mm/day varN = 1000.0 * 60.0 * 60.0 * 24.0 * np.squeeze( FileNA['QFLX'] / rhow) elif var in ["SHFLX"]: a1, a2, adiff = -30, 30.0, 6.0 b1, b2, bdiff = -10.0, 10.0, 2.0 varM = np.squeeze(FileMA[var]) # convert from m/s to mm/day varN = np.squeeze(FileNA[var]) lons = FileMA['lon'].values lats = FileMA['lat'].values varM = np.where(np.isnan(varM), -9999, varM) varN = np.where(np.isnan(varN), -9999, varN) varM, lons = Ngl.add_cyclic(varM, lons) varN = Ngl.add_cyclic(varN) elif var in ["PRECTZM"]: varM = 1000.0 * 60.0 * 60.0 * 24.0 * np.squeeze( FileMA['PRECT'].mean(dim='lon')) # convert from m/s to mm/day varN = 1000.0 * 60.0 * 60.0 * 24.0 * np.squeeze( FileNA['PRECT'].mean(dim='lon')) lats = FileMA['lat'].values elif var == "FSNSC": a1, a2, adiff = 50, 400, 35 b1, b2, bdiff = 0.0, 10.0, 5.0 varM = np.squeeze(FileMA['FSNSC']) landfrac = np.squeeze(FileMA['LANDFRAC'])
import Nio import numpy import os dirc=Ngl.pynglpath("data") file=Nio.open_file(os.path.join(dirc,"cdf","pop.nc")) wks_type="png" wks=Ngl.open_wks(wks_type,"map2") urot=file.variables["urot"] t=file.variables["t"] lat2d=file.variables["lat2d"] lon2d=file.variables["lon2d"] u=Ngl.add_cyclic(urot[:]) temp=Ngl.add_cyclic(t[0:]) lon=Ngl.add_cyclic(lon2d[0:]) lat=Ngl.add_cyclic(lat2d[0:]) resource=Ngl.Resources() resource.vfXArray=lon resource.vfYArray=lat resource.mpProjection="Stereographic" resource.mpFillOn=True resource.mpInlandWaterFillColor="SkyBlue" resource.mpProjection = "Stereographic" resource.mpEllipticalBoundary = True
filea = "ice5g_21k_1deg.nc" fileb = "sstanom.robinsonproj.nc" a = Nio.open_file(os.path.join(dirc, "cdf", filea)) b = Nio.open_file(os.path.join(dirc, "cdf", fileb)) topo = a.variables["Topo"][:, :] Lat = a.variables["Lat"][:] Lon = a.variables["Lon"][:] icem = a.variables["Icemask"][:, :] # Keep topo where icem.eq.1 topo = numpy.ma.where(icem == 1, topo, 1e20) # Add longitude cyclic point topo, Lon = Ngl.add_cyclic(topo, Lon) sst = b.variables["SST"][:, :] lat = b.variables["lat"][:] lon = b.variables["lon"][:] sst, lon = Ngl.add_cyclic(sst, lon) # # Start the graphics # wks_type = "png" wks = Ngl.open_wks(wks_type, "multi_plot") Ngl.merge_colormaps(wks, "BlWhRe", "default") #========================================================================== print("Beginning bar chart section")
#---Test if file exists if(not os.path.exists(diri+fname)): print("You do not have the necessary file (%s) to run this example." % (diri+fname)) print("You can get the files from the NCL website at:") print("http://www.ncl.ucar.edu/Document/Manuals/NCL_User_Guide/Data/") sys.exit() #-- open file and read variables f = Nio.open_file(diri + fname,"r") #-- open data file t = f.variables["t"] #-- get whole "t" variable t26 = t[0,:,26,:] #-- variable at lat index 26 lev = f.variables["lev"][:]*0.01 #-- all levels, convert to hPa lat = f.variables["lat"][:] #-- reverse latitudes lon = f.variables["lon"][:] #-- all longitudes t26,lon = Ngl.add_cyclic(t26,lon) strlat26 = lat[26] #-- retrieve data of lat index 26 #-- get the minimum and maximum of the data minval = int(np.amin(t[:])) #-- minimum value maxval = int(np.amax(t[:])) #-- maximum value inc = 5 #-- contour level spacing #-- values on which to place tickmarks on X and Y axis lons = np.arange(-180,240,60) levs = [1000,700,500,400,300,200,150,100,70,50,30,10] wks = Ngl.open_wks("png","plot_rectilinear_slice_ngl") #-- open workstation #-- set resources
res = Ngl.Resources() res.lbLabelBarOn = False # Filled contour/labels/labelinfos res.cnLinesOn = False res.cnFillOn = True res.cnLineLabelsOn = False res.cnInfoLabelOn = False res.mpGridAndLimbOn = False #anotherway to define colormap (overlay the predefined color map) # cmap = Ngl.read_colormap_file("WhiteBlueGreenYellowRed") #Level selection # res.lbBoxLinesOn = False res.cnLevelSelectionMode = "ExplicitLevels" # Set explicit contour levels res.cnLevels = np.arange(1e-5, 8.e-4, 4e-5) # 0,5,10,...,70 # maximize the plot res.nglMaximize = True res.nglFrame = False # coordinate settings NewTracerPlot, LonPlot = Ngl.add_cyclic(NewTracer_AI_Low[it, lev, :, :], lon_low) res.sfXArray = LonPlot res.sfYArray = lat_low[:] res.vpWidthF = 1 res.vpHeightF = 0.5 Ngl.contour_map(wks, NewTracerPlot, res) Ngl.frame(wks) # Ngl.Draw(wks) Ngl.destroy(wks) Ngl.end()
cmap = numpy.zeros((2,3),'f') cmap[0] = [1.,1.,1.] cmap[1] = [0.,0.,0.] rlist = Ngl.Resources() rlist.wkColorMap = cmap wks_type = "ps" wks = Ngl.open_wks(wks_type,"ngl11p",rlist) dirc = Ngl.pynglpath("data") data = Ngl.asciiread(dirc+"/asc/u.cocos",(39,14),"float") pressure = data[:,0] # First column of data is pressure (mb). height = data[:,1] # Second column is height (km). u = data[:,2:14] # Rest of columns are climatological zonal winds # (u: m/s) unew = Ngl.add_cyclic(u) # Add cyclic points to u. #----------- Begin first plot ----------------------------------------- resources = Ngl.Resources() resources.tiMainString = "~F26~Cocos Island" # Main title. resources.tiYAxisString = "~F25~Pressure (mb)" # Y axes label. resources.sfYCStartV = float(max(pressure)) # Indicate start and end of left resources.sfYCEndV = float(min(pressure)) # Y axes values. resources.trYReverse = True # Reverse the Y values. resources.trYLog = True # Use log scale. resources.tmXBMode = "Explicit" # Define your own tick mark labels.
maxval[k] = int(np.amax(temp[k])) i = i + 1 wks_type = "png" wks = Ngl.open_wks(wks_type, "U_winter") res = set_common_resources() # set resource for the base plot bres = set_common_resources() bres.mpFillOn = False bres.tiMainFontHeightF = 0.018 bres.cnFillOpacityF = 0.5 # for 850 hPa in spring U_850, lonnew = Ngl.add_cyclic(temp["winter"][0, 0, 2, :, :], lons[:]) bres.tiMainString = "DJF Mean U Wind (m/s) at 850 hPa from 1979 to 2009" bres.sfXArray = lonnew[:] bres.sfYArray = lats[:] bres.cnMinLevelValF = minval["winter"] bres.cnMaxLevelValF = maxval["winter"] bres.cnLevelSpacingF = 3 plot1 = Ngl.contour_map(wks, U_850, bres) #for 500 hPa U_500, lonnew = Ngl.add_cyclic(temp["winter"][0, 0, 5, :, :], lons[:]) bres.tiMainString = "DJF Mean U Wind (m/s) at 500 hPa from 1979 to 2009" bres.cnLevelSpacingF = 3 plot2 = Ngl.contour_map(wks, U_500, bres)
[0.50,0.00,1.00], [1.00,0.50,0.00], [0.00,0.50,1.00], \ [0.50,1.00,0.00], [0.50,0.00,0.50], [0.50,1.00,0.50], \ [1.00,0.50,1.00], [0.00,0.50,0.00], [0.50,0.50,1.00], \ [1.00,0.00,0.50], [0.50,0.50,0.00], [0.00,0.50,0.50], \ [1.00,0.50,0.50], [0.00,1.00,0.50], [0.50,0.50,0.50], \ [0.625,0.625,0.625] ],dtype=float) rlist = Ngl.Resources() rlist.wkColorMap = cmap wks_type = "ps" wks = Ngl.open_wks(wks_type,"ngl09p",rlist) # Open a workstation. resources = Ngl.Resources() resources.sfMissingValueV = fill_value icemonnew,hlonnew = Ngl.add_cyclic(icemon[0:nsub+1,:],hlon[:]) resources.sfXArray = hlonnew # Necessary for overlay on a map. resources.sfYArray = hlat[0:nsub+1] resources.nglSpreadColors = False # Do not interpolate color space. resources.tiMainString = "CSM Y00-99 Mean Ice Fraction Month =" + str(month) resources.pmTickMarkDisplayMode = "Never" map = Ngl.contour_map(wks,icemonnew,resources) # Draw a contour # over a map. nmos = 12 # Specify the number of months in the loop (max 120). for nmo in range(1,nmos): month = nmo+1 for i in xrange(fice_masked.shape[0]):
#-- define variables diri = "$HOME/NCL/general/data/new_data/" #-- data directory fname = "rectilinear_grid_2D.nc" #-- data file name minval = 250. #-- minimum contour level maxval = 315 #-- maximum contour level inc = 5. #-- contour level spacing ncn = (maxval-minval)/inc + 1 #-- number of contour levels. #-- open file and read variables f = Nio.open_file(diri + fname,"r") #-- open data file temp = f.variables["tsurf"][0,::-1,:] #-- first time step, reverse latitude lat = f.variables["lat"][::-1] #-- reverse latitudes lon = f.variables["lon"][:] #-- all longitudes tempac = Ngl.add_cyclic(temp[:,:]) #-- open a workstation wkres = Ngl.Resources() #-- generate an res object for workstation wkres.wkColorMap = "rainbow" #-- choose colormap wks_type = "x11" #-- graphics output type wks = Ngl.open_wks(wks_type,"plot_contour_PyNGL",wkres) #-- open workstation #-- set resources res = Ngl.Resources() #-- generate an resource object for plot if hasattr(f.variables["tsurf"],"long_name"): res.tiMainString = f.variables["tsurf"].long_name #-- set main title res.vpXF = 0.1 #-- start x-position of viewport res.vpYF = 0.9 #-- start y-position of viewport
# rlist = Ngl.Resources() rlist.wkColorMap = ["White","Black","Tan1","SkyBlue","Red"] wks_type = "ps" wks = Ngl.open_wks(wks_type,"vector_pop",rlist) # # Get the u/v and lat/lon variables. # urot = file.variables["urot"] vrot = file.variables["vrot"] lat2d = file.variables["lat2d"] lon2d = file.variables["lon2d"] t = file.variables["t"] u = Ngl.add_cyclic(urot[290:]) v = Ngl.add_cyclic(vrot[290:]) lon = Ngl.add_cyclic(lon2d[290:]) lat = Ngl.add_cyclic(lat2d[290:]) temp = Ngl.add_cyclic(t[290:]) # # Set up resource list. # # First we're going to draw a contour plot with the grid cells outlined # so you can see what the POP grid looks like. # cnres = Ngl.Resources() cnres.nglFrame = False #
nsub = 16 # Subscript location of northernmost hlat to be plotted. cmap = numpy.array([ \ [1.00,1.00,0.50], [0.00,0.00,0.50], [0.50,1.00,1.00], \ [0.50,0.00,0.00], [1.00,0.00,1.00], [0.00,1.00,1.00], \ [1.00,1.00,0.00], [0.00,0.00,1.00], [0.00,1.00,0.00], \ [1.00,0.00,0.00] ],dtype=float) wks_type = "png" wks = Ngl.open_wks(wks_type,"ngl09p") resources = Ngl.Resources() # Add a longitude cyclic point icemonnew,hlonnew = Ngl.add_cyclic(icemon[0:nsub+1,:],hlon[:]) resources.sfMissingValueV = fill_value resources.cnFillPalette = cmap resources.sfXArray = hlonnew # Necessary for overlay on a map. resources.sfYArray = hlat[0:nsub+1] resources.tiMainString = "CSM Y00-99 Mean Ice Fraction Month =" + str(month) resources.pmTickMarkDisplayMode = "Never" map = Ngl.contour_map(wks,icemonnew,resources) # Draw a contour # over a map. nmos = 12 # Specify the number of months in the loop (max 120). for nmo in range(1,nmos): month = nmo+1