查找最大值的方法点在线性图上

时间:2016-11-10 19:53:33

标签: python python-2.7 interpolation astronomy differentiation

这是天文学,但我认为我的问题可能非常基础 - 我不是很有经验,我道歉。

我正在绘制恒星形成星系(y轴)的颜色与红移(x轴)之间的关系。该图是一条从大约0上升到大约9的线,然后再次衰减到大约-2。在红移方面,峰值(~9色)约为4,我想更准确地发现峰值。红移是由一个相当混乱的功能给出的,我无法弄清楚如何区分它,否则我会这样做。

  • 我可以区分复杂的红移(z)功能吗?如果是这样,怎么样?

  • 如果没有,我怎样才能以图形/数字方式估算峰值?

对不起这个非常基本的问题,非常感谢你提前。我的代码如下。

import numpy as np
import matplotlib.pyplot as plt
import IGM
import scipy.integrate as integrate

SF = np.load('StarForming.npy')

lam = SF[0]

SED = SF[1]

filters = ['f435w','f606w','f814w','f105w','f125w','f140w','f160w']
filters_wl = {'f435w':0.435,'f606w':0.606,'f814w':0.814,'f105w':1.05,'f125w':1.25,'f140w':1.40,'f160w':1.60} # filter dictionary to give wavelengths of filters in microns

fT = {} # this is a dictionary

for f in filters:

data = np.loadtxt(f+'.txt').T

fT[f]= data    

fluxes = {}

for f in filters: fluxes[f] = [] # make empty list for each 

redshifts = np.arange(0.0,10.0,0.1) # redshifts going from 0 to 10

for z in redshifts:

    lamz = lam * (1. + z)
    obsSED = SED * IGM.madau(lamz, z)

    for f in filters:

        newT = np.interp(lamz,fT[f][0],fT[f][1]) # for each filter, refer back

        bb_flux = integrate.trapz((1./lamz)*obsSED*newT,x=lamz)/integrate.trapz((1./lamz)*newT,x=lamz) 
        # 1st bit integrates, 2nd bit divides by area under filter to normalise filter

        # loops over all z, for all z it creates a new SED, redshift wl grid    

        fluxes[f].append(bb_flux)


for f in filters: fluxes[f] = np.array(fluxes[f])

colour = -2.5*np.log10(fluxes['f435w']/fluxes['f606w'])

plt.plot(redshifts,colour)
plt.xlabel('Redshift')
plt.ylabel('Colour')
plt.show

1 个答案:

答案 0 :(得分:0)

我没有足够的声誉来评论,但这可能会解决你的问题,所以我想它的答案。将所有y坐标存储在列表中,然后使用max(list)函数查找最大值。如果需要有序对,请将坐标存储为(y,x)元组并使用max(list)

lst = [(3,2), (4,1), (1, 200)]
max(lst)

收益率(4,1)

相关问题