# Re: draw simple vector field

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Thu Mar 14 2013 - 15:07:28 MDT

Hi Yann,

The DIR field you refer (in newer versions of NCL it would be called SWDIR described as "Direction of swell waves") is in degrees. The vector plotting functions of NCL expect U and V components normally representing velocity in the east direction and velocity in the north direction. These quantities can be derived from direction and magnitude. You have a direction field but you do not seem to have a magnitude field. Perhaps you have another variable in your file that could be used for magnitude. Otherwise you could just assume a constant magnitude of, for example, 1.0. You will need to determine for yourself what the direction 0 degrees in your data represents, since "Degree True" as units does not tell us. It would probably be north or east.

d2r = atan(1) / 45 ; degrees to radians conversion constant

dir3d = fin->DIR
dir = dir3d(0,:,:)

; if 0 degrees is north then change it such that 0 degrees represents east
; dir = dir + 90
;

; if you have a mag field with the same dimensions as dir then
; u = mag * cos(dir * d2r)
; v = mag * sin (dir * d2r)
;
; otherwise assume magnitude of 1 everywhere
;

u = cos(dir * d2r)
v = sin (dir * d2r)

u!0 = "lat"
u!1 = "lon"
v!0 = "lat"
v!1 = "lon"
u&lat = f->lat_0 ; or dir&lat_0
u&lon = f->lon_0 ; etc.
v&lat = f->lat_0
v&lon = f->lon_0

...
plot = gsn_csm_vector_map(wks,u,v,res)

If you want to use gsn_csm_vector_scalar then you need a scalar field with the same dimensionality as dir, u, and v for the additional parameter.

This is untested but hopefully gets you started.
-dave

On Mar 14, 2013, at 2:30 AM, Yann Bertrand wrote:

>
>
> Hi,
> i try to draw a vector field :
> but i don't know how to get u and v (2-dimension)
> and the direction (which is the main information i want to get.
> Here's a piece of code.
> Thanks in advance.
>
> ncl_filedump gives :
>
> float DIR ( lv_OSEQD0, lat_0, lon_0 )
> center : US National Weather Service - NCEP (WMC)
> production_status : Operational products
> units : Degree True
> _FillValue : 1e+20
> grid_type : Latitude/longitude
> parameter_template_discipline_category_number : ( 0, 10, 0, 7 )
> level_type : Ordered Sequence of Data
> forecast_time : 96
> forecast_time_units : hours
>
>
> what i've tried :
>
> outfile="out"
> grib_file="grib.grib2"
> fin = addfile(grib_file,"r")
>
> ; get variable:
>
> dir3d = fin->DIR
> dir = dir3d(0,:,:)
>
> wks = gsn_open_wks("ps",outfile) ; open wk station
>
> res = True
>
> res@vcGlyphStyle = "LineArrow"
>
> res@mpLimitMode="latlon"
> res@mpMinLonF = -33
> res@mpMaxLonF = 2
> res@mpMinLatF = 21
> res@mpMaxLatF = 37
>
> res@mpProjection = "LambertConformal"
>
> plot = gsn_csm_vector_scalar(wks, dir(:,:), dir(:,:), dir3d(:,0,0), res)
>
>
>
> _______________________________________________
> 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 Thu Mar 14 15:07:36 2013

This archive was generated by hypermail 2.1.8 : Tue Mar 19 2013 - 16:31:18 MDT