用于屏蔽或无序输入数据的 Python 2d 插值

时间:2021-07-26 13:16:12

标签: python scipy interpolation masked-array

我拥有的数据是频率 (f) 和 theta *(th) *它们是对应于二维物体光束的坐标 ( b)。即:(f_i, th_i) == b_ii

我使用 scipy.interpolate.interp2d 设置了 2d 插值。效果很好,直到我按降序使用新输入数据或使用掩码数组 (掩码值变为 0 重新排序数据,使零值排在第一位。

如果我重新应用蒙版,由于数据的顺序,它会出现在不正确的位置。有人有简单的解决方法吗?

注意: 新输入值在原始网格设置的范围内。

1 个答案:

答案 0 :(得分:0)

来自Scipy-interp2d returned function sorts input argument automatically and undesirably的解决方案

基于以上链接提交的内容

from scipy.interpolate import interp2d
import numpy as np

class unsorted_interp2d(interp2d):
    def __call__(self, x, y, dx=0, dy=0):
        unsorted_idxs = np.argsort(np.argsort(x))
        return interp2d.__call__(self, x, y, dx=dx, dy=dy)[:,unsorted_idxs]

刚刚将 [unsorted_idxs] 更改为 [:,unsorted_idxs] 以适用于 2d 对象中的所有 x 值

相关问题