[ncl-talk] difference between using res at tfDoNDCOverlay and @lat2d @lon2d when overlaying wind vectors

xiaoming Hu yuanfangcan at hotmail.com
Wed May 2 11:03:20 MDT 2018


Mary


  Thanks a lot! I thought if I use gsn_csm_vector_map, the map outline will show automatically. Apparently not.

After adding

res at mpFillOn = False
res at mpOutlineOn = True
the map outline shows!

   Yes, if using tfDoNDCOverlay=True case, then the plot is correct, i.e., wind vectors follow pressure gradient.

   Thanks for keeping investigating the issue with CurlyVector  and without "tfDoNDCOverlay=True"!

Cheers!
Xiaoming

________________________________
From: Mary Haley <haley at ucar.edu>
Sent: Tuesday, May 1, 2018 4:46 PM
To: xiaoming Hu
Cc: ncl-talk; Xiaoming Hu
Subject: Re: difference between using res at tfDoNDCOverlay and @lat2d @lon2d when overlaying wind vectors

Xiaoming,

Regarding the curly vectors, I'm sorry I didn't test this first.  You're right in that it doesn't seem to have any effect.

I'm not sure if this is a bug or not, but I will file a ticket on it. Meanwhile, if you use tfDoNDCOverlay=True case, then the plot is correct, right?

As for the map outline, I'm not sure what you mean about not seeing it. The map is the area that is filled in light gray.  If you just want the map to be outlined and not filled in gray, then set:

res at mpFillOn = False
res at mpOutlineOn = True

You may also need to set mpOutlineBoundarySets, mpDataBaseVersion, and/or mpDataSetName if you want more control over what outlines to see.

You can visit our "maps only" page to see what these various resources do:

http://www.ncl.ucar.edu/Applications/maponly.shtml

--Mary


On Fri, Apr 27, 2018 at 4:19 PM, xiaoming Hu <yuanfangcan at hotmail.com<mailto:yuanfangcan at hotmail.com>> wrote:

Mary

  Thanks a lot for taking your time and your clear explanation!  "res at vcMapDirection=False" indeed made the difference for res at vcGlyphStyle="FillArrow"

   But if I use "CurlyVector",       "res at vcMapDirection = False" doesn't make difference.

See figure below, CurlyVector still appears incorrect.

I pasted my NCl below.

BTW: why the map did not show up?

Thanks a lot!

Xiaoming

[cid:399c97bf-60d0-4aa7-9d16-71b5940896b7]

[cid:983ba056-4968-4477-abe8-b7f11914001e]

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"

begin
  if(.not.isvar("ndc_overlay")) then
    ndc_overlay = False
  end if

  if(.not.isvar("map_direction")) then
    map_direction = False
  end if

;----------------------------------------------------------------------
; Get the data. You can set the filename on the command line, if
; desired:
;  ncl 'filename="wrfout_d01_2003-07-13_12:00:00"' wrf_vectors.ncl
;----------------------------------------------------------------------
  if(.not.isvar("filename")) then
    filename = "wrfout_d01_2011-08-08_12:00:00"
  end if
  print("==================================================")
  print("file: " + filename)
  f = addfile(filename+".nc","r")

  u     = wrf_user_getvar(f,"ua",0)
  v     = wrf_user_getvar(f,"va",0)
  pf    = wrf_user_getvar(f,"pressure",0) ; Full model pressure [hPa]
    geoHeight = ( f->PH(0,:,:,:) + f->PHB(0,:,:,:) ) / 9.81
    dim = dimsizes(geoHeight)
    geoHeight_nonstag = (geoHeight(0:dim(0)-2,:,:)+geoHeight(1:dim(0)-1,:,:))/2
      geoHeight_950 = wrf_interp_3d_z(geoHeight_nonstag,pf,950.)

  u_950 = wrf_interp_3d_z(u,pf,950.)
  v_950 = wrf_interp_3d_z(v,pf,950.)
  lat2d = f->XLAT(0,:,:)
  lon2d = f->XLONG(0,:,:)

  nlat = dimsizes(lat2d(:,0))
  nlon = dimsizes(lat2d(0,:))
  min_lat_diff = abs(min(lat2d(1,:)-lat2d(0,:)))
  min_lon_diff = abs(min(lon2d(:,1)-lon2d(0,0)))
  max_lat_diff = min_lat_diff
  max_lon_diff = min_lon_diff
  do n=2,nlat-1
    min_lat_diff = abs(min((/min_lat_diff,min(lat2d(n,:)-lat2d(n-1,:))/)))
    max_lat_diff = abs(max((/max_lat_diff,max(lat2d(n,:)-lat2d(n-1,:))/)))
  end do
  do n=2,nlon-1
    min_lon_diff = abs(min((/min_lon_diff,min(lon2d(:,n)-lon2d(:,n-1))/)))
    max_lon_diff = abs(max((/max_lon_diff,max(lon2d(:,n)-lon2d(:,n-1))/)))
  end do
  print("min lat diff = " + min_lat_diff)
  print("max lat diff = " + max_lat_diff)
  print("min lon diff = " + min_lon_diff)
  print("max lon diff = " + max_lon_diff)
