FUNCTION tilt,bestpic ;NAME:tilt ; ;PURPOSE:to find the angle of the slit with respect to the chip ; ;CALLING SEQUENCE: ; ;INPUTS:name of the "pic" - csmm pos -that has the most flux - pic(*,*,csmm) ; ;OPTIONAL KEYWORD: ; ;OUTPUTS: an array of three: slope, y-int and angle of tilt ; ;SIDE EFFECTS:?? ; ;RESTRICTIONS:?? ; ;EXAMPLES: ; ;MODIFICATION HISTORY:started on 1/3/03 ; ;------------------------------------ PRINT, "Finding the tilt between the array and the slit" ;name='' ;READ, name, PROMPT='Enter file name:' ;cube=RDFITSCUBE(name) ;best=pic(*,*,smMax) best=bestpic ;PRINT, 'Number of bins can be: 1,2,4,8,16, or 32' PRINT, 'If there is not enough flux in a single pixel,' PRINT, 'Then you can bin several together.' PIX: PRINT, 'Number of pixels per bin can be: 1,2,4,8, or 16' READ, nbin2, PROMPT='How many pixels in each bin?' If(nbin2 ne 1 and nbin2 ne 2 and nbin2 ne 4 and nbin2 ne 8 and $ nbin2 ne 16 and nbin2 ne 32) Then begin PRINT, 'Number of bins must divide into 32. Try again.' Goto, Pix ENDIF nbin=32/nbin2 maxcol=fltarr(nbin) xs=fltarr(nbin) xys=fltarr(nbin) xsquare=fltarr(nbin) k=0 again='' iter=32/nbin IF (nbin eq 32) then begin bin=best GOTO, maxbins Endif ;bin the rows bin=fltarr(32,nbin) for i=0,nbin-1 do BEGIN bin(*,i)=TOTAL(best(*,(i*iter):(i+1)*iter-1),2) endfor maxbins: ;fit the bined rows for i=0,nbin-1 DO Begin ;start with fitting all cols fit1=0 fit2=23 fitloop: ;Plot, bin(*,i), Title='Bin '+STRING(i),ytit='fluxes in DN/sec',$ ; xtit='col #',background=255, color=0, xticklen=1,xgridstyle=1,$ ; xticks=7 x=dindgen(fit2-fit1+1) for j=0,(fit2-fit1) do x(j)=fit1+j ;SPLINE_P,x, bin(fit1:fit2,i), XR,YR ;fit spline with mpfitpeak A=fltarr(4) ;quadfit=MPFITPEAK(xr,yr,A) yfit=MPFITPEAK(x,bin(fit1:fit2,i),A) PRINT, 'Coeff: ', A Mcol=A(1) maxcol(k)=mcol xs(k)=i PRINT, 'Max col: ',MAXCOL(k) ;get finer grid for gaussian check x2=fltarr(n_elements(x)*4) x2(0)=x(0) x2(n_elements(x2)-1)=x(n_elements(x)-1) xrange=x(n_elements(x)-1)-x(0) for j=1,n_elements(x2)-2 do x2(j)=x2(0)+j*(xrange/n_elements(x2)) z=(x2-A(1))/A(2) check=A(0)*EXP(-0.5*z^2)+A(3) checkbig=MAX(check) PLOT, x,bin(fit1:fit2,i),title='Fits to Bin'+STRING(i), ytit='Flux',$ xtit='Col #', background=255, color=0,yrange=[0,checkbig] ;OPLOT,XR,YR,linestyle=2,color=100 OPLOT,X2, check, linestyle=3,color=40 Maxrow=MAX(bin(fit1:fit2,i),mr) PRINT,'Do you want to use the max row? (r) It is row',mr+fit1 READ, again, PROMPT='Or, is this fit ok? (y/n):' If (again eq 'r') THen maxcol(k)=mr+fit1 IF (again eq 'n') Then begin ;get which cols to fit: oops: READ, fit1,Prompt='Where should the fit start?' READ, fit2,PROMPT='Where should the fit end?' if (fit2-fit1 le 3) then begin PLOT, x,bin(fit1:fit2,i),title='Fits to Bin'+STRING(i), ytit='Flux',$ xtit='Col #', background=255, color=0,yrange=[0,checkbig] oplot,X2, check, linestyle=3,color=40 print, 'There must be more than 3 columns to fit.' goto, oops endif goto, fitloop endif k=k+1 endfor IF (nbin eq 1) then begin Print, 'Maximum column is at: ', maxcol(0) m=0 b=maxcol(0) goto, onebin Endif ;fit line to maxcol ;PRINT,maxcol ;PRINT, 'Change values of maxcol if needed.' ;STOP for h=0,nbin-1 do begin xys(h)=xs(h)*maxcol(h) xsquare(h)=xs(h)*xs(h) endfor ys=maxcol delta=(nbin*TOTAL(xsquare)-(TOTAL(xs))^2) ;Slope m=(nbin*TOTAL(xys)-TOTAL(xs)*TOTAL(maxcol))/delta ;y intercept b=(TOTAL(xsquare)*TOTAL(maxcol) - TOTAL(xs)*TOTAL(xys))/delta ;UNCERTAINTIES ;sigma^2 sigma2=(TOTAL((ys-(m*xs+b))^2))/(k-2) ;y-intercept uncertainty squared intsigma2=(sigma2/delta)*TOTAL(xs^2) ;slope uncertainty squared slopesigma2=k*sigma2/delta PRINT, 'Slope= ',m,' +/-', SQRT(slopesigma2) PRINT, 'Y-Int= ',b,' +/-',SQRT(intsigma2) PRINT, 'Angle= ',ATAN(m) PLOT, xs, (m*xs+b),xtit='bin #', ytit='col #' Close, 15 OPENW,15, 'Tilt_details',/APPEND PRINTF,15, ' ' PRINTF,15, 'Number of pixels/bin:',nbin2 PRINTF,15, 'Slope: ',m,' +/-', SQRT(slopesigma2) PRINTF,15, 'Y-Int= ',b,' +/-',SQRT(intsigma2) PRINTF,15, 'Angle= ',ATAN(m) Close,15 onebin: RETURN, [m,b,ATAN(m),SQRT(slopesigma2),SQRT(intsigma2)] END