python - Method for finding max. point on linear plot -
this in astronomy, think question elementary - i'm not experienced, apologise.
i plotting relationship between colour of star-forming galaxy (y axis) redshift (x axis). plot line rises around 0 maybe 9, decays again -2. peak (~9 colour) around 4 in terms of redshift, , want find peak more exactly. redshift given quite confusing function, , can't figure out how differentiate or else that.
could maybe differentiate complicated redshift (z) function? if so, how?
if not, how estimate peak graphically/numerically?
sorry basic question , thank in advance. code below.
import numpy np import matplotlib.pyplot plt import igm import scipy.integrate 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 give wavelengths of filters in microns ft = {} # dictionary f in filters: data = np.loadtxt(f+'.txt').t ft[f]= data fluxes = {} f in filters: fluxes[f] = [] # make empty list each redshifts = np.arange(0.0,10.0,0.1) # redshifts going 0 10 z in redshifts: lamz = lam * (1. + z) obssed = sed * igm.madau(lamz, z) f in filters: newt = np.interp(lamz,ft[f][0],ft[f][1]) # each filter, refer bb_flux = integrate.trapz((1./lamz)*obssed*newt,x=lamz)/integrate.trapz((1./lamz)*newt,x=lamz) # 1st bit integrates, 2nd bit divides area under filter normalise filter # loops on z, z creates new sed, redshift wl grid fluxes[f].append(bb_flux) 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
i not have high enough reputation comment, may solve problem, guess answer. store y-coordinates in list, use max(list) function find max. if want ordered pair, store coordinates (y,x) tuples , use max(list)
lst = [(3,2), (4,1), (1, 200)] max(lst) yields (4,1)
Comments
Post a Comment