[ncl-talk] NCL script running slow for ploting Timeseries

LSL lslrsgis at whu.edu.cn
Fri Mar 8 01:18:44 MST 2019


Hi, everyone


I am using a NCL script to plot timeseries for daily precipitation in 
one year. However, the script is running very slow after generating 
around 10-15 figures.


Any indications? Thanks in advance.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190308/190ca22d/attachment.html>
-------------- next part --------------
;   Plot time series of Daily Precipitation (20->20H) for one year selected
;   INPUT : CMA file SURF_CLI_CHN_MUL_DAY-PRE-13011-SITE-51469-TT.TXT
;   OUTPUT: Timeseries_CMA_1Y_labels.png
;   
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"

begin
; SITE NUMBER
  sSite="57809"


;--Read in site file within WRF Domain 01
  DIR="/home/lsl/Downloads/DATA/wrfout_2015/Processed/"
  flnm = "PREP-SITE-LIST-LAT-LON-XY.TXT"
  strs_site = asciiread(DIR+flnm,-1,"string")

  delim = " "
  nfields = str_fields_count(strs_site(0), delim)

  field_site = str_get_field(strs_site, 1, delim)
  field_lat_LIST = stringtofloat(str_get_field(strs_site, 2, delim))
  field_lon_LIST = stringtofloat(str_get_field(strs_site, 3, delim))
  field_X   = stringtofloat(str_get_field(strs_site, 4, delim))
  field_Y   = stringtofloat(str_get_field(strs_site, 5, delim))

  nSite = dimsizes(field_site)
  field_X_r = floattointeger(floor(field_X))
  field_Y_r = floattointeger(floor(field_Y))

  delete(field_X)
  delete(field_Y)
  delete(field_X_r)
  delete(field_Y_r)


  do iSite=0,nSite-1
;  do iSite=0,10-1
;  print(sSite)
;  print(field_site(iSite))
  sSite=field_site(iSite)

  print(sSite)
  print(".......................")

; Read in CMA Site TXT Time Series
  DIR="/home/lsl/Downloads/DATA/CMA/PRE/PRE/"
  nPoint=1009
  flnm = "SURF_CLI_CHN_MUL_DAY-PRE-13011-SITE-"+sSite+"-TT.TXT"  ;OPTION for site: 51469
  strs = asciiread(DIR+flnm,-1,"string")


  delim = " "
  nfields = str_fields_count(strs(0), delim)

  field_sit = str_get_field(strs, 1, delim)
  field_lat = stringtofloat(str_get_field(strs, 2, delim))*0.01
  field_lon = stringtofloat(str_get_field(strs, 3, delim))*0.01
  field_ele = stringtofloat(str_get_field(strs, 4, delim))*0.10

  field_YY  = stringtoint(str_get_field(strs, 5, delim))
  field_MM  = stringtoint(str_get_field(strs, 6, delim))
  field_DD  = stringtoint(str_get_field(strs, 7, delim))

  field_PRE208  = stringtofloat(str_get_field(strs, 8, delim))*0.10
  field_PRE820  = stringtofloat(str_get_field(strs, 9, delim))*0.10
  field_PRE2020 = stringtofloat(str_get_field(strs,10, delim))*0.10

  field_Q_PRE208  = stringtoint(str_get_field(strs, 11, delim))
  field_Q_PRE820  = stringtoint(str_get_field(strs, 12, delim))
  field_Q_PRE2020 = stringtoint(str_get_field(strs, 13, delim))

  tstart = 2015  ;OPTION
  tend   = 2015 ;OPTION

  yyyymm   = yyyymmdd_time(tstart, tend, "integer")
  yyyyfrac = yyyymmdd_to_yyyyfrac(yyyymm,0)   ; create fractional years for 
                                            ; plotting purposes
