【问题标题】:histogram matching in PythonPython中的直方图匹配
【发布时间】:2023-04-05 04:46:02
【问题描述】:

我正在尝试将模拟数据与观测到的降水数据进行直方图匹配。下面显示了一个简单的模拟案例。我得到了模拟数据和观察数据的 CDF 并被困在那里。我希望一个线索能帮助我理解..提前谢谢你

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()

【问题讨论】:

  • 您的问题是什么?你想做什么却做不到?
  • @Ben,我正在尝试 CDF 匹配/直方图匹配,如图所示。s8.postimage.org/4txybzz8l/test.jpg。我无法反转观察到的数据的 CDF,这是下一步。
  • 看起来您需要为所需的 y 值插入 CDF,然后用旧的 x 值绘制它。
  • @tiago,如果您能提出解决方案,我将不胜感激。
  • @subash, what have you tried? 我不会为你写代码。您的示例代码主要是情节,您似乎没有尝试过任何解决此问题的方法。索取代码并不是 SO 的目的。

标签:
python
numpy
histogram
cdf