2

我试图找到观测数据的伽马函数的逆 CDF,以便找到传递函数。整个目标是通过 CDF 匹配 CDFobs(y) = CDFsim(x)来纠正模拟数据中的偏差。我尝试使用以下抛出和错误的方法来做到这一点。

下图显示了 CDF 和 plot(c) 中的传递函数。我正在尝试复制相同的内容。请帮助我实现情节。

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
import scipy.stats as st


sim = st.gamma(1,loc=0,scale=0.8) # Simulated
obs = st.gamma(2,loc=0,scale=0.7) # Observed
x = np.linspace(0,4,1000)
simpdf = sim.pdf(x)
obspdf = obs.pdf(x)
plt.plot(x,simpdf,label='Simulated')
plt.plot(x,obspdf,'r--',label='Observed')
plt.title('PDF of Observed and Simulated Precipitation')
plt.legend(loc='best')
plt.show()

plt.figure(1)
simcdf = sim.cdf(x)
obscdf = obs.cdf(x)
plt.plot(x,simcdf,label='Simulated')
plt.plot(x,obscdf,'r--',label='Observed')
plt.title('CDF of Observed and Simulated Precipitation')
plt.legend(loc='best')
plt.show()

# Inverse CDF
invcdf = interp1d(obscdf,x)
transfer_func = invcdf(simcdf)

plt.figure(2)
plt.plot(transfer_func,x,'g-')
plt.show()

回溯(最近一次通话最后):文件“/home/bias_correction.py”,第 54 行,在 transfer_func = invcdf(simcdf)

文件“/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py”,第 357 行,在 _ call _ out_of_bounds = self._check_bounds(x_new)

_check_bounds 中的文件“/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py”,第 415 行引发 ValueError(“x_new 中的值高于插值” ValueError:x_new 中的值高于插值范围。

4

1 回答 1

2

我认为 interp1d 的论点是相反的。它应该是

invcdf = interp1d(x, obscdf)
于 2013-01-02T14:54:10.790 回答