<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Time consuming? Do you have more dimensions than just (lat, lon)?</div><div><br></div><div>To improve run time, rearrange code to maximize the use of gridded operations. Loop over grid box offsets, not the whole grid. Something like this for 4-D, incomplete and untested. The subscripting (:,:,:,:) is only to clarify dimensions. It can be included or omitted with no change in performance.<br><br></div>do ioff = 0, 2<br> do joff = 0, 2</div> if (ioff .eq. 0 .and. joff .eq. 0) then<br> prc8 = prc24(:, :, ioff:nlat24-1:3, joff:mlon24-1:3)<br> else<div dir="ltr"> prc8(:,:,:,:) = (/ prc8(:,:,:,:) + prc24(:, :, ioff:nlat24-1:3, joff:mlon24-1:3) /)</div><div dir="ltr"> end if<br> end do<br>end do<br><br>prc8<span style="color:rgb(0,0,0);font-family:-webkit-standard;font-size:medium">(:,:,:,:)</span> = prc8<span style="color:rgb(0,0,0);font-family:-webkit-standard;font-size:medium">(:,:,:,:)</span> / (3 * 3)</div><div dir="ltr"><br></div><div dir="ltr">If you have missing values, the gridded approach will still work. You will need to add data masking and a count array.<br><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 1, 2020 at 10:26 AM Xueyan Zhang <<a href="mailto:xueyanzhang520@gmail.com">xueyanzhang520@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Thanks! I'll check it out! It's just time consuming if I use loops...<div><br></div><div>Xueyan</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 1, 2020 at 9:23 AM Dennis Shea <<a href="mailto:shea@ucar.edu" target="_blank">shea@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div> There is no builtin function, As suggested by Dave:</div><div><br></div><div> **UNTESTED** you nay have to make sure this is correct.</div><div><br></div><div> nm = 3<br></div><div> nlat24 =</div><div> mlon24 = <br></div><div> prc8 = prc24(1:nlat24-2:mn,1:mlon24-2:mn)</div><div> prc8 = prc24@_FillValue<br></div><div> printVarSummary(prc8)</div><div><br></div><div> dims_prc8 = dimsizes(prc8)</div><div> nlat8 = dims_prc8(0)</div><div> mlon8 = dims_prc8(1)</div><div> print(dims8_prc8)</div><div><br></div><div>; This does a straight arithmetic average.<br></div><div><br></div><div> do nl=1,nlat24-2,mm</div><div> do ml=1,mlon24-2,mn</div><div> prc8(nl/mn,ml/mn) = (prc24(nl+1,ml-1)+prc24(nl+1, ml )+prc24(nl+1,ml+1) \</div><div> +prc24(nl ,ml-1)+prc24(nl , ml )+prc24(nl ,ml+1)\</div><div> +prc24(nl-1,ml-1)+prc24(nl-1, ml )+prc24(nl-1,ml+1))/9.0</div><div> end do</div><div> end do</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 1, 2020 at 9:59 AM Dave Allured - NOAA Affiliate via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>In NCL, this kind of operation falls under regridding, not interpolation. I recommend one of the area averaging functions, such as area_conserve_remap, area_hi2lores, or ESMF_regrid.</div><div><br></div><div>None of those functions use the grid box calculation that you specified. If you want to perform that exact calculation over all grid boxes falling in a 1/8 degree box, you will need to write your own NCL code. I suggest that you use the dim_avg_n function inside a double loop over all output points on the 1/8 degree grid. "There is more than one way to do this."</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 1, 2020 at 8:58 AM Xueyan Zhang via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello NCL,<div><br></div><div>I want to interpolate precipitation data from 1/24 degree to 1/8 degree. The way I wanna do it is to: calculate the average of all grid boxes falling in a 1/8 degree box? Is there any function in NCL?</div><div><br></div><div>Thanks!</div><div><br></div><div>Xueyan</div></div></blockquote></div></div></div></div></blockquote></div>
</blockquote></div>
</blockquote></div></div></div></div></div></div></div></div></div>