[ncl-talk] Calculating annual averages from year/lat/lon grid

Toni Klemm toni-klemm at tamu.edu
Tue Jan 22 09:32:26 MST 2019


All,

I think I solved my own problem (see below). I used the avg function instead of dim_avg_n and looped through each year (because avg creates averages regardless of dimension, but I only wanted it to consider data from a single year), which produced the same averages I got from Excel. This is the code I used:

do z=0,84
  NPP_G_annual_avg(z) = avg(NPP_G(z,:,:))
end do


Please reply if this might still be wrong and/or if you have a different solution.

Thanks,
Toni


Toni Klemm, Ph.D.
Postdoctoral Research Associate
Department of Ecosystem Science and Management
College of Agriculture and Life Sciences
Texas A&M University, College Station, TX
Contributor to the Early Career Climate Forum <http://www.eccforum.org/>
www.toni-klemm.de <http://www.toni-klemm.de/> | @toniklemm <http://twitter.com/toniklemm>








> On Jan 22, 2019, at 9:58 AM, Toni Klemm <toni-klemm at tamu.edu> wrote:
> 
> Hello NCL community,
> 
> I have a three dimensional grid dataset (year/latitude/longitude) that want to calculate the annual average of by averaging the second and third dimension, but I don’t think my approach is correct. 
> 
> The data are projections of net primary productivity (NPP) of grassland in the US Great Plains from 2015 to 2099. Most of the grid cells are missing values because most grid cells are classified as shrubland, forest, etc. … but not grassland and therefore have no grassland NPP. 
> 
> My approach so far was to average the third dimension first and then the second dimension using this command:
> NPP_G_annual_avg = dim_avg_n(dim_avg_n(NPP_G,2),1)
> 
> However, I think this produces incorrect results. Comparing NCL with the average produced in Microsoft Excel, I get 394.8 from NCL and 417.6 from Excel for the year 2015 (the unit is grams of Carbon per square meter per year). I think Excel is correct, because it averages all values at once while NCL averages one dimension first and then the other, which I think creates a bias. Does anyone know how to average two dimensions at once in NCL? I attached the 2015 data for the Northern Great Plains as .csv file. Missing values are listed as “NaN”.
> 
> Thank you very much for your help! I really appreciate it.
> 
> Best,
> Toni
> 
> 
> Toni Klemm, Ph.D.
> Postdoctoral Research Associate
> Department of Ecosystem Science and Management
> College of Agriculture and Life Sciences
> Texas A&M University, College Station, TX
> Contributor to the Early Career Climate Forum <http://www.eccforum.org/>
> www.toni-klemm.de <http://www.toni-klemm.de/> | @toniklemm <http://twitter.com/toniklemm>
> 
> 
> 
> 
> 
> 
> 
> <NPP_G_annual_avg_NP_2015.csv>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190122/c018e70f/attachment.html>


More information about the ncl-talk mailing list