;  print(yyyymm)

  ;arr = random_uniform(-5.,10.,(tend-tstart+1)*12)	; create random 1D array
  print(dimsizes(field_PRE2020))
  if(dimsizes(field_PRE2020) .lt. 12419) 
  delete(strs)
  delete(flnm)

  delete(field_sit)
  delete(field_lat)
  delete(field_lon)
  delete(field_ele)

  delete(field_YY)
  delete(field_MM)
  delete(field_DD)

  delete(field_PRE208)
  delete(field_PRE820)
  delete(field_PRE2020)

  delete(field_Q_PRE208)
  delete(field_Q_PRE820)
  delete(field_Q_PRE2020)

    continue
  end if

  arr01 = field_PRE2020(11688+0:11688+365-1)
  arr01 at _FillValue = 3270
  arr01 = where(arr01 .eq. 3270, 0, arr01)
;  print(arr01)
;  print(field_PRE2020(11688+0:11688+365-1))
;  print(strs) 

  sLAT = field_lat_LIST(iSite)
  sLON = field_lon_LIST(iSite)

;  print(yyyyfrac)
  delete(strs)

  delete(field_sit)
  delete(field_lat)
  delete(field_lon)
  delete(field_ele)

  delete(field_YY)
  delete(field_MM)
  delete(field_DD)

  delete(field_PRE208)
  delete(field_PRE820)
  delete(field_PRE2020)

  delete(field_Q_PRE208)
  delete(field_Q_PRE820)
  delete(field_Q_PRE2020)


; Read in WRF Site TXT Time Series
  DIR_WRF="/home/lsl/Downloads/DATA/wrfout_2015/Processed/"
  fwrf=DIR_WRF+"TIMESERIES-PREP-SITE-"+sSite+".TXT"

  strs_wrf = asciiread(fwrf,-1,"string")
  field_ppt = stringtofloat(str_get_field(strs_wrf, 1, delim))
;  print(field_ppt)
  delete(strs_wrf)

  ;=================================================================================
  ;Plot two time series on one figure arr01/field_ppt
  wks = gsn_open_wks("png","Timeseries_CMA_WRF_1Y_SITE-"+sSite+"_lat_"+sLAT+"_lon_"+sLON)   ; send graphics to PNG file
	
  plot = new(2,graphic)	       ; Array to hold plots so we can panel them later.

  res           = True
  res at tiMainString           = "Precipitation Time Series (CMA OBS) SITE "+sSite+"_lat_"+sLAT+"_lon_"+sLON+")"
;  res at tiMainFont             = 0.5
  res at tiMainFontHeightF      = 0.020
  res at xyLineThicknessF       = 1.0            ; make thicker
  res at trXMinF   = tstart       ; starting point along X axis
  res at trXMaxF   = tend+1       ; ending point along X-axis
  res at trYMinF   =  0.0         ; starting point along Y axis
  res at trYMaxF   = 20.0         ; ending point along Y-axis
  res at vpWidthF  = 1.7          ; stretch the plot to be wider (in NDC units)
;  res at vpHeightF = 0.25         ; and not as tall
  res at vpHeightF = 0.20         ; and not as tall  
  res at vpXF      = 0.15         ; set the start point along the X-axis in NDC units
  res at gsnDraw   = False        ; do not draw the plot (plots will be paneled)
  res at gsnFrame  = False        ; do not advance the frame (plots will be paneled)
  res at gsnXYBarChart = True
	
  plot(0) = gsn_csm_xy(wks,yyyyfrac,arr01,res)
	
  res at tmXBFormat = "f"        ; remove the trailing ".0" 
  res at tiMainString           = "Precipitation Time Series (WRF SIM) SITE "+sSite+"_lat_"+sLAT+"_lon_"+sLON+")"
  res at tiMainFontHeightF      = 0.020
  plot(1) = gsn_csm_xy(wks,yyyyfrac,field_ppt,res)

  delete(res at tmXBFormat)
  delete(arr01)
			    
 ; plot(2) = gsn_csm_xy(wks,yyyyfrac(:12),arr(:12),res)			    

  resP             = True
  resP at gsnMaximize = True
  gsn_panel(wks,plot,(/2,1/),resP)  
  

  end do
  delete(field_lat_LIST)
  delete(field_lon_LIST)
end


More information about the ncl-talk mailing list