# Copyright(c) 2002-2003 Association of Universities for Research in Astronomy, Inc. procedure gmosaic(inimages) # Mosaic the 3 GMOS ccds # geotran gdata$g24173[1][33:2080,1:4608] chip1 "" "" xshift=-2.50 yshift=-1.58 \ # xrotation=-0.0027827 yrotation=-0.0027827 # # imcopy gdata$g24173[2][33:2080,1:4608] chip2 # geotran gdata$g24173[3][1:2048,1:4608] chip3 "" "" xshift=3.3723 yshift=-1.89 \ # xrotation=-0.056477 yrotation=-0.056477 # followed by imtile # Version Feb 28, 2002 IJ,BM v1.3 release # Apr 26, 2002 IJ handle raw images with no complaints, WCS warning # optional cleaning of OBSMODE=IMAGE # Jun 21, 2002 IJ fixed warning for missing WCS # Aug 26, 2002 KGB added parameter to specify interpolation type, default as before # Aug 26, 2002 IJ changed parameter name to geointer, parameter encoding # Aug 27, 2002 IJ allowed values on geointer, geointer in output header # Sept 20, 2002 IJ v1.4 release # Oct 14, 2002 BM generalize to GMOS-S # Jan 16, 2003 BM alternate amps 5,6 for 6 amp mode # Jan 24, 2003 ML updated numbers for GMOS-S # Feb 6, 2003 IJ fix the binx2 bug - I hope; enabled binx2 use for GMOS-S # Feb 14, 2003 IJ fixed handling of WCS. # Feb 19, 2003 IJ tweaked GMOS-N ccd3 shift with 0.5pix # March 4, 2003 IJ fixed rotation for Xbin!=Ybin case # fix rotation correction for multiple images processed # merged in new GMOS-S values from BM/ML, corrected lxbshift[2,3] # Mar 19, 2003 BM default pix value in chip gaps is -1, generalize mbpm for GMOS-N,S # Mar 20, 2003 BM changed lxbshift[2,3] for GMOS-S to get chip-gap separation correct (checked with images) # Apr 10, 2003 BM generalized to handle original GMOS-S geometry and geometry with new CCD1 # May 9, 2003 BM swap order for amps 1,2 for GMOS-S in 6 amp mode with new CCD # May 9, 2003 IJ clean-up logfile output for rotations # May 15, 2003 BM new GMOS-S numbers, 6amp mode for GMOS-N and GMOS-S # Jun 2, 2003 IJ transparent handling of old BPM names for GMOS-N. Released as bugfix. char inimages {"",prompt="GMOS image to mosaic"} # OLDP-1 char outimages {"",prompt="Output images or list"} # OLDP-1 char outpref {"m",prompt="Prefix for output images"} # OLDP-1 bool fl_paste {no,prompt="Paste images instead of mosaic"} # OLDP-3 char geointer {"linear",min="linear|nearest|poly3|poly5|spline3|sinc",prompt="Interpolant to use with geotran"} # OLDP-2 int gap {37,prompt="Gap between the CCDs in unbinned pixels"} # OLDP-3 char sci_ext {"SCI",prompt="Extension(s) to mosaic, use '' for raw data"} # OLDP-3 char key_detsec {"DETSEC",prompt="Header keyword for detector section"} # OLDP-3 char key_datsec {"DATASEC",prompt="Header keyword for data section"} # OLDP-3 char key_ccdsum {"CCDSUM",prompt="Header keyword for CCD binning"} # OLDP-3 char bpmfile {"gmos$data/chipgaps.dat",prompt="Info on location of chip gaps"} # OLDP-3 bool fl_fixpix {no,prompt="Interpolate across chip gaps"} # OLDP-3 bool fl_clean {yes,prompt="Clean imaging data outside imaging field"} # OLDP-3 char key_obsmode {"OBSMODE",prompt="Header keyword for observing mode"} # OLDP-3 char obsmode {"IMAGE",prompt="Value of key_obsmode for imaging data"} # OLDP-3 char statsec {"default",prompt="Statistics section for cleaning"} # OLDP-3 char logfile {"",prompt="Logfile"} # OLDP-1 bool verbose {yes,prompt="Verbose"} # OLDP-2 int status {0,prompt="Exit status (0=good)"} # OLDP-4 struct* scanfile {"",prompt="Internal use only"} # OLDP-4 begin char l_inimages, l_outimages, l_outpref, l_logfile char l_interp,l_sci_ext, l_key_detsec, l_key_datsec, l_key_ccdsum, l_bpmfile char l_key_obsmode, l_obsmode, l_statsec bool l_verbose, l_fl_paste,l_fl_fixpix, l_fl_clean int l_gap, l_status char tmpin, l_dsec, tmpout, l_paste, tmpbpm, l_pastel char tmpim[3], l_imext, tmptile[3], img char l_pixtype, sciext, mdf, l_locstatsec int n_ext, x1, x2, y1, y2, n_i, n_j, n_k int nimages,nsci,namp,nx,ny int Xoff, Yoff, Xbin, Ybin struct l_struct char filelist, l_temp, l_inim[200], l_outim[200], l_datsec[3] int maxfiles, nbad, inst, iccd int l_locgap # local use of gap size bool l_fl_bin, l_locclean real l_sky real lxshift[2,2,3], lyshift[2,2,3], lrotation[2,2,3], lxbshift[2,2,3] real lxrot[2,2,3], lyrot[2,2,3] # Transformation - unbinned pixels # GMOS-N #lxshift[1]=-2.50 ; lyshift[1]=-1.58 ; lrotation[1]=-0.0027827 # best for IFU #lxshift[1]=-2.50 ; lyshift[1]=-1.62 ; lrotation[1]=-0.004 # best overall lxshift[1,1,1]=-2.50 ; lyshift[1,1,1]=-1.58 ; lrotation[1,1,1]=-0.004 lxshift[1,1,2]=0. ; lyshift[1,1,2]=0. ; lrotation[1,1,2]=0. #lxshift[3]=3.3723 ; lyshift[3]=-1.89 ; lrotation[3]=-0.056477 # best for IFU (lower halves of chips) #lxshift[3]=3.3723 ; lyshift[3]=-1.99 ; lrotation[3]=-0.054 #lxshift[3]=3.3723 ; lyshift[3]=-2.05 ; lrotation[3]=-0.056 #lxshift[3]=3.3723 ; lyshift[3]=-1.89 ; lrotation[3]=-0.048 #best overall so far but need more than shift and rotation to match #lxshift[1,3]=3.3723 ; lyshift[1,3]=-1.86 ; lrotation[1,3]=-0.046 # Feb 14, 2003 lxshift[1,1,3]=3.8723 ; lyshift[1,1,3]=-1.86 ; lrotation[1,1,3]=-0.046 # Shift in X if binned pixels - still unbinned pixels in the shift #lxbshift[1,1]=-3.5 ; lxbshift[1,2]=0 ; lxbshift[1,3]=4.3723 lxbshift[1,1,1]=-3.5 ; lxbshift[1,1,2]=0 ; lxbshift[1,1,3]=4.8723 #GMOS-S #lxshift[2,1]=5.07 ; lyshift[2,1]=5.49 ; lrotation[2,1]=0.0 #lxshift[2,2]=0. ; lyshift[2,2]=0. ; lrotation[2,2]=0. #lxshift[2,3]=-0.81 ; lyshift[2,3]=9.37 ; lrotation[2,3]=0.02 #orig = 5.07,5.49,0.0 -0.81 9.37 0.02 lxshift[2,1,1]=-1.44 ; lyshift[2,1,1]=5.46 ; lrotation[2,1,1]=-0.01 lxshift[2,1,2]=0.0 ; lyshift[2,1,2]=0.0 ; lrotation[2,1,2]=0.00 lxshift[2,1,3]=7.53 ; lyshift[2,1,3]=9.57 ; lrotation[2,1,3]=0.02 # shifts for bin in X #lxbshift[2,1]=4.07 ; lxbshift[2,2]=0 ; lxbshift[2,3]=-1.81 lxbshift[2,1,1]=-2.44 ; lxbshift[2,1,2]=0 ; lxbshift[2,1,3]=7.53 #With new blue CCD1 #lxshift[2,2,1]=-2.43 ; lyshift[2,2,1]=0.0 ; lrotation[2,2,1]=-0.01 #lxshift[2,2,2]=0.0 ; lyshift[2,2,2]=0.0 ; lrotation[2,2,2]=0.00 #lxshift[2,2,3]=2.43 ; lyshift[2,2,3]=2.12 ; lrotation[2,2,3]=0.0 #lxbshift[2,2,1]=-3.43 ; lxbshift[2,2,2]=0 ; lxbshift[2,2,3]=2.43 # Numbers from May 15, 2003 lxshift[2,2,1]=-0.49 ; lyshift[2,2,1]=-0.10 ; lrotation[2,2,1]=0.012 lxshift[2,2,2]=0.0 ; lyshift[2,2,2]=0.0 ; lrotation[2,2,2]=0.00 lxshift[2,2,3]=2.31 ; lyshift[2,2,3]=1.91 ; lrotation[2,2,3]=0.015 lxbshift[2,2,1]=-1.49 ; lxbshift[2,2,2]=0 ; lxbshift[2,2,3]=3.31 l_inimages=inimages ; l_interp=geointer; l_sci_ext=sci_ext ; l_key_detsec=key_detsec l_outimages=outimages ; l_outpref=outpref l_key_datsec=key_datsec ; l_key_ccdsum=key_ccdsum l_verbose=verbose ; l_gap=gap ; l_fl_paste=fl_paste l_logfile=logfile l_fl_fixpix=fl_fixpix ; l_bpmfile=bpmfile l_fl_clean=fl_clean ; l_key_obsmode=key_obsmode ; l_obsmode=obsmode l_statsec=statsec maxfiles=200 if (l_sci_ext != "") { l_sci_ext = l_sci_ext//"," } tmpin="uparm$"//mktemp("tmpin") tmpout=mktemp("tmpout") tmpbpm=mktemp("tmpbpm") tmpim[1]=mktemp("tmpim1") tmpim[2]=mktemp("tmpim2") tmpim[3]=mktemp("tmpim3") tmptile[1]=mktemp("tmptile") tmptile[2]=mktemp("tmptile") tmptile[3]=mktemp("tmptile") filelist=mktemp("tmpfilelist") mdf=mktemp("tmpmdf") mdf=mdf//".fits" # cheap and fast - for now unlearn geotran cache("imgets","gimverify","tinfo","hedit","keypar") # Test the logfile: if (l_logfile == "" || stridx(" ",l_logfile)>0) { l_logfile = gmos.logfile if (l_logfile == "" || stridx(" ",l_logfile)>0) { l_logfile = "gmos.log" printlog("WARNING - GMOSAIC: Both gmosaic.logfile and gmos.logfile fields are empty",l_logfile,yes) printlog(" Using default file gmos.log",l_logfile,yes) } } date | scan(l_struct) printlog("----------------------------------------------------------------------------", logfile=l_logfile, verbose=l_verbose) printlog("GMOSAIC -- "//l_struct,l_logfile,l_verbose) printlog("",l_logfile,l_verbose) printlog("Input list = "//l_inimages,l_logfile,l_verbose) printlog("Output list = "//l_outimages,l_logfile,l_verbose) printlog("Output prefix = "//l_outpref,l_logfile,l_verbose) printlog("",l_logfile,l_verbose) if (l_inimages == "" || stridx(" ",l_inimages)>0) { printlog("ERROR - GMOSAIC: Input file not specified",l_logfile,yes) goto crash } # parse wildcard and comma-separated lists if(substr(l_inimages,1,1)=="@") { if(!access(substr(l_inimages,2,strlen(l_inimages))) ) { printlog("ERROR - GMOSAIC: Input list "//\ substr(l_inimages,2,strlen(l_inimages))//" not found",l_logfile,yes) goto crash } scanfile=substr(l_inimages,2,strlen(l_inimages)) } else { files(l_inimages,sort-, > filelist) scanfile=filelist } nbad=0 ; nimages=0 while(fscan(scanfile,l_temp) != EOF) { gimverify(l_temp) if(gimverify.status==1) { printlog("ERROR - GMOSAIC: Cannot access image "//l_temp,l_logfile,yes) nbad+=1 } else if(gimverify.status>1) { printlog("ERROR - GMOSAIC: Image "//l_temp//" is not a MEF file",l_logfile,yes) nbad+=1 } else { nimages+=1 if(nimages>maxfiles) { printlog("ERROR - GMOSAIC: Maxfiles "//maxfiles//" exceeded",l_logfile,yes) goto crash } l_inim[nimages]=gimverify.outname } } scanfile="" delete(filelist,ver-, >>& "dev$null") if(nbad>0) { goto crash } if(l_outimages=="") { # prefix nbad=0 for(n_i=1;n_i<=nimages;n_i+=1) { l_outim[n_i]=l_outpref//l_inim[n_i] gimverify(l_outim[n_i]) if(gimverify.status!=1) { printlog("ERROR - GMOSAIC: Output image "//l_outim[n_i]//" exists",l_logfile,yes) nbad+=1 } } if(nbad>0) { goto crash } # outimages } else { if(substr(l_outimages,1,1)=="@") { scanfile=substr(l_outimages,2,strlen(l_outimages)) } else { files(l_outimages,sort-, > filelist) scanfile=filelist } n_i=0 while(fscan(scanfile,l_temp) != EOF) { n_i+=1 gimverify(l_temp) ; l_outim[n_i]=gimverify.outname if(gimverify.status!=1) { printlog("ERROR - GMOSAIC: Output image "//l_outim[n_i]//" exists",l_logfile,yes) nbad+=1 } } delete(filelist,ver-, >>& "dev$null") if(nbad>0) { goto crash } if(n_i!=nimages) { printlog("ERROR - GMOSAIC: Different number of input and output images", l_logfile,yes) goto crash } } # end of checking output images # check bpm if (l_fl_fixpix && !access(l_bpmfile)) { printlog("ERROR - GMOSAIC: bpmfile does not exist",l_logfile,yes) goto crash } if(l_fl_paste) printlog("Pasting images, not using full transformations",l_logfile,l_verbose) else printlog("Mosaicing images, using full transformations and "//l_interp//" interpolation",l_logfile,l_verbose) # ----- The mosaicing ----- for(n_i=1;n_i<=nimages;n_i+=1) { # just for testing use l_fl_bin=yes in all cases # l_fl_bin=yes ; l_locgap=36 ; l_locclean=l_fl_clean # set back to the original for the final testing l_fl_bin=no ; l_locgap=l_gap ; l_locclean=l_fl_clean sciext="["//l_sci_ext//"1]" # Which instrument? imgets(l_inim[n_i]//"[0]","INSTRUME", >>& "dev$null") inst=1 iccd=1 if (imgets.value=="GMOS-S") { inst=2 #New CCD1 and new alignment? imgets(l_inim[n_i]//"[0]","DETECTOR", >>& "dev$null") if (imgets.value == "GMOS + Blue1 + new CCD1") { iccd=2 } } # Check existence of extension if (!imaccess(l_inim[n_i]//sciext) && l_sci_ext!="") { printlog("WARNING - GMOSAIC: "//l_inim[n_i]//sciext//" not found",l_logfile,yes) printlog(" Assuming the image is raw",l_logfile,yes) sciext="[1]" ; l_sci_ext="" if (!imaccess(l_inim[n_i]//sciext)) { printlog("ERROR - GMOSAIC: "//l_inim[n_i]//sciext//" not found",l_logfile,yes) goto crash } } # If there is a MDF, save it for later insertion in the final image tinfo(l_inim[n_i]//".fits[MDF]",ttout-, >& "dev$null") if (tinfo.tbltype=="fits") { printlog("Found a MDF, copying for later use.",l_logfile,l_verbose) tcopy(l_inim[n_i]//".fits[MDF]",mdf,verbose=no, >& "dev$null") } # Get OBSMODE and set local cleaning flag if(l_locclean) { keypar(l_inim[n_i]//"[0]",l_key_obsmode,silent+) if (keypar.found) { if(keypar.value!=l_obsmode) l_locclean=no } else { printlog("WARNING - GMOSAIC: "//l_inim[n_i]//" cannot determine OBSMODE, fl_clean=no",l_logfile,yes) l_locclean=no } } # Get binning imgets(l_inim[n_i]//sciext,l_key_ccdsum) print(imgets.value) | \ fields("STDIN","1,2",lines="1",quit_if_miss-,print_file-) | \ scan(Xbin,Ybin) if(Xbin>1) { l_fl_bin=yes l_locgap=36. } if((Xbin!=Ybin || Xbin>2) && l_locclean) { l_locclean=no printlog("WARNING - GMOSAIC: "//l_inim[n_i]//" no cleaning for bin>2 or Xbin!=Ybin",l_logfile,yes) } printlog("",l_logfile,l_verbose) printlog("Input image: "//l_inim[n_i]//" Output image: "//l_outim[n_i], l_logfile,l_verbose) # Get number of science extensions imgets(l_inim[n_i]//"[0]","NSCIEXT", >>& "dev$null") if (imgets.value=="0") { fxhead(l_inim[n_i]) | match("IMAGE","STDIN",stop-) | count("STDIN") | scan(nsci) } else { nsci=int(imgets.value) } # For each chip for(n_k=1;n_k<=3;n_k+=1) { img=l_inim[n_i] # If in 6 amp mode, join the two extensions for this chip if (nsci==6) { namp=n_k*2-1 if ((inst==1 && namp==5) || (inst==2 && ((iccd==1 && namp != 5) || (iccd==2 && namp==3)))) { # first amp #print("left amp") sciext="["//l_sci_ext//str(namp)//"]" imgets(l_inim[n_i]//sciext,l_key_datsec) l_datsec[n_k]=imgets.value l_pastel=l_inim[n_i]//sciext//l_datsec[n_k] # second amp #print("right amp") sciext="["//l_sci_ext//str((namp+1))//"]" imgets(l_inim[n_i]//sciext,l_key_datsec) l_datsec[n_k]=imgets.value l_pastel=l_pastel//","//l_inim[n_i]//sciext//l_datsec[n_k] } else { # Amps 5 and 6 read out in the opposite order # second amp #print("right amp") sciext="["//l_sci_ext//str((namp+1))//"]" imgets(l_inim[n_i]//sciext,l_key_datsec) l_datsec[n_k]=imgets.value l_pastel=l_inim[n_i]//sciext//l_datsec[n_k] # first amp #print("left amp") sciext="["//l_sci_ext//str(namp)//"]" imgets(l_inim[n_i]//sciext,l_key_datsec) l_datsec[n_k]=imgets.value l_pastel=l_pastel//","//l_inim[n_i]//sciext//l_datsec[n_k] } #imtile imgets(l_inim[n_i]//sciext,"i_pixtype") if (imgets.value=="11") { l_pixtype="l" } else { l_pixtype="r" } fxcopy(l_inim[n_i]//".fits",tmptile[n_k]//".fits",groups="0",new_file=yes,verbose=no, >>& "dev$null") imtile(l_pastel,tmptile[n_k]//"[1,append]",2,1,ncoverlap=0,trim_section="", missing_inpu="",start_tile="ll",row_order=yes,raster_order=no, median_secti="",subtract=no,ncols=INDEF,nlines=INDEF,nloverlap=-1, opixtype=l_pixtype,ovalue=-1,verbose=l_verbose) imgets(tmptile[n_k]//"[1]","i_naxis1") nx=int(imgets.value) imgets(tmptile[n_k]//"[1]","i_naxis2") ny=int(imgets.value) hedit(tmptile[n_k]//"[1]",l_key_datsec,"[1:"//str(nx)//",1:"//str(ny)//"]",update+,show-,add+,verify-) img=tmptile[n_k] sciext="[1]" } else { sciext="["//l_sci_ext//str(n_k)//"]" } imgets(img//sciext,l_key_datsec) l_datsec[n_k]=imgets.value # Correct the rotation for the binning, and use local lxrot and lyrot to prevent # multiple changes for multiple images processed at once # Changed 2003mar03 if (Xbin>1 || Ybin>1) { lyrot[inst,iccd,n_k] = lrotation[inst,iccd,n_k] * Ybin/Xbin lxrot[inst,iccd,n_k] = lrotation[inst,iccd,n_k] * Xbin/Ybin } else { lyrot[inst,iccd,n_k] = lrotation[inst,iccd,n_k] lxrot[inst,iccd,n_k] = lrotation[inst,iccd,n_k] } if(!l_fl_paste) { printf("Setting rotation Xrot[%s]= %9.6f\n",n_k,lxrot[inst,iccd,n_k]) | scan(l_struct) printlog(l_struct,l_logfile,l_verbose) printf("Setting rotation Yrot[%s]= %9.6f\n",n_k,lyrot[inst,iccd,n_k]) | scan(l_struct) printlog(l_struct,l_logfile,l_verbose) } # Setup parameters for imtile if(n_k==1) { l_locgap=nint(l_locgap/Xbin) if (l_fl_paste) { l_paste=img//sciext//l_datsec[n_k] } imgets(img//sciext,"i_pixtype") if (imgets.value=="11") { l_pixtype="l" } else { l_pixtype="r" } } else if(l_fl_paste) { l_paste=l_paste//","//img//sciext//l_datsec[n_k] } if(!l_fl_paste) { # geotran if(n_k!=2) { if(l_fl_bin) { geotran(img//sciext//l_datsec[n_k],tmpim[n_k],"","", xshift=(lxbshift[inst,iccd,n_k]/Xbin),yshift=(lyshift[inst,iccd,n_k]/Ybin), xrotation=lxrot[inst,iccd,n_k],yrotation=lyrot[inst,iccd,n_k], xmag=1,ymag=1,xmin=INDEF,xmax=INDEF,ymin=INDEF,ymax=INDEF, ncols=INDEF,nlines=INDEF,verbose=l_verbose,fluxconserve=yes, nxblock=2048,nyblock=2048,interpolant=l_interp,boundary="constant",constant=0) } else { geotran(img//sciext//l_datsec[n_k],tmpim[n_k],"","", xshift=(lxshift[inst,iccd,n_k]/Xbin),yshift=(lyshift[inst,iccd,n_k]/Ybin), xrotation=lxrot[inst,iccd,n_k],yrotation=lyrot[inst,iccd,n_k], xmag=1,ymag=1,xmin=INDEF,xmax=INDEF,ymin=INDEF,ymax=INDEF, ncols=INDEF,nlines=INDEF,verbose=l_verbose,fluxconserve=yes, nxblock=2048,nyblock=2048,interpolant=l_interp,boundary="constant",constant=0) } if (n_k==1) { l_paste=tmpim[n_k] } else { l_paste=l_paste//","//tmpim[n_k] } } if (n_k==2) { l_paste=l_paste//","//img//sciext//l_datsec[n_k] } } # end of !fl_paste } # end of running through the extensions #print(l_paste) # Get a PHU fxcopy(img//".fits",l_outim[n_i]//".fits",groups="0",new_file=yes,verbose=no, >>& "dev$null") # Tile - append extension printlog("",l_logfile,l_verbose) imtile(l_paste,l_outim[n_i]//"[1,append]",3,1,ncoverlap=-l_locgap,trim_section="", missing_inpu="",start_tile="ll",row_order=yes,raster_order=no, median_secti="",subtract=no,ncols=INDEF,nlines=INDEF,nloverlap=-1, opixtype=l_pixtype,ovalue=-1,verbose=l_verbose) hedit(l_outim[n_i]//"[1]","EXTNAME","SCI",add+,upd+,ver-,show-) hedit(l_outim[n_i]//"[1]","EXTVER","1",add+,upd+,ver-,show-) hedit(l_outim[n_i]//"[0]","NSCIEXT","1",add+,upd+,ver-,show-) hedit(l_outim[n_i]//"[0]","NEXTEND","1",add+,upd+,ver-,show-) flpr # Fixpix if desired if (l_fl_fixpix) { printlog("",l_logfile,l_verbose) printlog("Interpolating across chip gaps using "//l_bpmfile, l_logfile,l_verbose) if(Xbin==1 && Ybin==1) { badpiximage(l_bpmfile,l_outim[n_i]//"[SCI,1]",tmpbpm//".pl", goodvalue=0, badvalue=1) } else { copy(l_bpmfile,tmpbpm,verbose-) if(Xbin>1) { tcalc(tmpbpm,"c1","int((c1-1.)/"//str(Xbin)//"+0.5)") tcalc(tmpbpm,"c2","int((c2-1.)/"//str(Xbin)//"+0.5)") } tcalc(tmpbpm,"c4","int(c4/"//str(Ybin)//")") badpiximage(tmpbpm,l_outim[n_i]//"[SCI,1]",tmpbpm//".pl", goodvalue=0, badvalue=1) } fixpix(l_outim[n_i]//"[SCI,1]",tmpbpm//".pl",linterp="",cinterp="", ninterp="1",creplace="") delete(tmpbpm//".pl,"//tmpbpm,verify-, >>& "dev$null") } # Clean if desired if(l_locclean) { if(Xbin==1) { if (inst==1) { if(access("gmos$data/mgmosn_bpm11.pl")) tmpbpm="gmos$data/mgmosn_bpm11.pl" else tmpbpm="gmos$data/mgmos_bpm11.pl" } else { tmpbpm="gmos$data/mgmoss_bpm11.pl" } if(l_statsec=="default") l_locstatsec="[2150:3970,100:4400]" } else { if (inst==1) { if(access("gmos$data/mgmosn_bpm22.pl")) tmpbpm="gmos$data/mgmosn_bpm22.pl" else tmpbpm="gmos$data/mgmos_bpm22.pl" } else { tmpbpm="gmos$data/mgmoss_bpm22.pl" } if(l_statsec=="default") l_locstatsec="[1075:1985,50:2200]" } imstat(l_outim[n_i]//"[SCI,1]"//l_locstatsec,fields="midpt",format-) | scan(l_sky) printlog(" ",l_logfile,l_verbose) printlog("Cleaning areas outside imaging field, cleaning value : "//str(l_sky),l_logfile,l_verbose) imexpr("( b>0 ) ? "//str(l_sky)//" : a",l_outim[n_i]//"[SCI,1,overwrite]", l_outim[n_i]//"[SCI,1]",tmpbpm,verbose-) gemhedit(l_outim[n_i]//"[0]","GMOSCLVA",l_sky,"GMOSAIC cleaning value") } # add the MDF if (access(mdf)) { fxinsert(mdf//"[1]",l_outim[n_i]//".fits[1]","",verbose-, >& "dev$null") hedit(l_outim[n_i]//"[0]","NEXTEND",2,update+,verify-,show-) delete(mdf,verify-, >& "dev$null") } # Get the WCS from ext [2] +shift - no other SCI extension info should be needed #CTYPE1 = 'RA---TAN' / R.A. in tangent plane projection #CRPIX1 = 1044.60927497064 / Ref pix of axis 1 #CRVAL1 = 308.611677174582 / RA at Ref pix in decimal degrees #CTYPE2 = 'DEC--TAN' / DEC. in tangent plane projection #CRPIX2 = 2289.53839638225 / Ref pix of axis 2 #CRVAL2 = 28.2797249736673 / DEC at Ref pix in decimal degrees #CD1_1 = -2.0204567874974E-05 / WCS matrix element 1 1 #CD1_2 = 1.8157912081056E-08 / WCS matrix element 1 2 #CD2_1 = 2.39303378045856E-08 / WCS matrix element 2 1 #CD2_2 = 2.02198294404948E-05 / WCS matrix element 2 2 if (nsci==6) { sciext="["//l_sci_ext//"3]" } else { sciext="["//l_sci_ext//"2]" } imhead(l_inim[n_i]//sciext,long+) | match("CTYPE","STDIN",stop-, > filelist) imhead(l_inim[n_i]//sciext,long+) | match("CRPIX","STDIN",stop-, >> filelist) imhead(l_inim[n_i]//sciext,long+) | match("CRVAL","STDIN",stop-, >> filelist) imhead(l_inim[n_i]//sciext,long+) | match("CD","STDIN",stop-, >> filelist) imhead(l_inim[n_i]//sciext,long+) | match("GAIN","STDIN",stop-, >> filelist) imhead(l_inim[n_i]//sciext,long+) | match("RDNOISE","STDIN",stop-, >> filelist) mkheader(l_outim[n_i]//"[1]",filelist,append+,verbose-) mkheader(l_outim[n_i]//"[0]",filelist,append+,verbose-) delete(filelist,verify-, >>& "dev$null") hedit(l_outim[n_i]//"[0]","CCDNAME",delete+,verify-,show-) hedit(l_outim[n_i]//"[1]","CCDNAME",delete+,verify-,show-) hedit(l_outim[n_i]//"[0]","CCDSIZE",delete+,verify-,show-) hedit(l_outim[n_i]//"[1]","CCDSIZE",delete+,verify-,show-) hedit(l_outim[n_i]//"[0]","CCDSEC",delete+,verify-,show-) hedit(l_outim[n_i]//"[1]","CCDSEC",delete+,verify-,show-) # Apply shift - 32 pix overscan independent of binning # Feb 14, 2003: in fact this shift has been taken care of by IRAF during the trimming keypar(l_outim[n_i]//"[1]","CRPIX1",silent+) if(!keypar.found) { printlog("WARNING - GMOSAIC: Image "//l_outim[n_i]//" has no WCS",l_logfile,yes) } else { hedit(l_outim[n_i]//"[1]","CRPIX1",str(real(keypar.value)+2086./Xbin),add+,upd+,ver-,show-) hedit(l_outim[n_i]//"[0]","CRPIX1",str(real(keypar.value)+2086./Xbin),add+, upd+,ver-,show-) } date | scan(l_struct) gemhedit(l_outim[n_i]//"[0]","GMOSAIC",l_struct,"Time stamp for GMOSAIC") gemhedit(l_outim[n_i]//"[0]","GMSINTER",l_interp,"Interpolant used by GMOSAIC") gemhedit(l_outim[n_i]//"[0]","GEM-TLM",l_struct,"Last modification with GEMINI") if(!l_fl_paste) { imdelete(tmpim[1]//","//tmpim[3],ver-, >>& "dev$null") } if(nsci==6) { imdelete(tmptile[1]//","//tmptile[2]//","//tmptile[3],ver-, >>& "dev$null") } } # end of loop through images goto clean crash: status=1 goto clean clean: if(!l_fl_paste) { imdelete(tmpim[1]//","//tmpim[3],ver-, >>& "dev$null") } imdelete(tmptile[1]//","//tmptile[2]//","//tmptile[3],ver-, >>& "dev$null") scanfile="" delete(filelist//","//mdf,ver-, >>& "dev$null") printlog("----------------------------------------------------------------------------",l_logfile,l_verbose) end