;This program was made by students from Department of Astronomy, Faculty of Mathematics, ;University of Belgrade, Serbia during summer practice (9.7.2007.-3.8.2007.) at Department ;of Solar Physics, Astronomical Institute of Academy of Science, Czech Republic. ;The aim of the program is to select good pictures (without shifts of hairs) which will be ;used in program redat1.pro. ;SHORT MANUAL ;After compiling and running poluautomatski.pro you have to select test picture. ;On the graphic " Sum of rows" you have to pick hairs by clicking left mouse button. ;To continue with the procedure you have to click right mouse button anywhere on the graphic. ;The results of the program can be seen in file "automatski.txt" which is created in the ;program.If shift is 0 the hair is shift, and if shift is 1 the hair is not shift.The program ;doesn't work well, because it's not enough precise ( the second derivation). ;AUTHORS ;For all sugestions and complains please contact us: ;Sladjana Nikolic, meril@eunet.yu and ;Kristina Rackovic, rackovick@yahoo.com pro automatski,FILE=file filer='' a=filer+pickfile(/MUST_EXIST,TITLE=' Pick first picture',FILTER='*.fit', $ GET_PATH=pathk, /READ) ;!!! make matrix of picture and calculate sum of each row !!! a1= readfits(a, header) print,size(a1) suma=make_array(512) suma[*]=0 for j=0,511 do begin for i=0,1279 do begin suma[j]=suma[j]+a1[i,j] end end ;!!! make the graphic of the sum !!! WINDOW, 0 plot, title='sum of rows',suma ;!!! function for finding mouse position!!! i=0 n=INTARR(3) !mouse.button=1 WHILE(!MOUSE.BUTTON NE 4) DO BEGIN CURSOR,X1,Y1,/DATA,/DOWN IF !MOUSE.BUTTON EQ 1 THEN $ PRINT,FORMAT='("POSITION=[",I10.0,",",F10.2,"]")',X1,Y1 ;,Q[X,Y] n[i]=x1;use only x coordinate of the position i=i+1 endwhile nit1=n[0] ; the position of the first hair nit2=n[1] ; the position of the second hair print, 'nit1 = ', nit1, ' nit2 = ', nit2 ;!!! find dispersion of the hairs using plus-minus 20 pixels around the hair and fitting with gauss function !!! n1=make_array(41) n2=make_array(41) novi1=intarr(41) for i=nit1-20,nit1+20 do begin novi1[i-nit1+20]=i ;array of indices around the first hair n1[i-nit1+20]=suma[i] ; array of sum for elements around the first hair end print,'minimum for n1= ',min(n1) ;find real position of the first hair for i=0,40 do begin if min(n1) EQ n1[i] then begin print,'position of minimum is',novi1[i] print,'sum on minimum position is ',n1[i] nit=novi1[i] ; real position of the first hair endif end ;approximation with gauss yfit=gaussfit(novi1,n1,A) print,'dispersion of the first hair is',A[2] ; Load an appropriate color table: LOADCT, 30 ; Plot the original data: WINDOW,1 PLOT,title='gaussfit for the first hair', novi1, n1 ; Overplot the fitted data in a different color: OPLOT, novi1, yfit, COLOR = 100 novi2=intarr(41) for i=nit2-20,nit2+20 do begin novi2[i-nit2+20]=i ; array of indices around the second hair n2[i-nit2+20]=suma[i] ; array of sum for elements around the second hair end print, 'minimum for n2= ', min(n2) ;find real position of the second hair for i=0,40 do begin if min(n2) EQ n2[i] then begin print,'position of minimum is',novi2[i] nitt=novi2[i] ; real position of the second hair endif end ;approximation with gauss yfit=gaussfit(novi2,n2,B) print,'dispersion of the first hair is',B[2] ; Load an appropriate color table: LOADCT, 30 ; Plot the original data: WINDOW,3 PLOT,title='gaussfit for the second hair', novi2, n2 ; Overplot the fitted data in a different color: OPLOT, novi2, yfit, COLOR = 100 ; !!!calculate width of the hairs !!! sirina1=2*round(A[2])+1 sirina2=2*round(B[2])+1 print,sirina1,sirina2 ; !!! find the positions of the hairs by calculating minumum in each column using the half picture for each hair !!! niz1=make_array(256) m1=intarr(1279) i=0 k=0 while i NE 1279 do begin for j=0,255 do begin niz1[j]=a1[i,j] end n=min(niz1) for j=0,255 do begin if n EQ niz1[j] then nit1=j end m1[k]=nit1 ; positions of the first hair in each column k=k+1 i=i+1 endwhile ;plot the first hair window,4 plot,title='the first hair',m1 niz2=make_array(256) m2=intarr(1279) i=0 k=0 while i NE 1279 do begin for j=256,511 do begin niz2[j-256]=a1[i,j] end n=min(niz2) for j=256,511 do begin if n EQ niz2[j-256] then nit2=j end m2[k]=nit2 ; positions of the second hair in each column k=k+1 i=i+1 endwhile ;plot the second hair window,5 plot,title='the second hair',m2 ; !!! print the results !!! print,'left position of the first hair is',m1[0] print,'right position of the first hair is',m1[1278] print,'left position of the second hair is',m2[0] print,'right position of the second hair is',m2[1278] print,'space between the hairs is',m2[639]-m1[639] print,'width of the first hair is',sirina1 print,'width of the second hair is',sirina2 ; !!! quality of the picture !!! if abs(m1[1278]-m1[0]) LE sirina1 then print,'the first hair is good'$ else print,'the first hair is bad' if abs(m2[1278]-m2[0]) LE sirina2 then print,'the second hair is good'$ else print,'the second hair is bad' if (abs(m1[1278]-m1[0]) LE sirina1) and (abs(m2[1278]-m2[0]) LE sirina2) then begin print,'the picture is good' good=1 endif else begin print,'the picture is bad' good=0 print,'shift of the first hair is',m1[1278]-m1[0] print,'shift of the second hair is',m2[1278]-m2[0] end poz1=nit ; remember position of the first hair on the test picture poz2=nitt ; remember position of the second hair on the test picture ; !!! make file with results for pictures in one serie !!! ; PLEASE CHANGE PATH NAME ACCORDING YOUR NEEDS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! OPENW,FAJL1,'C:\Documents and Settings\sladjana\Desktop\automatski.txt',/GET_LUN, ERROR = err IF (err NE 0) then PRINTF, -2, !ERROR_STATE.MSG s1=' image path name ' s2='hair1' s3='hair2' s4='shift for the first hair' s5='shift for the second hair' s13='----------------------------------------------------------------------------------------------------------------------------' tekst= STRING(s13,FORMAT='(%"%s")') printf, FAJL1,tekst tekst=STRING(s2,s3,s4,s5,s1, FORMAT='(%" %s, %s, %s, %s, %s, %s")') printf,FAJL1,tekst tekst= STRING(s13,FORMAT='(%"%s")') printf, FAJL1,tekst tekst=STRING( poz1, poz2,pathk, $ FORMAT='(%" %d , %d , %s")') printf,FAJL1,tekst ; read pictures from the serie filenames = dialog_pickfile(/multiple_files, filter = '*.fts', $ title = 'FITS images ') ;how many images? nimages = n_elements(filenames) Print, 'nimages = ',nimages for q=0,nimages-1 DO BEGIN ; !!! make matrix of picture and calculate sum of each row !!! a1= readfits(filenames[q], header) print,size(a1) suma=make_array(512) suma[*]=0 for j=0,511 do begin for i=0,1279 do begin suma[j]=suma[j]+a1[i,j] end end ; !!! find the first and the second derivation of suma!!! result=make_array(512) result1=make_array(512) ind=make_array(512,/index) ; array of indices result= DERIV(ind,suma) ; Lagrange polinom make array of the first derivations result1=DERIV(ind,result) ; array of the second derivations n=make_array(512); array of minimums k=0 m=intarr(512) ; array of minimum positions for i=0,511 do begin if result1[i] GT 0 then begin n[k]=suma[i] m[k]=i k=k+1 endif end ; !!!find positions of hairs using the second derivation of suma !!! true=0 nit=m[0] for i=1,k-1 do begin if (m[i] LE poz1+1) and (m[i] GE poz1-1) then begin if m[i] GT nit then begin nit=m[i] endif true=1 endif end if true EQ 1 THEN BEGIN shift1=1 print,'the first hair is',nit print,'the first hair is on the same position like in the test pictur' endif if true NE 1 then begin shift1=0 print,'the first hair is shift' endif true=0 nitt=m[0] for i=1,k-1 do begin if (m[i] LE poz2+1) and (m[i] GE poz2-1) then begin if m[i] GT nitt then begin nitt=m[i] endif true=1 endif end if true EQ 1 THEN BEGIN shift2=1 print,'the second hair is',nitt print,'the second hair is on the same position like in the test picture' endif if true NE 1 then begin shift2=0 print,'the second hair is shift' endif tekst=STRING( nit, nitt,shift1,shift2,filenames[q],$ FORMAT='(%" %d , %d , %d , %d , %s")') printf,FAJL1,tekst end CLOSE, /all END