## grdtrack for interpolation

Dear All

I would like to calculate from a GMT grd (long,lat, a value) file using the nearest points within say 300km from

my intended interpolation point (longitude,latitude) pair.

I use the command grdtrack

grdtrack my_points.ll -nn -Gmy_grid.grd

I use the latest GMT version.

My GMT grid contains NaN values on land and a prescribed values on the ocean in geodetic coordinate system.

Where file my_points.ll contains a longitude and a latitude pair of interest, which presumably is located very near to the coast.

-n option is what I wanted, n = nearest-neighbor.

How do I set the 300km so that grdtrack will only use the nearest-neighbor within in the

prescribed 300km radius from the point of interest. For more clarification, please have a look at the

attached a picture of my intent. Or is there a better way of doing this ?

Regards

Yacob

IMG_1126.PNG - The gray is NaN values on land and the colors are values on the Ocean (234 KB)

### Replies (8)

#### RE: grdtrack for interpolation - Added by Joaquim 2 months ago

No, grdtrack cannot do that and honestly I don't even understand the idea. Nearest neighbor means exactly that, to get the value of the grid node that is closest to the interest point. How would you use the values of all nodes that are within a circle of 300 km distance form you point? Maybe you want to pre-process your grid with grdfilter.

#### RE: grdtrack for interpolation - Added by Yacob 2 months ago

Hi Joaquim,

Thank for your reply. I just want to evaluate to my point of interest from the grd file taking into consideration all the grid values within 300 km radius ?

Could this be clear ?

Regards

Yacob

#### RE: grdtrack for interpolation - Added by Joaquim 2 months ago

Could this be clear ?

Hmm, actually it could. What does it mean "take into consideration"? To take a mean of all or them?

Again, consult grdfilter to see if that's what you are after.

#### RE: grdtrack for interpolation - Added by Yacob 2 months ago

Hi Joaquim,

I mean taking all those grid points within the 300 km radius from my point, essentially taking a mean of all

those points. So are you saying that grdtrack can do this ?

I will look into grdfilter.

Regards

Yacob

#### RE: grdtrack for interpolation - Added by Joaquim 2 months ago

No, it can't. That's not a job for grdtrack. grdfilter should be able to create the grid that you need to later use in grdtrack.

#### RE: grdtrack for interpolation - Added by Paul 2 months ago

Run a 300 km full-width boxcar filter with grdfilter, then sample the filtered grid wherever you want with grdtrack.

#### RE: grdtrack for interpolation - Added by Yacob 2 months ago

Dear Paul

Pleased to read your response. I used the "grdfilter" command in the following way:

grdfilter input.grd -D1 -Fb300 -Nip -Goutput_filter_300km.grd

My input grid (x,y) are in longitude and latitude degrees where on land the values are set to NaN while on the Ocean with its prescribed values.

Here I chose -D1 option since my grid coordinates, grid (x,y) are in degrees and my filter width is in kilometers (300km).

But I got an identical result. The "input.grd" and "output_filter_300km.grd" are the same.

my input grid size is: 1.8 (along longitude) by 1.9 degrees (along latitude). I suspect that there is no input grid values

when I set -Fb300 , which is roughly 1.5 degree in the equator, less than my input resolutions.

I suspect that the correct width should be -Fb600 that filters within a radius of 300km.

grdfilter input.grd -D1 -Fb600 -Nip -Goutput_filter_300km.grd

-Nip controls how grdfilter controls the input and output NaN values

The above command with -Fb600 option seems to work.

Regards,

Yacob

#### RE: grdtrack for interpolation - Added by Paul 2 months ago

Yes, sorry, mean to say the full width equals the filter diameter, so 600 is correct.

(1-8/8)