Re: Overlay plots

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue, 5 May 2009 07:46:21 -0600 (MDT)

Moti,

The error message is occuring because you are trying to overlay a map
plot on a map plot. You can't overlay maps on other maps, but you can
overlay vectors and contours on maps.

At the least, you need to change:

   plot1 = gsn_csm_vector_map(wks,u, v, res)

to

   plot1 = gsn_csm_vector(wks,u, v, res)

Also, I didn't look at your whole script, but I did notice that you
are sharing resources between the two plot calls.

Since one plot is for contours and the other is for vectors, you
should use different resource lists, or make sure you call:

   delete(res)

once you are finished with the first plot. This way you start with a
clean resource list and you aren't trying to apply contour resources
to a vector plot (or vice versa).

--Mary

On Mon, 4 May 2009, Mittal, Moti wrote:

> Dennis,
>
> Thank you very much.
>
> I am trying to overlay the wind vectors over the O3 contour plots.
> I am trying to follow the nearest example gsn_vec_scal_2.ncl.
> However I am not successful in creating the overlay map although I can create separately both the plots.
> I am getting the error:
>
> fatal:NhlAddOverlay: plot class mapPlotClass cannot be overlay plot member
>
>
> I am attaching my script for your possible review and suggestion.
>
> 1 ;*************************************************
> 2
> 3 ;************************************************
> 4 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> 5 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> 6 load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRF_contributed.ncl"
> 7 load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
> 8 begin
> 9 ;************************************************
> 10 ; open file and read in data
> 11 ;************************************************
> 12 f = addfile ("/home/mmittal/CHENNAI/CHEM/WRFOUT/MAY/wrfout_d01_2007-05-03_06:00:00 .nc", "r")
> 13 ;************************************************
> 14 ; Read character variable Times; Convert to string for plots
> 15 ; Read vertical coordinate for plot labels
> 16 ;************************************************
> 17 times = chartostring(f->Times) ; built-in function
> 18 znu = f->ZNU(0,:) ; (Time, bottom_top)
> 19 lat2d = f->XLAT(0,:,:)
> 20 lon2d = f->XLONG(0,:,:)
> 21 U = f->U
> 22 V = f->V
> 23 ;************************************************
> 24 ; U and V are on different grids
> 25 ; determine the size of the "west_east_stag" dimension
> 26 ; determine the size of the "south_north_stag" dimension
> 27 ;************************************************
> 28 dimU = dimsizes(U) ; demo "dimsizes"
> 29 mlonU = dimU(3) ; number of "west_east_stag" longitudes
> 30
> 31 dimV = dimsizes(V)
> 32 nlatV = dimV(2) ; number of "south_north_stag" latitudes
> 33
> 34
> 35
> 36 ;************************************************
> 37 ; Read ozone at all times and levels
> 38 ;************************************************
> 39 x = f->o3 ; (Time, bottom_top, south_north, west_e ast)
> 40 x = x*1000
> 41 x_at_units = "ppbv"
> 42 x_at_description = "O3 concentration"
> 43
> 44 ;************************************************
> 45 ; create plots
> 46 ;************************************************
> 47 ;wks = gsn_open_wks("x11" ,"WRF_po") ; ps,pdf,x11,ncgm,eps
> 48 wks = gsn_open_wks("x11" ,"gsn_vec_scal") ; ps,pdf,x11,ncgm,eps
> 49 ;wks = gsn_open_wks("x11" ,"coneff") ; ps,pdf,x11,ncgm,eps
> 50 gsn_define_colormap(wks,"BlAqGrYeOrReVi200") ; select color map
> 51
> 52 res = True ; plot mods desired
> 53 ; res_at_gsnMaximize = True ; uncomment to maximize size
> 54 res_at_gsnSpreadColors = True ; use full range of colormap
> 55 res_at_cnFillOn = True ; color plot desired
> 56 res_at_cnLinesOn = False ; turn off contour lines
> 57 res_at_cnLineLabelsOn = True ; turn off contour labels
> 58 res_at_lbLabelAutoStride = True ; Control labelbar spacing
> 59 res_at_cnLevelSelectionMode = "ManualLevels"
> 60 res_at_cnMinLevelValF = 25.
> 61 res_at_cnMaxLevelValF = 35.
> 62 res_at_cnLevelSpacingF = 2.
> 63
> 64
> 65 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> 66
> 67 ;************************************************
> 68 ; Use WRF_contributed procedure to set map resources
> 69 ;************************************************
> 70 ; WRF_map_c (f, res, 0)
> 71 ;************************************************
> 72 ; set True for native projection (faster)
> 73 ;************************************************
> 74 res_at_tfDoNDCOverlay = True
> 75 res_at_mpMinLatF = 12.5
> 76 res_at_mpMaxLatF = 13.5
> 77 res_at_mpMinLonF = 79.5
> 78 res_at_mpMaxLonF = 80.5
> 79 ; res_at_tfDoNDCOverlay = False
> 80 x_at_lat2d = lat2d
> 81 x_at_lon2d = lon2d
> 82
> 83
> 84 ;************************************************
> 85 ; Turn on lat / lon labeling
> 86 ;************************************************
> 87 res_at_pmTickMarkDisplayMode = "Always" ; turn on tickmarks
> 88
> 89 ;************************************************
> 90 ; Loop over all times and levels ( uncomment )
> 91 ; Demo: one arbitrarily closen time and level
> 92 ;************************************************
> 93 dimx = dimsizes(x) ; dimensions of x
> 94 ntim = dimx(0) ; number of time steps
> 95 klev = dimx(1) ; number of "bottom_top" levels
> 96
> 97 ; nt = ntim/2 ; arbitrary time
> 98 ; kl = 1 ; " level
> 99 do nt=0,ntim-1 ; uncomment for loop
> 100 do kl=0,1
> 101 u = 0.5*(U(nt,kl,:,0:mlonU-2)+U(nt,kl,:,1:mlonU-1))
> 102 v = 0.5*(V(nt,kl,0:nlatV-2,:)+V(nt,kl,1:nlatV-1,:))
> 103 ;************************************************
> 104 ; associate the 2-dimensional coordinates to the variable for plotting
> 105 ; only if not a native projection [ res_at_tfDoNDCOverlay = False ]
> 106 ;************************************************
> 107 res_at_tiMainString = times(nt)
> 108 res_at_gsnLeftString = x_at_description+" z="+znu(kl)
> 109
> 110 res = True
> 111 if (.not.res_at_tfDoNDCOverlay) then
> 112 lat2d = f->XLAT(0,:,:)
> 113 lon2d = f->XLONG(0,:,:)
> 114
> 58 res_at_lbLabelAutoStride = True ; Control labelbar spacing
> 59 res_at_cnLevelSelectionMode = "ManualLevels"
> 60 res_at_cnMinLevelValF = 25.
> 61 res_at_cnMaxLevelValF = 35.
> 62 res_at_cnLevelSpacingF = 2.
> 63
> 64
> 65 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> 66
> 67 ;************************************************
> 68 ; Use WRF_contributed procedure to set map resources
> 69 ;************************************************
> 70 ; WRF_map_c (f, res, 0)
> 71 ;************************************************
> 72 ; set True for native projection (faster)
> 73 ;************************************************
> 74 res_at_tfDoNDCOverlay = True
> 75 res_at_mpMinLatF = 12.5
> 76 res_at_mpMaxLatF = 13.5
> 77 res_at_mpMinLonF = 79.5
> 78 res_at_mpMaxLonF = 80.5
> 79 ; res_at_tfDoNDCOverlay = False
> 80 x_at_lat2d = lat2d
> 81 x_at_lon2d = lon2d
> 82
> 83
> 84 ;************************************************
> 85 ; Turn on lat / lon labeling
> 86 ;************************************************
> 87 res_at_pmTickMarkDisplayMode = "Always" ; turn on tickmarks
> 88
> 89 ;************************************************
> 90 ; Loop over all times and levels ( uncomment )
> 91 ; Demo: one arbitrarily closen time and level
> 92 ;************************************************
> 93 dimx = dimsizes(x) ; dimensions of x
> 94 ntim = dimx(0) ; number of time steps
> 95 klev = dimx(1) ; number of "bottom_top" levels
> 96
> 97 ; nt = ntim/2 ; arbitrary time
> 98 ; kl = 1 ; " level
> 99 do nt=0,ntim-1 ; uncomment for loop
> 100 do kl=0,1
> 101 u = 0.5*(U(nt,kl,:,0:mlonU-2)+U(nt,kl,:,1:mlonU-1))
> 102 v = 0.5*(V(nt,kl,0:nlatV-2,:)+V(nt,kl,1:nlatV-1,:))
> 103 ;************************************************
> 104 ; associate the 2-dimensional coordinates to the variable for plotting
> 105 ; only if not a native projection [ res_at_tfDoNDCOverlay = False ]
> 106 ;************************************************
> 107 res_at_tiMainString = times(nt)
> 108 res_at_gsnLeftString = x_at_description+" z="+znu(kl)
> 109
> 110 res = True
> 111 if (.not.res_at_tfDoNDCOverlay) then
> 112 lat2d = f->XLAT(0,:,:)
> 113 lon2d = f->XLONG(0,:,:)
> 114
> 115 u_at_lat2d = lat2d
> 116 u_at_lon2d = lon2d
> 117 v_at_lat2d = lat2d
> 118 v_at_lon2d = lon2d
> 119 end if
> 120
> 121
> 122 res_at_vcRefMagnitudeF = 2. ; define vector ref mag
> 123 res_at_vcRefLengthF = 0.0080 ; define length of vec ref
> 124 res_at_vcRefAnnoOrthogonalPosF = -1.0 ; move ref vector
> 125 res_at_vcMinDistanceF = 0.01 ; larger means sparser
> 126 ;res_at_vcLineArrowHeadMaxSizeF = 0.0075 ; default: 0.05 (LineArrow), 0.012 (Cu rlyVector)
> 127 ;res_at_vcGlyphStyle = "LineArrow" ; default: "LineArrow"
> 128
> 129 plot1 = gsn_csm_vector_map(wks,u, v, res)
> 130
> 131
> 132 plot2 = gsn_csm_contour_map(wks,x(nt,kl,:,:),res)
> 133 ; now change the size of the tickmark labels
> 134 res_at_tmXBLabelFontHeightF = 0.02 ; resize tick labels
> 135 res_at_tmYLLabelFontHeightF = 0.02
> 136 ;***********************************************
> 137 overlay(plot2,plot1)
> 138 draw(plot2)
> 139 frame(wks)
> 140 psres =True
> 141 maximize_output(wks,psres)
> 142 end do
> 143 end do
> 144 end
> 145
>
>
>
> Thank you.
>
> Moti Mittal
> Professor, Department of Environment and Occupational Health
> College of Public Health
> University of South Florida
> 13201 Bruce B. Downs Blvd., MDC56
> Tampa, Fl 33612-3805
>
> Tel: (813) 974-9571
> Fax: (813) 974-4986
> Email: mmittal_at_health.usf.edu
> ________________________________________
> From: Dennis Shea [shea_at_ucar.edu]
> Sent: Monday, May 04, 2009 12:35 PM
> To: Mittal, Moti
> Cc: ncl-talk_at_ucar.edu
> Subject: Re: File uv300.nc
>
> At the very top of
>
> http://www.ncl.ucar.edu/Applications/index.shtml
>
> there is a link to downloadable datasets: "example datasets"
> The uv300.nc" is one of the files.
>
> ---
> http://www.ncl.ucar.edu/Document/Manuals/
>
> Click on: Getting Started Using NCL
>
> that will give you some basics.
>
> ---
> I suggest understanding the 'simple' netCDF-based variable model
> used by NCL. A 'picture' is at
>
> http://www.cgd.ucar.edu/~shea/netCDF-varimodel.png
>
> Mittal, Moti wrote:
>> I am trying to learn ncl by following the examples in the Scripts sub directory.
>> In the text*.ncl scripts a file uv300.nc is used. When I replace it with my wrfout file.nc, it does not work.
>> Can I get a sample uv300.nc file?
>>
>> Thank you.
>>
>> Moti
>> Professor, Department of Environment and Occupational Health
>> College of Public Health
>> University of South Florida
>> 13201 Bruce B. Downs Blvd., MDC56
>> Tampa, Fl 33612-3805
>>
>> Tel: (813) 974-9571
>> Fax: (813) 974-4986
>> Email: mmittal_at_health.usf.edu
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
>
> --
> ======================================================
> Dennis J. Shea tel: 303-497-1361 |
> P.O. Box 3000 fax: 303-497-1333 |
> Climate Analysis Section |
> Climate & Global Dynamics Div. |
> National Center for Atmospheric Research |
> Boulder, CO 80307 |
> USA email: shea 'at' ucar.edu |
> ======================================================
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue May 05 2009 - 07:46:21 MDT

This archive was generated by hypermail 2.2.0 : Wed May 06 2009 - 16:48:59 MDT