1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

scipy で多次元データ補間のメモ

Posted at

背景

たとえば三次元位置 + 時刻の4次元の値での法線(vector 値)の補間とかやりたい.
nearest neighbor or linear 補間でよい

scipy

Pythonでn次元のデータを補間して利用する方法
http://salamann.com/python-multi-dimension-data-interpolation

SciPy補間 (interpolate)
http://www.yamamo10.jp/yamamoto/comp/Python/library/SciPy/interpolate/index.php

scipy.interpolate.interpn, RegularGridInterpolator でよさそう(両方とも同じ?)

データは等間隔グリッドであるする. ただし間隔は不等間隔でもよいので, 軸は 4 点でそれぞれ対応する間隔は [0.0, 0.1, 0.5, 1.0] みたいなのは OK(のはず).

import scipy.interpolate

nx = 4
ny = 4
nz = 4
nw = 4
datanum = 3 # vector data at each grid point 

x1 = np.arange(4) / (nx - 1)
x2 = np.arange(4) / (ny - 1)
x3 = np.arange(4) / (nz - 1)
x4 = np.arange(4) / (nw - 1)

points = (x1, x2, x3, x4)

data = np.arange(0, nx * ny * nz * nw * datanum)
data = np.reshape(data, (nw, nz, ny, nx, -1))
# print(data)
          
# fn = pts(*np.meshgrid(*points))

ip = scipy.interpolate.interpn(points, data, (0.5, 0.5, 0.5, 0.5))
print(ip)

[[382.5 383.5 384.5]]

一応うまく補間できているっぽい?

  • TODO
    • 不等間隔なデータグリッドでの補間を試す: LinearNDInterpolator
      • 三次元ポリゴン頂点で値を補間したいときとか? しかし計算量かかりそうなので可能な限り等間隔グリッドにしてから処理するのがよさそう.
    • 多次元での cubic 補間を試す: xとf(x)が両方とも3次元なデータを補間 https://qiita.com/hajimen/items/021f83905f20645124ce
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?