;========================================================================== PRO det_scl ; ;Determines scale factor to be used for images throughout the program. ; ; XSize = the final resized X dimension of the image. ; YSize = the final resized Y dimension of the image. ; scl = integer scaling factor. COMMON GLOBE, WB, InX, InY, XCenter, YCenter, XSize, YSize, XHigh, XLow, $ YHigh, YLow, High, Low, scl, good_pix, exclude, include COMMON IMAG, Data1, NImages, Im_Num, Hi, Lo, Image, X_im, Y_im COMMON PCAP, Elem1, Elem2, Elem3, Elem4, Elem5, Elem6, Element1, Element2,$ X_pca, Y_pca, width, c_pix1, win, xrange, yrange COMMON PCA2, eigvals, new_vecs, PCArr COMMON COLOR, c_pix, Num_pix COMMON ENDM, N_EndM, End_M, EM_pix, EM_pix_set, EM_npca COMMON FRACAB, Frac, Frac2 COMMON RES, res_pix, res_pix2 COMMON WIND, clean, w0x, w1x, w2x, w0y, w1y, w2y ;COMMON SPEC, Sky, Sky_pca, Sky_pca2 COMMON SPEC2, old_vecs, n_oem_pix, N_iter, old_em_pix, em_pca_pix,N_EM ; ; The code below it will try to get a scale factor to display ; images as close as possible to 256x256. - D. Klassen 11/22/96 ; scl = 256/XSize > 256/YSize scl=fix(scl) print,'Image scale factor = ',scl ; return end ;========================================================================== PRO find_med ; ;MEDIAN is used to calculate the upper and lower cutoff limits for the ;image display for all images. ; ; Data1 = array containing images. ; Low = array containing lower cutoff limits for image display. ; High = array containing upper cutoff limits for image display. ; COMMON GLOBE, WB, InX, InY, XCenter, YCenter, XSize, YSize, XHigh, XLow, $ YHigh, YLow, High, Low, scl, good_pix, exclude, include COMMON IMAG, Data1, NImages, Im_Num, Hi, Lo, Image, X_im, Y_im COMMON PCAP, Elem1, Elem2, Elem3, Elem4, Elem5, Elem6, Element1, Element2,$ X_pca, Y_pca, width, c_pix1, win, xrange, yrange COMMON PCA2, eigvals, new_vecs, PCArr COMMON COLOR, c_pix, Num_pix COMMON ENDM, N_EndM, End_M, EM_pix, EM_pix_set, EM_npca COMMON FRACAB, Frac, Frac2 COMMON RES, res_pix, res_pix2 COMMON WIND, clean, w0x, w1x, w2x, w0y, w1y, w2y ;COMMON SPEC, Sky, Sky_pca, Sky_pca2 COMMON SPEC2, old_vecs, n_oem_pix, N_iter, old_em_pix, em_pca_pix,N_EM ; ;Finding MEDIAN for all images. Low = fltarr(NImages) High = fltarr(NImages) i = 0 while (i lt NImages) do begin Med = MEDIAN(Data1(i,XLow:XHigh,YLow:YHigh)) if Med eq 0.0 then Med = MEAN(Data1(i,XLow:XHigh,YLow:YHigh)) Low(i) = Med * 0.00 ; High(i) = Med * 2.34 High(i) = Med * 4.50 i = i + 1 endwhile ; return end ;========================================================================== PRO rsz_query ; ;Querying program to determine if initial image should be resized. ; COMMON GLOBE, WB, InX, InY, XCenter, YCenter, XSize, YSize, XHigh, XLow, $ YHigh, YLow, High, Low, scl, good_pix, exclude, include COMMON IMAG, Data1, NImages, Im_Num, Hi, Lo, Image, X_im, Y_im COMMON PCAP, Elem1, Elem2, Elem3, Elem4, Elem5, Elem6, Element1, Element2,$ X_pca, Y_pca, width, c_pix1, win, xrange, yrange COMMON PCA2, eigvals, new_vecs, PCArr COMMON COLOR, c_pix, Num_pix COMMON ENDM, N_EndM, End_M, EM_pix, EM_pix_set, EM_npca COMMON FRACAB, Frac, Frac2 COMMON RES, res_pix, res_pix2 COMMON WIND, clean, w0x, w1x, w2x, w0y, w1y, w2y ;COMMON SPEC, Sky, Sky_pca, Sky_pca2 COMMON SPEC2, old_vecs, n_oem_pix, N_iter, old_em_pix, em_pca_pix,N_EM ; restart: Chose = 0 xmenu,['Select SubImage', 'Use Full Image', 'Change Image Display Cutoffs'], $ BASE=base, BUTTONS=B, title='Image Selection Menu' WIDGET_CONTROL,base,/REALIZE event = WIDGET_EVENT(base) WIDGET_CONTROL, GET_UVALUE = Chose, event.id WIDGET_CONTROL, event.top, /DESTROY ; case Chose of 0: begin print, 'Displaying original image to select sub-image.' resize_im ;in pcalib2.pro det_scl ;in pcalib1.pro find_med ;in pcalib1.pro end ;0 1: begin XLow = 0 XHigh = InX - 1 YLow = 0 YHigh = InY - 1 find_med ;in pcalib1.pro end ;1 ; Change Image Display Cutoffs 2: begin print print, '==================================================' print, ' CHANGING IMAGE CUTOFFS' print, '==================================================' print, 'Median =', MEDIAN(Data1(Im_Num,XLow:XHigh,YLow:YHigh)) print, 'Minimum =', MIN(Data1(Im_Num,XLow:XHigh,YLow:YHigh)) print, 'Low Cutoff =', Low(Im_Num) print, 'High Cutoff =', High(Im_Num) print, '====================================================' print, 'NEW Cutoffs (Low, High)? ' read, Lowd, Highd High(Im_Num) = Highd Low(Im_Num) = Lowd Hi=High(Im_Num) Lo=Low(Im_Num) wset, 3 b = Data1(Im_Num,XLow:XHigh,YLow:YHigh) d = reform(b,XSize,YSize) Image = rebin(d,XSize*scl,YSize*scl,/sa) erase tvscl, Image < Hi > Lo print,'***** Image Contrast Adjusted *****' goto, restart end ;2 endcase ; return end ;========================================================================== PRO bad_pix1,skipzap=skipzap ; ;Procedure asking whether the images contain pixels that need to be zapped ;before they are run through PCAINIT. ; COMMON GLOBE, WB, InX, InY, XCenter, YCenter, XSize, YSize, XHigh, XLow, $ YHigh, YLow, High, Low, scl, good_pix, exclude, include COMMON IMAG, Data1, NImages, Im_Num, Hi, Lo, Image, X_im, Y_im COMMON PCAP, Elem1, Elem2, Elem3, Elem4, Elem5, Elem6, Element1, Element2,$ X_pca, Y_pca, width, c_pix1, win, xrange, yrange COMMON PCA2, eigvals, new_vecs, PCArr COMMON COLOR, c_pix, Num_pix COMMON ENDM, N_EndM, End_M, EM_pix, EM_pix_set, EM_npca COMMON FRACAB, Frac, Frac2 COMMON RES, res_pix, res_pix2 COMMON WIND, clean, w0x, w1x, w2x, w0y, w1y, w2y ;COMMON SPEC, Sky, Sky_pca, Sky_pca2 COMMON SPEC2, old_vecs, n_oem_pix, N_iter, old_em_pix, em_pca_pix,N_EM COMMON RESCALE, xygrid, Dim1, Dim2, xmargin, ymargin, bmargin, tmargin ; ;Displaying image. window,3,xs=scl*XSize,ys=scl*YSize,title='Image before Bad Pixel Removal',$ retain=2 b = Data1(Im_Num,XLow:XHigh,YLow:YHigh) d = reform(b,XSize,YSize) c = rebin(d,XSize*scl,YSize*scl,/sa) tv,bytscl(c) clean(3)=0 ; Choose = 0 if not(keyword_set(skipzap)) then begin xmenu, ['EXCLUDE PIXELS FROM PCA',$ 'INCLUDE ALL PIXELS'], BASE=base, BUTTONS=B, $ title='Bad Pixel Menu' WIDGET_CONTROL,base,/REALIZE event = WIDGET_EVENT(base) WIDGET_CONTROL, GET_UVALUE = Choose, event.id WIDGET_CONTROL, event.top, /DESTROY endif else begin Choose = 2 endelse ; case Choose of ;Some pixels need to be zapped from the images. 0: begin bad_pix2, c ;in pcalib1.pro print, 'Bad Pixel Elimination finished' end ;0 ;Continue with initialization. 1: begin XSize = long(XSize) YSize = long(YSize) good_pix=findgen(XSize*YSize) end ;1 else: endcase ; return end ;========================================================================== PRO bad_pix2, c ; ;Interactive method of eliminating bad pixels (ie. foreground stars, etc.) ;from the images before they are run through PCAINIT. ; ; width = array containing X and Y dimensions of box. ; X = X position for the center of the box. ; Y = Y position for the center of the box. ; XSize = the final resized X dimension of the image. ; YSize = the final resized Y dimension of the image. ; tvbox = display routine that draws box. COMMON GLOBE, WB, InX, InY, XCenter, YCenter, XSize, YSize, XHigh, XLow, $ YHigh, YLow, High, Low, scl, good_pix, exclude, include COMMON IMAG, Data1, NImages, Im_Num, Hi, Lo, Image, X_im, Y_im COMMON PCAP, Elem1, Elem2, Elem3, Elem4, Elem5, Elem6, Element1, Element2,$ X_pca, Y_pca, width, c_pix1, win, xrange, yrange COMMON PCA2, eigvals, new_vecs, PCArr COMMON COLOR, c_pix, Num_pix COMMON ENDM, N_EndM, End_M, EM_pix, EM_pix_set, EM_npca COMMON FRACAB, Frac, Frac2 COMMON RES, res_pix, res_pix2 COMMON WIND, clean, w0x, w1x, w2x, w0y, w1y, w2y ;COMMON SPEC, Sky, Sky_pca, Sky_pca2 COMMON SPEC2, old_vecs, n_oem_pix, N_iter, old_em_pix, em_pca_pix,N_EM ; badmin = -100 ;anything outside range is marked bad badmax = 24000 ;Entering center point for image box. Left = 1 tst = 0 XBSz = 24 YBSz = 24 num = 0 X_sv = intarr(15) Y_sv = intarr(15) XW_sv = intarr(15) YW_sv = intarr(15) YSize = long(YSize) XSize = long(XSize) ;N_pix2 = XSize * YSize good=findgen(XSize*YSize) while (tst ne 1) do begin print print, '==================================================' print, 'Click LEFT button to choose center point of image.' print, '==================================================' device, /cursor_crosshair cursor, X, Y, /dev ; if(!err eq Left) then begin lct_dmw ;in pcalib1.pro wid = [XBSz,YBSz] color = 1 tvbox, wid, X, Y, color ;in pcalib3.pro X_sv(num) = X Y_sv(num) = Y XW_sv(num) = wid(0) YW_sv(num) = wid(1) endif Choice = 0 xmenu,['CHANGE Box Size',$ 'IGNORE Box Choice',$ 'EXCLUDE Pixels from PCA',$ 'END Pixel Exclusion Routine'], BASE=base, BUTTONS=B, $ title='Bad Pixel Selection Menu' WIDGET_CONTROL,base,/REALIZE event = WIDGET_EVENT(base) WIDGET_CONTROL, GET_UVALUE = Choice, event.id WIDGET_CONTROL, event.top, /DESTROY case Choice of ;Changing the size of the box. 0: begin print print, '==================================================' print, ' CHANGING BOX SIZE' print, '==================================================' print, 'Length =',wid(0) print, 'Width =',wid(1) print, '==================================================' print, 'INPUT the new length, width of the box.' print, '(Length, Width)? ' lct_dmw ;in pcalib1.pro read, XSz, YSz wid = [XSz,YSz] XW_sv(num) = wid(0) YW_sv(num) = wid(1) tvscl, c < High(0) > Low(0) i = 0 color = 256 while (i le num) do begin wid = [XW_sv(i),YW_sv(i)] if (i eq num) then color = 1 tvbox, wid, X_sv(i), Y_sv(i), color ;in pcalib3.pro i = i + 1 endwhile end ;0 ;Ignore selection of bad pixels. 1: begin end ;Saving bad pixel map. 2: begin lct_dmw ;in pcalib1.pro tvscl,c i = 0 color = 255 while (i le num) do begin wid = [XW_sv(i),YW_sv(i)] tvbox, wid, X_sv(i), Y_sv(i), color ;in pcalib3.pro i = i + 1 endwhile width = [XW_sv(num),YW_sv(num)] X_im = X_sv(num) Y_im = Y_sv(num) image_pix ;in pcalib1.pro bad=c_pix good(bad)=-1. tst = 0 num = num + 1 print print, 'Bad pixels removed from PCA' end ;2 ;End pixel exclusion. 3: begin tst = 1 for i = 0,NImages-1 do begin bad=where(Data1(i,*,*) lt badmin) if (n_elements(bad) gt 1) then good(bad)=-1. endfor ;i good_pix=where(good gt 0) print end ;3 endcase ; endwhile ; return end ;========================================================================== PRO d_image, XDim, YDim, scale ; ;This procedure displays new images. Image data is taken from array Data1. ; ; ImN = Image number to be displayed. ; XDim = Low and High X limits to be displayed [X1,X2]. ; YDim = Low and High Y limits to be displayed [Y1,Y2]. ; win = Window in which image is to be displayed. ; scale = Scaling factor used to display image. ; COMMON GLOBE, WB, InX, InY, XCenter, YCenter, XSize, YSize, XHigh, XLow, $ YHigh, YLow, High, Low, scl, good_pix, exclude, include COMMON IMAG, Data1, NImages, Im_Num, Hi, Lo, Image, X_im, Y_im COMMON PCAP, Elem1, Elem2, Elem3, Elem4, Elem5, Elem6, Element1, Element2,$ X_pca, Y_pca, width, c_pix1, win, xrange, yrange COMMON PCA1, wavelength, eigvecs, wave_title COMMON PCA2, eigvals, new_vecs, PCArr COMMON COLOR, c_pix, Num_pix COMMON ENDM, N_EndM, End_M, EM_pix, EM_pix_set, EM_npca COMMON FRACAB, Frac, Frac2 COMMON RES, res_pix, res_pix2 COMMON WIND, clean, w0x, w1x, w2x, w0y, w1y, w2y ;COMMON SPEC, Sky, Sky_pca, Sky_pca2 COMMON SPEC2, old_vecs, n_oem_pix, N_iter, old_em_pix, em_pca_pix,N_EM COMMON RESCALE, xygrid, Dim1, Dim2, xmargin, ymargin, bmargin, tmargin ; tst = 0 while (tst ne 1) do begin print print, '==================================================' print, ' DISPLAYING NEW IMAGE' print, '==================================================' print, 'CURRENT displayed image is number ',Im_Num print, ' with wavelength ',wavelength[Im_Num] print, 'WHICH image would you like to see displayed? ' print, 'CHOOSE between 0 and ',NImages - 1 read,ImN if (ImN lt NImages) and (ImN ge 0) then begin b = Data1(ImN,XDim(0):XDim(1),YDim(0):YDim(1)) XLim = XDim(1) - XDim(0) + 1 YLim = YDim(1) - YDim(0) + 1 d = reform(b,XLim,YLim) c = rebin(d,XLim*scale,YLim*scale,/sa) Image = c print, ' Displaying Image',ImN print, ' Wavelength = ',wavelength[ImN] print, ' Scale Range = ',Low[ImN],High[ImN] wset, 3 tvscl, c < High(ImN) > Low(ImN) gifbar,c,Low(ImN),High(ImN),ct=0,tc=255,fname='original',dispwin=20, $ wintitle='Original - Image '+strno(fix(ImN)) BufImage=rebin(d,Xsize*xygrid,YSize*xygrid) OutImage=fltarr(Dim1,Dim2) OutImage(xmargin:Dim1-1-ymargin,bmargin:Dim2-1-tmargin)=BufImage writefits,'original.fit',OutImage Im_Num = ImN clean(3) = 0 tst = 1 endif endwhile ; clean(3)=0 return end ;========================================================================== PRO d_pcaplot ; ;Displaying new PCA Plot. COMMON GLOBE, WB, InX, InY, XCenter, YCenter, XSize, YSize, XHigh, XLow, $ YHigh, YLow, High, Low, scl, good_pix, exclude, include COMMON IMAG, Data1, NImages, Im_Num, Hi, Lo, Image, X_im, Y_im COMMON PCAP, Elem1, Elem2, Elem3, Elem4, Elem5, Elem6, Element1, Element2,$ X_pca, Y_pca, width, c_pix1, win, xrange, yrange COMMON PCA2, eigvals, new_vecs, PCArr COMMON COLOR, c_pix, Num_pix COMMON ENDM, N_EndM, End_M, EM_pix, EM_pix_set, EM_npca COMMON FRACAB, Frac, Frac2 COMMON RES, res_pix, res_pix2 COMMON WIND, clean, w0x, w1x, w2x, w0y, w1y, w2y ;COMMON SPEC, Sky, Sky_pca, Sky_pca2 COMMON SPEC2, old_vecs, n_oem_pix, N_iter, old_em_pix, em_pca_pix,N_EM ; print print, '==================================================' print, ' DISPLAYING NEW PCAPLOT' print, '==================================================' print s_pcaplot ;in pcalib1.pro print print, 'WHICH two elements would you like to see plotted? ' print, 'ENTER Eigenvector1, Eigenvector2' read,Element1,Element2 while (Element1 gt NImages) do begin print, 'Eigenvector1 too large. ENTER again.' read, Element1 endwhile while (Element2 gt NImages) do begin print, 'Eigenvector2 too large. ENTER again.' read, Element2 endwhile ; Element1 = long(Element1) Element2 = long(Element2) ; wset, win pcaplot,Element1,Element2,ps=1,iter=N_iter,outfile=win,xrange=xrange(*,win),yrange=yrange(*,win) ;in pcalib3.pro ;oplot,[Sky_pca(Element1)],[Sky_pca(Element2)],psym=1,color=1 ; if (win eq 0) then begin Elem1 = Element1 Elem2 = Element2 w0x = !x w0y = !y endif if (win eq 1) then begin Elem3 = Element1 Elem4 = Element2 w1x = !x w1y = !y endif if (win eq 2) then begin Elem5 = Element1 Elem6 = Element2 w2x = !x w2y = !y endif ; clean(win) = 0 ; return end ;========================================================================== PRO s_pcaplot ; ;Selecting PCA Plot to be manipulated. COMMON GLOBE, WB, InX, InY, XCenter, YCenter, XSize, YSize, XHigh, XLow, $ YHigh, YLow, High, Low, scl, good_pix, exclude, include COMMON IMAG, Data1, NImages, Im_Num, Hi, Lo, Image, X_im, Y_im COMMON PCAP, Elem1, Elem2, Elem3, Elem4, Elem5, Elem6, Element1, Element2,$ X_pca, Y_pca, width, c_pix1, win, xrange, yrange COMMON PCA2, eigvals, new_vecs, PCArr COMMON COLOR, c_pix, Num_pix COMMON ENDM, N_EndM, End_M, EM_pix, EM_pix_set, EM_npca COMMON FRACAB, Frac, Frac2 COMMON RES, res_pix, res_pix2 COMMON WIND, clean, w0x, w1x, w2x, w0y, w1y, w2y ;COMMON SPEC, Sky, Sky_pca, Sky_pca2 COMMON SPEC2, old_vecs, n_oem_pix, N_iter, old_em_pix, em_pca_pix,N_EM ; ; The folloing commented lines can be uncommented if you only want to ; work with one pcaplot at a time ;win = 0 ;wset,0 ;Element1 = Elem1 ;Element2 = Elem2 ; ; The following lines can be uncommented so that you can work with ; multiple pcaplots and thus will need to choose one to do the ; the actual plotting. Chose = 0 while (Chose ne 1) do begin xmenu,['Plot 0','Plot 1',' Plot 2 '],base=base, $ buttons=B, title='Choose PCA Plot' WIDGET_CONTROL,base,/REALIZE event=WIDGET_EVENT(base) WIDGET_CONTROL, GET_UVALUE=menu, event.id WIDGET_CONTROL, event.top, /destroy case menu of 0: begin win=0 wset,0 Element1=Elem1 Element2=Elem2 !x=w0x !y=w0y Chose=1 end ;0 1: begin win=1 wset,1 Element1=Elem3 Element2=Elem4 !x=w1x !y=w1y Chose=1 end ;1 2: begin win=2 wset,2 Element1=Elem5 Element2=Elem6 !x=w2x !y=w2y Chose=1 end ;2 endcase endwhile return end ;========================================================================== PRO pca_pix, ZC ; ; ; width = array containing X and Y dimensions of box. ; X_pca = X position for the center of the box (PCA Plot). ; Y_pca = Y position for the center of the box (PCA Plot). ; new_vecs = array containing transformed vectors from PCAINIT. COMMON GLOBE, WB, InX, InY, XCenter, YCenter, XSize, YSize, XHigh, XLow, $ YHigh, YLow, High, Low, scl, good_pix, exclude, include COMMON IMAG, Data1, NImages, Im_Num, Hi, Lo, Image, X_im, Y_im COMMON PCAP, Elem1, Elem2, Elem3, Elem4, Elem5, Elem6, Element1, Element2,$ X_pca, Y_pca, width, c_pix1, win, xrange, yrange COMMON PCA2, eigvals, new_vecs, PCArr COMMON COLOR, c_pix, Num_pix COMMON ENDM, N_EndM, End_M, EM_pix, EM_pix_set, EM_npca COMMON FRACAB, Frac, Frac2 COMMON RES, res_pix, res_pix2 COMMON WIND, clean, w0x, w1x, w2x, w0y, w1y, w2y ;COMMON SPEC, Sky, Sky_pca, Sky_pca2 COMMON SPEC2, old_vecs, n_oem_pix, N_iter, old_em_pix, em_pca_pix,N_EM ; ;Finding vectors inside box region from PCAPLOT. Len = width(0) Wid = width(1) Len2 = Len / 2 Wid2 = Wid / 2 print,'Box center coordinates =',X_pca,Y_pca X1 = X_pca - Len2 X2 = X_pca + Len2 Y1 = Y_pca - Wid2 Y2 = Y_pca + Wid2 ; Z1 = [X1,Y1] Z2 = [X2,Y2] ; ;Transform from display space to the PCA data space. Z3 = coords(Z1) ;in pcalib1.pro Z4 = coords(Z2) ;in pcalib1.pro ZC = coords([X_pca,y_pca]) ;in pcalib1.pro print,' PCA coordinates of box center = ',ZC print,' Box corners PCA corrdniates (x1,y1,x2,y2) = ',Z3,Z4 ;Find elements in the new PCA space. N_vec1 = new_vecs(good_pix,Element1) N_vec2 = new_vecs(good_pix,Element2) ; t_pix1 = where((N_vec2 le Z4(1)) and (N_vec2 ge Z3(1)) and $ (N_vec1 le Z4(0)) and (N_vec1 ge Z3(0))) if t_pix1[0] ne -1 then c_pix1 = good_pix(t_pix1) $ else c_pix1 = t_pix1 Num_pix = n_elements(c_pix1) if (Num_pix eq 1) and (c_pix1(0) eq -1) then Num_pix = 0 print,'# of pix in box = ',Num_pix print,'# of pix in space = ',n_elements(new_vecs(*,1)) ; return end ;========================================================================== PRO image_pix ; ;This procedure takes box information from get_box and determines the pixel ;values from the image frame. ; ; width = array containing X and Y dimensions of box. ; X_im = X position for the center of the box (image). ; Y_im = Y position for the center of the box (image). ; N_pix = Number of pixels selected from image to be colored. COMMON GLOBE, WB, InX, InY, XCenter, YCenter, XSize, YSize, XHigh, XLow, $ YHigh, YLow, High, Low, scl, good_pix, exclude, include COMMON IMAG, Data1, NImages, Im_Num, Hi, Lo, Image, X_im, Y_im COMMON PCAP, Elem1, Elem2, Elem3, Elem4, Elem5, Elem6, Element1, Element2,$ X_pca, Y_pca, width, c_pix1, win, xrange, yrange COMMON PCA2, eigvals, new_vecs, PCArr COMMON COLOR, c_pix, Num_pix COMMON ENDM, N_EndM, End_M, EM_pix, EM_pix_set, EM_npca COMMON FRACAB, Frac, Frac2 COMMON RES, res_pix, res_pix2 COMMON WIND, clean, w0x, w1x, w2x, w0y, w1y, w2y ;COMMON SPEC, Sky, Sky_pca, Sky_pca2 COMMON SPEC2, old_vecs, n_oem_pix, N_iter, old_em_pix, em_pca_pix,N_EM ; Len = width(0)/scl Wid = width(1)/scl Len2 = Len / 2 Wid2 = Wid / 2 Len2 = long(Len2) Wid2 = long(Wid2) X1 = (X_im/scl - Len2) X2 = X1 + Len Y1 = (Y_im/scl - Wid2) Y2 = Y1 + Wid X1 = long(X1) X2 = long(X2) Y1 = long(Y1) Y2 = long(Y2) Xdiff = X2 - X1 Ydiff = Y2 - Y1 N_pix = Xdiff * Ydiff if N_pix eq 0 then N_pix=1 Num_pix = N_pix ; c_pix = lonarr(N_pix) i = 0 while (i lt Ydiff) do begin j = 0 while (j lt Xdiff) do begin ; c_pix(i*Xdiff+j) = ((Y1+i) * XSize) + (X1 + j) + 1 c_pix(i*Xdiff+j) = ((Y1+i) * XSize) + (X1 + j) j = j + 1 endwhile i = i + 1 endwhile ; return end ;========================================================================== PRO refr_pca, ps=ps, zoom=zoom, iter1=iter1, color=color ; ;Procedure for refreshing pcaplots and original image. ; COMMON GLOBE, WB, InX, InY, XCenter, YCenter, XSize, YSize, XHigh, XLow, $ YHigh, YLow, High, Low, scl, good_pix, exclude, include COMMON IMAG, Data1, NImages, Im_Num, Hi, Lo, Image, X_im, Y_im COMMON PCAP, Elem1, Elem2, Elem3, Elem4, Elem5, Elem6, Element1, Element2,$ X_pca, Y_pca, width, c_pix1, win, xrange, yrange COMMON PCA2, eigvals, new_vecs, PCArr COMMON COLOR, c_pix, Num_pix COMMON ENDM, N_EndM, End_M, EM_pix, EM_pix_set, EM_npca COMMON FRACAB, Frac, Frac2 COMMON RES, res_pix, res_pix2 COMMON WIND, clean, w0x, w1x, w2x, w0y, w1y, w2y ;COMMON SPEC, Sky, Sky_pca, Sky_pca2 COMMON SPEC2, old_vecs, n_oem_pix, N_iter, old_em_pix, em_pca_pix,N_EM ; lct_dmw ;in pcalib1.pro if NOT KEYWORD_SET(iter1) then iter1=1 if not keyword_set(ps) then ps=0 if (clean(3) eq 1) then begin wset,3 tvscl,Image>Low(Im_Num) Lowd clean(3) = 0 endif else begin print, 'Incorrect component number' endelse ; return end ;========================================================================== PRO color_im ; ;This procedure takes box information from get_box to display pixels ;selected from the PCA Plot on an image. ; ; width = array containing X and Y dimensions of box. ; X_pca = X position for the center of the box (PCA Plot). ; Y_pca = Y position for the center of the box (PCA Plot). ; new_vecs = array containing transformed vectors from PCAINIT. ; COMMON GLOBE, WB, InX, InY, XCenter, YCenter, XSize, YSize, XHigh, XLow, $ YHigh, YLow, High, Low, scl, good_pix, exclude, include COMMON IMAG, Data1, NImages, Im_Num, Hi, Lo, Image, X_im, Y_im COMMON PCAP, Elem1, Elem2, Elem3, Elem4, Elem5, Elem6, Element1, Element2,$ X_pca, Y_pca, width, c_pix1, win, xrange, yrange COMMON PCA2, eigvals, new_vecs, PCArr COMMON COLOR, c_pix, Num_pix COMMON ENDM, N_EndM, End_M, EM_pix, EM_pix_set, EM_npca COMMON FRACAB, Frac, Frac2 COMMON RES, res_pix, res_pix2 COMMON WIND, clean, w0x, w1x, w2x, w0y, w1y, w2y ;COMMON SPEC, Sky, Sky_pca, Sky_pca2 COMMON SPEC2, old_vecs, n_oem_pix, N_iter, old_em_pix, em_pca_pix,N_EM ; pca_pix ;in pcalib1.pro if (Num_pix le 0) then print, 'No points inside boxed area.' ; ;Display selected points, in color, in window 0. if (Num_pix gt 0) then begin b = Data1(Im_Num,XLow:XHigh,YLow:YHigh) c = reform(b,Long(XSize)*Long(YSize)) c_pix2 = bytscl(c) > 8b c_pix2(c_pix1) = color c_pix3 = reform(c_pix2,XSize,YSize) c_pix4 = rebin(c_pix3,XSize*scl,YSize*scl,/sa) window,4,xs=XSize*scl,ys=YSize*scl,title='PCA pixels',retain=2 tv, c_pix4 endif ; return end ;========================================================================== PRO lct_dmw ; ;Purpose: Load personal color table. ; ; 0: black ; 1: red ; 2: yellow ; 3: green ; 4: Turquiose ; 5: blue ; 6: violet ; 7: white ; 8-255: black to grey to white ; inx=indgen(256) red=inx green=inx blue=inx red(7)=255 blue(7)=255 green(7)=255 line=[1,1,0,0,0,1]*255 red(1:6)=line green(1:6)=shift(line,2) blue(1:6)=shift(line,4) tvlct,red,green,blue return end ;========================================================================== FUNCTION coords,X ; ;This function converts from display frame coordinates to data space ;coordinates. ; ; X = [X1,Y1] the coordinates in the display frame. ; p = [X2,Y2] the coordinates in the data space. ; xn = float(X(0)) / !D.X_VSIZE yn = float(X(1)) / !D.Y_VSIZE ; xp = (xn - !X.S(0)) / !X.S(1) yp = (yn - !Y.S(0)) / !Y.S(1) p = [xp,yp] return, p end ;========================================================================== ;FUNCTION residual,X ;This function is bizarre and incorrectly documented, it needs to be ;redocumented/renamed. As far as can be seen, it is no longer used. ;This function converts coordinates in data space to a corresponding pixel ;location. ; ; X = [X1,Y1] the coordinates in the data space. ; pixl = the pixel in the data space. ; ;COMMON GLOBE, WB, InX, InY, XCenter, YCenter, XSize, YSize, XHigh, XLow, $ ; YHigh, YLow, High, Low, scl, good_pix, exclude, include ;COMMON PCA2, eigvals, new_vecs, PCArr ;COMMON ENDM, N_EndM, End_M, EM_pix, EM_pix_set, EM_npca ; ;N_pix = XSize * YSize ;Res = fltarr(N_pix,N_EndM-1) ;Res2 = fltarr(N_pix) ;for j = 0,1 do begin ; for i = 0l,N_pix-1 do begin ; Res(i,j) = (X(j) - new_vecs(i,j)) * (X(j) - new_vecs(i,j)) ; endfor ;i ;endfor ;j ; ;for ii = 0l,N_pix-1 do begin ; for jj = 0l, N_EndM-2 do begin ; Res2(ii) = Res2(ii) + Res(ii,jj) ; endfor ;jj ;endfor ;ii ; ;pixval = MIN(Res2,pixl) ; ;return, pixl ;end