2017-12-20 22 views
1

(x, y, z, V) 형태로 제공되는 데이터가 있습니다. 여기서 x, y, z는 거리이고 V는 습기입니다. thisthis 유용한 게시물과 같은 파이썬 보간에 대해 StackOverflow에서 많이 읽었지만, 모두는 x, y, z의 일반 그리드에 관한 것이 었습니다. 즉 x의 모든 값은 y의 모든 점과 모든 점 z에 똑같이 기여합니다. 반면에, 요점은 격자가 일정하지 않은 3D 유한 요소 격자 (아래)와 같습니다. 파이썬으로 불규칙한 (x, y, z) 격자를위한 4D 보간

enter image description here

두는 그들 (3 차원 예에서) 다음 cartcoord = zip(x, y) scipy.interpolate.LinearNDInterpolator(cartcoord, z) 같은 것을 사용 별도 NumPy와 배열로 X, Y, Z의 각각의 정의 소식 12을 언급했다. 3D 그리드가 규칙적이지 않기 때문에 각 포인트가 다른 포인트에 기여하지 않기 때문에 이러한 접근 방법을 반복 할 때 많은 null 값을 발견하고 많은 오류가 발생합니다. 여기

[x, y, z, V]

data = [[27.827, 18.530, -30.417, 0.205] , [24.002, 17.759, -24.782, 0.197] , 
[22.145, 13.687, -33.282, 0.204] , [17.627, 18.224, -25.197, 0.197] , 
[29.018, 18.841, -38.761, 0.212] , [24.834, 20.538, -33.012, 0.208] , 
[26.232, 22.327, -27.735, 0.204] , [23.017, 23.037, -29.230, 0.205] , 
[28.761, 21.565, -31.586, 0.211] , [26.263, 23.686, -32.766, 0.215]] 

내가 보간 값 (25, 20, -30)

내가 그것을 어떻게 얻을 수있는 포인트의 V를 얻으려면의 형태로 10 샘플 포인트입니까?

답변

3

답변을 찾았으며 StackOverflow 독자를 위해 게시했습니다.

1- 수입 : 다음

import numpy as np 
from scipy.interpolate import griddata 
from scipy.interpolate import LinearNDInterpolator 

2- 데이터를 준비 :

# put the available x,y,z data as a numpy array 
points = np.array([ 
     [ 27.827, 18.53 , -30.417], [ 24.002, 17.759, -24.782], 
     [ 22.145, 13.687, -33.282], [ 17.627, 18.224, -25.197], 
     [ 29.018, 18.841, -38.761], [ 24.834, 20.538, -33.012], 
     [ 26.232, 22.327, -27.735], [ 23.017, 23.037, -29.23 ], 
     [ 28.761, 21.565, -31.586], [ 26.263, 23.686, -32.766]]) 
# and put the moisture corresponding data values in a separate array: 
values = np.array([0.205, 0.197, 0.204, 0.197, 0.212, 
        0.208, 0.204, 0.205, 0.211, 0.215]) 
# Finally, put the desired point/points you want to interpolate over 
request = np.array([[25, 20, -30], [27, 20, -32]]) 

-3- 얻을 코드의 마지막 라인을 작성을 다음과 같이

방법은 보간 된 값

방법 1, usi NG griddata

print griddata(points, values, request) 
# OUTPUT: array([ 0.20448536, 0.20782028]) 

방법 2, LinearNDInterpolator

# First, define an interpolator function 
linInter= LinearNDInterpolator(points, values) 

# Then, apply the function to one or more points 
print linInter(np.array([[25, 20, -30]])) 
print linInter(xi) 
# OUTPUT: [0.20448536 0.20782028] 
# I think you may use it with python map or pandas.apply as well 

희망이 혜택 모두를 사용하여.

내기