[ncl-talk] Sum over a variable using several netcdf files

Dennis Shea shea at ucar.edu
Fri Feb 18 15:41:36 MST 2022


The NCL code segment I  sent, should do what you stated that you wanted:

"sum over all these 4 files to have a total temperature value"





On Fri, Feb 18, 2022 at 12:37 PM Setareh Rahimi <setareh.rahimi at gmail.com>
wrote:

> Dear Dennis,
> I need sum!
> Thanks  for your advice. It seems I have no way except using NCO or CDO. I
> will try it.
> Best wishes,
>
> On Fri, Feb 18, 2022 at 10:53 PM Dennis Shea <shea at ucar.edu> wrote:
>
>> "sum over all these 4 files to have a total temperature value"
>>
>> sum or average?
>>
>> =====================
>>
>>
>>    diri = "./"
>>    fili = systemfunc("cd "+diri+" ; ls FOO*.nc")
>>    nfili= dimsizes(fili)
>>    print("nfili="+nfili)
>>    f    = addfiles(diri+fili,"r")
>>    tmp  = f[:]->TEMP
>>
>>    printVarSummary(tmp)      ; tmp(time,lat,lon)
>>                              ;       0   1   2
>>
>>    tavg = *dim_avg_n*_*Wrap* <https://www.ncl.ucar.edu/Document/Functions/Contributed/dim_avg_n_Wrap.shtml>(tmp,0)   ; _Wrap ==> return meta data
>>
>>    printVarSummary(tavg)     ; tavg(lat,lon)
>>
>> or
>>
>>    tsum = *dim_sum_n_Wrap* <https://www.ncl.ucar.edu/Document/Functions/Contributed/dim_sum_n_Wrap.shtml> (tmp,0)
>>
>>    printVarSummary(tsum)     ; tsum(lat,lon)
>>
>>  =============
>>
>> You could use the NCO or CDO from an NCL script.
>>
>> Use *systemfunc* <https://www.ncl.ucar.edu/Document/Functions/Built-in/systemfunc.shtml>
>>
>>     path = ....
>>
>>     systemfunc("...")   ; use CDO or NCO to create a file;; say  FOO_Avg.nc
>>
>>     favg = addfile("FOO_Avg.nc", r)  ; read the file created by NCO or CDO
>>
>>     tavg = favg->T...
>>
>>
>> other examples are at:
>>
>> *https://www.ncl.ucar.edu/Applications/* <https://www.ncl.ucar.edu/Applications/>
>>
>> See under
>>
>> *Miscellaneous*
>>
>> *Specifically:  System interactions and scripting <https://www.ncl.ucar.edu/Applications/system.shtml>*
>>
>>
>>
>>
>> *https://www.ncl.ucar.edu/Applications/system.shtml* <https://www.ncl.ucar.edu/Applications/system.shtml>
>>
>>
>> On Fri, Feb 18, 2022 at 8:40 AM Setareh Rahimi via ncl-talk <
>> ncl-talk at mailman.ucar.edu> wrote:
>>
>>> Dear Joe,
>>> So many thanks for your advice, but this calculation is part of my NCL
>>> script, and can not shift to NCO.
>>> Best wishes,
>>>
>>> On Fri, Feb 18, 2022 at 7:03 PM Joseph Zambon <jbzambon at ncsu.edu> wrote:
>>>
>>>> Setareh,
>>>>
>>>> NCO utilities might be the easiest way to attack that problem.
>>>>
>>>> e.g. http://nco.sourceforge.net/nco.html#ncbo
>>>> http://nco.sourceforge.net/nco.html#ncap2
>>>>
>>>> -Joe
>>>>
>>>>
>>>> Joseph B. Zambon, Ph.D.
>>>> Research Assistant Professor
>>>>
>>>> Ocean Observing and Modeling Group
>>>> Department of Marine, Earth and Atmospheric Sciences
>>>> North Carolina State University
>>>> Jordan Hall rm 4140
>>>> 919.515.7928
>>>> jbzambon at ncsu.edu
>>>> www.joezambon.com
>>>>
>>>> On Feb 18, 2022, at 10:29, Setareh Rahimi via ncl-talk <
>>>> ncl-talk at mailman.ucar.edu> wrote:
>>>>
>>>> Dear NCL users,
>>>> I have 4 netcdf files containing temperature ( T(time,lat,lon)). I need
>>>> to sum over all these 4 files to have a total temperature value . May I ask
>>>> you to kindly advise me how I can  do this please?
>>>> many thanks in advance,
>>>> Best wishes,
>>>>
>>>> --
>>>> S.Rahimi
>>>>
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> ncl-talk at mailman.ucar.edu
>>>> List instructions, subscriber options, unsubscribe:
>>>> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>>
>>>>
>>>
>>> --
>>> S.Rahimi
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at mailman.ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
> --
> S.Rahimi
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20220218/97404b74/attachment.html>


More information about the ncl-talk mailing list