-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nearest Neighbor Interpolation #29
base: main
Are you sure you want to change the base?
Conversation
What's wrong with the interpolation we currently have? |
It uses a sorted binary search on a 1D array to find the index corresponding to the closest point. In this case, the coordinates are 2D and one of them is not sorted (the longitude) |
Certainly this bug should be documented in an issue... |
I don't think we ever tackled the problem of interpolation from an |
Just show us the code that has the problem |
# We assume that all points are very close to each other, so a longitude difference of 180 should not possible, | ||
# this means that the we are on the same side of the globe, but that the longitude is displaced by 360 degrees. | ||
@inline massage_longitude(λ₀, λ) = ifelse(abs(λ₀ - λ) > 180, | ||
ifelse(λ₀ > 180, λ + 360, λ - 360), λ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ifelse(λ₀ > 180, λ + 360, λ - 360), λ) | |
ifelse(λ₀ > 180, λ + 360, λ - 360), λ) | |
Co-authored-by: Navid C. Constantinou <[email protected]>
Co-authored-by: Navid C. Constantinou <[email protected]>
Co-authored-by: Navid C. Constantinou <[email protected]>
Co-authored-by: Navid C. Constantinou <[email protected]>
Co-authored-by: Navid C. Constantinou <[email protected]>
Co-authored-by: Navid C. Constantinou <[email protected]>
Co-authored-by: Navid C. Constantinou <[email protected]>
I wouldn't necessarily say that the code has a problem, just that it does not support interpolation on a "semi-unstructured" grid. We don't have an interpolation method for an |
Probably, this algorithm wouldn't work for a general |
show the code that doesn't work |
No I mean can you produce a code snippet that will fail like |
Ah ok in that sense! using Oceananigans
using OrthogonalSphericalShellGrids
using Oceananigans.Fields: interpolate!
trg = TripolarGrid(size = (10, 10, 10), z = (0, 1))
llg = LatitudeLongitudeGrid(size = (10, 10, 10), latitude = (-75, 75), longitude = (0, 360), z = (0, 1))
ctrg = CenterField(trg)
cllg = CenterField(llg)
interpolate!(cllg, ctrg) |
hallelujah |
This PR introduces an NN interpolation routine to interpolate data from a TRG to a latitude-longitude grid. It is quite crude at the moment and not reliable near the fold, but it looks like it performs ok for the rest of the domain.
I am now using it only for visualization and to perform zonal averages, I am not even sure we want to use this algorithm for actual interpolation in Oceananigans.
Anywas, since I am using it, I ll leave it here so we can decide what to do about it