【问题标题】:Trouble Finding Spectrum Peaks on Python/ Google Colab在 Python/Google Colab 上查找谱峰时遇到问题
【发布时间】:2021-04-20 06:47:57
【问题描述】:

我在 cvs 文件中有一个(油样)光谱作为 2D 数组,我想在波长 600 - 1800 cm-1 中找到峰值。我试过 scipy.signal.find_peaks 但这需要一个一维数组,我有一个二维数组,其中包含波长和相应的峰值。 任何帮助都会受到赞赏,因为我是 python 的初学者

编辑:我还尝试了以下操作:

从检测导入检测峰值

ind = detect_peaks(df)

其中 df 是我的数组的名称(它有两列)并且会弹出一个错误:ValueError: all the input arrays must have the same number of dimensions, but the array at index 0 has 2 dimension(s) and the索引 1 处的数组有 1 个维度

【问题讨论】:

    标签: python matlab numpy data-analysis spectra


    【解决方案1】:

    scipy.signal.find_peaks() 只采用包含峰值的一维数组。因此,您应该能够像这样选择 DataFrame 中具有峰值的列:

    # note that find_peaks returns an array of peak indices, and a dictionary of properties 
    ind, properties = scipy.signal.find_peaks(df["name of column with peaks"]) 
    

    然后,如果您只想要峰值,请使用您刚刚创建的 ind 数组选择行:

    peak_df = df[df.index.isin(ind)]
    

    【讨论】:

    • 谢谢你的帮助,我把它放进去并没有出现任何峰值,输出是: Empty DataFrame Columns: [cm, A] Index: []
    • ind 填充了来自find_peaks() 的索引吗?
    • 我这么认为?这是我的代码: ind = scipy.signal.find_peaks(df["cm"]) peak_df = df[df.index.isin(ind)] print(peak_df)
    • 使用"A" 列,而不是"cm" 列。 cm 肯定是指上升的波长(没有峰值),A 是振幅
    • 是的,对不起,我的错。我将其更改为 A 列,它仍然给我相同的输出
    猜你喜欢
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    • 2011-05-09
    • 2021-05-23
    相关资源
    最近更新 更多