Re: Plotting stretched grids in NCL Contours

From: Mary Haley (haley AT XXXXXX)
Date: Tue Jun 25 2002 - 19:05:42 MDT

  • Next message: Dave Brown: "Re: Plotting stretched grids in NCL Contours"

    >
    > Hello:
    >
    > I am still confused as to how to contour data that has uneven grid
    > spacing along the coordinate axes. My coordinates are only functions
    > of x OR y, that
    > is xg = f(x), and yg= f(y).
    >
    > When I try and use sfXArray Scalar data information in the ContourClass,
    > I either get a warning that this is not implemented under the cn class,
    > or no
    > warning at all. The contour plot then ignores the change in coordinates.

    Hi Lou,

    If you are using straight NCL code (not GSUN), then you need to set
    the "sfXArray" resource when you create the data object
    (scalarFieldClass) and not as part of the contour plot class
    (contourPlotClass). The contour plot class doesn't recognize the "sf"
    resources.

    Secondly, if your data is truly irregular along one axis, and you want
    to "linearize" this axis, then you will need to overlay the contour
    plot on a LogLin plot (logLinPlotClass). This will force a
    transformation to take place along the irregular axis, and you'll get
    the effect you're expecting.

    There's a good example of how to do this in frame 4 of the the NCL
    example "cn03n". To generate this example, type:

        ng4ex cn03n

    Then, edit the file and search for "logLinPlotClass", and you'll see
    how the overlay is done. Below is a similar example of how this might
    work.

      contour_data = (/some 2D array/)
    ;
    ; Open an X11 workstation.
    ;
      wks = create "x11" xWorkstationClass defaultapp end create
    ;
    ; Create a data object.
    ;
      dataid = create "data" scalarFieldClass defaultapp
        "sfXArray" : xg
        "sfYArray" : yg
      end create
    ;
    ; Create a contour plot object.
    ;
      contour = create "plot" contourPlotClass wks
        "cnScalarFieldData" : dataid
      end create
    ;
    ; Retrieve the viewport coordinates so we can use them to
    ; specify the exact same coordinates for the loglin plot.
    ;
      getvalues contour
        "vpXF" : vpx
        "vpYF" : vpy
        "vpWidthF" : vpw
        "vpHeightF" : vph
      end getvalues
    ;
    ; Create a loglin plot object.
    ;
      loglin = create "LogLin" logLinPlotClass wks
        "vpXF" : vpx
        "vpYF" : vpy
        "vpWidthF" : vpw
        "vpHeightF" : vph
      end create
    ;
    ; Overlay the contour plot on the loglin plot.
    ;
      overlay(loglin,contour)
    ;
    ; The loglin plot becomes the base plot that contains the
    ; contour plot, so to draw the contour plot, you must draw
    ; the loglin plot.
    ;
      draw(loglin)
    ;
    ; Advance the frame.
    ;
      frame(wks)
        
    >
    > When I try and use the gsn_contour routine and set the attributes, I
    > also get the correct cooridinate values plotted but no change in the plot.
    >
    >
    > Lou Wicker
    >

    This whole process is a little easier if you are using gsn_contour.
    You can set the special "gsn" resource "gsnYAxisIrregular2Linear" to
    True, and the creating/overlaying of the logLinPlotClass will take
    place behind the scenes.

    Your GSUN script might look something like this:

       contour_data = (/some 2D array/)
       wks = gsn_open_wks("x11","example") ; Open an X11 workstation.
          
       res = True
       res@sfXArray = xg
       res@sfYArray = yg
       res@gsnYAxisIrregular2Linear = True

       contour = gsn_contour(wks,contour_data,res) ; Draw plot and advance frame.

    --Mary

    >
    > ================================================
    > Dr. Louis J. Wicker
    > Research Scientist, National Severe Storms Lab
    > 1313 Halley Cir, Norman, OK 73069
    > E-mail: Louis.Wicker AT nssl.noaa.gov
    > Phone: (405) 366-0416 / Fax: (405) 579-0808
    > Norman's Little River Zoo on SE 120th off Rt. 9:
    > Your zoo for life!
    > ===============================================
    _______________________________________________
    ncl-talk mailing list
    ncl-talk AT ucar.edu
    http://mailman.ucar.edu/mailman/listinfo/ncl-talk



    This archive was generated by hypermail 2b29 : Tue Jun 25 2002 - 19:09:16 MDT