[ncl-talk] do loop and average

Debasish Hazra debasish.hazra5 at gmail.com
Sun Nov 6 10:18:56 MST 2016


Hi,

I have point observation data of for a month which are at irreular
intervals in .csv format. I am readin it in year,month, day, hh format. But
I would like to do averages at certain intervals to compare against 3
hourly forecast of model. So I need to do average of the point data for all
days ina month, such that for 9z data will be average of 8z and 10z, for
12z it is 11 and 13z, for 15z between 14z and 16z and for 18z it will be
between 17z and 19z of the input. Any help on how to do that. Attached is
input data and .txt ncl code.

Thanks.
Debasish.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161106/1ae919b6/attachment.html 
-------------- next part --------------
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/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
;********************************************
begin

    filename = "./Test_reads.csv"

;*********************
    month_abbr = (/"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep", \
                    "Oct","Nov","Dec"/)    
     
    lines = asciiread(filename,-1,"string")
    nlines = dimsizes(lines)-1
    delim = ","

  mhs     = str_get_field(lines(1:),1,delim)
  time_s      = str_get_field(lines(1:),2,delim)
  ppt_s      = str_get_field(lines(1:),3,delim)
   
;     print(mhs)
;     print(time_s)

     time = stringtofloat(time_s)
     ppt  = stringtofloat(ppt_s)

;;      time at calendar = "366_day"
;;    time at units = "days since 2016-01-01 00:00:0.0"
    time at units = "days since 2015-12-31 00:00:0.0"
    utc_date = cd_calendar(time, 0)

   year   = tointeger(utc_date(:,0))    ; Convert to integer for
   month  = tointeger(utc_date(:,1))    ; use sprinti
   day    = tointeger(utc_date(:,2))
   hour   = tointeger(utc_date(:,3))
   minute = tointeger(utc_date(:,4))
   second = utc_date(:,5)
 

   date_str = sprinti("%0.2iZ ", hour) + sprinti("%0.2i ", day) + \
              month_abbr(month) + " "  + sprinti("%0.4i", year)


     data1 = new((/240/),float)
     TIME = yyyymmddhh_time(2016, 2016, 3, "integer")
     time2 = TIME({2016090100:2016093021})
 
     data1!0="timee"
     data1&timee=time2

;;     printVarSummary(data1)

   ppt_dates = new ((/458,2/), "integer")
   ppt_dates(:,0) = day
   ppt_dates(:,1) = hour

   ppt_9Z=new((/26,2/),"float")
   ;ppt_9temp=new(/26/,float)
   ppt at _FillValue= -2147483647

      printVarSummary(ppt_dates)
      printVarSummary(ppt_9Z)

     do while (ppt_dates(:,0)=1,458
      ppt_9_ind = ind( ppt_dates(i,:).ge.8.0 .and. ppt_dates(i,:) .le.10.0)
  print(ppt_9_ind)
    ppt_9_dim =  dimsizes(ppt_9_ind)
    ppt_9Z(i-1,0) = (sum(ppt(ppt_9_ind)))/ppt_9_dim
    ppt_9Z(i-1,1) = avg(ppt(ppt_9_ind))
  end do

print(ppt_9Z)

 

;********************************************
end
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Test_reads.csv
Type: text/csv
Size: 13552 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161106/1ae919b6/attachment.bin 


More information about the ncl-talk mailing list