<div dir="ltr"><div dir="ltr"><div dir="ltr"><pre>Maybe:<br>===============<br>let: x(time,lat,lon) where lat[*] and lon [*]<br></pre><pre> clat = <a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/cos.shtml"><strong>cos</strong></a>(lat*rad)
xAve = <a href="http://www.ncl.ucar.edu/Document/Functions/Contributed/wgt_areaave_Wrap.shtml"><strong>wgt_areaave_Wrap</strong></a>(x, clat, 1.0, 1)<br></pre><pre> <b>printVarSummary</b>(xAve) <br><br></pre><pre>=== For a non-rectilinear grid<br></pre><pre> q = f->Q ; (ntim,nlat,mlon)
lat2d = f->LAT ; (nlat,mlon)
clat2d = <a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/cos.shtml"><strong>cos</strong></a>(lat2d*0.01745329) ; (nlat,mlon)
qAve = <a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/wgt_areaave2.shtml"><strong>wgt_areaave2</strong></a>(q, clat2d, opt) ; opt = 0 or 1; (ntim)<br></pre><pre> copy_VarMeta(q(:,0,0), qAve)<br></pre><pre> printVarSummary(qAve)<br></pre></div><div dir="ltr"><br></div><div>other functions:<b> </b><br></div><div dir="ltr"><br></div><div dir="ltr"><a href="http://www.ncl.ucar.edu/Document/Functions/Contributed/month_to_annual.shtml"><b>http://www.ncl.ucar.edu/Document/Functions/Contributed/month_to_annual.shtml</b></a></div><div dir="ltr"><br></div><div><b>D</b><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 22, 2019 at 9:32 AM Toni Klemm <<a href="mailto:toni-klemm@tamu.edu">toni-klemm@tamu.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;">All,<div><br></div><div>I think I solved my own problem (see below). I used the <font face="Courier">avg</font> function instead of <font face="Courier">dim_avg_n</font> and looped through each year (because <font face="Courier">avg</font> 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:</div><div><br></div><div><div><font face="Courier">do z=0,84</font></div><div><font face="Courier"> NPP_G_annual_avg(z) = avg(NPP_G(z,:,:))</font></div><div><span style="font-family:Courier">end do</span></div><div><br></div><div><br></div><div>Please reply if this might still be wrong and/or if you have a different solution.</div><div><br></div><div>Thanks,</div><div>Toni</div><div>
<div dir="auto" style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="auto" style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="auto" style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="auto" style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="auto" style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="color:rgb(0,0,0);font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Calibri"><br class="gmail-m_-941660536421261816Apple-interchange-newline"><br></font></div><div style="color:rgb(0,0,0);font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Calibri"><b>Toni Klemm, Ph.D.<br></b>Postdoctoral Research Associate</font></div><div style="color:rgb(0,0,0);font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Department of Ecosystem Science and Management</div><div style="color:rgb(0,0,0);font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">College of Agriculture and Life Sciences</div><div style="color:rgb(0,0,0);font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Texas A&M University, College Station, TX</div><div style="color:rgb(0,0,0);font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Calibri">Contributor to the <a href="http://www.eccforum.org" target="_blank">Early Career Climate Forum</a><br><a href="http://www.toni-klemm.de" target="_blank">www.toni-klemm.de</a> | <a href="http://twitter.com/toniklemm" target="_blank">@toniklemm</a></font></div><div style="color:rgb(0,0,0);font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Calibri"><br></font></div><div style="color:rgb(0,0,0);font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Calibri"><br></font></div></div></div><br class="gmail-m_-941660536421261816Apple-interchange-newline"></div><br class="gmail-m_-941660536421261816Apple-interchange-newline"></div><br class="gmail-m_-941660536421261816Apple-interchange-newline"></div><br class="gmail-m_-941660536421261816Apple-interchange-newline"><br class="gmail-m_-941660536421261816Apple-interchange-newline">
</div>
<div><br><blockquote type="cite"><div>On Jan 22, 2019, at 9:58 AM, Toni Klemm <<a href="mailto:toni-klemm@tamu.edu" target="_blank">toni-klemm@tamu.edu</a>> wrote:</div><br class="gmail-m_-941660536421261816Apple-interchange-newline"><div><div style="overflow-wrap: break-word;">Hello NCL community,<div><br></div><div>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. </div><div><br></div><div>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. </div><div><br></div><div>My approach so far was to average the third dimension first and then the second dimension using this command:</div><div><font face="Courier">NPP_G_annual_avg = dim_avg_n(dim_avg_n(NPP_G,2),1)</font></div><div><br></div><div>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”.</div><div><br></div><div>Thank you very much for your help! I really appreciate it.</div><div><br></div><div>Best,</div><div>Toni<br><div>
<div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="auto" style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Calibri"><br class="gmail-m_-941660536421261816Apple-interchange-newline"><br></font></div><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Calibri"><b>Toni Klemm, Ph.D.<br></b>Postdoctoral Research Associate</font></div><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Department of Ecosystem Science and Management</div><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">College of Agriculture and Life Sciences</div><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Texas A&M University, College Station, TX</div><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Calibri">Contributor to the <a href="http://www.eccforum.org/" target="_blank">Early Career Climate Forum</a><br><a href="http://www.toni-klemm.de/" target="_blank">www.toni-klemm.de</a> | <a href="http://twitter.com/toniklemm" target="_blank">@toniklemm</a></font></div><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Calibri"><br></font></div><div style="font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Calibri"><br></font></div></div></div><br class="gmail-m_-941660536421261816Apple-interchange-newline"></div><br class="gmail-m_-941660536421261816Apple-interchange-newline"></div><br class="gmail-m_-941660536421261816Apple-interchange-newline"></div><br class="gmail-m_-941660536421261816Apple-interchange-newline"><br class="gmail-m_-941660536421261816Apple-interchange-newline">
</div>
</div></div><span id="gmail-m_-941660536421261816cid:939E3856-A87B-4C83-8025-8E5CB5AD495F"><NPP_G_annual_avg_NP_2015.csv></span><div style="overflow-wrap: break-word;"><div></div></div></div></blockquote></div><br></div></div>_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</blockquote></div>