Esempio n. 1
0
def gen_dummy_data():
  minlat =   24
  maxlat =   50
  minlon = -125
  maxlon =  -67

#---Size of dummy data. Use smaller values (16x32) for faster code speed
  nlat   =  64
  nlon   = 128

  data   = Ngl.generate_2d_array([nlat,nlon], 10, 19, 0., 100.)
  lat    = Ngl.fspan(minlat,maxlat,nlat)
  lon    = Ngl.fspan(minlon,maxlon,nlon)

  return data,lat,lon
Esempio n. 2
0
def add_highlights(wks,plot,xmin,xmax,ymin,ymax,title):
  nboxes = 10
  xbox   = Ngl.fspan(xmin,xmax,nboxes)
  ybox   = [ymin,ymin,ymax,ymax,ymin]
  nboxes = xbox.shape[0]-1

#---Resources for filled purple boxes.
  gnres                 = Ngl.Resources()
  gnres.gsFillColor     = "goldenrod" # "MediumPurple1"
  gnres.gsFillOpacityF  = 0.15

  id = []
  for n in range(0,nboxes-1,2):
    id.append(Ngl.add_polygon(wks,plot,\
              [xbox[n],xbox[n+1],xbox[n+1],xbox[n],xbox[n]],\
              ybox,gnres))


#---Resources to outline box of interest
  lnres                  = Ngl.Resources()
  lnres.gsLineThicknessF = 3.0
  border = Ngl.add_polyline(wks,plot,[xmin,xmax,xmax,xmin,xmin],\
                                      [ymin,ymin,ymax,ymax,ymin],lnres)

  txres                 = Ngl.Resources()
  txres.txFontHeightF   = 0.022
  txres.txFont          = "Helvetica-Bold"
  txres.txJust          = "TopCenter"
  text = Ngl.add_text(wks,plot,title,(xmin+xmax)/2.,ymax-0.05,txres)

  return([id,border,text])
Esempio n. 3
0
#
#  Notes:
#

from __future__ import print_function
import Ngl
import numpy

wks_type = "png"
wks = Ngl.open_wks(wks_type, "format")

#
# Create some dummy data for an XY plot. We are only doing this
# to create an object that has tickmarks.
#
x = Ngl.fspan(0, 1, 20)
y = x

#
# Set some resouces for a dummy XY plot.
#
res = Ngl.Resources()
res.nglMaximize = False
res.nglDraw = False
res.nglFrame = False

res.xyLineColor = -1  # Transparent line

#
# Resources for main title and Y axis title.
#
Esempio n. 4
0
#---Start the graphics
wks_type = "png"
wks = Ngl.open_wks(wks_type, "mpas2")

res = Ngl.Resources()  # Plot mods desired.

res.nglDraw = False  # Turn off plot draw and frame advance. We will
res.nglFrame = False  # do it later after adding subtitles.

res.cnFillOn = True  # color plot desired
res.cnFillPalette = "ncl_default"
res.cnLinesOn = False  # turn off contour lines
res.cnLineLabelsOn = False  # turn off contour labels

res.cnLevelSelectionMode = "ExplicitLevels"
res.cnLevels = Ngl.fspan(min(t2m), max(t2m),
                         253)  # 253 levels (hence 254 colors)

res.lbOrientation = "Horizontal"  # vertical by default
res.lbBoxLinesOn = False  # turn off labelbar boxes
res.lbLabelFontHeightF = 0.01

res.mpFillOn = False
res.mpGridAndLimbOn = False

res.sfXArray = lonCell  # where to overlay contours
res.sfYArray = latCell

#
# It may be necessary to use RasterFill or CellFill for large grids.
#
# The default "AreaFill" can be too slow and/or will run out of
Esempio n. 5
0
#
# Leave these both alone, regardless of what module you are testing.
#
import numpy

from utils import *

#
# Begin linmsg tests.
#

#
# Correct value for first set of tests.
#
npts = 101
x = Ngl.fspan(0., npts - 1, 101)
y = Ngl.fspan(0., npts - 1, 101)
xorig = Ngl.fspan(0., npts - 1, 101)

xnew = Ngl.linmsg(x)
test_values("linmsg (float)", xnew, xorig)
check_type(xnew, default_type)
del xnew

xnew = Ngl.linmsg(x, 0)
test_values("linmsg (float,int)", xnew, xorig)
check_type(xnew, default_type)
del xnew

