Ejemplo n.º 1
0
resources.tiMainFont      = "Helvetica" # Font for title
resources.tiXAxisFont     = "Helvetica" # Font for X axis label
resources.tiYAxisFont     = "Helvetica" # Font for Y axis label
  
resources.xyMarkLineModes = ["Lines","Markers","MarkLines"]
resources.xyMarkers       = [0,1,3]     # (none, dot, asterisk)
resources.xyMarkerColor   = 107         # Marker color
resources.xyMarkerSizeF   = 0.03        # Marker size (default
                                          # is 0.01)
  
plot = Ngl.xy(wks,x,y2,resources)       # Draw an XY plot.
  
#---------- Begin fifth plot ------------------------------------------
  
filename = os.path.join(Ngl.pynglpath("data"),"asc","xy.asc")
data     = Ngl.asciiread(filename,(129,4),"float")
  
#
#  Define a two-dimensional array of data values based on
#  columns two and three of the input data.
#
uv = numpy.zeros((2,129),'f')
uv[0,:] = data[:,1]
uv[1,:] = data[:,2]
  
#
#  Use the first column of the input data file (which is simply the
#  row number) for longitude values.  The fourth column of data is
#  not used in this example.
#
lon     = data[:,0]
Ejemplo n.º 2
0
#    This example produce two visualizations:
#      1.)  A Raob sounding with no winds.
#      2,)  A Raob sounding with wind barbs at height levels and a
#           height scale in feet.
#
#  Notes:
#    This example was updated in January 2006 to include the new
#    Skew-T resource names decided on.
#     

import Ngl
import numpy

nlvl = 30  
ncol = 16
TestData = Ngl.asciiread(Ngl.pynglpath("data") + "/asc/sounding_testdata.asc", \
                   [nlvl,ncol], "float")

p    = TestData[:,1]
z    = TestData[:,2]
tc   = TestData[:,5] + 2.    # for demo purposes
tdc  = TestData[:,9]

#
#  Set winds to missing values so that they will not be plotted.
#
wspd = -999.*numpy.ones(nlvl,'f')
wdir = -999.*numpy.ones(nlvl,'f')

#
#  Plot 1 - Create background skew-T and plot sounding.
#
Ejemplo n.º 3
0
#    This example produces two visualizations:
#      1.) A colored contour plot with a label bar where negative
#          interpolated values are allowed.
#      2.) A colored contour plot with a label bar where negative
#          interpolated values are not allowed.
#
#  Notes:
#     
import numpy
import Ngl

#  
#  Open the ASCII file of seismic data.
#  
dirc    = Ngl.pynglpath("data")
seismic = Ngl.asciiread(dirc + "/asc/seismic.asc" ,[52,3],"float")

#
#  Extract coordinate triples from the data file.
#
x = numpy.array(seismic[:,0],'f')
y = numpy.array(seismic[:,1],'f')
z = numpy.array(seismic[:,2],'f')-785.

#
#  Define output grid for the calls to "natgrid".
#
numxout, numyout = 20, 20 
xmin, xmax, ymin, ymax   = min(x), max(x), min(y), max(y)
xc      = (xmax-xmin)/(numxout-1)
yc      = (ymax-ymin)/(numyout-1)
Ejemplo n.º 4
0
#
#  Import numpy.
#
import numpy

#
#  Import Ngl support functions.
#
import Ngl
import Nio

#  
#  Open the ASCII file.
#  
dirc    = Ngl.pynglpath("data")
seismic = Ngl.asciiread(dirc + "/asc/seismic.asc" ,[52,3],"float")

#
#  Read in X,Y,Z data.
#
x = numpy.array(seismic[:,0],'f')
y = numpy.array(seismic[:,1],'f')
z = numpy.array(seismic[:,2],'f')

#
#  Interpolate to a 2D output grid using natgrid.
#
numxout = 20     # Define output grid for call to "natgrid".
numyout = 20
xmin    = min(x)
ymin    = min(y)
Ejemplo n.º 5
0
Archivo: cn12p.py Proyecto: akrherz/me
  "burundi","cameroon","central-african-republic","chad","congo","djibouti", \
  "egypt","equatorial-guinea","ethiopia","gabon","gambia","ghana","guinea",  \
  "guinea-bissau","ivory-coast","kenya","lesotho","liberia","libya",         \
  "madagascar","malawi","mali","mauritania","mauritius","morocco",           \
  "mozambique","namibia","niger","nigeria","rwanda","senegal","sierra-leone",\
  "somalia","south-africa","sudan","swaziland","tanzania","togo","tunisia",  \
  "uganda","upper-volta","western-sahara","zaire","zambia","zimbabwe"]

