Sie sind hier: Startseite / Services / Data Analysis and Visualization / Visualization / Software / NCL / examples / source_code / DKRZ NCL Workshop: vectors
Info
Alle Inhalte des Nutzerportal sind nur auf Englisch verfügbar.

DKRZ NCL Workshop: vectors

All vector exercises from the DKRZ NCL Workshop. Requirement: NCL version 6.2.0 and higher

 

1. Simple vector plot:

begin

   f   =  addfile("$NCL_TUT/data/ECHAM5_OM_A1B_2001_0101-1001_2D.nc","r")
   u   =  f->u10(0,:,:)         		;-- u-velocity, first time step
   v   =  f->v10(0,:,:)         		;-- v-velocity, first time step

;-- define the workstation (graphic will be written to a file)
   wks =  gsn_open_wks("png","part_III_simple_vectors")

;-- set resources
   res               =  True                ;-- create plot resource object
   res@tiMainString  = "Simple vector plot" ;-- draw a title on top of the plot

;-- create the plot
   plot = gsn_csm_vector_map_ce(wks,u,v,res)

end 

 

2. Vector plot settings:

begin

   f   =  addfile("$NCL_TUT/data/ECHAM5_OM_A1B_2001_0101-1001_2D.nc","r")
   u   =  f->u10(0,:,:)         		;-- u-velocity, first time step
   v   =  f->v10(0,:,:)         		;-- v-velocity, first time step

;-- define the workstation (graphic will be written to a file)
   wks =  gsn_open_wks("png","part_III_vector_settings")

;-- set resources
   res                  =  True          ;-- create plot resource object
   res@tiMainString     = "Vector plot settings" ;-- draw a title on top of the plot

   res@vcRefMagnitudeF  =  5.            ;-- make vectors larger
   res@vcRefLengthF     =  0.02          ;-- ref vec length
   res@vcMinDistanceF   =  0.01          ;-- thin out vectors

;-- create the plot
   plot = gsn_csm_vector_map_ce(wks,u,v,res)

;-- set vector style
   res@vcGlyphStyle     = "CurlyVector"  ;-- turn on curly vectors

;-- create the second plot
   plot = gsn_csm_vector_map_ce(wks,u,v,res)

end 

 

3. Set vector color and land/ocean color:

begin

   f   =  addfile("$NCL_TUT/data/ECHAM5_OM_A1B_2001_0101-1001_2D.nc","r")
   u   =  f->u10(0,:,:)         		;-- u-velocity, first time step
   v   =  f->v10(0,:,:)         		;-- v-velocity, first time step

;-- define the workstation (graphic will be written to a file)
   wks =  gsn_open_wks("png","part_III_vector_colorize")

;-- set resources
   res                           =  True             ;-- create plot resource object
   res@tiMainString              = "Vector plot colorize" ;-- draw a title on top of the plot

;-- vector resources
   res@vcMinDistanceF            =  0.01             ;-- thin out vectors
   res@vcGlyphStyle              = "CurlyVector"     ;-- turn on curly vectors
   res@vcLineArrowColor          = "white"           ;-- change vector color to white
   res@vcLineArrowThicknessF     =  2.0              ;-- change vector thickness
   res@vcRefMagnitudeF           =  5.               ;-- make vectors larger
   res@vcRefLengthF              =  0.025            ;-- ref vector length
   res@vcRefAnnoArrowUseVecColor =  False            ;-- don't use vcLineArrowColor for ref
;   res@vcRefAnnoOrthogonalPosF   = -1.0             ;-- move ref vector upper right edge

;-- map resources
   res@mpOutlineOn               =  True             ;-- draw coastlines
   res@mpLandFillColor           = "AntiqueWhite2"   ;-- fill land areas with color
   res@mpOceanFillColor          = "lightblue"       ;-- fill ocean areas with color
   res@mpInlandWaterFillColor    = "lightblue"       ;-- fill inland water areas with color

;-- create the plot
   plot = gsn_csm_vector_map_ce(wks,u,v,res)

end 

 

 4. Vector plot colorized by temperature variable:

 begin

   f =  addfile("$NCL_TUT/data/ECHAM5_OM_A1B_2001_0101-1001_2D.nc","r")
   u =  f->u10(0,:,:)            ;-- u-velocity, first time step
   v =  f->v10(0,:,:)            ;-- v-velocity, first time step
   t =  f->tsurf(0,:,:)          ;-- surface temperature

;-- define the workstation (graphic will be written to a file)
   wks =  gsn_open_wks("png","part_III_vector_colorize_temp")

