[ncl-talk] how to plot divergent winds, divergence and velocity potential in one single plot?

Vyankatesh Manoj Mundhada vyankatesh at iiserb.ac.in
Sat Feb 24 02:33:57 MST 2018


Hello,

I am new to NCL and I am trying to plot annual mean climatology for
divergent winds (vectors), divergence (contours (shading)) and velocity
potential (contours (lines)) in a single plot using velocities u and v
only. I am using two input .nc files f1 and f2, where f1 contains u and v
and f2 contains velocity potential.
I am trying to plot divergent velocities over velocity potential using the
following script:

begin
;*************************************************
; open file and read in data: data are on a gaussian grid
;*************************************************
  f1    = addfile ("ERAI_200uvd_1979-2010_new.nc", "r")
  u    = f1->u
  v    = f1->v
  f2    = addfile ("ERAI_200sfvp_1979-2010_new.nc", "r")
  vp    = f2->velopot
;*************************************************
; calculate divergence on a gaussian grid
;*************************************************
  div = uv2dvG_Wrap(u,v)                                        ; u,v ==>
divergence
  div at long_name  = "Divergence"
  div at units      = "s-1"
;*************************************************
; calculate velocity potential
;*************************************************
  ;chi = ilapsG_Wrap ( div , 0)
  chi  = new ( dimsizes(vp), double, vp at _FillValue )
  chi = (/vp/1e4/)                                                 ;
arbitrary scale
  copy_VarCoords(vp, chi )
    ;chi at long_name = "velocity potential"
  ;chi at units     = "m^2/s"
;*************************************************
; calculate divergent wind component
; --
; note: the calculation uses a procedure, so memory
; must be preallocated.
;*************************************************
  ud    = new ( dimsizes(u), double, u at _FillValue )
  vd    = new ( dimsizes(v), double, v at _FillValue )

  dv2uvg(div,ud,vd) ; div  ==> divergent  wind components

  copy_VarCoords(u, ud )
  copy_VarCoords(v, vd )
  ud at long_name  = "Zonal Divergent Wind"
  ud at units      = u at units
  vd at long_name  = "Meridional Divergent Wind"
  vd at units      = v at units

    ;udAve = avg(ud(:,:,:,:))
    ;vdAve = avg(vd(:,:,:,:))
    ;scale    =(/vdAve/udAve/)
    ;ud    =    (/scale*ud/)

    ud = (/ud/1e3/)
    vd = (/vd/1e3/)
    div = (/div*1e3/)

    ;UD = month_to_annual(ud, 1)
    ;VD = month_to_annual(vd, 1)
    ;DIV = month_to_annual(div, 1)
    ;CHI = month_to_annual(chi, 1)

    UDavg    =    dim_avg_n_Wrap(ud, (/0,1/))
    VDavg    =    dim_avg_n_Wrap(vd, (/0,1/))
    DIVavg    =    dim_avg_n_Wrap(div, (/0,1/))
    CHIavg    =    dim_avg_n_Wrap(chi, (/0,1/))
    CHIavg    =    abs(CHIavg)

;*************************************************
; plot results
;*************************************************
  wks  = gsn_open_wks("png","vp_dv_d")             ; send graphics to PNG
file
  ;cmap = read_colormap_file("GMT_polar")
    ;cmap = read_colormap_file("GMT_seis")
    cmap = read_colormap_file("cmp_b2r")
  nc   = dimsizes(cmap(:,0))

    res                          = True
    res at gsnDraw                                 = False
    res at gsnFrame                             = False
    cnres1                                        = res
    cnres2                                        = res
    vcres                                            = res

  cnres1 at cnFillOn           = True               ; color on
  cnres1 at cnLinesOn          = False              ; turn off contour lines
    cnres1 at cnFillPalette      = cmap(:nc-4,:)
    cnres1 at tiMainString       = "Divergent Winds, Divergence and Velocity
Potential"
  cnres1 at cnLevelSelectionMode     = "ManualLevels"    ; manually set the
contour levels with the following 3 resources
  cnres1 at cnMinLevelValF              = -5.                                ;
set the minimum contour level
  cnres1 at cnMaxLevelValF              = 5.                                ;
set the maximum contour level
  cnres1 at cnLevelSpacingF             = 0.5                                ;