;  printMinMax(u_950,0)
;  printMinMax(v_950,0)

;----------------------------------------------------------------------
; Set the plotting options
;----------------------------------------------------------------------
  res                         = True
  res at gsnMaximize             = True
  res at gsnAddCyclic            = False          ; don't add a longitude cyclic point

  res at tfDoNDCOverlay          = ndc_overlay    ; True / False

  res at pmTickMarkDisplayMode   = "Always"       ; turn on nice tickmarks

  res at vcMapDirection          = map_direction  ; True / False
  res at vcRefMagnitudeF         = 8.             ; define vector ref mag
  res at vcRefLengthF            = 0.025          ; define length of vec ref
  res at vcMinDistanceF          = 0.02           ; larger means sparser
  res at vcFillArrowEdgeColor    = "black"
  res at vcFillArrowEdgeThicknessF = .25
  res at vcGlyphStyle            = "FillArrow"
  res at gsnScalarContour      = True               ; contours desired
  res at cnFillOn              = True             ; color plot desired
  res at cnLinesOn             = False            ; turn off contour lines
  res at cnLineLabelsOn        = False            ; turn off contour labels
  res at cnLevelSelectionMode  = "ManualLevels"
  res at cnLevelSpacingF   = 5
  res at cnMaxLevelValF        = 585+10
  res at cnMinLevelValF       =  530
  res at lbLabelStride         = 4
;  res at gsnLeftString="GeoHeight at 950mb"

  res = wrf_map_resources(f, res)

  if(.not.ndc_overlay) then
    u_950 at lat2d = lat2d
    u_950 at lon2d = lon2d
    v_950 at lat2d = lat2d
    v_950 at lon2d = lon2d
   geoHeight_950 at lat2d = lat2d
   geoHeight_950 at lon2d = lon2d
;  n_cutoff = 150
;  res at mpLeftCornerLonF = lon2d(0,n_cutoff)
;  res at mpLeftCornerLatF = lat2d(0,n_cutoff)

  end if

  res at tiMainString   = "FillArrow"
  res at gsnLeftString  = "tfDoNDCOverlay=" + ndc_overlay
  res at gsnRightString = "vcMapDirection=" + map_direction

  figurename = str_sub_str(filename,":","_")

;----------------------------------------------------------------------
; Create the plot
;----------------------------------------------------------------------
  wks = gsn_open_wks("png",figurename + "_ndc_" + ndc_overlay + "_mapdir_" + map_direction+"_vcGlyphStyle_FillArrow")
;  vector_plot  = gsn_csm_vector_map(wks,u_950,v_950,res)
 plot                 = gsn_csm_vector_scalar_map(wks,u_950,v_950,geoHeight_950,res)

end




________________________________
From: Mary Haley <haley at ucar.edu<mailto:haley at ucar.edu>>
Sent: Friday, April 27, 2018 2:34 PM
To: xiaoming Hu
Cc: ncl-talk; Xiaoming Hu
Subject: Re: difference between using res at tfDoNDCOverlay and @lat2d @lon2d when overlaying wind vectors

Xiaoming,

I finally had a chance to look at this.

I first took your script and reduced it to just create a basic line vector plot, because I wanted to make sure there were no extraneous resources being set that could be the source of the problem.

