Below is an annotated version of the script poly_vec_demo.jnl


poly_vec_demo.jnl 7/03 *acm*

Description: demonstrate plotting vectors as filled polygons. Uses poly_vectors.jnl and mp_poly_vectors.jnl scripts contributed by E. D. Cokelet, NOAA/PMEL, 2003. All of these scripts will be included in the Ferret v5.53 release.

The scripts poly_vectors.jnl and mp_poly_vectors.jnl compute polygon coordinates for drawing vectors in Cartesian or curvlilinear coordinates as polygon arrows or sticks, optionally filled with color. These scripts are similar to scattered_vectors.jnl in that they set up data, which is then plotted with a separate command, in this case, the polygon command. A third script, poly_arrow_key.jnl makes an arrow key at any location on the page. This script reqires capabilities of Ferret V5.53 to work correctly. Please see the documentation for on these scripts by typing e.g.,

   yes? go/help poly_vectors.jnl


First lets make a plot in Cartesian coordinates. We will call the script poly_vectors.jnl to set up the polygons for plotting.

   yes? SET WINDOW/siz=0.6
   yes? CANCEL MODE logo

   yes? USE coads_climatology
   yes? SET REGION/X=120:180/Y=20:60/L=1

poly_vectors.jnl must have the plot parameters (such as axis lengths) already set. Draw a 2-D plot over the region of interest.

   yes? GO basemap X=120:180 Y=20:60 20
   yes? LABEL/NOUSER `($ppl$xlen)/2`, `($ppl$yorigin)-1`, 0, 0, 0.16, "UWND, VWND"

The inputs to poly_vectors.jnl are the vectors to be plotted and the X and Y coordinates of the vectors. We need to limit the region of the data explicitly, so that the calculations are done only for the vectors we are interested in.

   yes? LET x_vec = X[GX=uwnd,X=120:180] + 0*Y[GY=uwnd,Y=20:60]
   yes? LET y_vec = 0*X[GX=uwnd,X=120:180] + Y[GY=uwnd,Y=20:60]
   yes? LET u_vec = uwnd[X=120:180,Y=20:60,L=1]
   yes? LET v_vec = vwnd[X=120:180,Y=20:60,L=1]

Call poly_vectors to set up the vectors to be plotted as polygons

   yes? GO poly_vectors.jnl x_vec y_vec u_vec v_vec 5 "arrow"

Draw the arrow polygons. We can use a third argument on the POLYGON command to fill the polygons with colors according to a variable. Make a list of the values of sea level pressure which corresponds to the original vector components. The color key is for the fill color. We use the /LINE qualifier to outline the arrows with black.

   yes? LET press = YSEQUENCE(slp[X=120:180,Y=20:60,L=1])
   yes? POLYGON/OVER/NOAX/NOLAB/KEY/LINE/PAL=rainbow plt_x_arrow, plt_y_arrow, press

Make a vector arrow key.

   yes? GO poly_arrow_key "winds", "5 m/s"


For a larger-scale plot we need to sub-sample the vectors before sending them as arguments to the poly_vectors script.


   yes? USE coads_climatology
   yes? CAN REGION
   yes? SET REGION/L=1/X=0:360/Y=-80:80
   yes? CAN VAR/ALL

Make a 2-D plot to set plot parameters.

   yes? GO basemap x=0:360 y=-80:80 20

Subsample the vector data and set up the vectors to be plotted as polygons

   yes? LET x_vec = X[GX=uwnd,X=0:360:10] + 0*Y[GY=uwnd,Y=-80:80:5]
   yes? LET y_vec = 0*X[GX=uwnd,X=0:360:10] + Y[GY=uwnd,Y=-80:80:5]
   yes? LET u_vec = uwnd[X=0:360:10,Y=-80:80:5,L=5]
   yes? LET v_vec = vwnd[X=0:360:10,Y=-80:80:5,L=5]

   yes? GO poly_vectors.jnl x_vec y_vec u_vec v_vec 8 "arrow"

Draw the arrow polygons, colored by SLP, and make a key for the arrows. Note the different plot appearance when we leave off the LINE qualifier on the polygon command.

   yes? LET press = YSEQUENCE(slp[X=0:360:10,Y=-80:80:5,L=5])
   yes? POLYGON/OVER/NOAX/NOLAB/KEY/PAL=rainbow/LEV=(980,1030,5) plt_x_arrow, plt_y_arrow, press
   yes? GO poly_arrow_key "", "8 m/s", red



Next we will do some some polygon-vector plots using map projections.

The steps are: Define a subset of the data to plot, define a map projection, and draw some plot in the map projection, using the curvilinear form of the plotting command. Define variables with with U, V, X, and Y for the vectors, call mp_poly_vectors to set up the polygon coordinates and use a curvlinear polygon command to plot them.

   yes? CAN REGION
   yes? CAN VAR/ALL

   yes? USE coads_climatology

   yes? SET REGION/X=131:181/Y=21:61/L=5
   yes? LET mp_central_meridian = (131+181)/2
   yes? LET mp_standard_parallel = (21+61)/2

   yes? GO mp_stereographic_north `mp_central_meridian` `mp_standard_parallel`
   yes? SET GRID uwnd
   yes? GO mp_aspect

