How interpolate latitude/longitude points from grid to reals points of interest and compute agregated values?

Please consider a df1 :
df.dtypes

DAT_RUN             datetime64[ns]
DAT_FORECAST        datetime64[ns]
LIB_SOURCE          object
LONGITUDE           object
LATITUDE            object
MEASURE1            float64
MEASURE2	        float64

12 first rows (grouped by DAT_RUN and DAT_FORECAST):

      DAT_RUN        DAT_FORECAST LIB_SOURCE LONGITUDE 		LATITUDE  	MEASURE1  	MEASURE2     
0  2022-04-02 2022-04-02 01:00:00    gfs_025          43.5         3.75         5.542505          54.8  
1  2022-04-02 2022-04-02 01:00:00    gfs_025          43.5          4.0        12.542505          57.7  
2  2022-04-02 2022-04-02 01:00:00    gfs_025          43.5         4.25        10.842505          53.7  
3  2022-04-02 2022-04-02 01:00:00    gfs_025          43.5          4.5         8.742505          49.1  
4  2022-04-02 2022-04-02 01:00:00    gfs_025         43.75         3.75         2.042505          58.1  
5  2022-04-02 2022-04-02 01:00:00    gfs_025         43.75          4.0         3.742505          46.9  
6  2022-04-02 2022-04-02 01:00:00    gfs_025         43.75         4.25         4.942505          42.9  
7  2022-04-02 2022-04-02 01:00:00    gfs_025         43.75          4.5         4.142505          45.5  
8  2022-04-02 2022-04-02 01:00:00    gfs_025          44.0         3.75        -0.057495          58.3  
9  2022-04-02 2022-04-02 01:00:00    gfs_025          44.0          4.0         1.942505          53.0  
10 2022-04-02 2022-04-02 01:00:00    gfs_025          44.0         4.25         3.542505          47.0  
11 2022-04-02 2022-04-02 01:00:00    gfs_025          44.0          4.5         4.242505          45.6  

And df2 dataframe with:

df2
  LATITUDE LONGITUDE
0       x1        y1
1       x2        y2
2       x3        y3
3       x4        y4
4       x5        y5

I want to interpolate df1 data:

  1. for each df1 subgroup grouped by DAT_RUN and DAT_FORECAST (12 rows):
  2. Consider that first 3 rows (0, 1 and 2) of df1 are nearest df2 (x1, y1).

How to interpolate and create a new row in df3 with :
LATITUDE = x , LONGITUDE = y, mean (or other operation) applied to MEASURE1 and MEASURE2:

So from 12 df1 rows we get 5 news rows (rows number of df2).

Here is the fist df3 row:

df3 : 
DAT_RUN        DAT_FORECAST        LIB_SOURCE LONGITUDE LATITUDE MEASURE1  	                    MEASURE2     
0  2022-04-02 2022-04-02 01:00:00  gfs_025    x1        x2       mean(5.542505+12.542505+10.842505) mean(54.8+57.7+53.7) 

Perhaps use scipy or https://www.pygmt.org/latest/api/generated/pygmt.grdtrack.html?highlight=grdtrack#pygmt.grdtrack but I have non idea for this last.

Thanks.

I haven’t read your post too clearly, but it sounds like you might want to look at pandas.groupby, see https://pandas.pydata.org/pandas-docs/stable/user_guide/groupby.html or https://pandas.pydata.org/pandas-docs/stable/user_guide/window.html to do a mean operation over your time-series bins. The grdtrack operation probably isn’t what you want because that function is selecting values from a raster grid based on X/Y points.

Ok thanks. But firstly I have to find nearest GPS points to a POI. Is pygmt.grdtrack do the job?

No, you would need to use a nearest neighbor algorithm for this, see e.g. https://stackoverflow.com/questions/58938702/how-to-do-nearest-neighbour-analysis-using-geopandas-geo-python-gis#58943061