def plot_map(wks, x, y, data, **kwargs): # Set up annoying plot resources res = ngl.Resources() res.cnFillOn = True res.cnLinesOn = False res.cnFillPalette = 'MPL_viridis' # Add cyclic point if we need to if len(data.shape) == 2 and x.max() < 360: data, x = ngl.add_cyclic(data, x) # If passed 2d coordinate arrays assume they represent cell vertices, # otherwise assume cell centers if len(x.shape) == 2: res.cnFillMode = 'CellFill' res.sfXCellBounds = x res.sfYCellBounds = y else: res.cnFillMode = 'RasterFill' res.sfXArray = x res.sfYArray = y # Tweak plot appearance res.mpGridAndLimbOn = False res.mpPerimOn = False # Additional options passed via kwargs for key, val in kwargs.items(): setattr(res, key, val) # Make the plot plot = ngl.contour_map(wks, data, res) return plot
def plot_time_series(time, data, **kwargs): # Setup a plot resources object res = ngl.Resources() # Set resource values by keyword for key, val in kwargs.items(): setattr(res, key, val) # Make plot pl = ngl.xy(wks, time, data, res) return pl
def plot_image_gdal( wks, band1, band2, band3, lat1=-90, lat2=90, lon1=0, lon2=360, **kwargs): # Clip if over maximum band1[band1>255] = 255 band2[band2>255] = 255 band3[band3>255] = 255 # Construct RGBA colormaps ramp = np.linspace(0.,1.,255) reds = np.zeros((255,4)) greens = np.zeros((255,4)) blues = np.zeros((255,4)) reds[:,0] = ramp greens[:,1] = ramp blues[:,2] = ramp # Set alpha channel (a = 1: 100% opaque; a = 0: 100% transparent) reds[:,3] = 1.0 #0.8 greens[:,3] = 0.0 #0.44444 blues[:,3] = 0.0 #0.3077 # Generate coordinate variables since they do not exist in the data y = ngl.fspan(-90, 90, band1.shape[0]) x = ngl.fspan(0, 360, band1.shape[1]) # Set up plot resources mapres = ngl.Resources() mapres.nglDraw = True mapres.nglFrame = False mapres.cnFillOn = True mapres.cnLinesOn = False mapres.cnLineLabelsOn = False mapres.cnInfoLabelOn = False mapres.cnFillMode = 'RasterFill' mapres.cnLevelSelectionMode = "ExplicitLevels" mapres.cnLevels = np.arange(0,254,1) mapres.cnFillBackgroundColor = [1., 1., 1., 1.] #set it to black mapres.cnLinesOn = False mapres.cnLineLabelsOn = False mapres.lbLabelBarOn = False mapres.sfXArray = x mapres.sfYArray = y # NOTE: pyngl will complain about these for the non-map plots, # but I want everything set ahead of time so that I can override # with kwargs passed into this function mapres.mpFillOn = False mapres.mpGridAndLimbOn = False mapres.mpProjection = "Orthographic" mapres.mpLimitMode = "LatLon" mapres.mpMinLatF = lat1 mapres.mpMaxLatF = lat2 mapres.mpMinLonF = lon1 mapres.mpMaxLonF = lon2 # Set additional plot resource passed via kwargs for key, value in kwargs.items(): setattr(mapres, key, value) # The green and blue maps will be overlaid on top of the red map, # The red map serves as the base upon which the others are overlaid, # so we can make this one an actual map. NOTE: I am manually overlaying # these plots, because I want them all to use the same plot resources. mapres.cnFillColors = reds redMap = ngl.contour_map(wks,band1,mapres) mapres.cnFillColors = greens greenMap = ngl.contour_map(wks,band2,mapres) mapres.cnFillColors = blues blueMap = ngl.contour_map(wks,band3,mapres) # Return plot objects return redMap, greenMap, blueMap
def increase_workspace_memory(value=10000000000): ws_id = ngl.get_workspace_id() rlist = ngl.Resources() rlist.wsMaximumSize = value ngl.set_values(ws_id,rlist)