xnew = Ngl.linmsg(x, 0, 0)
test_values("linmsg (float,int,int)", xnew, xorig)
Esempio n. 6
0
skewtOpts.sktWindDirectionMissingV = -999.  # Missing value for
# wind direction.
skewtOpts.sktColoredBandsOn = True  # Default is False
skewtOpts.tiMainString = "Raob Data; No Winds"

skewt_bkgd = Ngl.skewt_bkg(wks, skewtOpts)
skewt_data = Ngl.skewt_plt(wks, skewt_bkgd, p, tc, tdc, z,  \
                                wspd, wdir, skewtOpts)
Ngl.draw(skewt_bkgd)
Ngl.draw(skewt_data)
Ngl.frame(wks)

#
#  Plot 2 - Create background skew-T and plot sounding and winds.
#
wspd = Ngl.fspan(0., 150., nlvl)  # wind speed at each level.
wdir = Ngl.fspan(0., 360., nlvl)  # wind direction.

#
#  Create a few artificial "pibal" reports.
#
hght = numpy.array([1500., 6000., 10000., 15000.], 'f')  # Meters
hspd = numpy.array([50., 27., 123., 13.], 'f')
hdir = numpy.array([315., 225., 45., 135.], 'f')

dataOpts = Ngl.Resources()  # Options describing
# data and plotting.
dataOpts.sktHeightWindBarbsOn = True  # Plot wind barbs at
# height levels.
dataOpts.sktPressureWindBarbComponents = "SpeedDirection"  # Wind speed and
# dir [else: u,v].
Esempio n. 7
0
#---Create dummy data for additional curve.
npts2 = 40
y2 = numpy.zeros([npts2], 'f')
for i in range(npts2):
    y2[i] = 3.0 - 6. * random.random()

#---Force some of the y2 points be missing
y2 = ma.array(y2,mask=[0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,\
                       1,1,0,0,0,0,1,1,1,0,1,0,0,0,1,0,0,1,1,1])

#---Set some resources for the polyline
gsres = Ngl.Resources()
gsres.gsLineColor = "Blue"
gsres.gsLineThicknessF = 3.

#---Add the line to existing plot
x = Ngl.fspan(min(years), max(years), npts2)
prim1 = Ngl.add_polyline(wks, plot, x, y2, gsres)

#---Change the main title of original plot.
srlist = Ngl.Resources()
srlist.tiMainString = "Adding a blue curve with missing values"
Ngl.set_values(plot, srlist)

#---Draw plot (and its attached line)
Ngl.draw(plot)
Ngl.frame(wks)

Ngl.end()
Esempio n. 8
0
#
#  Output:
#     A single visualization with nine plots
#
from __future__ import print_function
import numpy, os
import Ngl, Nio

#---Start the graphics section
wks_type = "png"
wks = Ngl.open_wks(wks_type, "newcolor4")

#---Generate some dummy lat/lon data
nlat = 64
nlon = 128
lat = Ngl.fspan(-90, 90, nlat)
lon = Ngl.fspan(-178.5, 178.5, nlon)

#---Values to use for contour labelbar
dmins = [-20., -10., -21.]  # Data mins
dmaxs = [16., 10., 17.]  # Data maxs
dspas = [4., 1., 3.]  # Data spacing

# One color map per row of plots
colormaps = ["wgne15", "StepSeq25", "BlueDarkRed18"]

# Create resource list for customizing contour over maps
res = Ngl.Resources()

res.nglMaximize = False
res.nglFrame = False
Esempio n. 9
0
Ngl.wmsetp("col", 2)  # Draw in red.
Ngl.wmsetp("wbs", .035)  # Increase the size of the barb.

#
#  For illustration use numpy arrays for storing the wind
#  barb information for the wmbarbmap call (could more easily
#  make individual calls in a loop in the case here).
#
lat = numpy.zeros([3, 10], 'f')
lon = numpy.zeros([3, 10], 'f')
u = 0. * numpy.ones([3, 10], 'f')
v = 90. * numpy.ones([3, 10], 'f')
lat[0, :] = 65.
lat[1, :] = 70.
lat[2, :] = 75.
lonp = Ngl.fspan(-40., 5., 10)
lon[0, :] = lonp
lon[1, :] = lonp
lon[2, :] = lonp
Ngl.wmbarbmap(wks, lat, lon, u, v)

