zerothi / sisl

Electronic structure Python package for post analysis and large scale tight-binding DFT/NEGF calculations
https://zerothi.github.io/sisl
Mozilla Public License 2.0
201 stars 60 forks source link

Interpolate from grid. #590

Open pfebrer opened 1 year ago

pfebrer commented 1 year ago

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?

zerothi commented 1 year ago

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 ?

pfebrer commented 1 year ago

What about allowing somekind of grid directly?

Do you mean interpolating the grid into another grid?

zerothi commented 1 year ago

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

pfebrer commented 1 year ago

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 (?)

zerothi commented 1 year ago

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 commented 9 months ago

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.

pfebrer commented 9 months ago

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.