#
#  Open a workstation.
#
wks_type = "ps"
wks = Ngl.open_wks(wks_type,"cn12p")

dirc = Ngl.ncargpath("data")
z    = Ngl.asciiread(dirc+"/asc/cn12n.asc",len_dims,"float")
 
resources = Ngl.Resources()
resources.sfXCStartV  = -18.0
resources.sfXCEndV    =  52.0
resources.sfYCStartV  = -35.0
resources.sfYCEndV    =  38.0
resources.vpXF        =   0.1
resources.mpMaskAreaSpecifiers  =  mask_specs
resources.mpFillAreaSpecifiers  =  fill_specs
resources.pmLabelBarDisplayMode =  "always"
Ngl.contour_map(wks,z[:,:],resources)

del resources
Ngl.end()
Ejemplo n.º 6
0
#
#  Import numpy.
#
import numpy, os

#
#  Import Ngl support functions.
#
import Ngl

#
#  Open the ASCII file.
#
dirc = Ngl.pynglpath("data")
seismic = Ngl.asciiread(os.path.join(dirc, "asc", "seismic.asc"), [52, 3],
                        "float")

x = numpy.array(seismic[:, 0], 'f')
y = numpy.array(seismic[:, 1], 'f')
z = numpy.array(seismic[:, 2], 'f')

numxout = 20  # Define output grid for call to "natgrid".
numyout = 20
xmin = min(x)
ymin = min(y)
xmax = max(x)
ymax = max(y)

xc = (xmax - xmin) / (numxout - 1)
yc = (ymax - ymin) / (numyout - 1)
Ejemplo n.º 7
0
resources.tiMainFont = "Helvetica"  # Font for title
resources.tiXAxisFont = "Helvetica"  # Font for X axis label
resources.tiYAxisFont = "Helvetica"  # Font for Y axis label

resources.xyMarkLineModes = ["Lines", "Markers", "MarkLines"]
resources.xyMarkers = [0, 1, 3]  # (none, dot, asterisk)
resources.xyMarkerColor = 107  # Marker color
resources.xyMarkerSizeF = 0.03  # Marker size (default
# is 0.01)

plot = Ngl.xy(wks, x, y2, resources)  # Draw an XY plot.

#---------- Begin fifth plot ------------------------------------------

filename = os.path.join(Ngl.pynglpath("data"), "asc", "xy.asc")
data = Ngl.asciiread(filename, (129, 4), "float")

#
#  Define a two-dimensional array of data values based on
#  columns two and three of the input data.
#
uv = numpy.zeros((2, 129), 'f')
uv[0, :] = data[:, 1]
uv[1, :] = data[:, 2]

#
#  Use the first column of the input data file (which is simply the
#  row number) for longitude values.  The fourth column of data is
#  not used in this example.
#
lon = data[:, 0]
Ejemplo n.º 8
0
#
from __future__ import print_function
import Ngl
import os

#
#  xy.asc has 4 vars of length 129 longitudes, u, v, and t.
#
#  The data is taken at 43N latitude.  Longitude is an index
#  1-129 standing for 0 deg - 360 deg in steps of 360/128.
#  u and v are in m/s, and t is in deg K.
#
dirc     = Ngl.pynglpath("data")
data     = Ngl.asciiread(os.path.join(dirc,
                                      "asc",
                                      "xy.asc"),
                         [516],
                         "float")

lon  = data[0:512:4]    # First column of data is longitude.
u    = data[1:513:4]    # Second column is u
v    = data[2:514:4]    # Third column is v (not used in this example)
t    = data[3:515:4]    # Fourth column is t

lon = (lon-1.) * 360./128.
t   = (t-273.15) * 9./5. + 32.

#
# Open a workstation.
#
wks_type = "png"
Ejemplo n.º 9
0
#      1.)  Shows the full radiosonde.
#      2.)  "thins" the number of wind barbs plotted and
#           uses a Centigrade scale.  Setting "Wthin" to 3
#           causes the plotting of every third wind barb.
#
#  Notes:
#    This example was updated in January 2006 to include the new
#    Skew-T resource names decided on.
#

from __future__ import print_function
import Ngl, os

nlvl = 65
ncol = 7
TestData =  Ngl.asciiread(os.path.join(Ngl.pynglpath("data"),"asc","sounding_ATS.asc"), \
                          [nlvl,ncol], "float")

#
# Order: Surface is 'bottom'  eg: 1000,950,935,897,...
#
p = TestData[:, 0]  # pressure     [mb / hPa]
tc = TestData[:, 1]  # temperature  [C]
tdc = TestData[:, 2]  # dew pt temp  [C]
z = TestData[:, 4]  # geopotential [gpm]
wspd = TestData[:, 5]  # wind speed   [knots or m/s]
wdir = TestData[:, 6]  # meteorological wind dir

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