Long story short: if you set tfDoNDCOverlay=False and use the special lat2d/lon2d attributes to create the plot, then you also need to set:

  res at vcMapDirection = False

See the attached wrf_vectors.ncl (which I will make an official example on the WRF examples page somewhere).

This script allows you to try different combinations of vcMapDirection and tfDoNDCOverlay in one script so you can compare the images. You can also plug in other WRF output files and it should work.

To try different combinations of these two resources setting, set ndc_overlay and/or map_direction to True / False on the NCL command line. For example:

ncl map_direction=False ndc_overlay=True wrf_vectors.ncl
ncl map_direction=False ndc_overlay=False wrf_vectors.ncl
ncl map_direction=True ndc_overlay=True wrf_vectors.ncl
ncl map_direction=True ndc_overlay=False wrf_vectors.ncl

For the case of map_direction = True (vcMapDirection) and ndc_overlay = False (tfDoNDCOverlay), the vectors are slightly shifted (and incorrect as you pointed out).

For the other three combinations of these two settings, the vector plots are the same. I've attached all four PNGs to this email.

I have to admit that the vcMapDirection resource is a bit of a mystery to me as to when it should be True or False.  It is documented on the vectors resource page<http://www.ncl.ucar.edu/Document/Graphics/Resources/vc.shtml#vcMapDirection>:

vcMapDirection
This resource controls whether the vector direction is mapped into the same coordinate space as the vector location, or whether it is rendered in a locally uniform cartesian coordinate space. This resource has an effect whenever a non-uniform transformation is in effect. These include most of the MapTransformation transformations and IrregularTransformation transformations. Also included are logarithmic transformations provided by the LogLinTransformation and even linear transformations when the X and Y unit sizes are different.
Default: True


If you look at our vectors examples page (which I just updated):

http://www.ncl.ucar.edu/Applications/vector.shtml

it talks about the vcMapDirection resource and how it must be set to False if the latitude spacings are very different from the longitude spacings. With your data, the latitude spacings vary from 0.097 to 0.11, whereas the longitude spacings vary from 0.1 to 11.0. This is enough of a difference that vcMapDirection needs to be set to False.

As an extra test, I asked Bill Ladwig to plot this same data using a Python script that uses PyNIO to read in the data and matplotlib to plot it. I've attached the Python script and the wrf_quiver.png file so you can compare.

To learn more about wrf-python, see:

http://wrf-python.readthedocs.io/en/latest/

Thanks for your patience.

--Mary



On Fri, Apr 20, 2018 at 1:47 PM, xiaoming Hu <yuanfangcan at hotmail.com<mailto:yuanfangcan at hotmail.com>> wrote:

Realized ncl scripts are not attached in previous email.  Here again!


 Thanks a lot for helping on this!

 Now I changed to  NCl 6.3.0 and used wrf_map_resources and added res at gsnAddCyclic = False

 But I still did not make the case of tfDoNDCOverlay not being set    to be consistent with  the case of tfDoNDCOverlay setting to True

 I attached 2 cleaned script

 with plot_geoHeight950mb_combine2episodes_with_ndc_overlay.ncl I got:


with plot_geoHeight950mb_combine2episodes_without_ndc_overlay.ncl, I got:


The previous issue still exists, plus the map is gone. :)

See the difference between the 2 scripts:

< ;  res at tfDoNDCOverlay       = True
<   res at tfDoNDCOverlay       = False
---
>   res at tfDoNDCOverlay       = True
> ;  res at tfDoNDCOverlay       = False
134,140d132
<    u_950 at lat2d = lat2d
<    u_950 at lon2d = lon2d
<    v_950 at lat2d = lat2d
<    v_950 at lon2d = lon2d
<    geoHeight_950 at lat2d = lat2d
<    geoHeight_950 at lon2d = lon2d
<
146,147c138,139
< ;    plot                 = gsn_csm_vector_scalar_map(wks,u_950(:,n_cutoff:),v_950(:,n_cutoff:),geoHeight_950(:,n_cutoff:),res)
<     plot                 = gsn_csm_vector_scalar_map(wks,u_950,v_950,geoHeight_950,res)
---
>     plot                 = gsn_csm_vector_scalar_map(wks,u_950(:,n_cutoff:),v_950(:,n_cutoff:),geoHeight_950(:,n_cutoff:),res)
> ;    plot                 = gsn_csm_vector_scalar_map(wks,u_950,v_950,geoHeight_950,res)

