Kludgy efficiency improvement

From: Jack Glendening <ncarg_drjack_at_nyahnyahspammersnyahnyah>
Date: Fri, 28 Jul 2006 20:40:00 -0700

I've raised the concern of improving plot efficiency when creating
plots of different parameters which all use the same background,
seeking to avoid computation time spent re-creating that background
for every plot. My last post mentioned how this can be done simply
and elegantly for simple plots by setting resource "vpUseSegments"
True and using "setvalues" to alter an existing object (instead
creating a new one), as in example gsun09n.

However my attempts to use that method with my regular plotting
program failed. While much worked successfully and I was able to plot
different parameters over a background map, some details of my code
reacted differently from when a new object was created and I could not
successfully find a way to fix that behavior. If I pursued that route
I could foresee many details needing individual attention and
alteration to get things to work properly, given the complex nature of
my code (my "background" consists of a map with geographic boundaries
and lat/long lines overplotted by text identifiers and lines based on
lat/lon coordinates and then overplotted by terrain line contours).

So I decided to use a "kludgy" approach, which is not elegant or
sophisticated but works without having do delve into the guts of my
existing program. For my complex background cases this version took
only 45% of the time of the previous version in which the background
was re-computed for each plot. [That timing is a wall clock value
which includes some parameter calculation, etc. in addition to the
actual plotting.] Since my plotting program currently runs for about
an hour each day and I plan to double its use in the future, the CPU
savings is worth coding time investment.

In brief, I do a once-only computation of the background plot after
which each parameter is looped, plotting its data over a _blank_ map
and then overplotting that with the background plot. (Strictly
speaking, my "background" is an over-plot of a parameter contour fill
plot).

In skeleton form, code for creating an individual ncgm
file for each parameter is:

  ;;; CREATE TEMPORARY WORKSTATION FOR BACKGROUND PLOT
    wks_background = create "tempWorkstation" ncgmWorkstationClass ...
  ;;; SET RESOURCES FOR BACKGROUND (TERRAIN CONTOURS ON COMPLEX MAP)
    mpopts_background_at_mpOutlineOn = True
    ...
    cnopts_background_at_cnFillOn = False
    ...
  ;;; CREATE BACKGROUND PLOT (TERRAIN CONTOURS ON COMPLEX MAP)
    background_plot = create "mp" mapPlotClass wks_background ...
    terrain_plot = create "cn" contourPlotClass wks_background ...
    overlay ( background_plot, terrain_plot )
  ;;; LOOP OVER PARAMETERS
    do iparam=0,(nparam-1)
      ;;; CREATE INDIVIDUAL NCGM FILE FOR EACH PARAMETER
        wks = create "plotWorkstation" ncgmWorkstationClass ...
      ;;; SET RESOURCES TO PLOT PARAMETER FILL CONTOURS ON BLANK MAP
        mpopts_parameter_at_mpOutlineOn = False
        mpopts_parameter_at_mpGridAndLimbOn = False
        ...
        cnopts_parameter_at_cnFillOn = True
        ...
      ;;; CREATE PARAMETER FILL CONTOURS ON BLANK MAP
        parameter_plot = create "mp" mapPlotClass wks ...
        contourfill_plot = create "cn" contourPlotClass wks ...
        overlay ( parameter_plot, contourfill_plot )
      ;;; PLOT PARAMETER FILL CONTOURS, THEN BACKGROUND
        draw( parameter_plot )
        NhlChangeWorkstation( background_plot, wks )
        draw( background_plot )
        ;;; must prevent destruction of background_plot when new ncgm
file workstation created
        NhlChangeWorkstation( background_plot, wks_background )
      frame ( wks )
    end do

For cases where output is written to a single file or X11 display the
above can be simplified by eliminating the separate "temp_wks"
workstation.

If there is a way to simplify this, as by eliminating the kludgy use
for a temporary workstation for the background plot, I'd like to hear
about it.

              Jack

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Jul 28 2006 - 21:40:00 MDT

This archive was generated by hypermail 2.2.0 : Mon Jul 31 2006 - 11:31:36 MDT