sisl icon indicating copy to clipboard operation
sisl copied to clipboard

Interpolate from grid.

Open pfebrer opened this issue 1 year ago • 7 comments

I would like to add a method to interpolate values from a Grid, given some coordinates. I have looked into it and it seems like the way to go is to use scipy.interpolate.RegularGridInterpolator.

To clarify, the method would work something like this:


rho = sisl.Grid(...)

# Get the value of the electronic density at the points that we are interested, even
# if they are not part of the grid.
interesting_points = [[0,1.3, 4.5], [2.3, 4.7, 10]]
rho_vals = rho.interpolate(interesting_points) 

(1) Do you think it makes sense? (2) Where would you put it, given that there is already a method named interp?

pfebrer avatar Jun 21 '23 11:06 pfebrer

I agree this would be nice.

What about allowing somekind of grid directly? That grid could be GridPoints for subsets, or something similar. Much along the line of your proposal #502 ?

zerothi avatar Jun 21 '23 11:06 zerothi

What about allowing somekind of grid directly?

Do you mean interpolating the grid into another grid?

pfebrer avatar Jun 21 '23 11:06 pfebrer

yes, basically the grid.interp does this by just changing the shape (retaining everything else).

zerothi avatar Jun 21 '23 11:06 zerothi

Ok, that is my final goal (I'm thinking of ways to speed up the computation of the psi values). But I'm not sure if there is a faster/better way than computing the coordinates of all points of your target grid and then passing them to the interpolator "individually".

Maybe with fourier transforms (?)

pfebrer avatar Jun 21 '23 11:06 pfebrer

Ok, that is my final goal (I'm thinking of ways to speed up the computation of the psi values). But I'm not sure if there is a faster/better way than computing the coordinates of all points of your target grid and then passing them to the interpolator "individually".

Maybe with fourier transforms (?)

interpolations can be quite slow unless highly optimized. So far from all times will it be good. Secondly, FFT might not always work, so backend selection should be vital.

zerothi avatar Jun 21 '23 11:06 zerothi

could we change interp to accept a lattice object and rescale everything there? Or perhaps the first argument could just be another Grid so the lattice can be re-used, and the grid-shape taken from there.

zerothi avatar Feb 28 '24 11:02 zerothi

Yes I think that there should be a base class as abstract as Space and then we could implement interpolation algorithms between the different subclasses of space. E.g. from Grid to SpacePoints.

Then interp would receive the space object into which the data should be interpolated.

pfebrer avatar Feb 28 '24 13:02 pfebrer