|
User Documentation |
|||||||||
| prev file | next file | ||||||||||
| SUMMARY: fields | routine DETAILS: routine | ||||||||||
./toolbox gauss_fits.pro
| gauss_fits |
function gauss_fits(xx, yy, nregions, regions, inits, ngauss, max_iters, coefficients, errors, [parinfo=array], _EXTRA=_EXTRA) |
This code came mostly from Tom Bania's GBT_IDL work. Local modifications include:
; make a simple gauss x = indgen(150) h = 400000. c = 75. w = 15. noise = 10000 data=h*exp(-4.0*alog(2)*(x-c)^2/w^2)+(randomn(seed,n_elements(x))*noise) ; make an initial guess to this guassian h = 400000. c = 75. w = 15. inits = [h,c,w] nregions = 1 regions = [[20,120]] ngauss = 1 max_iters = 500 yfit = gauss_fits(x,data,nregions,regions,inits,ngauss,max_iters,coefficients,errors,quiet=1) ; view the results plot, data gbtoplot, x[regions[0]:regions[1]], yfit, color=!red, /chancomplex examle: multiple gaussians in multiple regions
; create 5 gaussians in the same plot
a1 = [400000.,35.,15.]
a2 = [100000.,15,7.5]
a3 = [200000.,110,8.0]
a4 = [100000.,150,5.5]
a5 = [100000.,170,5.5]
a = [a1,a2,a3,a4,a5]
x = indgen(200)
data = make_gauss(x,a,10000.)
plot, data
; specify 3 regions
nregions = 3
regions = [[5,75],[90,130],[135,190]]
inits = [[a1],[a2],[a3],[a4],[a5]]
ngauss = 5
max_iters = 500
p = replicate({value:0.D, fixed:0, limited:[0,0], $
limits:[0.D,0]}, 15)
; 15 = 5 gauss * 3 parameter per guass
p[*].value = a
; hold the first gaussians height fixed
p[0].fixed = 1
; find all the fits at once
yfit = gauss_fits(x,data,nregions,regions,inits,ngauss,max_iters,coefficients,errors,parinfo=p,quiet=1)
; unwrap the results and plot them
ystart = 0
for i=0,(nregions-1) do begin
b = regions[0,i]
e = regions[1,i]
yend = ystart + (e-b)
y = yfit[ystart:yend]
ystart = yend + 1
gbtoplot, x[b:e], y, color=!red, /chan
endfor