PRO lambdacal ;NAME:lambdacal ; ;PURPOSE:calibrate the wavelength for the SED mode ; ;CALLING SEQUENCE: ; ;INPUTS:name of fits image (one telescope position) this will have 12 ;on/off pairs ; ;OPTIONAL KEYWORD: ; ;OUTPUTS:LambdaCal.txt - list of wavelength, row number for a col number ; ;SIDE EFFECTS:chages the color ; ;RESTRICTIONS:?? ; ;EXAMPLES: ; ;MODIFICATION HISTORY:started on 2/26/03 ; ;------------------------------------ PRINT,'On a separate IDL prompt,run lambdalook.pro with the same file.' ;set the color right loadct,39 pcolor=[20,40,70,100,150,190,20,40,70,100,150,190,25 ] ;name='ffene3.fits' ;name='ffene2.fits' ;name='fhear2.fits' ;name='fobject2.fits' Print, 'Some test files are ffene3.fits, ffene2.fits, fhear2.fits,' print, 'and fobject2.fits' name='' READ, name, PROMPT='Enter file name:' ;cube=RDFITSCUBE(name) ;ffile=cube(0) ffile=READFITS(name) CLOSE, 10 OPENW,10,'LambdaCal.txt',/APPEND PRINTF,10, '#For file',name PRINTF,10,'# Wavelength Row # StartCol EndCol' top=max(ffile, MIN=bottom) PLOT,ffile(0,*),background=255, color=0,xtit='row # (wavelength)',$ ytit='Flux (mJans/ster)',yrange=[0,top] for i=1,23 do begin OPLOT, ffile(i,*), color=i*10 endfor ;PRINT, 'Type .c to continue' ;stop ;slaffi,ffile READ,num,PROMPT='How many wavelengths will be fit in this file?' ;PRINT, 'Which cols would you like to use? Max range = 0 to 23' ;READ,startcol,PROMPT='Which col to start on?' ;READ,endcol,PROMPT='Which col to end on?' ;PRINT, 'Number of cols per bin can be: 1,2,3,4,6,8,12 or 24' ;READ, nbin2, PROMPT='How many cols in each bin?' ;nbin=24/nbin2 ;lambda=fltarr(nbin,num) ;maxcol=fltarr(nbin,num) ;xs=fltarr(nbin*num) ;xys=fltarr(nbin*num) ;xsquare=fltarr(nbin*num) ;k=0 again='' ll='' flip='' ;iter=24/nbin PRINT, 'You can combine columns (spacial direction) for a better flux.' PRINT, 'If you do not want to do this, choose 24 bins.' READ, nbin, PROMPT='How many bins would you like?' IF (nbin eq 24) then begin bin=ffile startbin=dindgen(24) endbin=dindgen(24) GOTO, maxbins Endif ;bin the columns startbin=fltarr(nbin) endbin=fltarr(nbin) bin=fltarr(nbin,32) for i=0,nbin-1 do BEGIN PRINT, 'For bin #',i PRINT, 'Bin counting starts at 0' READ, sb,PROMPT= 'What col to start the bin?' startbin(i)=sb READ, eb,PROMPT= 'What col to end the bin?' endbin(i)=eb ; bin(i,*)=TOTAL(ffile((i*iter):(i+1)*iter-1,*),1) bin(i,*)=TOTAL(ffile(startbin(i):endbin(i),*),1) endfor maxbins: FOr ii=0,num-1 DO Begin ;for each wavelength ;PLOT,TOTAL(ffile(0:23,*),1),background=255, color=0 ;PLOT,TOTAL(ffile(startcol:endcol+1,*),1),background=255, color=0 ;start with fitting all rows fit1=0 fit2=31 READ,lam, PROMPT='What wavelength (in microns) is this fitting?' READ, flip,PROMPT='Is this an emission or absorbtion line? (em/ab):' ;PRINT, flip ;IF (flip eq 'ab') then bin=MAX(bin)-bin ;lambda(k,ii)=lam ;fit the bined rows for i=0,nbin-1 DO Begin ;for i=startcol, endcol Do Begin 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 y=dindgen(fit2-fit1+1) for j=0,(fit2-fit1) do y(j)=fit1+j ;fit with mpfitpeak A=fltarr(4) yfit=MPFITPEAK(y,bin(i,fit1:fit2) , A) PRINT, 'Coeff: ', A Mcol=A(1) ;maxcol(k)=mcol PRINT, 'Max Row: ',MCOl ;get finer grid for gaussian check y2=fltarr(n_elements(y)*4) y2(0)=y(0) y2(n_elements(y2)-1)=y(n_elements(y)-1) yrange=y(n_elements(y)-1)-y(0) for j=1,n_elements(y2)-2 do y2(j)=y2(0)+j*(yrange/n_elements(y2)) z=(y2-A(1))/A(2) check=A(0)*EXP(-0.5*z^2)+A(3) checkbig=MAX(check) PLOT, y,bin(i,fit1:fit2),title='Fits to Col/Bin'+STRING(i), ytit='Flux',$ xtit='Row #', background=255, color=0,yrange=[0,checkbig] OPLOT,y2, check, linestyle=3,color=40 If (flip eq 'ab') then begin Minrow=MIN(bin(i,fit1:fit2),mr) PRINT, 'Do you want to use the min row? (r) It is row',mr+fit1 endif If (flip eq 'em') then begin Maxrow=MAX(bin(i,fit1:fit2),mr) PRINT,'Do you want to use the max row? (r) It is row',mr+fit1 endif READ, again, PROMPT='Is this fit ok?(y/n) Or should it be skipped (s): ' If (again eq 's') Then Goto, skipped If (again eq 'r') THen Mcol=mr+fit1 IF (again eq 'n') Then begin ;get which cols to fit: READ, fit1,Prompt='Where should the fit start?' READ, fit2,PROMPT='Where should the fit end?' for j=0,fit1-1 do bin(i,j)=ffile(i, fit1) for j=fit2+1,31 do bin(i,j)=ffile(i,fit2) goto, fitloop endif PRINTF,10, lam, FLOAT(Mcol), startbin(i),endbin(i) ;k=k+1 skipped: endfor;fitting cols endfor ;wavelength PRINT, 'Info written to LambdaCal.txt' CLOSE,10 END