Документ взят из кэша поисковой машины. Адрес оригинального документа : http://lnfm1.sai.msu.ru/~kupry/SOFTWARE/poluautomatski.pro
Дата изменения: Thu Aug 2 20:21:46 2007
Дата индексирования: Mon Oct 1 23:02:50 2012
Кодировка:

Поисковые слова: elliptical galaxy
;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 "poluautomatski.txt" which is created in the
;program. If good=1 the picture is good,if good=0 the picture is bad.

;AUTHORS
;For all sugestions and complains please contact us:
;Sladjana Nikolic, meril@eunet.yu and
;Kristina Rackovic, rackovick@yahoo.com

pro poluautomatski,FILE=file

filer=''

a=filer+pickfile(/MUST_EXIST,TITLE=' Pick test 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\poluautomatski.txt',/GET_LUN, ERROR = err
IF (err NE 0) then PRINTF, -2, !ERROR_STATE.MSG
s1=' image path name '
s2='hair1'
s3='hair2'
s4='left pos1'
s5='right pos1'
s6='shift1'
s7='shift2'
s8='left pos2'
s9='right pos2'
s10='width1'
s11='width2'
s12='good/bad'
s13='----------------------------------------------------------------------------------------------------------------------------'

tekst= STRING(s13,FORMAT='(%"%s")')
printf, FAJL1,tekst
tekst=STRING(s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s1, FORMAT='(%"%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s")')
printf,FAJL1,tekst
tekst= STRING(s13,FORMAT='(%"%s")')
printf, FAJL1,tekst
tekst=STRING( poz1, poz2, m1[0], m1[1278], m1[1278]-m1[0], m2[0], m2[1278], m2[1278]-m2[0], sirina1, sirina2, good,pathk, $
FORMAT='(%" %d , %d , %d , %d , %d , %d , %d , %d , %d , %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

;procedure is the same like in the first part of the program

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


WINDOW, 0
plot, title='sum of rows',suma

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
i=i+1
endwhile

nit1=n[0]
nit2=n[1]

WDELETE,0

n1=make_array(41)
n2=make_array(41)

novi1=intarr(41)
for i=nit1-20,nit1+20 do begin
novi1[i-nit1+20]=i
n1[i-nit1+20]=suma[i]
end

for i=0,40 do begin
if min(n1) EQ n1[i] then begin
nit=novi1[i]
endif
end


yfit=gaussfit(novi1,n1,A)


novi2=intarr(41)
for i=nit2-20,nit2+20 do begin
novi2[i-nit2+20]=i
n2[i-nit2+20]=suma[i]
end

for i=0,40 do begin
if min(n2) EQ n2[i] then begin
nitt=novi2[i]
endif
end

yfit=gaussfit(novi2,n2,B)

sirina1=2*round(A[2])+1
sirina2=2*round(B[2])+1

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
k=k+1
i=i+1
endwhile

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
k=k+1
i=i+1
endwhile

if ((nit GE poz1-1) and (nit LE poz1+1)) and ((nitt GE poz2-1) and (nitt LE poz2+1)) then good=1 else good=0

tekst=STRING( nit, nitt, m1[0], m1[1278], m1[1278]-m1[0], m2[0], m2[1278], m2[1278]-m2[0], sirina1, sirina2, good,filenames[q],$
FORMAT='(%" %d , %d , %d , %d , %d , %d , %d , %d , %d , %d , %d , %s")')
printf,FAJL1,tekst

end


CLOSE, /ALL


END