########################################################################### # Gemini NIFS data reduction script # Reduction for: SCIENCE DATA # # DESCRIPTION: # # This script is a pyraf-compatible version of the original NIFS scripts # written by Tracy Beck. To use this script, do the following: # # 1) In the call to gemlist below, update the raw_dir, rootname and file # numbers corresponding to your calibration files. # # 2) In the directory where the files reside, run this script within pyraf # using the following command: # # ---> pyexecute("NIFS_Basecalib.py") # # Notes: # - The sky subtraction list of files will need edited if you do not have # the same number of sky files as science frames. (See below notes). # # - This reduction script does the extraction of the science spectra and # telluric correction in the "nftelluric" step interactively, and requires # user input at this stage. You will also need to have a image display (e.g. # ds9) running. # # - Merging of data cubes is not implemented here. # # - Data used are available via the Gemini web pages: # http://www.gemini.edu/sciops/instruments/nifs/data-format-and-reduction # # or via the Gemin Science Archive: # http://www1.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/gsa/ # # File rootname: N20100401S (but we use daytime calibrations from 20100410) # Files for Science Reduction # 182-189 Science frames, inc. sky observed in ABABABAB pattern # 362 Shift File (from Basecalib Reduction) # 362 Flat (from Basecalib Reduction) # 375 Ronchi Flats (from Basecalib Reduction) # 362 BPM (from Basecalib Reduction) # 181 Arc (from Basecalib Reduction) # # VERSION: # 1.0: Adapted from original cl scripts by Tracy Beck. R.McDermid, 05Sep2012 # # AUTHOR: R.McDermid (rmcdermid@gemini.edu) # ########################################################################### ############################################################### # STEP 1: PREPARE IRAF # ############################################################### # Import some useful python utilities import sys import getopt import os import time import shutil # Import the pyraf module and relevant packages from pyraf import iraf iraf.gemini() iraf.nifs() iraf.gnirs() iraf.gemtools() import pyfits # Unlearn the used tasks iraf.unlearn(iraf.gemini,iraf.gemtools,iraf.gnirs,iraf.nifs) # Create a log file and back up the previous one if it already exists log = 'Science.log' if os.path.exists(log): t = time.localtime() app = "_"+str(t[0])+str(t[1]).zfill(2)+str(t[2]).zfill(2)+'_'+ \ str(t[3]).zfill(2)+':'+str(t[4]).zfill(2)+':'+str(t[5]).zfill(2) shutil.move(log,log+app) iraf.set(stdimage='imt2048') # Prepare the package for NIFS iraf.nsheaders("nifs",logfile=log) ############################################################### # STEP 2: SET REDUCTION FILE NAMES AND PATHS # ############################################################### # Set clobber to 'yes' for the script. This still does not make the gemini tasks # overwrite files, so you will likely have to remove files if you re-run the script. user_clobber=iraf.envget("clobber") iraf.reset(clobber='yes') #------------------------------------------------------------------------- # BEGIN EDITING HERE # # Change the "raw_data" and "cal_data" to correspond to the # directory paths for your raw science frames and processed # calibrations,respectively. If all of your data is in your # working directory, change both values to "" (null strings). raw_data = "/Data/NIFS/NIFS_Tutorial_Data/HD141004/K/pytest/" cal_data = "/Data/NIFS/NIFS_Tutorial_Data/Cals/pytest/" calflat = "N20100410S0362" arc = "N20100401S0181" ronchiflat = "N20100410S0375" telluric = "/Data/NIFS/NIFS_Tutorial_Data/HD141004/K/Telluric/pytest/gxtfbrsnN20100401S0138.fits" # Define object ('science') and sky frame lists. These data were taken in a simple # ABABABAB pattern, so can be defined efficiently with gemlist. Depending on # your strategy, you may have to define these lists manually or with a different # tool. For example, you may use the POFFSET and QOFFSET keywords to determine # which frames are offset sky frames (since SQRT(POFF^2+QOFF^2) should be e.g. # larger than 3" for sky frames). You can also use the header keywords to # determine which sky frames were closest in time to your science. iraf.gemlist('N20100401S', '182-188x2',Stdout='scilist') iraf.gemlist('N20100401S', '183-189x2',Stdout='skylist') # # END EDITING HERE #-------------------------------------------------------------------------- ########################################################################### # STEP 3: Get the Calibrations for the Reduction # # NOTE: Do this step only if your calibration directory is different # # from your current working directory. # ########################################################################### iraf.copy(cal_data+"rgn"+ronchiflat+".fits",output="./") iraf.copy(cal_data+"wrgn"+arc+".fits",output="./") if not os.path.isdir("./database"): os.mkdir('./database/') iraf.copy(cal_data+"database/*",output="./database/") ########################################################################### # STEP 4: Reduce the Science Data # ########################################################################### iraf.nfprepare("@scilist", rawpath=raw_data, shiftimage=cal_data+"s"+calflat,fl_vardq='yes', bpm=cal_data+"rgn"+calflat+"_sflat_bpm.pl", logfile=log) iraf.nfprepare("@skylist", rawpath=raw_data, shiftimage=cal_data+"s"+calflat,fl_vardq='yes', bpm=cal_data+"rgn"+calflat+"_sflat_bpm.pl", logfile=log) ############################################################# # DATA REDUCTION HINT - # # # # At the present time, we found that there are problems # # with the WCS coordinates. The automatic sky # # frame ID and subtraction does not work very well in # # "nsreduce" for NIFS data reductions if the number of sky # # frames does not equal the number if science frames. As # # a result, the sky subtraction in this script was set up # # to work outside of the "nsreduce" call. This should work # # for most modes of science acquisition. However you do # # have to ensure that each frame in 'scilist' has a # # corresponding frame in the "skylist" file. If you share # # sky frames between differerent science exposures, you will# # have to duplicate those in the skylist. # ############################################################# # Read in the frame lists (removing '\n' line breaks from the strings) scilist=open("scilist", "r").readlines() scilist=[word.strip() for word in scilist] skylist=open("skylist", "r").readlines() skylist=[word.strip() for word in skylist] for i in range(len(scilist)): iraf.gemarith ("n"+scilist[i], "-", "n"+skylist[i], "gn"+scilist[i], fl_vardq="yes", logfile=log) # Flat field and cut the data iraf.nsreduce("gn@scilist", fl_nscut='yes', fl_nsappw='yes', fl_dark='no', fl_sky='no', fl_flat='yes', flatimage=cal_data+"rgn"+calflat+"_flat", fl_vardq='yes',logfile=log) # Interpolate over bad pixels flagged in the DQ plane iraf.nffixbad("rgn@scilist",logfile=log) # Derive the 2D to 3D spatial/spectral transformation iraf.nsfitcoords("brgn@scilist",lamptransf="wrgn"+arc, sdisttransf="rgn"+ronchiflat,logfile=log) # Apply the transformation determined in the nffitcoords step iraf.nstransform("fbrgn@scilist", logfile=log) # correct the data for telluric absorption features # NOTE: the default for nftelluric is to run the task interactivly # to determine the shift/scale values. See the help file # for nftelluric for additional information. iraf.nftelluric("tfbrgn@scilist", telluric, logfile=log) # Reformat the data into a 3-D datacube iraf.nifcube ("atfbrgn@scilist", logfile=log) ########################################################################### # Reset to user defaults # ########################################################################### if user_clobber == "no": iraf.set(clobber='no') ########################################################################### # End of the Science Data Reduction # # # # The output of this reduction is a set of 3-D data cubes that have been # # sky subtracted, flat fielded, cleaned for bad pixels, telluric # # corrected and rectified into a cohesive datacube format. In the case # # of this reduction, the final output files are called: catfbrgn+science, # # or: catfbrgnN20100401S0182.fits # # catfbrgnN20100401S0184.fits # # catfbrgnN20100401S0186.fits # # catfbrgnN20100401S0188.fits # # # # The meaning of the output prefixes are described below: # # # # g = gemcombined n=nfprepared s=skysubtracted r=nsreduced # # b = bad pixel corrected f= run through nffitcoords # # t = nftransformed a = corrected for telluric absorption features # # c = rectified to a 3D datacube # # # # This script is meant to be a guideline as a method of a typical data # # reduction for NIFS frames. Of course, NIFS PIs can add or skip steps # # in this reduction as they deem fit in order to reduce their particular # # datasets. # # # ###########################################################################