Re: WRF: Daily Precipitation

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Tue Apr 20 2010 - 08:46:20 MDT

It looks like an existing script has been used. It looks like the code
for calculating daily means [previous question] has been
'stuck' in the middle of a loop.

[1]
Based on a previous question, the user stated that
each file has *one* time step

   do it = 0,ntimes-1 ; OUTER LOOP
      [snip]

     do nt=0,ntim-1,ntJump ; INNER LOOP ... *not* appropriate
        prcDay(nt/24,:,:) = dim_sum_n(rainfall_tot(ntStrt:ntLast,:,:), 0)
     end do

   end do

This is obviously incorrect. **Please think about what is being done!**

[2]
Currently, "wrf_user_getvar" only accepts one file at a time.
Hence, it is the user's responsibility to create an array that
will contain the 72 hourly values
  ;***********************************************************************)
  datadir = "/casvol5/basantas/cas/WRF3-1/output-wrf/2010041400/"
  FILES= systemfunc ("ls -1 " + datadir + "wrfout_d01_2010-04* " )
  numFILES = dimsizes(FILES)

  f0 = addfile(FILES(0), "r")
  xlat = f0->XLAT(0,:,:)
  xlon = f0->XLONG(0,:,:)
  dimll= dimsizes( xlat )
  nlat = dimll(0)
  mlon = dimll(1)

  ntim = numFiles
  rainfall_hour = new ( (/ntim,nlat,mlon/), "float")

  it = 0 ; one time per file [time step 0]
  do ifil = 0,numFILES-1
     it = ifil
     wrf_out = addfile(FILES(ifil)+".nc","r")
     rain_con = wrf_user_getvar(wrf_out,"RAINC",it)
     rain_exp = wrf_user_getvar(wrf_out,"RAINNC",it)
     rainfall_hour(it) = rain_con(it) + rain_exp(it)
  end do

  ntJump = 24 ; 24 'samples' per day
  prcDay = rainfall_hour(::ntJump,:,:)

  ntStrt = 0
  ntLast = ntJump-1

  do nt=0,ntim-1,ntJump
     prcDay(nt/24,:,:) = dim_sum_n(rainfall_tot(ntStrt:ntLast,:,:), 0)
     ntStrt = ntStrt + ntJump
     ntLast = ntLast + ntJump
  end do

  prcDay@long_name = "Daily total precipitation"
  prcDay@units = rain_con@units
  copy_VarCoords(xlat,prcDay(0,:,:))

  printVarSummary(prcDay)

