I am working with some xarray
data arrays which have some data at particular latitude/longitude coordinates.
For each lat/long coordinate pair in data array 1 (da1
) I want to find the closest lat/long pair in data array 2 (da2
).
Following this StackOverflow answer a solution that seems to work is:
lats = xr.DataArray(da1.latitude.data, dims='z') #'z' is an arbitrary name placeholder
lons = xr.DataArray(da1.longitude.data, dims='z')
data = da2.sel(latitude = lats, longitude = lons, method = 'nearest')
This returns the data
dataset which has the same length as da1
.
My questions are:
- How does the nearest method trade off "nearness" in each of the latitude and longitude coordinates?
For example, one can imagine a case where the match in the longitude is very close, and the match in latitude is a bit worse, compared with the opposite case where the match in the longitude is not so good close, but the match in latitude is very close. By what metric does the 'nearest' method judge this?
When setting a tolerance, does this tolerance apply to the latitude and longitude separately?
What is the default tolerance?