简体   繁体   English

numpy 2D数组的怪异插值

[英]Weird interpolation of a numpy 2D array

I've got a bunch of data sets in the form of 131 by 20 2D numpy arrays and I'm trying to interpolate those to square 131x131 ones. 我有一堆20个2D numpy数组形式的131个数据集,我正尝试将其插值为131x131平方。 I've seen others' code many times now but I'm still getting some odd results. 我已经看过很多遍别人的代码了,但是我仍然得到一些奇怪的结果。 Here is my interpolation code: 这是我的插值代码:

import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate

# bunch of code

# radarray.shape = (131, 20)

T0 = np.arange(0, radarray.shape[1], 1)
Z0 = np.arange(0, radarray.shape[0], 1)

t, z = np.meshgrid(T0, Z0)

f = interpolate.interp2d(t, z, radarray, kind='quintic')

T = np.linspace(0, radarray.shape[1], 131)
Z = np.arange(0, radarray.shape[0], 1)
radinterp = f(T, Z)
plt.imshow(radinterp, aspect='auto', interpolation='none')
plt.gca().invert_yaxis()
plt.savefig('interp')

This is what the raw data from radarray looks like: 这是来自radarray的原始数据如下所示:

And this is the result: 结果如下:

I've tried switching the interpolation methods and the radarray.shape indices but everything results in just a green field or these weird vaguely sine bumps that have nothing to do with my data. 我尝试过切换插值方法和radarray.shape索引,但是所有结果只会导致一个绿色区域或这些与我的数据无关的模糊的正弦波。 Where did I screw up? 我在哪里弄糟?

Why don't you use skimage's resize ? 为什么不使用skimage的resize

from skimage.transform import resize

radinterp = resize(radarray, (131, 131), anti_aliasing=True)

Should do the trick for you. 应该为您解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM