Personal tools

##### Sektionen
You are here: Home / Beispiele und Aufgaben Teil VIII - Animationen
Info
Our docs have moved to https://docs.dkrz.de This portal will be shutdown as soon the last content is migrated.

# Beispiele und Aufgaben Teil VIII - Animationen

NCL Skripte zur Erzeugung von Animationen.

Zeitliche Animation eines Konturen Plots:

```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
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@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```

Zeitliche Animation eines Vektoren Plots:

```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
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@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```

## Für die Aufgabe:

part_VIII_animation_contour_map.ncl

```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
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@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```

Document Actions