PRO DIG_FLAT2,mereni,xpix,ypix,dc,flat,a,b,c,x0,line_name ; ;Flatfielding ;Version 2, multiple flatfields possible. ; ;INPUTS: mereni - path to data directory ; xpix, ypix - x, y dimensions of the spectrum ;OUTPUTS: dc - dark field (integer) ; flat - clean flatfield without sp. lines (float, norm.to 1) ; a,b,c - parabolic coefficients for line curvature ; x0 - line centre position (pix) ; line_name - string 'HA' or 'K3' ; ; Copyright M. Klvana and M. Sobotka, ASU AVCR Ondrejov, Czech Rep., 2014 ; Read flat and dark on_error,1 ffname=findfile(mereni + '\' + 'FF*.SP',count=foundff) if foundff lt 1 then goto,bad print,'FLATFIELDS: ',ffname dcname=findfile(mereni + '\' + 'DC*.SP',count=found) if found lt 1 then goto,bad dcname=dcname(0) if foundff eq 1 then begin ffname=ffname(0) ff=intarr(xpix,ypix) ; raw flat openr,102,ffname readu,102,ff close,102 endif else begin fr=intarr(xpix,ypix) fff=intarr(xpix,ypix,foundff) ; multiple flats for i=0,foundff-1 do begin openr,102,ffname(i) readu,102,fr close,102 fff(*,*,i)=fr endfor ff=total(fff,3)/float(foundff) endelse dc=intarr(xpix,ypix) ; dark openr,102,dcname readu,102,dc close,102 ;---------------------------------------------- ff=ff*1.8 ; to match the spectrum intensity ;---------------------------------------------- ff=(ff-dc)>1 ; Line curvature LINECURV2,ff,a,b,c LINERECT,ff,a,b,c,rff,x0 ; Removing spectral lines ff1=total(rff,2)/ypix flat=fltarr(xpix,ypix) for j=0,ypix-1 do flat(*,j)=float(rff(*,j))/ff1 flat=flat>0.001 window,0,xsiz=xpix,ysiz=ypix tvscl,flat ; Line identification (Ca II K or H-alpha) according to the width, ; FWHM limit is set to 20 pix mi=min(ff1,minpos) ma=max(ff1) half=0.4*(ma+mi) ; 0.5-->0.4 to avoid telluric lines, 15.10.2012 dife=abs(ff1-half) mi1=min(dife(0:minpos-1),pos1) mi2=min(dife(minpos+1:*),pos2) fwhm=pos2+minpos+1-pos1 if fwhm gt 20 then line_name='K3' else line_name='HA' ; 25-->20 15.10.2012 goto,fin bad: window,2,xsiz=600,ysiz=400 xyouts,100,250,'ERROR',/device,charsize=10,charthick=10 xyouts,70,200,'Missing flatfield (darkfield)',/device,charsize=3,charthick=3 xyouts,50,130,mereni,/device,charsize=2,charthick=2 xyouts,50,70,'Exit IDL and remove the measurement',/device,charsize=2,charthick=2 wdelete,3 message,'ERROR - flatfield or darkfield not found' fin: END