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

DKRZ NCL Workshop: animations

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

 

1. Time animation of a contour plot:

undef ("getDate")
function getDate(time)
local utc_date, year, mon, day, hours, mins, str_date
begin
   utc_date   = cd_calendar(time, 0)                        ;-- convert date to UT-referenced date
   year       = sprinti("%0.4i",tointeger(utc_date(:,0)))   ;-- get year as integer value
   mon        = sprinti("%0.2i",tointeger(utc_date(:,1)))   ;-- get month as integer value
   day        = sprinti("%0.2i",tointeger(utc_date(:,2)))   ;-- get day as integer value
   hours      = sprinti("%0.2i",tointeger(utc_date(:,3)))   ;-- get day as integer value
   mins       = sprinti("%0.2i",tointeger(utc_date(:,4)))   ;-- get day as integer value
   str_date   = year+"/"+mon+"/"+day+" "+hours+":"+mins     ;-- yyyy/mm/dd HH:MM
   return(str_date)
end

;-----------------------------------------------------
;-- main script
;-----------------------------------------------------

begin
  f     = addfile("$NCL_TUT/data/ECHAM5_OM_A1B_2001_0101-1001_2D.nc","r")
  temp  = f->tsurf                                 ;-- temperature data 1st time step
  time  = f->time                                  ;-- time values

;-- open a workstation
  wks_type                 = "png"                  ;-- plot output type
  wks = gsn_open_wks(wks_type,"part_VIII_animation_contour_map")

;-- set resources
  res = True
  res@gsnMaximize          =  True                  ;-- maximize plot output
  res@gsnAddCyclic         =  False                 ;-- don't add cyclic point
  res@gsnRightString       = ""                     ;-- don't draw right string
  res@gsnLeftString        = ""                     ;-- don't draw left string

  res@cnFillPalette        = "BlueWhiteOrangeRed"   ;-- choose color map
  res@cnLevelSelectionMode = "ManualLevels"         ;-- use manual contour line levels
  res@cnMinLevelValF       =  250.0                 ;-- contour min. value
  res@cnMaxLevelValF       =  300.0                 ;-- contour max. value
  res@cnLevelSpacingF      =  1.0                   ;-- contour interval
  res@cnFillOn             =  True                  ;-- enable color fill
  res@cnLinesOn            =  False                 ;-- disable contour lines
  res@cnFillMode           = "RasterFill"           ;-- set fill mode
  res@cnRasterSmoothingOn  =  True                  ;-- smooth contouring

  res@lbBoxLinesOn         =  False                 ;-- no lines around labelbar boxes

  res@mpDataBaseVersion    = "MediumRes"            ;-- set map data base
  res@mpMinLonF            = -10.6                  ;-- lon min. value
  res@mpMinLatF            =  36.8                  ;-- lat min. value
  res@mpMaxLonF            =  34.6                  ;-- lon max. value
  res@mpMaxLatF            =  69.8                  ;-- lat max. value

;  res@tiMainFont           =  29                    ;-- set title font to "Courier"
  res@tiMainFontHeightF    =  0.02                  ;-- main title font size
  res@tiMainOffsetYF       =  0.06                  ;-- move title upward

;-- create plots, loop along time
  ntimes = dimsizes(time)
  do i=0,ntimes-1
     res@tiMainString      = "Surface Temperature~F29~~Z70~            " + getDate(time(i)) + "~N~" ;-- draw title
     plot = gsn_csm_contour_map(wks,temp(i,:,:),res)   ;-- create the plots
    print("Plot time:  "+i+"  "+getDate((time(i))))
  end do

;-- if wks_type = "ps": make sure that the PS file is closed
  delete(wks)

;-- convert the plot output from PNG to Animated GIF
  print("Converting to GIF....")
  system("convert -delay 75 part_VIII_animation_contour_map*.png part_VIII_animation_contour_map.gif")
  system("rm -rf part_VIII_animation_contour_map.*.png")
  
end

 

2. Time animation of vectors on contour plot:

undef ("getDate")
function getDate(time)
local utc_date, year, mon, day, hours, mins, str_date
begin
   utc_date   = cd_calendar(time, 0)                        ;-- convert date to UT-referenced date
   year       = sprinti("%0.4i",tointeger(utc_date(:,0)))   ;-- get year as integer value
   mon        = sprinti("%0.2i",tointeger(utc_date(:,1)))   ;-- get month as integer value
   day        = sprinti("%0.2i",tointeger(utc_date(:,2)))   ;-- get day as integer value
   hours      = sprinti("%0.2i",tointeger(utc_date(:,3)))   ;-- get day as integer value
   mins       = sprinti("%0.2i",tointeger(utc_date(:,4)))   ;-- get day as integer value
   str_date   = year+"/"+mon+"/"+day+" "+hours+":"+mins     ;-- yyyy/mm/dd HH:MM
   return(str_date)