#
Ejemplo n.º 10
0
#  Import numpy.
#
import numpy, os

#
#  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
#
Ejemplo n.º 11
0
Archivo: skewt3.py Proyecto: akrherz/me
#            PO 3007, Boulder, Colorado
#
#   Date:    Tue Mar  1 14:58:28 MST 2005
# 
#   Description:
#            Produces two plots using real data:
#              1. Shows the full radiosonde.
#              2. This "thins" the number of wind barbs plotted and 
#                 uses a Centigrade scale.  Setting Wthin to 3 causes
#                 the plotting of every third wind barb.
#    
import Ngl
  
nlvl = 65
ncol = 7
TestData =  Ngl.asciiread(Ngl.ncargpath("data") + "/asc/sounding_ATS.asc", \
                          [nlvl,ncol], "float")

#
# Order: Surface is 'bottom'  eg: 1000,950,935,897,...  
#
p    = TestData[:,0]    # pressure     [mb / hPa] 
tc   = TestData[:,1]    # temperature  [C]    
tdc  = TestData[:,2]    # dew pt temp  [C]   
z    = TestData[:,4]    # geopotential [gpm] 
wspd = TestData[:,5]    # wind speed   [knots or m/s]    
wdir = TestData[:,6]    # meteorological wind dir   

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

#
	
  2018-08-28  kmf