#############################
#                           #
#  Upper right quadrant.    #
#                           #
#############################
#
#  Plot some station model data for some cities in
#  Kansas and Oklahoma.
#
# Change location of map in frame. Size is the same as before.
Esempio n. 10
0
def draw_lines():
  mkres = Ngl.Resources()    # Marker resources
  lnres = Ngl.Resources()    # Line resources

  xline  = Ngl.fspan(0.15,0.85,80)
  yline1 = 0.025 * (numpy.cos(2.*PI*(Ngl.fspan(1,80,80)/20.))) + 0.9
  yline2 = 0.045 * (numpy.sin(2.*PI*(Ngl.fspan(1,80,80)/20.))) + 0.8
  yline3 = 0.045 * (numpy.sin(2.*PI*(Ngl.fspan(1,80,80)/10.))) + 0.7

# Draw 3 sets of lines.
  lnres.gsLineColor      = "forestgreen"      # Black is the default
  lnres.gsLineThicknessF = 4.0                # 1.0 is the default
  Ngl.polyline_ndc(wks,xline,yline1,lnres)

  lnres.gsLineColor       = "brown4"
  lnres.gsLineThicknessF  = 3.0
  lnres.gsLineDashPattern = 2     # Default is a solid line (0)
  Ngl.polyline_ndc(wks,xline,yline2,lnres)

  lnres.gsLineColor       = "NavyBlue"
  lnres.gsLineThicknessF  = 2.0
  lnres.gsLineDashPattern = 11
  Ngl.polyline_ndc(wks,xline,yline3,lnres)

# Draw markers at the end of each of the 3 lines.
  mkres.gsMarkerColor = "ForestGreen"
  mkres.gsMarkerIndex = 6
  mkres.gsMarkerSizeF = 0.02
  Ngl.polymarker_ndc(wks,[xline[0],xline[-1]],[yline1[0],yline1[-1]],mkres)

  mkres.gsMarkerColor = "brown4"
  mkres.gsMarkerIndex = 11
  Ngl.polymarker_ndc(wks,[xline[0],xline[-1]],[yline2[0],yline2[-1]],mkres)

  mkres.gsMarkerColor = "NavyBlue"
  mkres.gsMarkerIndex = 16
  mkres.gsMarkerSizeF = 0.01
  Ngl.polymarker_ndc(wks,[xline[0],xline[-1]],[yline3[0],yline3[-1]],mkres)

#
# Draw a vertical line with some missing values. Include markers
# so you can see where the missing values were.
#
  lnres.gsLineColor       = "blue4"
  lnres.gsLineThicknessF  = 1.5
  lnres.gsLineDashPattern = 0
  vxline = ma.array(yline2[25::3] - .65)
  vyline = ma.array( xline[25::3] - .30)
#
# Draw the markers for each point.
#
  mkres.gsMarkerColor      = "mediumorchid4"
  mkres.gsMarkerIndex      = 12     # Stars
  mkres.gsMarkerThicknessF = 2.0    # Default is 1.0
  Ngl.polymarker_ndc(wks,vxline,vyline,mkres)
#
# Make vxline a masked array and set some values to missing
# using the "mask" array.  Note that if there's a single point
# surrounded by missing values, it will become a marker when
# drawn with Ngl.polyline_ndc.
#
  vxline = ma.array(vxline,mask=[0,1,0,1,0,0,0,0,0,1,1,0,0,1,0,0,0,1,0])
  Ngl.polyline_ndc(wks,vxline,vyline,lnres)
#
# Draw a text string describing the above line.
#
  tres               = Ngl.Resources()
  tres.txAngleF      = -90.
  tres.txFontHeightF = 0.03
  tres.txJust        = "CenterCenter"
  Ngl.text_ndc(wks,"Line with msg vals",0.23,0.31,tres)

#
# Put a box around the missing value curve.
#
  bres                  = Ngl.Resources()
  bres.gsLineColor      = "lightsalmon4"
  bres.gsLineThicknessF = 3.0
  Ngl.polyline_ndc(wks,[.09,.28,.28,.09,.09],[.04,.04,.57,.57,.04],bres)
Esempio n. 11
0
cdf_file = Nio.open_file(os.path.join(dirc,"cdf","chi200_ud_smooth.nc"))
chi  = cdf_file.variables["CHI"]
chi  = chi[:,:]/1e6
lon  =  cdf_file.variables["lon"][:]
time =  cdf_file.variables["time"][:]
 
