# Re: interpolate data from observation stations to regular grid box

Date: Thu, 29 Dec 2005 16:56:42 -0700

Hi Liz,

I don't think that NCL has an automatic way to restict interpolation
based on the distance to nearest data pt.

However, you can apply a distance restriction yourself by creating a
filter that uses gc_latlon. You would only have to run the filter once.
Unfortunately, there will be a triple do loop, so restricting your 2x2
grid to around Europe would speed things up.

http://www.ncl.ucar.edu/Document/Functions/Built-in/gc_latlon.shtml
(If anyone can come up with a faster way to do this please do...)

; Untested!
; cssout contains the output from cssgrid (2x2 grid), oldlat = 1D array
; of station latitudes, oldlon = 1D array of station longitudes.
;
distance = 500 ; set maximum distance in kilometers

lat = cssout&lat
lon = cssout&lon

temp = oldlat ; preallocate space for float array
do gg = 0,dimsizes(lat)-1
do hh = 0,dimsizes(lon)-1
do ii = 0,dimsizes(oldlat)-1
temp(ii) = gc_latlon(lat(gg),lon(hh),oldlat(ii),oldlon(ii),2,4)
end do
if (all(temp.gt.distance)) then
cssout(gg,hh) = cssout@_FillValue
end if
end do
end do

If multiple maps (on the same 2x2 grid based on the same stations)
require filtering, use the mask function to apply the same masking to
other maps. Applying the filtering to cssout2:

Hope that helps.

Liangying Zhang wrote:
> Dear all,
>
> I would like to interpolate some data from observation stations to
> regular grid box(2x2) and then plot it as contour lines. I found a
> function called "cssgrid" to do interpolation. But for those grid boxes
> which have no data nearby, I rather have missing value other than doing
> interpolation (It gave me very unreasonable data). Is there any way to
> put distance restriction for interpolation? Or NCL provides other
> functions which can do this?
>
> Attached is a plot with polymarkers on observation stations.
>
> Thanks a lot!
> Liz
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

```--
--------------------------------------------------------------