; VIDEO2.PRO ; ; Originally written to show images from Polar Camera initial field test ; at Ryning Farm Observatory ; Modified 1993/1/29 by DPS to handle images from image tree structure ; on /jasper/cnsr3_data1 ; Modified 1994/2/7 by DPS to read images from associated files, ; where the latter are formatted as 512-byte headers followed by ; 256x256 bytes. The images are scaled to 8 bits for storage, and ; are reconstituted by multiplying by 2^p, where the value of p is ; stored in byte 290 of the header (counting from 0). ; ; Modified 970214 by DPS to display a succession of images from two ; selected channels, typically 608 nm and 630 nm or 558 nm, in order to ; clarify whether drifting features are cloud or airglow. ; COMMON date,year,month,day COMMON skypixels,sigpix COMMON headbytes,oldfname,hbytes,utsec,exptimes,fwtemps,bad_image ; create byte-valued input parameters cam=0 & filt=cam & day=cam & month=cam ; load various string-valued arrays needed @isitdos take2=0B IF !D.WINDOW EQ 0 THEN WDELETE,0 ; tell user what imaging modes and filters are available cam_filt,filters ; prompt user and get input PRINT,'Enter the year, month, day, camera, and filter desired' READ,year,month,day,cam,filt PRINT,'Enter the hour, minute, and second to start (default 00:00:00 UT)' get_hms,sthms,hour,minute,second PRINT,'Enter the minimum time between image refreshes (default = 1.0s)' interval=1.0 ir='' READ,ir IF isnumber(ir,irv) NE 0 THEN interval=FLOAT(irv) ptype='' READ,'Map the images to a coordinate grid? ([Y]/N) ',ptype ptype=STRUPCASE(ptype) IF ptype EQ 'N' THEN BEGIN !ORDER=1 IF dos THEN fac=2 ELSE fac=3 ; fac=3 image_height=fac*256 ENDIF ELSE BEGIN mtype='' READ,'Geographic coordinates or an MLT/MLat dial? [G/M] ',mtype mtype=STRUPCASE(mtype) fac=2 image_height=fac*383 eheight=[87,100,300,120,100,87,100,120,97,100] PRINT,'Default emission height is '+STRTRIM(eheight(5*cam+filt),2) $ +' km; enter preferred height or to accept this one:' htstr='' READ,htstr IF htstr NE '' THEN eht=ROUND(FLOAT(htstr)) ELSE eht=eheight(5*cam+filt) READ,'Enter the van Rhijn background (R) to subtract: ',vRbg ENDELSE ; ensure a 4-digit year for display; make reasonable assumptions IF year LT 1900 THEN BEGIN IF year LT 50 THEN year=year+2000 IF year GT 50 THEN year=year+1900 ENDIF ; create title for image plot site_names=['','Spyhill Airglow Observatory','Rabbit Lake, SK' $ ,'Eureka AStrO Lab'] site=site_names(PoCasite(year,month,day)) wtitle=STRING(filters(cam*5+filt),FORMAT='("Polar Camera",2X,A)') wtitle=[wtitle,site+' '+ymd2date(year,month,day,format='d$ n$ y$')] ; Display only those pixels viewing the sky ; mk,mask ; sigpix=rdsigpix(cam) ; mask(sigpix)=1 resp='' Read,Prompt='Was the moonshade in place? ([Y]/N) ',resp moonshade=(StrUpCase(resp) NE 'N') IF moonshade THEN BEGIN getsig,year,month,day,mask0,mask1 CASE cam OF 0: mask=mask0 1: mask=mask1 ELSE: MESSAGE,'Bad value for ''cam'''+STRTRIM(cam,2),/INFORMATIONAL ENDCASE ENDIF ELSE BEGIN mk,mask mask(*)=1 ENDELSE ; Offer option of plotting "negative" images ct=0 IF ct EQ 0 THEN BEGIN Read,Prompt='Do you want to plot images as negatives? (Y/[N]) ',resp neg=(StrUpCase(resp) EQ 'Y') ENDIF ELSE neg=0 ; define path to desired images template=filocate(year,month,day,cam,filt) IF StrLen(template) LT 12 THEN BEGIN Message,'Bad template: '+template,/Informational Goto, Done ENDIF ; Open the file as a series of small (header-size) units and get ; the header information nimages=rdhbytes(template) ; identify image sequences and prompt user for sequence(s) to display dt=ABS(utsec-SHIFT(utsec,1)) ; rectify big negative number in front seqstart=WHERE(dt GT 600) ; semi-arbitrary large number (10 min) RESTART: IF seqstart(0) GE 0 THEN BEGIN PRINT,'Sequences begin with the following image numbers(s):' PRINT,seqstart ENDIF mnex=MIN(exptimes,MAX=mxex) IF mnex NE mxex THEN BEGIN PRINT,mnex,mxex $ ,FORMAT='("Exposure times range from ",F4.1," to ",F4.1," s")' PRINT,'Enter the exposure time of interest ( for all)' texp='' READ,texp selexp=isnumber(texp,expt) ENDIF ELSE BEGIN selexp=0 expt=FIX(ROUND(mnex)) ENDELSE IF NOT take2 THEN BEGIN IF sthms EQ '' THEN BEGIN PRINT,'Enter the range of image numbers to display ( for all images)' instring='' & READ,instring f=isnumber(instring,inf) IF f NE 0 THEN BEGIN ; user entered at least one number inf=FIX(inf) IF f GT 0 $ ; user entered only one number THEN inl=nimages-1 $ ELSE BEGIN f=isnumber(getwrd(instring,1),inl) IF f NE 0 THEN inl=FIX(inl) ELSE inl=nimages-1 ENDELSE ENDIF ELSE BEGIN inf=0 inl=nimages-1 ENDELSE ENDIF ELSE BEGIN startut=(hour*60L+minute)*60L+second inf=MIN(WHERE(utsec GE startut)) inl=nimages-1 ENDELSE ENDIF ; Set up image display barwidth=32 ; Open plotting window and hide it temporarily IF dos $ THEN WINDOW,0,XPOS=300,YPOS=30,XSIZE=700,YSIZE=700 $ ELSE WINDOW,0,XPOS=10,YPOS=110,XSIZE=1230,YSIZE=900 WShow,0,0 TVSCL,BINDGEN(256) ; wake up the X window and set !D.N_COLORS correctly psres=100. ; dummy value ; Now load the colour table IF NOT neg THEN BEGIN cf=5*cam+filt CASE cf OF 2: ct=3 7: ct=1 8: ct=8 ELSE: ct=0 ENDCASE ENDIF loadct,ct,/silent ; Prompt user for fixed saturation brightness PRINT,'If you want to assign the top of the color bar to a fixed number of counts,' PRINT,'enter that number now, otherwise enter anything else for auto-scaling.' tops='' READ,tops flag=isnumber(tops,topnum) ; topnum=0 if tops doesn't represent a number ; Now reveal image display window and title it WShow,0 disptitl,wtitle,fac,image_height,psres ; Calculate coordinates of LL corner of images llx=(!D.X_SIZE-image_height)/2 lly=0 ; create and display color bar barlength=image_height nquad=2*!ORDER+1 bar=ROTATE(congrid(BINDGEN(256,barwidth),barlength,barwidth,/minus_one),nquad) mtv,BYTSCL(bar,TOP=!D.N_COLORS-1),llx+image_height,lly,res=psres,neg=neg ; Open the single big file and associate it to variable. OPENR,imunit,template,/GET_LUN files=ASSOC(imunit,BYTARR(66048)) ; Set up to display image information colfac=0.8 textcol=ROUND(colfac*!D.N_COLORS) IF Keyword_Set(neg) THEN textcol=(!D.N_Colors-1)-textcol ; read in each image, decode the header, and renormalize as necessary ip=-1 FOR i=inf(0),inl(0) DO BEGIN whbad=WHERE(bad_image EQ i,nwhbad) IF nwhbad EQ 0 THEN BEGIN file=files(i) im=LONG(BYTE(file,512,256,256)) ; If file was renormalized to fit 8 bits, reverse this. IF file(290) GT 0 THEN BEGIN IF file(291) EQ 1 THEN im=LONG(im)*(2^file(290)) IF file(291) EQ 0 THEN im=LONG(im)*file(290) ENDIF KIh=gethd(hbytes(*,i)) ip=ip+1 ; extract exposure time if necessary IF selexp THEN BEGIN thisexp=KIh.misc.exp_scale*KIh.exp.exposure/1000. go_on=(ABS(thisexp-expt) LT 1.0) ENDIF ELSE go_on=1 IF go_on THEN BEGIN ; If autoscaling is desired, find lmaxi, otherwise use topnum IF topnum EQ 0 $ ; Is there any useful information left in the image? ; identify useful min and max values for byte-scaling THEN lmaxi=pcentile(im,0.999) $ ELSE lmaxi=topnum im(255,98)=lmaxi ; force image to scale properly lmaxbh=pcentile(im,0.001) ; show image orientation, one time only IF (i EQ inf(0)) AND (ptype EQ 'N') $ THEN compass,KIh.misc.az,barlength,fac,psres ; generate the image to plot IF ptype EQ 'N' $ THEN pimg=ROTATE(im*mask,5) $ ELSE BEGIN IF mtype EQ 'M' $ THEN map_pgm,hbytes(*,i),im*mask,eht,88.664 $ ,-83.444,pimg,vRbg=vRbg $ ,fullscale=[lmaxbh,lmaxi],/annotate $ ELSE map_geo,hbytes(*,i),im*mask,eht,pimg $ ,vRbg=vRbg,fullscale=[lmaxbh,lmaxi] $ ,/annotate ifac=(lmaxi-lmaxbh)/FLOAT(!D.N_COLORS-1) pimg=ROUND(ifac*TEMPORARY(pimg))+lmaxbh pimg=FIX(TEMPORARY(pimg)) ENDELSE ; display the image mtv,REBIN(pimg,image_height,image_height,/SAMPLE) $ ,llx,lly,low=lmaxbh,high=lmaxi,res=psres,neg=neg ; label the image labelimg,hbytes(*,i),lmaxi,lmaxbh,llx,lly,image_height,image_height,fac $ ,psres=psres,color=textcol,sun=(ptype EQ 'N') ; Interpret user's latest keystroke EMPTY otime=SYSTIME(1) PRINT,'.',FORMAT='(A,$)' IF (ip+1) MOD 80 EQ 0 THEN PRINT,FORMAT='()' ; wait until the image has been up for at least the time interval ; requested by the user IF KEYWORD_SET(otime) THEN $ REPEAT stime=SYSTIME(1) UNTIL (stime-otime GT 1.01*interval) k=GET_KBRD(0) CASE STRUPCASE(k) OF 'X': GOTO,DONE 'P': REPEAT k=GET_KBRD(1) UNTIL STRUPCASE(k) NE '' ELSE: ENDCASE ENDIF EMPTY ENDIF ENDFOR DONE: PRINT,FORMAT='()' Free_LUN,imunit END