end

;-----------------------------------------------------
;-- main script
;-----------------------------------------------------

begin
  f     = addfile("$NCL_TUT/data/ECHAM5_OM_A1B_2001_0101-1001_2D.nc","r")
  temp  = f->tsurf                                 ;-- temperature data
  u     = f->u10                                   ;-- 10m u-velocity
  v     = f->v10                                   ;-- 10m v-velocity
  time  = f->time                                  ;-- time values

;-- open a workstation
  wks_type                 = "png"                  ;-- plot output type
  wks = gsn_open_wks(wks_type,"part_VIII_animation_simple_vector_contour_map")

;-- set resources
  res = True
  res@gsnMaximize          =  True                  ;-- maximize plot output
  res@gsnAddCyclic         =  False                 ;-- don't add cyclic point
  res@gsnRightString       = ""                     ;-- don't draw right string
  res@gsnLeftString        = ""                     ;-- don't draw left string
  res@gsnScalarContour     =  True                  ;-- must be set for overlay vectors on contour map

  res@cnFillPalette        = "BlueWhiteOrangeRed"   ;-- choose color map
  res@cnLevelSelectionMode = "ManualLevels"         ;-- use manual contour line levels
  res@cnMinLevelValF       =  250.0                 ;-- contour min. value
  res@cnMaxLevelValF       =  300.0                 ;-- contour max. value
  res@cnLevelSpacingF      =  1.0                   ;-- contour interval
  res@cnFillOn             =  True                  ;-- enable color fill
  res@cnLinesOn            =  False                 ;-- disable contour lines
  res@cnFillMode           = "RasterFill"           ;-- set fill mode
  res@cnRasterSmoothingOn  =  True                  ;-- smooth contouring
  res@cnLabelBarEndStyle   = "ExcludeOuterBoxes"    ;-- don't draw outer boxes

  res@lbBoxMinorExtentF    =  0.2                   ;-- decrease height of labelbar boxes
  res@lbBoxLinesOn         =  False                 ;-- no lines around labelbar boxes
  res@lbTitleString        =  temp@long_name+" ["+temp@units+"]" ;-- labelbar title
  res@lbTitlePosition      =  "Bottom"              ;-- labelbar title position
  res@lbTitleFontHeightF   =  0.015                 ;-- labelbar title font size
  res@lbBottomMarginF      =  0.1                   ;-- move the labelbar title up
  
  res@mpDataBaseVersion    = "MediumRes"            ;-- set map data base
  res@mpMinLonF            = -10.6                  ;-- lon min. value
  res@mpMinLatF            =  36.8                  ;-- lat min. value
  res@mpMaxLonF            =  34.6                  ;-- lon max. value
  res@mpMaxLatF            =  69.8                  ;-- lat max. value

  res@vcLineArrowColor     = "grey30"               ;-- streamline color
  res@vcGlyphStyle         = "CurlyVector"          ;-- curly vectors
  res@vcRefMagnitudeF      =  10                    ;-- define vector ref mag 
  res@vcRefLengthF         =  0.045                 ;-- define length of vec ref
  res@vcRefAnnoOrthogonalPosF = -0.124              ;-- move ref vec into plot
  res@vcRefAnnoParallelPosF = 0.999                 ;-- move ref vec to the right into plot
  res@vcLineArrowThicknessF = 2.0                   ;-- make vector lines thicker
  
  res@tiMainFontHeightF    =  0.02                  ;-- main title font size
  res@tiMainOffsetYF       =  0.06                  ;-- move title upward

;-- create plots, loop along time
  ntimes = dimsizes(time)
  do i=0,ntimes-1
     res@tiMainString      = "Horizontal wind field~F29~~Z70~            " + getDate(time(i)) + "~N~~C~~Z60~[m/s] ~N~" ;-- draw title
     plot  = gsn_csm_vector_scalar_map(wks,u(i,:,:),v(i,:,:),temp(i,:,:),res)   ;-- vectors on contours map 
    print("Plot time:  "+i+"  "+getDate((time(i))))
  end do

;-- if wks_type = "ps": make sure that the PS file is closed
  delete(wks)

;-- convert the plot output from PNG to Animated GIF
  print("Converting to GIF....")
  system("convert -delay 50 part_VIII_animation_simple_vector_contour_map*.png part_VIII_animation_simple_vector_contour_map.gif")
  system("rm -rf part_VIII_animation_simple_vector_contour_map.*.png")
  
end 

 

Artikelaktionen