"""
from __future__ import print_function
import numpy as np
import Ngl

#-- file has 21361 lines but 1 header line
#-- 3 columns
nrows = 21360  #-- file has 21361 lines but 1 header line
ncols = 3  #-- file has 3 columns
num_lon = 240  #-- number of longitudes
num_lat = 89  #-- number of latitudes

#-- read all data
data = Ngl.asciiread("asc6.txt", (nrows, ncols), "float")

#-- select lat, lon and temp data
lat = data[::num_lon, 0]
lon = data[:num_lon, 1]
temp1D = data[:, 2]

#-- size of lat, lon and temp1d
nlats = len(lat)
nlons = len(lon)
ntemp = len(temp1D)

#-- reshape temp1d to 2D-array temp2d with size (89,240)
temp2D = np.reshape(temp1D, (nlats, nlons))

#-- print information
Ejemplo n.º 13
0
#
#  Import NGL support functions.
#
import Ngl

#
#  Open a workstation.
#
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.
Ejemplo n.º 14
0
#
#  Import Nio for a NetCDF reader.
#
import Nio

#
#  Import PyNGL support functions.
#
import Ngl
import os, string, types

# Read data off file.

filename = os.path.join(Ngl.pynglpath("data"), "asc", "fcover.dat")
data = Ngl.asciiread(filename, [3, 73, 73], "float")

# Send graphics to PNG file
wks_type = "png"
wks = Ngl.open_wks(wks_type, "streamline2")

stres = Ngl.Resources()
cnres = Ngl.Resources()
mpres = Ngl.Resources()

cnres.nglDraw = False
cnres.nglFrame = False
mpres.nglDraw = False
mpres.nglFrame = False
stres.nglDraw = False
stres.nglFrame = False
Ejemplo n.º 15
0
Archivo: multi_y.py Proyecto: yyr/pyngl
#     

#
#  Import Ngl support functions.
#
import Ngl

#
#  xy.asc has 4 vars of length 129 longitudes, u, v, and t.
#
#  The data is taken at 43N latitude.  Longitude is an index
#  1-129 standing for 0 deg - 360 deg in steps of 360/128.
#  u and v are in m/s, and t is in deg K.
#
dirc     = Ngl.pynglpath("data")
data     = Ngl.asciiread(dirc+"/asc/xy.asc",[516],"float")

lon  = data[0:512:4]    # First column of data is longitude.
u    = data[1:513:4]    # Second column is u
v    = data[2:514:4]    # Third column is v (not used in this example)
t    = data[3:515:4]    # Fourth column is t

lon = (lon-1.) * 360./128.
t   = (t-273.15) * 9./5. + 32.

#
# Open a workstation.
#
wks_type = "ps"
wks = Ngl.open_wks(wks_type,"multi_y")
Ejemplo n.º 16
0
#
#  Import numpy.
#
import numpy, os

#
#  Import Ngl support functions.
#
import Ngl

#  
#  Open the ASCII file.
#  
dirc    = Ngl.pynglpath("data")
seismic = Ngl.asciiread(os.path.join(dirc,"asc","seismic.asc") ,[52,3],"float")

x = numpy.array(seismic[:,0],'f')
y = numpy.array(seismic[:,1],'f')
z = numpy.array(seismic[:,2],'f')

numxout = 20     # Define output grid for call to "natgrid".
numyout = 20
xmin    = min(x)
ymin    = min(y)
xmax    = max(x)
ymax    = max(y)

xc      = (xmax-xmin)/(numxout-1)
yc      = (ymax-ymin)/(numyout-1)
Ejemplo n.º 17
0
#
import numpy

#
#  Import NGL support functions.
#
import Ngl

#
#  Open a workstation.
#
wks_type = "png"
wks = Ngl.open_wks(wks_type,"ngl11p")

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
Ejemplo n.º 18
0
#

#
#  Import Ngl support functions.
#
import Ngl

#
#  xy.asc has 4 vars of length 129 longitudes, u, v, and t.
#
#  The data is taken at 43N latitude.  Longitude is an index
#  1-129 standing for 0 deg - 360 deg in steps of 360/128.
#  u and v are in m/s, and t is in deg K.
#
dirc = Ngl.pynglpath("data")
data = Ngl.asciiread(dirc + "/asc/xy.asc", [516], "float")

lon = data[0:512:4]  # First column of data is longitude.
u = data[1:513:4]  # Second column is u
v = data[2:514:4]  # Third column is v (not used in this example)
t = data[3:515:4]  # Fourth column is t

lon = (lon - 1.) * 360. / 128.
t = (t - 273.15) * 9. / 5. + 32.

#
# Open a workstation.
#
wks_type = "png"
wks = Ngl.open_wks(wks_type, "multi_y")
Ejemplo n.º 19
0
Archivo: ngl11p.py Proyecto: yyr/pyngl
#
import Ngl

#
#  Define a color table and open a workstation.
#
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
Ejemplo n.º 20
0
#    This example produce two visualizations:
#      1.)  A Raob sounding with no winds.
#      2,)  A Raob sounding with wind barbs at height levels and a
#           height scale in feet.
#
#  Notes:
#    This example was updated in January 2006 to include the new
#    Skew-T resource names decided on.
#

import Ngl
import numpy

nlvl = 30
ncol = 16
TestData = Ngl.asciiread(Ngl.pynglpath("data") + "/asc/sounding_testdata.asc", \
                   [nlvl,ncol], "float")

p = TestData[:, 1]
z = TestData[:, 2]
tc = TestData[:, 5] + 2.  # for demo purposes
tdc = TestData[:, 9]

#
#  Set winds to missing values so that they will not be plotted.
#
wspd = -999. * numpy.ones(nlvl, 'f')
wdir = -999. * numpy.ones(nlvl, 'f')

#
#  Plot 1 - Create background skew-T and plot sounding.
#
Ejemplo n.º 21
0
	
	2.00;3.50;5.10;8.20
	2.40;3.10;4.80;8.90
	2.60;3.70;5.30;10.10
	2.75;3.90;5.55;10.25
	3.00;4.10;6.05;10.50

  2018-08-28  kmf
"""
import numpy as np
import Ngl

#--  data file name
diri = "./"
fili = "Test_6h.csv"

#-- number of lines and columns in input file
nrows = 5
ncols = 4

#-- read all data
vals = Ngl.asciiread(diri + fili, (nrows, ncols), "float", sep=';')

#-- print information
print("vals: {}".format(vals))
print("")
print("--> rank of vals:     {}".format(len(vals.shape)))
print("--> shape vals:       {}".format(vals.shape))

exit()
Ejemplo n.º 22
0
Archivo: ngl08p.py Proyecto: akrherz/me
#
#  Import NumPy.
#
import Numeric

#
#  Import Ngl support functions.
#
import Ngl

#  
#  Open the ASCII file.
#  
seismic = Ngl.asciiread("seismic.asc" ,[52,3],"float")

x = Numeric.array(seismic[:,0],Numeric.Float0)
y = Numeric.array(seismic[:,1],Numeric.Float0)
z = Numeric.array(seismic[:,2],Numeric.Float0)

numxout = 20     # Define output grid for call to "natgrid".
numyout = 20
xmin    = min(x)
ymin    = min(y)
xmax    = max(x)
ymax    = max(y)

xc      = (xmax-xmin)/(numxout-1)
yc      = (ymax-ymin)/(numyout-1)

xo = xmin + xc*Numeric.arange(0,numxout)
yo = ymin + yc*Numeric.arange(0,numxout)
Ejemplo n.º 23
0
#
from __future__ import print_function
import numpy, os

#
#  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.