Make a FILL plot using the map projection to set the plot parameters for the mp_poly_vectors script

   yes? FILL/NOAXIS/NOKEY/PAL=greyscale/TITLE="Winds Colored by Pressure" slp, x_page,y_page
   yes? GO mp_fland 20 black

Call mp_poly_vectors to set up the vectors to be plotted as polygons

   yes? LET x_vec = X[GX=uwnd,X=131:181] + 0*Y[GY=uwnd,Y=21:61]
   yes? LET y_vec = 0*X[GX=uwnd,X=131:181] + Y[GY=uwnd,Y=21:61]
   yes? LET u_vec = uwnd[X=131:181,Y=21:61,L=5]
   yes? LET v_vec = vwnd[X=131:181,Y=21:61,L=5]

   yes? GO mp_poly_vectors x_vec y_vec u_vec v_vec 4 "arrow"

Draw the polygons, colored by SLP

   yes? LET press = YSEQUENCE(slp[X=131:181,Y=21:61,L=5])
   yes? POLYGON/OVER/NOAX/NOLAB/KEY/LINE/PAL=rainbow mp_x_arrow, mp_y_arrow, press

   yes? GO mp_graticule 131 181 12.5 21 61 10

Now we illustrate positioning the vector arrow key, by putting four different keys on the plot. By default the key is positioned at the lower left. We can choose to center it horizontally or vertically by sending the letter C as the argument for a position.

   yes? GO poly_arrow_key "default key", "4 m/s", red, line
   yes? GO poly_arrow_key "left top key", 4, blue, " ", 2, `($ppl$height)-1.5`
   yes? GO poly_arrow_key "centered bottom", 4, violet, " ", c, 0.2
   yes? GO poly_arrow_key "upper right", 4, green, line, `($ppl$width)-1.6`, `($ppl$height)-1.5`,0.14



Next we'll make a view from space. We need the mp_mask for this projection, to keep the vectors on other side of the earth from "showing through" the map. Apply it to the polygon data as it is plotted. This time we use explicit regridding to put the vector components onto a coarser grid.

   yes? CAN DATA/ALL
   yes? CAN VAR/ALL
   yes? CAN REGION

   yes? USE coads_climatology
   yes? SET REGION/L=1

   yes? DEFINE AXIS/X=0:360:8 xax
   yes? DEFINE AXIS/Y=-80:80:4 yax
   yes? DEFINE GRID/X=xax/Y=yax gxy

   yes? LET x_vec = X[GX=xax] + 0*Y[GY=yax]
   yes? LET y_vec = 0*X[GX=xax] + Y[GY=yax]
   yes? LET u_vec = uwnd[g=gxy,L=1]
   yes? LET v_vec = vwnd[g=gxy,L=1]

Make a plot with the map projection to set the plot parameters. (A FILL plot with the palette set to all white, for a blank underlying plot)

   yes? GO mp_orthographic 210 45
   yes? SET GRID gxy
   yes? GO mp_aspect

   yes? FILL/NOAXIS/NOKEY/NOLAB/PAL=white/TITLE="Winds Colored by Pressure" u_vec, x_page,y_page
   yes? GO mp_fland
   yes? GO mp_graticule 0 360 30 -90 90 20

Set up the vectors to be plotted as polygons

   yes? GO mp_poly_vectors x_vec y_vec u_vec v_vec 5 "arrow"

Draw the arrow polygons, colored by SLP, and the vector key

   yes? LET press = YSEQUENCE(slp[g=gxy,L=1])
   yes? POLYGON/OVER/NOAX/NOLAB/LINE/KEY/PAL=rainbow mp_mask*mp_x_arrow, mp_mask*mp_y_arrow, mp_mask*press

   yes? GO poly_arrow_key " ", "5 m/s", red, " ", 1, `($ppl$yorg)`


Finally, the poly_vector scripts also have the option to plot the vectors as stick vectors, rather than arrows. All the commands stay the same, but with the final argument to poly_vectors.jnl or mp_poly_vectors.jnl being "stick" rather than "arrow". Here is the first plot from this demo made with stick vectors:

   yes? CAN DATA/ALL
   yes? CAN VAR/ALL
   yes? CAN REGION

   yes? USE coads_climatology
   yes? SET REGION/X=120:180/Y=20:60/L=1

   yes? LET x_vec = X[GX=uwnd,X=120:180] + 0*Y[GY=uwnd,Y=20:60]
   yes? LET y_vec = 0*X[GX=uwnd,X=120:180] + Y[GY=uwnd,Y=20:60]
   yes? LET u_vec = uwnd[X=120:180,Y=20:60,L=1]
   yes? LET v_vec = vwnd[X=120:180,Y=20:60,L=1]

   yes? GO basemap X=120:180 Y=20:60 20
   yes? LABEL/NOUSER `($ppl$xlen)/2`, `($ppl$yorigin)-1`, 0, 0, 0.16, "Wind Vectors Colored by SLP"

   yes? GO poly_vectors.jnl x_vec y_vec u_vec v_vec 5 "stick"

   yes? LET press = YSEQUENCE(slp[X=120:180,Y=20:60,L=1])
   yes? POLYGON/OVER/NOAX/NOLAB/KEY/PAL=rainbow plt_x_arrow, plt_y_arrow, press

   yes? GO poly_arrow_key "winds", "5 m/s" red



oar.pmel.contact_ferret@noaa.gov 4 August, 2003