本文介绍了内插一维非函数数据点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难为我的数据点找到插值.这条线应该有点像负二次二次曲线(即像一个反向的c").

I am having difficulties finding an interpolation for my data points. The line should slightly resemble a negative inverse quadratic (ie like a backwards 'c').

由于这不是一个函数(x 可以有多个 y 值),我不确定要使用什么插值.

Since this is not a function (x can have multiple values of y), I am not sure what interpolation to use.

我在想也许我应该使用 UnivariateSpline 之类的东西翻转轴来创建插值点/线,然后在绘制它时将其翻转回来?

I was thinking that perhaps I should flip the axis to create the interpolation points/line using something like UnivariateSpline and then flip it back when I am plotting it?

这是单个点的图表:

这是我的代码:

import datetime as dt
import matplotlib.pyplot as plt
from scipy import interpolate

file = open_file("010217.hdf5", mode = "a", title = 'Sondrestrom1')
all_data = file.getNode('/Data/Table Layout').read()
file.close()


time = all_data['ut1_unix'] #time in seconds since 1/1/1970
alt = all_data['gdalt'] #all altitude points
electronDens = all_data['nel'] #all electron density points
x = []
y = []
positions = []

for t in range(len(time)): #Looking at this specific time, find all the respective altitude and electron density points
    if time[t] == 982376726:
        x.append(electronDens[t])
        y.append(alt[t])
        positions.append(t)

#FINDING THE DATE
datetime1970 = dt.datetime(1970,1,1,0,0,0)
seconds = long(time[t])
newDatetime = datetime1970 + dt.timedelta(0, seconds)
time1 = newDatetime.strftime('%Y-%m-%d %H:%M:%S')
title = "Electron Density vs. Altitude at "
title += time1

plt.plot(x,y,"o")
plt.title(title)
plt.xlabel('Electron Density (log_10[Ne])')
plt.ylabel('Altitude (km)')
plt.show()

推荐答案

正如图表标题所说的电子密度 vs. Altidude",我想纵轴上的每个点只有一个值?

As the graph heading says "electron density vs. Altidude", I suppose there's only one value per point on the vertical axis?

这意味着您实际上正在查看一个已翻转的函数,以便使 x 轴垂直,因为垂直轴上的高度对人类来说更直观.

This means you are actually looking at a function that has been flipped, in order to make the x axis vertical because having altitude on the vertical axis is just more intuitive to humans.

查看您的代码,似乎有一项测量同时测量了高度和电子密度.因此,即使我上面的理论是错误的,您仍然应该能够插入时域中的所有内容并从中创建样条.

Looking at your code, there seems to have been a measurement where both altitude and electron density were measured. Therefore, even if my theory above is wrong, you should still be able to interpolate everything in the time domain and create a spline from that.

...如果你真的想要一条完全通过每个点的曲线.看到数据中有多少分散,您可能应该选择不完全复制每个测量值的曲线拟合:scipy.interpolate.Rbf 应该可以正常工作,同样,为此您应该切换轴,即计算电子密度作为高度的函数.请务必使用 smooth=0.01 或多一点(0.0 将准确地通过每个点,并且在嘈杂的数据上看起来有点傻).

... that's if you really want to have a curve that goes exactly through every point.Seeing as how much scatter there is in the data, you should probably go for a curve fit that doesn't exactly replicate every measurement:scipy.interpolate.Rbf should work alright, and again, for this you should switch the axes, i.e. compute electron density as function of altitude. Just be sure to use smooth=0.01 or maybe a little more (0.0 will exactly go through every point and look a little silly on noisy data).

...实际上,您的大部分问题似乎是更好地理解您的数据:)

... actually it seems most of your problem is understanding your data better :)

这篇关于内插一维非函数数据点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:03