#
# Open a PS file.
#
wks_type = "ps"
wks = Ngl.open_wks(wks_type,"contour3")

#
# Create arrays of longitude/time values and their corresponding labels.
#
lon_values  = Ngl.fspan(0., 315., 8)
lon_labels  = ["0","45E","90E","135E","180","135W","90W","45W"]
time_values = [   0,    30,   61,   89,  120,  150,  181]
time_labels = ["DEC","JAN","FEB","MAR","APR","MAY","JUN"]

cnres = Ngl.Resources()

cnres.nglDraw                  = False    # Turn off draw and frame.
cnres.nglFrame                 = False    # We will do this later.

cnres.sfXArray                 = lon
cnres.sfYArray                 = time

cnres.tmXBMode                 = "Explicit"    # Label X and Y axes
cnres.tmYLMode                 = "Explicit"    # with explicit labels.
cnres.tmXBValues               = lon_values
Esempio n. 12
0
#    o  Drawing lines and polygons in NDC space.
#    o  Conversions between the three color spaces: RGB, HSV, YIQ.
#
#  Output:
#    o Three color wheels are drawn using three different settings
#      for the "value" component in HSV space.
#    o Possible warnings to standard out if color conversion tests fail.
#

import Ngl
import math
import numpy
#
#  Define the hues, and saturations, and values (the HSV) to be used.
#
hues = Ngl.fspan(0., 337.5, 16)
saturations = Ngl.fspan(0., 1., 4)
values = [0.50, 0.75, 1.00]

#
#  Define the radian increment to be used for spacing the
#  color wedges around the wheels.
#
pi = 3.14159265
radian_inc = 2 * pi / float(len(hues))

#
#  Specify the Y-coordinates for the saturation labels.
#
slab_y = [.375, .292, .217]
Esempio n. 13
0
cdf_file = Nio.open_file(os.path.join(dirc,"cdf","chi200_ud_smooth.nc"))
chi  = cdf_file.variables["CHI"]
chi  = chi[:,:]/1e6
lon  =  cdf_file.variables["lon"][:]
time =  cdf_file.variables["time"][:]
 
#
# Open a PNG file.
#
wks_type = "png"
wks = Ngl.open_wks(wks_type,"contour3")

#
# Create arrays of longitude/time values and their corresponding labels.
#
lon_values  = Ngl.fspan(0., 315., 8)
lon_labels  = ["0","45E","90E","135E","180","135W","90W","45W"]
time_values = [   0,    30,   61,   89,  120,  150,  181]
time_labels = ["DEC","JAN","FEB","MAR","APR","MAY","JUN"]

cnres = Ngl.Resources()

cnres.nglDraw                  = False    # Turn off draw and frame.
cnres.nglFrame                 = False    # We will do this later.

cnres.sfXArray                 = lon
cnres.sfYArray                 = time

cnres.tmXBMode                 = "Explicit"    # Label X and Y axes
cnres.tmYLMode                 = "Explicit"    # with explicit labels.
cnres.tmXBValues               = lon_values
Esempio n. 14
0
#    o  Drawing lines and polygons in NDC space.
#    o  Conversions between the three color spaces: RGB, HSV, YIQ.
#
#  Output:
#    o Three color wheels are drawn using three different settings
#      for the "value" component in HSV space.
#    o Possible warnings to standard out if color conversion tests fail.
#

import Ngl 
import math
import numpy
#
#  Define the hues, and saturations, and values (the HSV) to be used.
#
hues        = Ngl.fspan(0., 337.5, 16)
saturations = Ngl.fspan(0., 1., 4)
values      = [0.50, 0.75, 1.00]

#
#  Define the radian increment to be used for spacing the
#  color wedges around the wheels.
#
pi = 3.14159265
radian_inc = 2*pi/float(len(hues))

#
#  Specify the Y-coordinates for the saturation labels.
#
slab_y = [.375, .292, .217]
Esempio n. 15
0
skewtOpts.sktWindDirectionMissingV = -999.     # Missing value for 
                                               # wind direction.
skewtOpts.sktColoredBandsOn        = True      # Default is False
skewtOpts.tiMainString             = "Raob Data; No Winds" 

skewt_bkgd = Ngl.skewt_bkg(wks, skewtOpts)
skewt_data = Ngl.skewt_plt(wks, skewt_bkgd, p, tc, tdc, z,  \
                                wspd, wdir, skewtOpts)
Ngl.draw(skewt_bkgd)
Ngl.draw(skewt_data)
Ngl.frame(wks)

#
#  Plot 2 - Create background skew-T and plot sounding and winds.
#
wspd = Ngl.fspan(0., 150., nlvl)   # wind speed at each level.
wdir = Ngl.fspan(0., 360., nlvl)   # wind direction.

#
#  Create a few artificial "pibal" reports.
#
hght = numpy.array([1500., 6000., 10000., 15000.], 'f') # Meters
hspd = numpy.array([  50.,   27.,   123.,    13.], 'f')
hdir = numpy.array([ 315.,  225.,    45.,   135.], 'f')

dataOpts                               = Ngl.Resources()  # Options describing 
                                                          # data and plotting.
dataOpts.sktHeightWindBarbsOn          = True             # Plot wind barbs at
                                                          # height levels.
dataOpts.sktPressureWindBarbComponents = "SpeedDirection" # Wind speed and 
                                                          # dir [else: u,v].
Esempio n. 16
0
          [0.,0.,res.trYMinF,res.trYMinF,0.],fillres))

#
# Draw some boxes and bars on the XY plot using calls to Ngl.add_polyline.
#
# First draw a thick line at Y = 0.
#
lineres                  = Ngl.Resources()
lineres.gsLineThicknessF = 3.
zero_line = Ngl.add_polyline(wks,plot,[res.trXMinF,res.trXMaxF],
                                      [0.,0.],lineres)

#
# Add the vertical green "error" bars.
#
time  = Ngl.fspan(1,5,5)
lineres.gsLineThicknessF = 2.5
lineres.gsLineColor      = "DarkGreen"
vlines = []
for ii in range(5):
  ii1 = ii + 1
  vlines.append(Ngl.add_polyline(wks,plot,[ii1,ii1],
                                   [minval[ii],maxval[ii]],lineres))
  vlines.append(Ngl.add_polyline(wks,plot,[ii1-.08,ii1+.08], \
                                   [maxval[ii],maxval[ii]],lineres))
  vlines.append(Ngl.add_polyline(wks,plot,[ii1-.08,ii1+.08], \
                                 [minval[ii],minval[ii]],lineres))

# 
# Draw boxes going up or down from Y=0 line.
#
Esempio n. 17
0
          [0.,0.,res.trYMinF,res.trYMinF,0.],fillres))

#
# Draw some boxes and bars on the XY plot using calls to Ngl.add_polyline.
#
# First draw a thick line at Y = 0.
#
lineres = Ngl.Resources()
lineres.gsLineThicknessF = 3.
zero_line = Ngl.add_polyline(wks, plot, [res.trXMinF, res.trXMaxF], [0., 0.],
                             lineres)

#
# Add the vertical green "error" bars.
#
time = Ngl.fspan(1, 5, 5)
lineres.gsLineThicknessF = 2.5
lineres.gsLineColor = "DarkGreen"
vlines = []
for ii in range(5):
    ii1 = ii + 1
    vlines.append(
        Ngl.add_polyline(wks, plot, [ii1, ii1], [minval[ii], maxval[ii]],
                         lineres))
    vlines.append(Ngl.add_polyline(wks,plot,[ii1-.08,ii1+.08], \
                                     [maxval[ii],maxval[ii]],lineres))
    vlines.append(Ngl.add_polyline(wks,plot,[ii1-.08,ii1+.08], \
                                   [minval[ii],minval[ii]],lineres))

#
# Draw boxes going up or down from Y=0 line.
Esempio n. 18
0
import Ngl, numpy
from numpy import ma
from utils import *

npts = 400
x = Ngl.fspan(100., npts - 1, npts)
y = 500. + x * numpy.sin(0.031415926535898 * x)

wks = Ngl.open_wks("ps", "datandc")

xy = Ngl.xy(wks, x, y)

#
# Test with all in-range values and no missing values present.
#
x_dat = x
y_dat = numpy.absolute(y)

x_ndc, y_ndc = Ngl.datatondc(xy, x_dat, y_dat)
x_dat2, y_dat2 = Ngl.ndctodata(xy, x_ndc, y_ndc)

check_type(x_ndc)
check_type(y_ndc)
check_type(x_dat2)
check_type(y_dat2)

test_values("no oor or msg data: datatondc/ndctodata",
            x_dat,
            x_dat2,
            delta=1e-4)
