FUNCTION polyphot,array,polyx=polyx,polyy=polyy,area=area,usexy=usexy, $ showsub=showsub,noplot=noplot ;+ ; POLYPHOT ; ; Perform aperture photometry with a polygonal aperture. ; ; Calling Sequence ; ; Flux = polyphot([array]) ; ; Arguments ; ; Array The array to perform photometry on. If array is not ; specified, then the current active array is used. ; ; ; Keywords ; ; POLYX, If specified along with /Usexy, then this defines the ; POLYY vertices of the polygon to be used. If /Usexy is NOT set ; then polyx and polyy are set to the interactively ; specified vertices. ; ; Usexy If specified, the interactive phase of the program is ; skipped, and the specified X,Y coordinates are used. ; ; Noplot Normally the aperture is plotted on top of the current ; window. Noplot suppresses that plot. Noplot is only ; effective if the interactive phase of the program is also ; disabled using /Usexy. ; ; Note that the interactive phase of the program as well as the ; plotting assume that Data Coordinates are properly established ; for the graphics window, which is accomplished with the WWPKG ; routines. ; ; Showsub If specified, then the aperture and its contents are ; displayed in a separate window. ; ; Area If set to a variable, returns the actual size (in square ; pixels) of the aperture used. Note that the aperture ; is sized in units of .01 pixels. ;- common active,active common polyphot_block, lastx, lasty, havelast if (not keyword_set(array)) then useactive=1 else useactive=0 if(keyword_set(usexy)) then begin if (not keyword_set(noplot)) then plots,polyx,polyy,/data endif else begin print,'MARK THE VERTICES OF THE POLYGON' device, get_graphics = old, set_graphics = 6 ;Set xor col = (!d.n_colors/2) cursor,x0,y0,/data polyx=[x0] & polyy=[y0] tempx=polyx & tempy=polyy plots,tempx,tempy,/data,col=col !err=0 quit=0 repeat begin cursor,x,y,/change wait,0.1 case !err of 0: begin plots,tempx,tempy,/data,col=col x0=x & y0=y tempx=[polyx,x0] & tempy=[polyy,y0] plots,tempx,tempy,/data,col=col endcase 1: begin plots,tempx,tempy,/data,col=col polyx=[polyx,x0] & polyy=[polyy,y0] tempx=polyx & tempy=polyy plots,tempx,tempy,/data,col=col tvcrs,x0,y0,/data endcase 2: begin plots,tempx,tempy,/data,col=col plots,[polyx,polyx(0)],[polyy,polyy(0)],/data,col=col quit=1 endcase else : endcase endrep until (quit) device,set_graphics=old endelse xlow=fix(min(polyx)-1.5) & ylow=fix(min(polyy)-1.5) xhigh=fix(max(polyx)+1.5) & yhigh=fix(max(polyy)+1.5) if(useactive) then suba=active(xlow:xhigh,ylow:yhigh) $ else suba=array(xlow:xhigh,ylow:yhigh) polyxv=polyx-xlow & polyyv=polyy-ylow xside=10*(xhigh-xlow+1) yside=10*(yhigh-ylow+1) suba=rebin(suba,xside,yside,/sample) polyxv=polyxv*10+4.5 & polyyv=polyyv*10+4.5 pts=polyfillv(polyxv,polyyv,xside,yside) area=n_elements(pts)/100. flux=total(suba(pts))/100. if (keyword_set(showsub)) then begin mask=0.*suba mask(pts)=1 wid=!d.window wwindow,array=suba,/free scale=autoscale(mask*suba) tv,255-bytscl(mask*suba,min=scale(0),max=scale(1)) wwset,wid endif return,flux end