I'm trying to regrid vector component data (u and v representing positive x and y) on an EASE coordinate system to East and West components on a latitude longitude coordinate system. The vector components need to be rotated in addition to any interpolation. Below is a brute force method I used but it's slow - I'm new to programming and feel there should be a better way.
I'm getting confused by the indexing when trying to use xr.interp(). The data is indexed u(y, x, time) - with x, y in meters. Latitude and longitude variables are included and indexed(y, x).
Thank you!
xn = np.arange(-179.75, 179.75, 0.5)
yn = np.arange(-90, -60, 0.5)
# Initialize array for East component
E_1 = np.zeros((len(yn), len(xn)))
# Iterate through each new lon and lat grid point
for i in range(len(xn)):
for j in range(len(yn)):
# Find absolute value distances of j'th lat from entire lat_ease array and store in array
dy = (yn[j]-lat_ease)**2
# Find absolute value distances of i'th lat from entire lat_ease array and store in array
dx1 = (xn[i]-lon_ease)**2
# Account for possibilities with periodicity
dx2 = (xn[i]-lon_ease+360)**2
dx3 = (xn[i]-lon_ease-360)**2
# Find miniumum dx array between the three different arrays accounting for periodicity
dx = np.minimum.reduce([dx1, dx2, dx3])
# Find distances (we don't need sqrt here b/c not using actual value, just minimum)
ds = dx + dy
# Find indices of minimum ds value
i_neighbors = np.where(ds == np.min(ds))
ii = np.min(i_neighbors[0])
jj = np.min(i_neighbors[1])
# NOTE: Could use np.argmin() to return the index of first minimum occuring value
E_1[j, i] = u_ease[0, jj, ii]*np.cos(np.radians(lon_ease[jj, ii])) - v_ease[0, jj, ii]*np.sin(np.radians(lon_ease[jj,ii]))
```