test_values("no oor or msg data: datatondc/ndctodata",
Esempio n. 19
0
    return


#----------------------------------------------------------------------
# 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.
Esempio n. 20
0
#     A single visualization with four plots is produced.
#
#  Notes:
#

from __future__ import print_function
import Ngl
import math
import numpy

#
# Create dummy data for XY plot.
#

npts = 501
xspan = Ngl.fspan(0, npts - 1, npts)
x = numpy.zeros([npts], 'f')
y = numpy.zeros([npts], 'f')

for i in range(0, npts):
    x[i] = 500. + .9 * xspan[i] * math.cos(0.031415926535898 * xspan[i])
    y[i] = 500. + .9 * xspan[i] * math.sin(0.031415926535898 * xspan[i])

wks_type = "png"
wks = Ngl.open_wks(wks_type, "xy1")

#
# Even though some resources are the same, create four different
# resource lists for each XY plot we plan to create.
#
xyres1 = Ngl.Resources()
Esempio n. 21
0
#
import Ngl

#
#  Open the ASCII file containing the climate division numbers
#  and additional data.
#
dirc     = Ngl.pynglpath("data")
filename = os.path.join(dirc,"asc","climdivcorr.txt")
cldata = Ngl.asciiread(filename,[345,3],"float")
clmin = min(cldata[:,2])
clmax = max(cldata[:,2])


# Group each datum into 1 of 20 equally-spaced bins
bins    = Ngl.fspan(clmin,clmax,20)
lencl   = len(cldata[:,0])
databin = numpy.zeros([lencl],'i')
for i in range(lencl):
  ii = numpy.greater_equal(bins,cldata[i,2])
  for j in range(len(ii)):
    if ii[j]:
      databin[i] = j + 1
      break
#
# Start the graphics.
#
rlist = Ngl.Resources()
rlist.wkColorMap = "gui_default"
wks_type = "ps"
wks = Ngl.open_wks (wks_type,"clmdiv2",rlist)
Esempio n. 22
0
    res.nglMaximize = True
    res.nglFrame = False
    # res.nglDraw = False
    # map background
    # res.mpGridAndLimbOn        = False
    # res.mpGeophysicalLineColor = "Black"
    # coordinate settings
    res.sfXArray = lon[it, 0:ncols[it]]
    res.sfYArray = lat[it, 0:ncols[it]]
    res.vpWidthF = 1
    res.vpHeightF = 0.5
    # Set resources necessary to get map projection correct.
    # res.mpCenterLonF       = 180 

    # label settings
    lon_values  = Ngl.fspan(np.min(lon), np.max(lon), 5)
    lon_labels  = ["0","90","180","270","360"]
    lat_values  = Ngl.fspan(np.min(lat), np.max(lat), 5)
    lat_labels = ["-90", "-45", "0", "45", "90"]
    res.tmXBMode                 = "Explicit"    # Label X and Y axes
    res.tmYLMode                 = "Explicit"    # with explicit labels.
    res.tmXBValues               = lon_values
    res.tmYLValues               = lat_values
    res.tmXBLabels               = lon_labels
    res.tmYLLabels               = lat_labels

    contour = Ngl.contour(wks,q[it, 0:ncols[it]],res)

    gsres                  = Ngl.Resources()
    gsres.gsLineColor      = "Gray25"
    gsres.gsLineThicknessF = 3.0
Esempio n. 23
0
#     A single visualization with several tickmark objects is produced.
#
#  Notes:
#

import Ngl
import numpy

wks_type = "ps"
wks = Ngl.open_wks(wks_type, "format")

#
# Create some dummy data for an XY plot. We are only doing this
# to create an object that has tickmarks.
#
x = Ngl.fspan(0, 1, 20)
y = x

#
# Set some resouces for a dummy XY plot.
#
res = Ngl.Resources()
res.nglMaximize = False
res.nglDraw = False
res.nglFrame = False

res.xyLineColor = -1  # Transparent line

#
# Resources for main title and Y axis title.
#
Esempio n. 24
0
def draw_lines():
    mkres = Ngl.Resources()  # Marker resources
    lnres = Ngl.Resources()  # Line resources

    xline = Ngl.fspan(0.15, 0.85, 80)
    yline1 = 0.025 * (numpy.cos(2.0 * PI * (Ngl.fspan(1, 80, 80) / 20.0))) + 0.9
    yline2 = 0.045 * (numpy.sin(2.0 * PI * (Ngl.fspan(1, 80, 80) / 20.0))) + 0.8
    yline3 = 0.045 * (numpy.sin(2.0 * PI * (Ngl.fspan(1, 80, 80) / 10.0))) + 0.7

    # Draw 3 sets of lines.
    lnres.gsLineColor = 21  # Color index 1 is the default
    lnres.gsLineThicknessF = 1.5  # 1.0 is the default
    Ngl.polyline_ndc(wks, xline, yline1, lnres)

    lnres.gsLineColor = 85
    lnres.gsLineThicknessF = 2.0
    lnres.gsLineDashPattern = 2  # Default is a solid line (0)
    Ngl.polyline_ndc(wks, xline, yline2, lnres)

    lnres.gsLineColor = 42
    lnres.gsLineThicknessF = 3.5
    lnres.gsLineDashPattern = 11
    Ngl.polyline_ndc(wks, xline, yline3, lnres)

    # Draw markers at the end of each of the 3 lines.
    mkres.gsMarkerColor = 21
    mkres.gsMarkerIndex = 6
    mkres.gsMarkerSizeF = 0.02
    Ngl.polymarker_ndc(wks, [xline[0], xline[-1]], [yline1[0], yline1[-1]], mkres)

    mkres.gsMarkerColor = 85
    mkres.gsMarkerIndex = 11
    Ngl.polymarker_ndc(wks, [xline[0], xline[-1]], [yline2[0], yline2[-1]], mkres)

    mkres.gsMarkerColor = 42
    mkres.gsMarkerIndex = 16
    mkres.gsMarkerSizeF = 0.01
    Ngl.polymarker_ndc(wks, [xline[0], xline[-1]], [yline3[0], yline3[-1]], mkres)

    #
    # Draw a vertical line with some missing values. Include markers
    # so you can see where the missing values were.
    #
    lnres.gsLineColor = 80
    lnres.gsLineThicknessF = 1.5
    lnres.gsLineDashPattern = 0
    vxline = ma.array(yline2[25::3] - 0.65)
    vyline = ma.array(xline[25::3] - 0.30)
    #
    # Draw the markers for each point.
    #
    mkres.gsMarkerColor = 15
    mkres.gsMarkerIndex = 12  # Stars
    mkres.gsMarkerThicknessF = 2.0  # Default is 1.0
    Ngl.polymarker_ndc(wks, vxline, vyline, mkres)
    #
    # Make vxline a masked array and set some values to missing
    # using the "mask" array.  Note that if there's a single point
    # surrounded by missing values, it will become a marker when
    # drawn with Ngl.polyline_ndc.
    #
    vxline = ma.array(vxline, mask=[0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0])
    Ngl.polyline_ndc(wks, vxline, vyline, lnres)
    #
    # Draw a text string describing the above line.
    #
    tres = Ngl.Resources()
    tres.txAngleF = -90.0
    tres.txFontHeightF = 0.03
    tres.txJust = "CenterCenter"
    Ngl.text_ndc(wks, "Line with msg vals", 0.23, 0.31, tres)

    #
    # Put a box around the missing value curve.
    #
    bres = Ngl.Resources()
    bres.gsLineColor = 79
    bres.gsLineThicknessF = 3.0
    Ngl.polyline_ndc(wks, [0.09, 0.28, 0.28, 0.09, 0.09], [0.04, 0.04, 0.57, 0.57, 0.04], bres)
Esempio n. 25
0
#  Import Ngl support functions.
#
import Ngl

#
#  Open the ASCII file containing the climate division numbers
#  and additional data.
#
dirc = Ngl.pynglpath("data")
filename = os.path.join(dirc, "asc", "climdivcorr.txt")
cldata = Ngl.asciiread(filename, [345, 3], "float")
clmin = min(cldata[:, 2])
clmax = max(cldata[:, 2])

# Group each datum into 1 of 20 equally-spaced bins
bins = Ngl.fspan(clmin, clmax, 20)
lencl = len(cldata[:, 0])
databin = numpy.zeros([lencl], 'i')
for i in range(lencl):
    ii = numpy.greater_equal(bins, cldata[i, 2])
    for j in range(len(ii)):
        if ii[j]:
            databin[i] = j + 1
            break
#
# Start the graphics.
#
rlist = Ngl.Resources()
rlist.wkColorMap = "gui_default"
wks_type = "png"
wks = Ngl.open_wks(wks_type, "clmdiv2", rlist)