[ncl-talk] Sum over a variable using several netcdf files
Dennis Shea
shea at ucar.edu
Fri Feb 18 12:23:31 MST 2022
"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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20220218/75f2e33e/attachment.html>
More information about the ncl-talk
mailing list