[ncl-talk] ncl plot getting killed
Komal Shukla
komalshukla1992 at gmail.com
Thu Nov 29 04:04:36 MST 2018
Mary,
It works just the right,4th option is most optimised. thanks!
On Wed, Nov 28, 2018 at 8:49 PM Mary Haley <haley at ucar.edu> wrote:
> Hi Kim,
>
> You could be correct that this is a memory issue. Are you getting any
> errors from NCL before it quits?
>
> You can save on memory by not creating so many local variables. Below are
> four possible scenarios you can try:
>
> [1] You can delete a variable after you no longer need it, which will free
> up some memory.
>
> no = aa[:]->no
> no_avg=dim_avg_n(no,0)
> delete(no)
> no2 = aa[:]->no2
> no2_avg=dim_avg_n(no2,0)
> delete(no2)
> oli = aa[:]->oli
> oli_avg=dim_avg_n(oli,0)
> delete(oli)
>
> [2] You can use [/.../] to delete several variables at once, if you don't
> need to free them individually:
>
> no = aa[:]->no
> no_avg=dim_avg_n(no,0)
> no2 = aa[:]->no2
> no2_avg=dim_avg_n(no2,0)
> oli = aa[:]->oli
> oli_avg=dim_avg_n(oli,0)
> delete([/no,no2,oli/])
>
> [3] Even better, if there's no reason that variables like "no", "no2", and
> "oli" need to exist, then there's no need to save them to a local variable
> before taking the average:
>
> no_avg = dim_avg_n(aa[:]->no,0)
> no2_avg= dim_avg_n(aa[:]->no2,0)
> oli_avg = dim_avg_n(aa[:]->oli,0)
>
> [4] Since you are doing the same operation repeatedly, you can use a do
> loop and save yourself some more memory.
>
> vars_to_avg = (/"no","no2","oli","csl","olt","xyl","ald","hc8",\
> "hcho","ol2","tol","hc5","hc3","ket"/)
> nvars = dimsizes(vars_to_avg)
>
> ;---Average the first one and store to variable
> Mpan_avg = dim_avg_n(aa[:]->$vars_to_avg(0)$,0)
>
> ;---Loop thru rest of vars and sum their averages
> do nv=1,nvars-1
> Mpan_avg = Mpan_avg + dim_avg_n(aa[:]->$vars_to_avg(nv)$,0)
> end do
> Mpan_avg=Mpan_avg*1000
> Mpan_avg2D=Mpan_avg(0,:,:)
> . . .
>
> The above is not tested, so hopefully there are no syntax errors in it.
>
> --Mary
>
>
> On Wed, Nov 28, 2018 at 2:49 AM Komal Shukla <komalshukla1992 at gmail.com>
> wrote:
>
>> Hi
>>
>> I am trying to add a variable from netcdf files, and make an average
>> plot. My scripts is mentioned below, but the process gets killed. Maybe
>> because of memory.
>>
>> Can you please suggest a "efficient" way of writing this? Please help.
>>
>> Script ----------
>> begin
>> a = addfile("../wrfout_d01_2012-05-01_00:00:00.nc","r")
>>
>> it = 0 ; first time step
>> hgt = wrf_user_getvar(a,"HGT_M",it) ; Terrain elevation
>> hgt at lat2d = wrf_user_getvar(a,"XLAT",it) ; latitude/longitude
>> hgt at lon2d = wrf_user_getvar(a,"XLONG",it) ; required for plotting
>>
>> wks = gsn_open_wks("png","try1")
>>
>> FILES = systemfunc ("ls ../wrfout_d01_2012-05*") ; file paths
>>
>> numFILES = dimsizes(FILES)
>> aa = addfiles (FILES+".nc", "r") ;add multiple files
>> ;;;;;;;;;;;;
>>
>> no = aa[:]->no
>> no_avg=dim_avg_n(no,0)
>> no2 = aa[:]->no2
>> no2_avg=dim_avg_n(no2,0)
>> oli = aa[:]->oli
>> oli_avg=dim_avg_n(oli,0)
>> csl = aa[:]->csl
>> csl_avg=dim_avg_n(csl,0)
>> olt = aa[:]->olt
>> olt_avg=dim_avg_n(olt,0)
>> xyl = aa[:]->xyl
>> xyl_avg=dim_avg_n(xyl,0)
>> ald = aa[:]->ald
>> ald_avg=dim_avg_n(ald,0)
>> hc8 = aa[:]->hc8
>> hc8_avg=dim_avg_n(hc8,0)
>> hcho = aa[:]->hcho
>> hcho_avg=dim_avg_n(hcho,0)
>> ol2 = aa[:]->ol2
>> ol2_avg=dim_avg_n(ol2,0)
>> tol = aa[:]->tol
>> tol_avg=dim_avg_n(tol,0)
>> hc5= aa[:]->hc5
>> hc5_avg=dim_avg_n(hc5,0)
>> hc3= aa[:]->hc3
>> hc3_avg=dim_avg_n(hc3,0)
>> ket= aa[:]->ket
>> ket_avg=dim_avg_n(ket,0)
>>
>>
>> Mpan_avg=no_avg+no2_avg+oli_avg+csl_avg+olt_avg+xyl_avg+ald_avg+hc8_avg+hcho_avg+ol2_avg+tol_avg+hc5_avg+hc3_avg+ket_avg
>> Mpan_avg=Mpan_avg*1000
>> Mpan_avg2D=Mpan_avg(0,:,:)
>> Mpan_avg2D at lat2d = wrf_user_getvar(a,"XLAT",it) ; latitude/longitude
>> Mpan_avg2D at lon2d = wrf_user_getvar(a,"XLONG",it) ; required for plotting
>> --some plotting options here--
>> contour = gsn_csm_contour_map(wks,Mpan_avg2D,res)
>> draw(contour)
>> frame(wks)
>>
>> Thanks
>> Kim
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20181129/f3bfcc73/attachment.html>
More information about the ncl-talk
mailing list