On 4/20/10 7:50 AM, Mary Haley wrote:
> Sahidul,
>
> The error message is telling you exactly what's wrong. It says you are
> trying to treat the variable as if it is a 3-dimensional variable, when in
> reality it is only 2-dimensional.
>
> When it says "(2) Subscripts expected", this means you have a 2D array.
>
> You are subscripting rainfall_tot with (::ntJump,:,:). You may need to
> correct this by subscripting it with (::ntJump,:).
>
> I'm not sure how "rainfall_tot" is defined, because it looks like part
> of the
> code is missing below.You are actually referencing rainfall_tot before
> it is ever defined, which would give you an error too:
>
> rainfall_tot(it) = rain_con(it) + rain_exp(it)
>
> You can't subscript a variable if it hasn't been defined yet. And,
> here, you are referencing it as a 1D array.
>
> Maybe you meant to do:
>
> rainfall_tot = rain_con(it) + rain_exp(it)
>
> ?
>
> Please review your code carefully to understand what the dimension
> sizes are of your various arrays. It helps call "printVarSummary" on
> a variable so you can see exactly dimensions it has.
>
> --Mary
>
> On Apr 20, 2010, at 6:52 AM, Sahidul wrote:
>
>> Dear NCl help,
>>
>> I tried to plot according to youe suggestion. I am facing problem like:
>> in line: prcDay = rainfall_tot(::ntJump,:,:)
>> = = = = = == =
>> fatal:Number of subscripts on rhs do not match number of dimensions of
>> variable,(3) Subscripts used, (2) Subscripts expected
>> fatal:Execute: Error occurred at or near line 109 in file
>> precipitation.ncl
>> = = = = = == =
>>
>> The code is:
>> = = = = = = =
>> ;***********************************************************************
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>>
>> begin
>> ;***********************************************************************
>> ; Open wrfout file.
>> ;***********************************************************************)
>> datadir = "/casvol5/basantas/cas/WRF3-1/output-wrf/2010041400/"
>> FILES = systemfunc ("ls -1 " + datadir + "wrfout_d01_2010-04* " )
>> numFILES = dimsizes(FILES)
>>
>> do ifil = 0,numFILES-1
>> wrf_out = addfile(FILES(ifil)+".nc","r")
>> ;***********************************************************************
>> ; Read time dimesion.
>> ;***********************************************************************
>> times = wrf_user_list_times(wrf_out)
>> ntimes=dimsizes(times)
>>
>> do it = 0,ntimes-1,1
>>
>> ;***********************************************************************
>> ;Open Workstation ps,eps,X11,pdf,ncgm
>> ;***********************************************************************
>> type = "ps"
>> wks = gsn_open_wks(type,"precip_animation")
>>
>> res = True
>> res@InitTime = False
>> res@Footer = False
>> res@gsnMaximize = True
>> res@MainTitle = "Total Precipitation"
>>
>> opts = res
>> opts@cnLinesOn = False
>> opts@cnFillOn = True
>> opts@UnitLabel = "mm"
>> opts@cnFillColors = (/"White","White","DarkOliveGreen1", \
>> "DarkOliveGreen3","Chartreuse", \
>> "Chartreuse3","Green","ForestGreen", \
>> "Yellow","Orange","Red","Violet"/)
>> opts@cnInfoLabelOn = False
>> opts@cnConstFLabelOn = False
>>
>> pltres = True
>> mpres = True
>> mpres@mpOutlineBoundarySets = "National"
>> mpres@mpNationalLineThicknessF = 1.5
>> mpres@mpNationalLineColor = "Red"
>> mpres@mpGeophysicalLineColor = "Red"
>> mpres@mpGeophysicalLineThicknessF = 1.5
>>
>> ;***********************************************************************
>> ; Total Rainfall calculation
>> ;***********************************************************************
>>
>> rain_con = wrf_user_getvar(wrf_out,"RAINC",it)
>> printVarSummary(rain_con)
>> rain_exp = wrf_user_getvar(wrf_out,"RAINNC",it)
>> printVarSummary(rain_exp)
>> rainfall_tot(it) = rain_con(it) + rain_exp(it)
>> rainfall_tot@description = "Total Precipitation"
>>
>> printVarSummary(rainfall_tot)
>> ;***********************************************************************
>> ;Ploting Total Precipitation
>> ;***********************************************************************
>>
>> daily_precip = rainfall_tot(0::72,:,:)
>> printVarSummary(daily_precip)
>>
>> dimprc = dimsizes(rainfall_tot)
>> printVarSummary(dimprc)
>> ntim = dimprc(0) ; total number of time steps
>> ntJump = 24 ; eight samples per day (=24/3)
>>
>> prcDay = rainfall_tot(::ntJump,:,:) ; create array with meta data
>>
>> ntStrt = 0
>> ntLast = ntJump-1
>>
>> do nt=0,ntim-1,ntJump
>>
>> prcDay(nt/24,:,:) = dim_sum_n(rainfall_tot(ntStrt:ntLast,:,:), 0)
>> ntStrt = ntStrt + ntJump
>> ntLast = ntLast + ntJump
>>
>> contour_tot = wrf_contour(wrf_out,wks,prcDay,opts)
>> plot = wrf_map_overlays(wrf_out,wks,(/contour_tot/),pltres,mpres)
>> end do
>> printVarSummary(prcDay)
>> end do ; Time Looend do
>>
>> end do
>> end
>>
>> Kindly help me to solve this.
>>
>>
>> with regards,
>>
>> On Mon, Apr 19, 2010 at 10:34 PM, Dennis Shea <shea@ucar.edu
>> <mailto:shea@ucar.edu>> wrote:
>>
>> Please see the FAQ:
>>
>> http://www.ncl.ucar.edu/FAQ/
>>
>> Data Analysis: Example 1
>>
>> ===
>> You must write your own script.
>> ===
>>
>> In your case:
>>
>> (1) ntJump = 24 ; 24 samples per day
>> (2) Use dim_sum_n
>> (3) See
>>
>> do nt=0,ntim-1,ntJump
>> prcDay(nt/8,:,:) = dim_sum_n(prc(ntStrt:ntLast,:,:), 0)
>> ntStrt = ntStrt + ntJump
>> ntLast = ntLast + ntJump
>>
>> ; write netCDF
>> ; http://www.ncl.ucar.edu/Applications/method_1.shtml
>> end do
>>
>>
>>
>> On 04/18/2010 01:08 AM, Sahidul wrote:
>>
>> Dear NCL Users,
>>
>> I am having hourly WRF forecast files. The number of files is
>> 72. ( each
>> file having only 1 time )
>> Using this, I would like to calculate Daily Precipitation,
>> i.e., 24
>> hourly accumulated rainfall. So I want to create 3 files, for
>> example,
>> day1, day2 & day3.
>>
>> Can I have any script for this calculations.?
>>
>> Thanking you,
>>
>> Sahidul
>>
>>
>> _______________________________________________
>> 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
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Apr 20 08:46:52 2010

This archive was generated by hypermail 2.1.8 : Fri Apr 23 2010 - 14:40:07 MDT