Skip to content
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

On the performances of interpGrid #8

Open
matteodefelice opened this issue Jun 13, 2017 · 3 comments
Open

On the performances of interpGrid #8

matteodefelice opened this issue Jun 13, 2017 · 3 comments
Assignees

Comments

@matteodefelice
Copy link
Contributor

matteodefelice commented Jun 13, 2017

Hi, I was interpolation a high-res field and I had to stop the computation after one hour because it was still running... I took the occasion to better analyse the difference between akima::interp and fields::interp.surface.grid. Apparently, the former is faster with smaller grids, the latter becomes significantly faster when the grid has more than 10k points. Here a reproducible example to compare the performances:

##
library(akima)
library(fields)
library(microbenchmark)
SIZE = 50
## test data
x = seq(0, 1, length.out = SIZE)
y = seq(0, 1, length.out = SIZE)
df = expand.grid(x = x, y = y)
df$z = rnorm(nrow(df))
z_matrix = matrix(df$z, ncol = length(y), nrow = length(x))

xo = seq(0, 1, length.out = SIZE*10)
yo = seq(0, 1, length.out = SIZE*10)

mb = microbenchmark(
i1 <- akima::interp(df$x, df$y, df$z, xo, yo),
i2 <- fields::interp.surface.grid(list(x = x, y = y, z = z_matrix),
                                 list(x = xo, y = yo)), times = 10
)

This is very important to help the user to choose the best bilin.method.

UPDATE: We have a problem. I did a small benchmark with a real NetCDF with loadGridData + interpGrid and... the fields version took a few seconds while the akima is still running...(five minutes now). Can someone trying something similar?

2nd UPDATE: Switching all my code to fields has really improved the execution time, unbelievable. I'd suggest also considering the inclusion of bicubic.grid from akima that seems faster than both.

@jbedia
Copy link
Member

jbedia commented Jun 21, 2017

Hi Matteo, thanks for reporting. Certainly relevant information to better inform the users. Regarding nearest neighbours (by far the most advisable method in most climate applications...), I am right now looking at a faster Rcpp-based implementation. To be updated soon -hopefully-.

@jbedia jbedia self-assigned this Jun 21, 2017
@matteodefelice
Copy link
Contributor Author

Thanks @jbedia, I am rather surprised by your statement about nearest neighbours...I have never used it, normally I use interpolation to match two grids, for example increasing the resolution of a climate forecast to the grid of observations (for example, System4 to E-OBS). Do you think in this case I should use NN?

@jbedia
Copy link
Member

jbedia commented Jul 19, 2017

It depends on the characteristics of your study of course, but in most cases I'd rather opt for NN in order to preserve the original data and avoid spurious gradients, particularly when the difference in resolution between both datasets is large.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants