用于3D表面预测的薄板样条

时间:2016-11-10 13:12:24

标签: r spline

我试过这个答案

get a surface plot in R

但它没有真正帮助。 我想在XYZ数据帧上执行TPS(使用来自Fields {}的Tps),其中xy是co-orinates,z是厚度。然后我想首先在TPS之前然后在TPS之后想象该情节..?这可能吗。 然后我想提取一组给定的新xy坐标的预测厚度。?

如果可能,请告诉我

My Dataframe看起来像这样,数据帧称为LSP:

import networkx as nx
import matplotlib.pyplot as plt
from networkx.drawing.nx_agraph import graphviz_layout

G = nx.DiGraph()

l=[
    ('a','b'),
    ('b','c'),
    ('c','d'),
    ('d','e'),
    ('e','f'),
    ('w','x'),
    ('w','t'),
    ('t','q'),
    ('q','r'),
    ('q','u')
    ]

for t in l:
    G.add_edge(t[0], t[1])

pos=graphviz_layout(G, prog='dot')
nx.draw(G, pos, with_labels=True)   
plt.show()

所以我尝试了这个:

time   PART   MEAS    PARTSUB   XLOC   YLOC
xxxx   1      1.956   a         -3465  -94350
xxxx   1      1.962   a         -3465  -53850
xxxx   1      1.951   a         50435  -40350
xxxx   1      1.958   a         -57365 -40350

但是out.p只是NULL ..?

所以尝试情节给了我:

LSP.spline <- Tps(LSP[,5:6], LSP$MEAS)
out.p <- predict.surface(LSP.spline, xy = c(1,2))
plot.surface(out.p, type="p")

感谢任何帮助。 保罗。

1 个答案:

答案 0 :(得分:2)

predict.surface现在是一个过时/弃用的功能。请改用predictSurface

fit<- Tps( BD[,1:4], BD$lnya)  # fit surface to data 

# evaluate fitted surface for  first two 
# variables holding other two fixed at median values

out.p<- predictSurface(fit)
surface(out.p, type="C") 

enter image description here

  

谢谢你 - 我的第二个问题......如何为一组给定的XY位置提取预测的表面厚度值??

使用predict功能。阅读?predict.Tps。对于上面的例子,假设我们想要预测BD[, 1:4]中的前4个位置,我们可以做

predict(fit, x = BD[1:4, 1:4])

#          [,1]
#[1,] 11.804124
#[2,] 11.804124
#[3,]  8.069056
#[4,]  9.501551

通常,将x传递给两列矩阵。