;-- set resources
   res                           =  True             ;-- create plot resource object
   res@tiMainString              = "Vector plot colorized by surface temperature" ;-- draw a title

;-- vector resources
   res@vcGlyphStyle              = "CurlyVector"     ;-- turn on curly vectors
   res@vcLineArrowThicknessF     =  2.0              ;-- change vector thickness
   res@vcRefAnnoArrowUseVecColor =  False            ;-- don't use vcLineArrowColor for ref
;   res@vcRefAnnoOrthogonalPosF   = -1.0             ;-- move ref vector upper right edge
   res@vcRefMagnitudeF           =  5.               ;-- make vectors larger
   res@vcRefLengthF              =  0.025            ;-- ref vector length
   res@vcMinDistanceF            =  0.01             ;-- thin out vectors

;-- map resources
   res@mpOutlineOn               =  True             ;-- draw coastlines
   res@mpLandFillColor           = "DarkGreen"       ;-- fill land areas with color
   res@mpOceanFillColor          = "midnightblue"            ;-- fill ocean areas with color
   res@mpInlandWaterFillColor    = "midnightblue"            ;-- fill inland water areas with color

   res@lbBoxMinorExtentF         =  0.15             ;-- decrease the height of the labelbar
   res@pmLabelBarOrthogonalPosF  = -0.2              ;-- move the labelbar up

;-- create the plot; using scalar variable t to colorize the vectors
   plot = gsn_csm_vector_scalar_map_ce(wks,u,v,t,res)

   res@mpLandFillColor           = "AntiqueWhite2"   ;-- fill land areas with color
   res@mpOceanFillColor          = "lightblue"       ;-- fill ocean areas with color
   res@mpInlandWaterFillColor    = "lightblue"       ;-- fill inland water areas with color

;-- create a second plot, but use other colors for land and water
   plot = gsn_csm_vector_scalar_map_ce(wks,u,v,t,res)

end 

 

5. Vector plot overlayed by contour plot:

begin

   f   =  addfile("$NCL_TUT/data/ECHAM5_OM_A1B_2001_0101-1001_2D.nc","r")
   u   =  f->u10(0,:,:)                         ;-- first time step
   v   =  f->v10(0,:,:)                         ;-- first time step
   t   =  f->tsurf(0,:,:)                       ;-- first time step

;-- define the workstation (graphic will be written to a file)

   wks =  gsn_open_wks("png","part_III_vector_colorize_overlay")
   gsn_define_colormap(wks,"ncl_default")       ;-- choose color map

;-- set plot resources
   cnres                     =  True            ;-- contour resources
   cnres@gsnDraw             =  False           ;-- don't draw plot, yet
   cnres@gsnFrame            =  False           ;-- don't advance frame
   cnres@gsnLeftString       =  t@long_name     ;-- change left string
   cnres@gsnRightString      =  t@units         ;-- change right string

   cnres@tiMainString        = "Overlay vectors on surface temperature contour plot"

   cnres@cnFillOn            =  True            ;-- turn on fill colors
   cnres@cnLinesOn           =  False           ;-- don't draw contour lines

   cnres@mpFillOn            =  False           ;-- turn off map fill

;-- set the vector resources
   vcres                     =  True            ;-- vector resources
   vcres@gsnDraw             =  False           ;-- don't draw vector plot, yet
   vcres@gsnFrame            =  False           ;-- don't advance frame
   vcres@gsnRightString      = " "              ;-- no right string
   vcres@gsnLeftString       = " "              ;-- no left string
   vcres@tiXAxisString       = " "              ;-- don't draw x-axis labels

   vcres@vcGlyphStyle        = "CurlyVector"    ;-- use curly vectors
   vcres@vcRefMagnitudeF     =  20              ;-- define vector reference magnitude
   vcres@vcRefLengthF        =  0.045           ;-- define length of reference vector
   vcres@vcRefAnnoOrthogonalPosF =  -1.36        ;-- move reference vector into plot
   vcres@vcRefAnnoString2On  =  False

;-- create the plots, but don't draw them
   cont_plot  = gsn_csm_contour_map_ce(wks,t,cnres)
   vec_plot   = gsn_csm_vector(wks,u,v,vcres)

;-- overlay vec_plot on cont_plot, but don't draw them
   overlay(cont_plot, vec_plot)

;-- now, draw the plot and advance frame
   draw(cont_plot)
   frame(wks)

end 

 

 

 

Artikelaktionen