Extract variable data

The NCL graphics package.

Extract variable data

Postby Derri Haryoni Febri » Wed Apr 08, 2015 11:47 pm

Hei, my name is Derri. I am undergraduate student of Meteorology from Indonesia.

I need some help about NCL script to extract rain data from wrf_output.nc.

i did spatial visualizing using NCL from wrf out files using this script,

; Example script to produce plots for a WRF real-data run,
; with the ARW coordinate dynamics option.

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"

begin
;
; The WRF ARW input file.
; This needs to have a ".nc" appended, so just do it.
wrffiles = systemfunc("ls /media/derri/DiskLess/Skripsi/wrf-ems_out/exp7dan8/2014080912/NETCDF/Domain3/wrfout_d03_2014*")
a = addfile("wrfout_d03_2014-08-09_12%3A00%3A00","r")

numFiles = dimsizes(wrffiles)
do i = 0, numFiles-1
wrffiles(i) = wrffiles(i)+".nc"
end do
inpFiles = addfiles(wrffiles,"r")


; We generate plots, but what kind do we prefer?
type = "png"
; type = "pdf"
; type = "ps"
; type = "ncgm"
wks = gsn_open_wks(type,"wrfout")


; Set some basic resources
res = True
res@MainTitle = ""

resB = True
resB@MainTitle = ""
resB@Footer = False
resB@cnFillOn = True
resB@cnLineColor = "Black"
resB@mpOutlineBoundarySets = "National"

pltres = True
mpres = True
mpres@pmTickMarkDisplayMode = "Always"
mpres@mpDataBaseVersion = "MediumRes"
mpres@mpOutlineBoundarySets = "AllBoundaries"
mpres@mpOutlineOn = True
mpres@mpGeophysicalLineThicknessF = 1.5
mpres@mpGeophysicalLineColor = "Black"
mpres@mpNationalLineThicknessF = 1.5
mpres@mpUSStateLineThicknessF = 1.5
mpresB = mpres
mpresB@mpGeophysicalLineColor = "Black"
mpresB@mpNationalLineColor = "Black"
mpresB@mpUSStateLineColor = "Black"
mpresB@mpGridLineColor = "Black"
mpresB@mpLimbLineColor = "Black"
mpresB@mpPerimLineColor = "Black"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; What times and how many time steps are in the data set?
FirstTime = True
do ifile = 0,numFiles -1
a = inpFiles[ifile]
times = wrf_user_list_times(a) ; get times in the file
ntimes = dimsizes(times) ; number of times in the file

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; do it = 0,ntimes-1,2 ; TIME LOOP
do it = 0, ntimes-1 ; Modified to do every time step

print("Working on time: " + times(it) )
if (FirstTime) then ; Save some times for tracking tendencies
times_sav = times(it)
end if
res@TimeLabel = times(it) ; Set Valid time to use on plots

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; First get the variables we will need
; Get non-convective, convective and total precipitation
; Calculate tendency values
rain_exp = wrf_user_getvar(a,"RAINNC",it)
rain_con = wrf_user_getvar(a,"RAINC",it)
rain_tot = rain_exp + rain_con
rain_tot@description = "Total Precipitation"

if( FirstTime ) then
if ( it .eq. 0 ) then
rain_exp_save = rain_exp
rain_con_save = rain_con
rain_tot_save = rain_tot
else
rain_exp_save = wrf_user_getvar(a,"RAINNC",it-1)
rain_con_save = wrf_user_getvar(a,"RAINC",it-1)
rain_tot_save = rain_exp_save + rain_con_save
FirstTime = False
times_sav = times(it-1)
end if
end if

rain_exp_tend = rain_exp - rain_exp_save
rain_con_tend = rain_con - rain_con_save
rain_tot_tend = rain_tot - rain_tot_save
rain_exp_tend@description = "Explicit Precipitation Tendency"
rain_con_tend@description = "Param Precipitation Tendency"
rain_tot_tend@description = "Precipitation"

; Bookkeeping, just to allow the tendency at the next time step
rain_exp_save = rain_exp
rain_con_save = rain_con
rain_tot_save = rain_tot

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Don't skip the first time: we need an image at each time stamp
; if( .not. FirstTime ) then ; We will skip the first time
; Plotting options for Precipitation
opts_r = res
opts_r@UnitLabel = "mm"
opts_r@cnLevelSelectionMode = "ExplicitLevels"
opts_r@cnLevels = (/ 0.0, 0.5, 2.0, 4.0, 6.0, 8.0, 10.0, \
12.0, 14.0, 16.0, 18.0, 20.0/)
opts_r@cnFillColors = (/"White","White","DarkOliveGreen1", \
"Chartreuse","Green", \
"ForestGreen","Yellowgreen","Yellow", \
"Darkgoldenrod1","Darkorange2","Orange","Tomato1","Red"/)
opts_r@cnInfoLabelOn = False
opts_r@cnConstFLabelOn = False
opts_r@cnFillOn = True


; Total Precipitation (color fill)
contour_tot = wrf_contour(a,wks, rain_tot, opts_r)

; Precipitation Tendencies
opts_r@SubFieldTitle = ""

contour_tend = wrf_contour(a,wks, rain_tot_tend,opts_r) ; total (color)
contour_res = wrf_contour(a,wks,rain_exp_tend,opts_r) ; exp (color)
opts_r@cnFillOn = False
opts_r@cnLineColor = "Red4"
contour_prm = wrf_contour(a,wks,rain_con_tend,opts_r) ; con (red lines)
delete(opts_r)


; MAKE PLOTS

; Total Precipitation
; plot = wrf_map_overlays(a,wks,contour_tot,pltres,mpres)

; Total Precipitation Tendency
plot = wrf_map_overlays(a,wks,contour_tend,pltres,mpres)

; Non-Convective and Convective Precipiation Tendencies
;plot = wrf_map_overlays(a,wks,(/contour_res,contour_prm/),pltres,mpres)

; end if ; END IF FOR SKIPPING FIRST TIME - commented out

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

times_sav = times(it)
FirstTime = False

end do ; END OF TIME LOOP
end do ; END OF LOOP OVER FILES

end

i am facing problem to make a script to extract rain_tot_tend in a specifics lat and lon.

any suggestions?
Derri Haryoni Febri
 
Posts: 3
Joined: Wed Apr 08, 2015 11:34 pm

Re: Extract variable data

Postby pepeleon » Mon Dec 14, 2015 12:20 pm

Hello,

You should do it with GrADS. Is more easy.

Regards!
pepeleon
 
Posts: 15
Joined: Mon Dec 09, 2013 12:15 pm


Return to NCL

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron