[ncl-talk] How to interpolate precipitation without losing much confidence?
Dave Allured - NOAA Affiliate
dave.allured at noaa.gov
Thu Oct 1 12:29:04 MDT 2020
Time consuming? Do you have more dimensions than just (lat, lon)?
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.
do ioff = 0, 2
do joff = 0, 2
if (ioff .eq. 0 .and. joff .eq. 0) then
prc8 = prc24(:, :, ioff:nlat24-1:3, joff:mlon24-1:3)
else
prc8(:,:,:,:) = (/ prc8(:,:,:,:) + prc24(:, :, ioff:nlat24-1:3,
joff:mlon24-1:3) /)
end if
end do
end do
prc8(:,:,:,:) = prc8(:,:,:,:) / (3 * 3)
If you have missing values, the gridded approach will still work. You will
need to add data masking and a count array.
On Thu, Oct 1, 2020 at 10:26 AM Xueyan Zhang <xueyanzhang520 at gmail.com>
wrote:
> Thanks! I'll check it out! It's just time consuming if I use loops...
>
> Xueyan
>
> On Thu, Oct 1, 2020 at 9:23 AM Dennis Shea <shea at ucar.edu> wrote:
>
>> There is no builtin function, As suggested by Dave:
>>
>> **UNTESTED** you nay have to make sure this is correct.
>>
>> nm = 3
>> nlat24 =
>> mlon24 =
>> prc8 = prc24(1:nlat24-2:mn,1:mlon24-2:mn)
>> prc8 = prc24 at _FillValue
>> printVarSummary(prc8)
>>
>> dims_prc8 = dimsizes(prc8)
>> nlat8 = dims_prc8(0)
>> mlon8 = dims_prc8(1)
>> print(dims8_prc8)
>>
>> ; This does a straight arithmetic average.
>>
>> do nl=1,nlat24-2,mm
>> do ml=1,mlon24-2,mn
>> prc8(nl/mn,ml/mn) = (prc24(nl+1,ml-1)+prc24(nl+1, ml
>> )+prc24(nl+1,ml+1) \
>> +prc24(nl ,ml-1)+prc24(nl ,
>> ml )+prc24(nl ,ml+1)\
>> +prc24(nl-1,ml-1)+prc24(nl-1,
>> ml )+prc24(nl-1,ml+1))/9.0
>> end do
>> end do
>>
>> On Thu, Oct 1, 2020 at 9:59 AM Dave Allured - NOAA Affiliate via ncl-talk
>> <ncl-talk at mailman.ucar.edu> wrote:
>>
>>> 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.
>>>
>>> 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."
>>>
>>>
>>> On Thu, Oct 1, 2020 at 8:58 AM Xueyan Zhang via ncl-talk <
>>> ncl-talk at mailman.ucar.edu> wrote:
>>>
>>>> Hello NCL,
>>>>
>>>> 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?
>>>>
>>>> Thanks!
>>>>
>>>> Xueyan
>>>>
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20201001/899d980f/attachment.html>
More information about the ncl-talk
mailing list