Did I miss anything?


  I put the data (1.9G) at

 http://www.caps.ou.edu/micronet/HurricaneImpactonO3/WRFV3.9.1/YSU/wrfchem3.9.1_ERA2d_CONUS_NLCD_NEI2011_MEGAN_nudge2.2011082500/wrfout_d01_2011-08-08_12:00:00


Thanks a lot!

Xiaoming

________________________________
From: Mary Haley <haley at ucar.edu<mailto:haley at ucar.edu>>
Sent: Wednesday, April 18, 2018 7:18:48 PM
To: xiaoming Hu
Cc: ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>; Xiaoming Hu
Subject: Re: [ncl-talk] difference between using res at tfDoNDCOverlay and @lat2d @lon2d when overlaying wind vectors

Xiaoming,

You have an out-dated function call (WRF_map_c) that might possibly be the source of the problem. This is a deprecated function and you should use wrf_map_resources to set your WRF map projection instead:

http://www.ncl.ucar.edu/Document/Functions/WRF_arw/wrf_map_resources.shtml
wrf_map_resources - CISL's NCAR Command Language (NCL)<http://www.ncl.ucar.edu/Document/Functions/WRF_arw/wrf_map_resources.shtml>
www.ncl.ucar.edu<http://www.ncl.ucar.edu>
NCL Home > Documentation > Functions > WRF, Graphics routines wrf_map_resources. Sets map plotting resources based on an input WRF-ARW file. Available in version 6.1.0 and later.



I can't tell from your code why the two results are different, because it's not clear to me if the only thing you are changing is whether or not tfDoNDCOverlay is set.

If I'm understanding your email correctly, it sounds like the plot that is created when tfDoNDCOverlay is set to True is the one that's correct. However, I'm surprised it's working for you because:

[1] If you set tfDoNDCOverlay to True, you should NOT attach any lat2d/lon2d attributes to your data variables.

[2] Also, if tfDoNDCOverlay is True, you must be using the EXACT map projection that was defined on the file.  But, you are using WRF_map_c which hasn't been updated in years, so this function could likely be giving you wrong results. Also, you are setting:

  n_cutoff = 150
  res at mpLeftCornerLonF = lon2d(0,n_cutoff)
  res at mpLeftCornerLatF = lat2d(0,n_cutoff)

which looks to me like you are zooming in on the map, but you haven't also zoomed in on the data in the same way, so again, I don't know how your plots can be correct.

[3] For the case of tfDoNDCOverlay not being set, you may need to set res at gsnAddCyclic = False to prevent a longitude cyclic point from being added.

Please visit this WRF examples page, which has examples of plotting WRF data with both tfDoNDCOverlay set and without it set:

http://www.ncl.ucar.edu/Applications/wrfgsn.shtml

I've attached two modified versions of your script. Since I don't have the data, I am unable to test these scripts. But, hopefully they help show the difference between these two scenarios.

If you continue to have problems with this, please post back to ncl-talk, but include a clean, updated script if possible.

Good luck,

--Mary







On Tue, Apr 17, 2018 at 11:04 PM, xiaoming Hu <yuanfangcan at hotmail.com<mailto:yuanfangcan at hotmail.com>> wrote:

Hello


 If I use res at tfDoNDCOverlay  I got the figure of


But If I use @lat2d @lon2d without res at tfDoNDCOverlay  I got


The wind vectors near the right edge in the left panel do not follow the pressure lines now.


Any comments on overlaying wind vectors using res at tfDoNDCOverlay    or using @lat2d @lon2d without res at tfDoNDCOverlay ?

I attached my ncl script

Thanks

Xiaoming


_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180502/99a372c7/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedImage.png
Type: image/png
Size: 140036 bytes
Desc: pastedImage.png
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180502/99a372c7/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedImage.png
Type: image/png
Size: 151930 bytes
Desc: pastedImage.png
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180502/99a372c7/attachment-0003.png>


More information about the ncl-talk mailing list