set the interval between contours
    cnres1 at lbOrientation           = "vertical"
    cnres1 at lbBoxSeparatorLinesOn = False
    cnres1 at lbTitleString             = div at long_name
    cnres1 at lbTitlePosition        = "Left"
    cnres1 at lbAutoManage             = False
    cnres1 at lbTitleFontHeightF    = 0.012
    ;cnres1 at lbLabelStrings =  (/"-5.0","-2.5","0","2.5","5.0"/)
    cnres1 at mpMinLonF          =   0
  cnres1 at mpMaxLonF          = 360
  cnres1 at mpCenterLonF       = 180     ; This is necessary to get the
correct map
    cnres1 at mpMinLatF          = -80
  cnres1 at mpMaxLatF          = 80

    vcres at vcRefMagnitudeF     = 10.                 ; make vectors larger
  vcres at vcRefLengthF        = 0.05              ; ref vector length
  vcres at vcGlyphStyle        = "CurlyVector"      ; turn on curly vectors
  vcres at vcMinDistanceF      = 0.012              ; thin the vectors
  vcres at vcRefAnnoOrthogonalPosF  = 0        ; Move ref anno into plot
    vcres at vcRefAnnoBackgroundColor = "Background"
    vcres at vcRefAnnoString2On    = False
    ;vcres at vcRefAnnoSide            =    "Left"

  ;cnres2 at gsnCenterString    = "Chi scaled by 1e8"
    cnres2 at cnFillOn                        = False
    cnres2 at cnLinesOn                    = True
    ;cnres2 at mpMinLonF          =   0
  ;cnres2 at mpMaxLonF          = 360
  ;cnres2 at mpCenterLonF       = 180     ; This is necessary to get the
correct map
    cnres2 at trGridType                     = "TriangularMesh"

    plot1 = gsn_csm_vector(wks,UDavg(:,:),VDavg(:,:),vcres)
    plot2    =
gsn_csm_contour_map_overlay(wks,DIVavg(:,:),CHIavg(:,:),cnres1,cnres2)

    overlay(plot2,plot1)

    draw(plot2)
    frame(wks)

end


I am getting the following warning messages:

(0)    check_for_y_lat_coord: Warning: Data either does not contain a valid
latitude coordinate array or doesn't contain one at all.
(0)    A valid latitude coordinate array should have a 'units' attribute
equal to one of the following values:
(0)        'degrees_north' 'degrees-north' 'degree_north' 'degrees north'
'degrees_N' 'Degrees_north' 'degree_N' 'degreeN' 'degreesN' 'deg north'
(0)    check_for_lon_coord: Warning: Data either does not contain a valid
longitude coordinate array or doesn't contain one at all.
(0)    A valid longitude coordinate array should have a 'units' attribute
equal to one of the following values:
(0)        'degrees_east' 'degrees-east' 'degree_east' 'degrees east'
'degrees_E' 'Degrees_east' 'degree_E' 'degreeE' 'degreesE' 'deg east'


and the plot which is attached to this mail. I think I am getting proper
divergence but velocity potential lines are not getting plotted at all and
I feel the direction of winds are also wrong. So please help me to get a
proper plot without error. I am expecting humble reply from your side.

Thanking you,

Vyankatesh Mundhada

On Wed, Feb 21, 2018 at 5:40 PM, Vyankatesh Manoj Mundhada <
vyankatesh at iiserb.ac.in> wrote:

> Thank you very much. That was really helpful.
>
> Regards,
> Vyankatesh
>
> On Wed, Feb 21, 2018 at 4:03 PM, Guido Cioni <guidocioni at gmail.com> wrote:
>
>> Hi,
>> This error usually pops up when you're doing assignment that delete the
>> original attributes of the variable, including the reference to the
>> coordinate variables.
>>
>> I'm just speculating but...could it be this line?
>>
>>     plot1 = gsn_csm_vector_map(wks,0.001*ud(0,0,:,:),0.001*vd(0,0,:,:),v
>> cres)
>>
>> You are doing 0.001*ud(0,0,:,:), so merely assigning a new variable
>> without copying the attributes.
>> You should instead do the scaling first
>>
>> ud=0.001*ud(:,:,:,:) ; here the attributes are preserved
>>
>> and then plot ud(0,0,:,:).
>> Or just a define a new variable based un ud first.
>>
>> Let us know whether that works, that's the first thing that comes to my
>> mind.
>>
>>
>>
>> On 21. Feb 2018, at 10:20, Vyankatesh Manoj Mundhada <
>> vyankatesh at iiserb.ac.in> wrote:
>>
>> 0.001*vd(0,0,:,:)
>>
>>
>>
>> Guido Cioni
>> http://guidocioni.altervista.org
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180224/4e5564fa/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vp_dv_d.png
Type: image/png
Size: 431268 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180224/4e5564fa/attachment-0001.png>


More information about the ncl-talk mailing list