[ncl-talk] Calculate Average value for a number of files

Jack Ogaja jack.ogaja at gmail.com
Mon Nov 23 11:06:42 MST 2015


Ioannis,

Sorry, I oversaw one point in your script, the "density weighted sum”. However, 
> I would like to calculate the average value for big number of files wrfoutput which it seems to be infeasible with the revised version of the script (readwrite_dust_all_2_Jack….
for which dimension do you want to calculate the average? time? level? It was not clear in your first email and unfortunately it is still not clear in your recent email what you mean by “average”. If the rest of your files have been written at each time step as it seems to be with the two files you uploaded, then the only possible average will be in “levels” if you want the output as indicated in the last email.

Sure, you wouldn’t use “readwrite_dust_all_2_Jack…” script to read multiple files. In this case you need the “addfiles” function. Please, find attached a modification of your latest script. Unlike the earlier script, I have stayed as close as possible to the original coding and I have only added “addfiles” and “dim_sum_n” functions to your script. You can read more about the functions in the documentation.

Assuming you mean to calculate average in the vertical direction, just switch between
;==
   dust_tot = dust_J(level,:,:)
;==
and
;==
    ;+dust_tot = dim_avg_n(dust_J,0)
;==
in lines 54 and 56 respectively, otherwise for the two data files you uploaded, the modified script should give you the exact numbers as your original script(you should confirm it). If you add more files, the modified script should print to the output file multiple columns representing values from each file.

If you need further clarification/help, don’t hesitate to write back to the ncl-talk.  

Jack




> On 23 Nov 2015, at 15:44, Ioannis Koletsis <koletsis at meteo.noa.gr> wrote:
> 
> Dear Jack,
>  
> Thanks for your time and your quick reply….
> I had already checked my initial script before wrote to the list and group and of course I understood that something was going wrong with the definition and dimension of the new variable…..
>  
> I followed step by step your suggestions and ran your revised script….
>  
> However, the script didn’t work properly and something is going wrong with the calculation of the average value….
>  
> Into the All_Dust.txt file (output of readwrite_dust_all.ncl, https://www.dropbox.com/s/g8yscu2qvj3muuk/All_Dust.txt?dl=0 <https://www.dropbox.com/s/g8yscu2qvj3muuk/All_Dust.txt?dl=0> ), the dust_tot values for each lat, lon as well as for each file is written down in the 4th and 5th column.
> According to the new script, at the output file Dust_NEW.txt (output of readwrite_dust_all_2_Jack…. https://www.dropbox.com/s/oe0dq61161zzpt8/Dust_NEW.txt?dl=0 <https://www.dropbox.com/s/oe0dq61161zzpt8/Dust_NEW.txt?dl=0> ) the average value of the above columns is estimated which nevertheless doesn’t match with the real average value….
>  
> Moreover, I would like to calculate the average value for big number of files wrfoutput which it seems to be infeasible with the revised version of the script (readwrite_dust_all_2_Jack….)….
>  
> A sample of the wrfout files are attached (https://www.dropbox.com/s/g95nul82e1g8kzu/wrfout_d01_2015-09-12_18%253A00%253A00?dl=0 <https://www.dropbox.com/s/g95nul82e1g8kzu/wrfout_d01_2015-09-12_18%253A00%253A00?dl=0> , https://www.dropbox.com/s/zrztjaqtjuo30wz/wrfout_d01_2015-09-12_21%253A00%253A00?dl=0 <https://www.dropbox.com/s/zrztjaqtjuo30wz/wrfout_d01_2015-09-12_21%253A00%253A00?dl=0> ).
>  
> I think that something should be changed in loop in order to work properly, but I cannot find it. May be is more easy that I think….
>  
> Dear Jack and other ncl users, have you got any idea?
>  
> Any help would be kindly appreciated
>  
> Best regards
>  
> Ioannis          
>  
>  
> From: ncl-talk-bounces at ucar.edu [mailto:ncl-talk-bounces at ucar.edu] On Behalf Of Jack Ogaja
> Sent: Thursday, November 19, 2015 8:38 PM
> To: Ioannis Koletsis
> Cc: ncl-talk [ncl-talk]
> Subject: Re: [ncl-talk] Calculate Average value for a number of files
>  
> Sorry. Change the following lines;
>  
> ;===
>      dust_tot=(/dustJ1,dustJ2,dustJ3,dustJ4,dustJ5/)
> to
>      dust_tot=dim_sum_n((/dustJ1,dustJ2,dustJ3,dustJ4,dustJ5/),0)
>  
> and
>     dustnew = dim_avg_n(dust_tot, (/0,1,2/))
> to
>     dustnew = dim_avg_n(dust_tot, (/0,1/))
> ;===
>  
> Jack
>  
>> On 19 Nov 2015, at 19:04, Jack Ogaja <jack.ogaja at gmail.com <mailto:jack.ogaja at gmail.com>> wrote:
>>  
>> Dear Ioannis,
>>  
>> I think sometimes it is better if you just show the error message instead of asking people to download the data. For example your script simply generates the following error;
>> ;=====
>> fatal:Number of subscripts do not match number of dimensions of variable,(2) Subscripts used, (1) Subscripts expected
>> fatal:["Execute.c":8575]:Execute: Error occurred at or near line 77 in file readwrite_dust_all_2.ncl
>> ;=====
>> which should be a clear message and indicating where the error occurs.
>>  
>> Anyway, since you are only interested in the numbers, I think you would understandably do away with the outer loop and try something like;
>>  
>> ;=====
>>      aJ = addfile(FILES(0)+".nc","r")
>>      bJ = addfile(FILES(1)+".nc","r")
>>>>      dustJ1  = (/wrf_user_getvar(aJ,"DUST_1",it), wrf_user_getvar(bJ,"DUST_1",it)/)
>>      .
>>      .
>>      .
>>      dustJ5  = …
>>  
>>      dustnew = dim_avg_n(dust_tot, (/0,1,2/)) 
>>      .
>>      .
>>      .
>> ;=====
>>  
>> See the attached script with such lines(modified from your original script).
>>  
>> Jack
>>  
>> <readwrite_dust_all_2_Jack20151119.ncl>
>>  
>>> On 19 Nov 2015, at 16:04, Ioannis Koletsis <koletsis at meteo.noa.gr <mailto:koletsis at meteo.noa.gr>> wrote:
>>>  
>>> Dear all,
>>> I would like to write down the average value of a variable for each lat, lon point from a number of wrfoutput files….
>>>  
>>> The input files are the wrfoutput files which you can find here 
>>> (https://www.dropbox.com/s/kgogk9jcn0m65e8/wrfout_d01_2015-09-12_12%253A00%253A00?dl=0 <https://www.dropbox.com/s/kgogk9jcn0m65e8/wrfout_d01_2015-09-12_12%253A00%253A00?dl=0> , https://www.dropbox.com/s/u8d0wkr2i2u7ydc/wrfout_d01_2015-09-12_15%253A00%253A00?dl=0 <https://www.dropbox.com/s/u8d0wkr2i2u7ydc/wrfout_d01_2015-09-12_15%253A00%253A00?dl=0> ) 
>>> and the variable that I want to calculate the average value from the input files is the dust_tot…
>>>  
>>> Have you got any idea what is going wrong with my script?
>>> Any help would be appreciated …
>>>  
>>> Best Regards
>>>  
>>> Ioannis 
>>>  
>>>  
>>>  
>>>  
>>>  
>>>  
>>> Dr. Ioannis Koletsis
>>> National Observatory of Athens
>>> Institute for Environmental Research
>>> Lofos Koufou
>>> 15236-Penteli
>>> Athens-Greece
>>> Tel: +30 2108109134
>>> e-mail: koletsis at meteo.noa.gr <mailto:koletsis at meteo.noa.gr>
>>> ----------------------------------------------------------------------------------------
>>> Weather forecasts: http://www.noa.gr/forecast <http://www.noa.gr/forecast> (in english)
>>> or http://www.meteo.gr <http://www.meteo.gr/> (in greek)
>>> Weather forecasts for Europe: http://www.eurometeo.gr <http://www.eurometeo.gr/> (in english)
>>> ----------------------------------------------------------------------------------------
>>>  
>>> 
>>> 
>>>  <https://www.avast.com/antivirus>	
>>> Αυτό το e-mail ελέγχθηκε για ιούς από το πρόγραμμα Avast antivirus. 
>>> www.avast.com <https://www.avast.com/antivirus>
>>>  
>> 
>> <readwrite_dust_all_2.ncl>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
>>  
> 
>  
> 
> 
>  <https://www.avast.com/antivirus>	
> Αυτό το e-mail ελέγχθηκε για ιούς από το πρόγραμμα Avast antivirus. 
> www.avast.com <https://www.avast.com/antivirus>
> <readwrite_dust_all_2_Jack20151119.ncl><readwrite_dust_all.ncl>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151123/0a750821/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: readwrite_dust_all_Jack20151123.ncl
Type: application/octet-stream
Size: 2599 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151123/0a750821/attachment.obj 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151123/0a750821/attachment-0001.html 


More information about the ncl-talk mailing list