;pro Tri_Color_Image ; ;PURPOSE: ; To form a tri-color image from a set of either two or three images ; ; The program accepts a FileList as input. The Filelist has the format of ; ; [Lines 1-3] FileNames w/full path (\t) XOffset (\t) YOffset. ; ; [Lines 4-6] Bright Star Coordinates in First File ; ; Col 0 Col1 Col2 Col3 Col4 Col5 ; [Lines 7] "RMin" RMin "RMax" RMax "RGam" RGam ; [Lines 8] "GMin" GMin "GMax" GMax "GGam" GGam ; [Lines 9] "BMin" BMin "BMax" BMax "BBam" BBam ; ; where IMin,IMax, etc. are the color scale ranges for that particular ; color. R - Red, G-Green, B-Blue. The files should be ordered U, V, B. ; ;INPUTS: ; FITSDIR: (string) ; The directory that contains the FILELIST and the files to be used in ; forming the tri-color image. ; FILELIST: (string) ; The relative name of the file containing the information described above. ; OBJECTNAME: (string) ; The name of the object in the exposures. This will be used in the file name ;OUTPUTS: ; 1) [Tri-color].tif ; 2) [Tri-color].png ; These files will have the following name ; [FitsDir+ObjectName] ; ;KEYWORDS: ; TVFLAG: (int) ; 0 - Don't plot the star centroiding process ; 1 - Plot the star centroids ; SKIPSTAR: (int) ; The number of stars to skip over before the plotting begins in the ; case that TVFLAGLOCAL != 0 ; SKIPY: (int) ; 0 - An image from the Y filter is not being used ; 1 - An image from the Y filter is being used ; STRETCH: (int) ; 0 - Use linear scaling ; 1 - Use Gamma scaling (note that the Gam and GammaVals must be set in ; FileList in order for this to work) ; REDFACTOR: (int) ; A scaling factor to compensate for the lack of quantum efficiency in ; the redder filters. ; USESTARALIGN: (int) ; 0 - Don't use stars to align the images ; 1 - Use a set of stars to align the images ; NSFlipped: (int) ; 0 - North and South are correct ; 1 - North and South are flipped ; ;CALLING SEQUENCE: ; Tri_Color_Image_xRG, FitsDir, FileList ; ;EXAMPLES: ; Tri_Color_Image_xRG, '/nfs/slac/g/ki/ki03/lances/H2RG-32-147/ASIC/Reduced/07Dec12/NGC2683', 'NGC2683_GI_Slopes.lst' ; ;/////////////////////////////////////////////////////////////////////////// pro Tri_Color_Image, FitsDir, FileList, ObjectName, $ TvFlag = TvFlag, SkipStar=SkipStar, $ StretchT = StretchT, RedFactor = RedFactor, $ UseStarAlign=UseStarAlign, NSFlipped=NSFlipped ;Move to the dir cd, FitsDir ;Set the Keyword Parameters If N_Elements(StretchT) eq 0 then StretchT = 0 If N_Elements(SkipStar) eq 0 then SkipStar = 0 If N_Elements(RedFactor) eq 0 then RedFactor = 0 If N_Elements(UseStarAlign) eq 0 then UseStarAlign = 0 If N_Elements(NSFlipped) eq 0 then NSFlipped = 0 ;Get the files from a list in a file ReadCol, FileList, RawFiles, XOffs, YOffs, Format = 'A,I,I' if UseStarAlign eq 1 then begin ;Get the bright star coordinates from the same file ReadCol, FileList, XStart, YStart, Format = 'I,I', $ SkipLine = N_Elements(RawFiles) endif ;Get the color minima and maxima from the file ReadCol, FileList, Mins, MinVals, Maxs, MaxVals, Gams, GammaVals, $ Format='A,D,A,D,A,D,A,D' NumRawFiles = N_elements(RawFiles) ;Figure out the biggest dimensions of the colored images XSizeMax = 0L & YSizeMax = 0L For FileNum = 0, NumRawFiles -1 do begin Fits_Read, RawFiles(FileNum), NoData, FitsHeader, /header_only XSizeMax = XSizeMax > long(SxPar(FitsHeader, 'NAXIS1')) YSizeMax = YSizeMax > long(SxPar(FitsHeader, 'NAXIS2')) EndFor ;Find the Maximums for the dimensions of the array ValidRAs = XOffs ValidDECs = YOffs MinRAOff = Min(ValidRAs) & MaxRAOff = Max(ValidRAs) MinDECOff = Min(ValidDECs) & MaxDECOff = Max(ValidDECs) NewArrXSize = XSizeMax + (MaxRAOff - MinRAOff) NewArrYSize = YSizeMax + (MaxDECOff - MinDECOff) ;Form an array big enough for all the dithers FullIms = DblArr(NewArrXSize, NewArrYSize, 3) FoundY = 0 FiltersUsed = '' For FileNum= 0, NumRawFiles - 1 do begin print, 'Dithering with File : ' + RawFiles(FileNum) ;Read in the frame Fits_Read, RawFiles(FileNum), Frame, FitsHeader ThisNaxis1 = long(SxPar(FitsHeader,'NAXIS1')) ThisNaxis2 = long(SxPar(FitsHeader,'NAXIS2')) ThisFilter = Strtrim(SxPar(FitsHeader, 'FILTER'),2) print,min(frame), max(frame) print, ThisFilter ;Put Proper Color in proper spot ;I - 742 nm ; G - 476 nm ; I+G/2 - 620 or so If stregex(strtrim(ThisFilter,2),'Red',/boolean) eq 1 then begin print, 'Found Red' Cube = 0 RCube = 0 FiltersUsed = FiltersUsed+'R' EndIf Else if stregex(strtrim(ThisFilter,2),'Green',/boolean) eq 1 then begin print , 'Found Green' Cube = 1 GCube = 1 FiltersUsed = FiltersUsed+'G' EndIf Else if stregex(strtrim(ThisFilter,2),'Blue',/boolean) eq 1 then begin print, 'Found Blue' Cube = 2 BCube = 2 FiltersUsed = FiltersUsed+'B' EndIf print, 'Putting Filter : ' + ThisFilter + ' In ' +Strtrim(Cube,2) ;Shift the images in the opposite direction to stack XOff = -(XOffs(FileNum)-MaxRAOff) YOff = -(YOffs(FileNum)-MaxDECOff) FullIms(XOff : XOff +ThisNaxis1-1, $ YOff : YOff +ThisNaxis2-1, $ Cube) = Frame EndFor If StretchT eq 0 then begin ;Linear Scaling FullImScaled = BytArr(NewArrXSize, NewArrYSize, 3) FullImScaled(*,*,RCube)=BytScl(FullIms(*,*,RCube)+$ RedFactor*FullIms(*,*,RCube),$ min=MinVals(RCube),max=MaxVals(RCube)) FullImScaled(*,*,GCube)=BytScl(FullIms(*,*,GCube),$ min=MinVals(GCube),max=MaxVals(GCube)) FullImScaled(*,*,BCube)=BytScl(FullIms(*,*,BCube),$ min=MinVals(BCube),max=MaxVals(BCube)) EndIf else if StretchT eq 1 then begin FullImScaled = BytArr(NewArrXSize, NewArrYSize, 3) FullImScaled(*,*,RCube)=GMaScl(FullIms(*,*,RCube),Gamma=GammaVals(RCube), $ min=MinVals(RCube),max=MaxVals(RCube)) FullImScaled(*,*,GCube)=GMaScl(FullIms(*,*,GCube),Gamma=GammaVals(GCube), $ min=MinVals(GCube),max=MaxVals(GCube)) FullImScaled(*,*,BCube)=GMaScl(FullIms(*,*,BCube),Gamma=GammaVals(BCube), $ min=MinVals(BCube),max=MaxVals(BCube)) EndIf ;Cut it down to avoid the edges FullImScaled = FullImScaled(Max(XOffs):NewArrXSize-1, $ Max(YOffs):NewArrYSize-1, $ *) ;Write a fits file Fits_Write, FitsDir+ObjectName+'_'+$ Strtrim(FiltersUsed,2)+'Color.fits', FullIms ;Attempt to put image in right orientation If NSFlipped eq 1 then FullImScaled = Reverse(FullImScaled,1) ;Window,xsize=700,ysize=700 ;Set_Plot,'z' Write_Tiff, FitsDir+ObjectName+'_'+$ Strtrim(FiltersUsed,2)+'_Color.tif', $ red=FullImScaled(*,*,0),$ green=FullImScaled(*,*,1),$ blue=FullImScaled(*,*,2),$ planarconfig=2 If stregex(!version.os, 'Win', /boolean) then begin set_plot,'WIN' EndIf else begin set_plot,'X' EndElse Window,xsize=700,ysize=700 Tv,congrid(FullImScaled(*,*,*),700,700,3),true=3 PngImg = tvrd(true=1) PngImg = reverse(PngImg,2) tvlct,reds,greens,blues,/get write_png, FitsDir+ObjectName+$ '_'+Strtrim(FiltersUsed,2)+'_Color.png', $ PngImg,reds,greens,blues If stregex(!version.os, 'Win', /boolean) then begin set_plot,'WIN' EndIf else begin set_plot,'X' EndElse stop end