; STARID.PRO ; ;This program is designed to identify stars in an auroral or airglow ;image; specifically those taken at Rabbit Lake. The purpose of this is so that ;the exact position of the star will be known in row and column terms of the ;image, and by comparing these coordinates with known positions of the stars at ;the time of the exposure, a correlation between image position and sky position ;can be established. ;The process compares the image with those taken directly before and ;after the specified image, so the program will read in the specified image and ;the images preceeding and proceeding the specified image. The images chosen are ;based on the camera and filter numbers, the exposure time and consecutive image ;numbers. Since the program is to be used to identify stars, the ideal images ;are those with clearly visible stars and almost no cloud or aurora. ; ; MODES : 0 - Aurora; 1 - Bias; 2 - Calibration; 3 - Dark Frame; 4 - Flat Field; ; 5 - Airglow ;Modified on May 8, 1994 by T A Oliynyk: can now be used on unix or dos machines. PRO starid,day,cam,filt,binfac,texp,mode,imnum,sdev,amp,readdk=readdk IF N_PARAMS() LT 7 THEN BEGIN MESSAGE,'Usage: starid,day,cam,filt,binfac,texp,mode,imnum[,sdev,amp,/readdk]' $ ,/INFORMATIONAL MESSAGE,'Mode: 0=aurora 1=bias 2=cal 3=dark 4=flat 5=airglow' $ ,/INFORMATIONAL RETURN ENDIF ; Define OS-dependent parameters @isitdos IF N_PARAMS() EQ 7 THEN BEGIN sdev=3 amp=3 ENDIF cols=512/binfac rows=cols ;initializing variables rimg = INTARR(cols,rows,3) ; array of the 3 images to be compared pimg = rimg & dimg = rimg IF N_Elements(readdk) GT 0 THEN readdk=1 ELSE readdk=0 IF readdk THEN BEGIN STOP dkpath=iroot+dd+imagetype(3)+dd+cc+StrTrim(Fix(cam),2) dkfilt=String(day,Format='("d",I2.2,"*.*")') dkname=PickFile(path=dkpath,filter=dkfilt,/read) rdkimg,dkname,dkhd,dk ENDIF ELSE rdmeandk,FIX(cam),FIX(texp),dk dksize=SIZE(dk) IF dksize(1) NE cols THEN dk=binf(dk,dksize(1)/cols) WHILE imnum-1 LT 0 DO BEGIN ;cannot have an extension number less than zero PRINT,'Choose a new image number; no image previous to this one' READ,imnum ENDWHILE path = STRING(mpaths(mode),dd,cc,cam,dd,ff,filt,dd,firstchars(mode),day $ ,cam,filt,texp,imnum $ ,FORMAT='(A,A1,A,I1,A1,A,I1,A1,A,I2.2,2I1,I3.3,".",I3.3)') path=STRLOWCASE(path) ;filename of image ;find all images with the same filename, excluding the extension ;this is used to find the images previous to and following the image path2=STRING(mpaths(mode),dd,cc,cam,dd,ff,filt,dd,firstchars(mode),day $ ,cam,filt,texp $ ,FORMAT='(A,A1,A,I1,A1,A,I1,A1,A,I2.2,2I1,I3.3,".*")') fl=rfindfile(path2) w=where(fl eq path) w=w(0) file=strarr(3) ;read in the image, the one with the same cam, filt, exposure, one image before ;the specified image, and the image after. FOR j=w-1,w+1 DO file(j-(w-1))=fl(j) FOR i=0,2 DO BEGIN print,file(i),FORM='("READING : ",A)' rdkimg,file(i),hb,ximg kh = gethd(hb) help,/st,kh.misc.tm rimg(*,*,i) = ximg(*,*) IF i EQ 1 THEN head = hb ENDFOR medsize=cols/64+1 dilsize=medsize+cols/128 FOR i=0,2 DO BEGIN tmp0=rimg(*,*,i)-dk IF i EQ 1 THEN umed=tmp0 pimg(*,*,i)=tmp0-MEDIAN(tmp0,medsize) sig=stdev(pimg(*,*,i),mean) IF i EQ 1 THEN u=mean pimg(*,*,i)=(pimg(*,*,i)-mean)/sig cell=REPLICATE(1B,dilsize,dilsize) dimg(*,*,i)=DILATE((pimg(*,*,i) GT sdev),cell) ENDFOR simg=TOTAL(dimg,3) nimg=(simg GT 2) stimg=nimg*(pimg(*,*,1) GT sdev) wkimg=(rimg(*,*,1)-dk)+amp*umed*stimg stars=WHERE(stimg) ; FOR i=0,2 DO BEGIN ; tpt=0 & pt=0 & pt2=0 & bpt= 0 & x=0 ; ; ns=1.5 ; ng=2. ; dr=FLOAT(cols)/128 ; ; dim=SIZE(rimg(*,*,i)) ; g1=ABS(rimg(*,*,i)-SHIFT(rimg(*,*,i),dr,0)) ; g1(dr-1,*)=0 ; sd = STDEV(g1,m) & gt1=m+ns*sd ; g1big=WHERE(g1 GT gt1) ; IF (g1big(0) NE -1) THEN big1=g1(g1big) ELSE big1=-1 ; ; g2=ABS(rimg(*,*,i)-SHIFT(rimg(*,*,i),0,dr)) ; g2(*,rows-dr)=0 ; sd = STDEV(g2,m) & gt2=m+ns*sd ; g2big=WHERE(g2 GT gt2) ; IF (g2big(0) NE -1) THEN big2=g2(g2big) ELSE big2=-1 ; ; g3=ABS(rimg(*,*,i)-SHIFT(rimg(*,*,i),-dr,0)) ; g3(cols-dr,*)=0 ; sd = STDEV(g3,m) & gt3=m+ns*sd ; g3big=WHERE(g3 GT gt3) ; IF (g3big(0) NE -1) THEN big3=g3(g3big) ELSE big3=-1 ; ; g4=ABS(rimg(*,*,i)-SHIFT(rimg(*,*,i),0,-dr)) ; g4(*,dr-1)=0 ; sd = STDEV(g4,m) & gt4=m+ns*sd ; g4big=WHERE(g4 GT gt4) ; IF (g4big(0) NE -1) THEN big4=g4(g4big) ELSE big4=-1 ; ; gradthresh=MAX([gt1,gt2,gt3,gt4]) ; select the largest gradient ; ; vbig=WHERE(big1 GT gradthresh) ; restrict big gradients to ; IF (vbig(0) NE -1) THEN g1big=g1big(vbig) ELSE g1big=-1;those greater than gradthresh ; vbig=WHERE(big2 GT gradthresh) ; IF (vbig(0) NE -1) THEN g2big=g2big(vbig) ELSE g2big=-1 ; vbig=WHERE(big3 GT gradthresh) ; IF (vbig(0) NE -1) THEN g3big=g3big(vbig) ELSE g3big=-1 ; vbig=WHERE(big4 GT gradthresh) ; IF (vbig(0) NE -1) THEN g4big=g4big(vbig) ELSE g4big=-1 ; nbig=INTARR(cols,rows) ; no. of big gradients at each pixel ; IF (g1big(0) NE -1) THEN nbig(g1big)=nbig(g1big)+1 ; IF (g2big(0) NE -1) THEN nbig(g2big)=nbig(g2big)+1 ; IF (g3big(0) NE -1) THEN nbig(g3big)=nbig(g3big)+1 ; IF (g4big(0) NE -1) THEN nbig(g4big)=nbig(g4big)+1 ; toobig=WHERE(nbig GE ng) ; r=toobig/cols ; c=toobig MOD cols ; tmp=WHERE(((dr-1 LT c) AND (c LT cols-dr)) AND $ ; ((dr-1 LT r) AND (r LT rows-dr))) ; toobig=toobig(tmp) ; r=r(tmp) & c=c(tmp) ; stimg = INTARR(cols,rows) ; stimg(toobig) = rimg(toobig +i*FLOAT(cols)^2) ; ; ;here, we have either stars or hot spots ; pt = where((stimg GT 0) $ ; AND stimg GE SHIFT(stimg,1,0) $ ; AND stimg GE SHIFT(stimg,0,1) $ ; AND stimg GE SHIFT(stimg,-1,0) $ ; AND stimg GE SHIFT(stimg,0,-1) $ ; AND stimg GE SHIFT(stimg,0,2) $ ; AND stimg GE SHIFT(stimg,2,0) $ ; AND stimg GE SHIFT(stimg,0,-2) $ ; AND stimg GE SHIFT(stimg,-2,0) $ ; AND stimg GE SHIFT(stimg,1,1) $ ; AND stimg GE SHIFT(stimg,1,-1) $ ; AND stimg GE SHIFT(stimg,-1,1) $ ; AND stimg GE SHIFT(stimg,-1,-1)) ; ; stimg2 = INTARR(cols,rows) ; stimg2(pt) = stimg(pt) ; ptimg(*,*,i)=(stimg2 gt 0) ; ; ENDFOR ; surrsize=cols/64+1 ; surr=REPLICATE(1,surrsize,surrsize) ; d0img = DILATE(ptimg(*,*,0),surr) ; d2img = DILATE(ptimg(*,*,2),surr) ; finimg = d0img AND ptimg(*,*,1) AND d2img ; tvscl,ptimg(*,*,1),2 ; tvscl,finimg,0 ; im = ptimg(*,*,1)-finimg ; tvscl,im,3 ; tvscl,rimg(*,*,1)