Пример #1
0
    def reduceIm(self, inIm, **kwargs):

        print "\nREDUCING", inIm

        # remove previously reduced exposures
        inPref = inIm[:inIm.find(".") - 14]
        if inPref == "":
            outPref = "g"
            images = outPref + inIm

            outPref = "r" + outPref
            images += "," + outPref + inIm
        else:
            outPref = ""
            images = ""

        if "fl_gscrrej" in kwargs.keys() and kwargs["fl_gscrrej"] == "yes":
            outPref = "x" + outPref
            images += "," + outPref + inIm
        else:
            pass

        if "fl_scatsub" in kwargs.keys() and kwargs["fl_scatsub"] == "yes":
            outPref = "b" + outPref
            images += "," + outPref + inIm
        else:
            pass

        if "fl_qecorr" in kwargs.keys() and kwargs["fl_qecorr"] == "yes":
            outPref = "q" + outPref
            images += "," + outPref + inIm
        else:
            pass

        if "fl_extract" in kwargs.keys() and kwargs["fl_extract"] == "no":
            pass
        else:
            outPref = "e" + outPref
            images += "," + outPref + inIm

        iraf.imdelete(images)

        # reduce the image
        iraf.gfreduce(inIm, **kwargs)

        return
Пример #2
0
iraf.unlearn('gfscatsub')

# ---------- Pre-processing of the science frames ---------- #

# MDF, bias, and overscan
iraf.imdelete('g@' + ic.lst_std)
iraf.imdelete('rg@' + ic.lst_std)

iraf.gfreduce('@' + ic.lst_std,
              rawpath=ic.rawdir,
              fl_extract='no',
              bias=ic.caldir + ic.procbias,
              fl_over='yes',
              fl_trim='yes',
              mdffile=ic.nmdf,
              mdfdir='./',
              slits=ic.cslit,
              line=pk_line,
              fl_fluxcal='no',
              fl_gscrrej='no',
              fl_wavtran='no',
              fl_skysub='no',
              fl_vardq='yes',
              fl_inter='no')

# Scattered light
blkmsk = np.loadtxt("blkmask_name.txt", dtype=str).item(0)
blkmsk0 = blkmsk

iraf.imdelete('brg@' + ic.lst_std)

std = np.loadtxt(ic.lst_std, dtype=str)
Пример #3
0
def reduce_science(rawdir, rundir, flat, arc, twilight, twilight_flat, sciimg,
                   starimg, bias, overscan, vardq, observatory, lacos,
                   apply_lacos, lacos_xorder, lacos_yorder, lacos_sigclip,
                   lacos_objlim, bpm, instrument, slits, fl_gscrrej,
                   wltrim_frac, grow_gap, cube_bit_mask):
    """
    Reduction pipeline for standard star.

    Parameters
    ----------
    rawdir: string
        Directory containing raw images.
    rundir: string
        Directory where processed files are saved.
    flat: string
        Names of the files containing flat field images.
    arc: string
        Arc images.
    twilight: string
        Twilight flat images.
    twilight_flat: string
        Flat field for twilight image.
    starimg: string
        Name of the file containing the image to be reduced.
    bias: string
        Bias images.
    grow_gap: number
        Number of pixels by which to grow the bad pixel mask around
        the chip gaps.

    """

    iraf.set(stdimage='imtgmos')

    iraf.gemini()
    iraf.unlearn('gemini')

    iraf.gmos()
    iraf.unlearn('gmos')

    iraf.gemtools()
    iraf.unlearn('gemtools')

    # os.path.isfile('arquivo')

    iraf.unlearn('gemini')
    iraf.unlearn('gmos')

    iraf.task(lacos_spec=lacos)

    # set directories
    iraf.set(caldir=rawdir)  #
    iraf.set(rawdir=rawdir)  # raw files
    iraf.set(procdir=rundir)  # processed files

    iraf.gmos.logfile = 'logfile.log'
    iraf.gfextract.verbose = 'no'

    iraf.cd('procdir')

    flat = flat.replace('.fits', '')
    twilight = twilight.replace('.fits', '')
    twilight_flat = twilight_flat.replace('.fits', '')
    arc = arc.replace('.fits', '')
    starimg = starimg.replace('.fits', '')
    sciimg = sciimg.replace('.fits', '')
    mdffile = 'mdf' + flat + '.fits'

    iraf.gfreduce.bias = 'caldir$' + bias
    iraf.gfreduce.fl_fulldq = 'yes'
    iraf.gfreduce.fl_fixgaps = 'yes'
    iraf.gfreduce.grow = grow_gap
    iraf.gireduce.bpm = 'rawdir$' + bpm
    iraf.gfextract.verbose = 'no'

    cal_reduction(rawdir=rawdir,
                  rundir=rundir,
                  flat=flat,
                  arc=arc,
                  twilight=twilight,
                  bias=bias,
                  bpm=bpm,
                  overscan=overscan,
                  vardq=vardq,
                  instrument=instrument,
                  slits=slits,
                  twilight_flat=twilight_flat,
                  grow_gap=grow_gap)
    #
    #   Actually reduce science
    #
    image_name = 'rg' + sciimg + '.fits'
    if os.path.isfile(image_name):
        pipe.skipwarn(image_name)
    else:
        iraf.gfreduce(sciimg,
                      slits='header',
                      rawpath='rawdir$',
                      fl_inter='no',
                      fl_addmdf='yes',
                      key_mdf='MDF',
                      mdffile=mdffile,
                      weights='no',
                      fl_over=overscan,
                      fl_trim='yes',
                      fl_bias='yes',
                      trace='no',
                      recenter='no',
                      fl_fulldq='yes',
                      fl_flux='no',
                      fl_gscrrej='no',
                      fl_extract='no',
                      fl_gsappwave='no',
                      fl_wavtran='no',
                      fl_novl='yes',
                      fl_skysub='no',
                      fl_vardq=vardq,
                      mdfdir='procdir$')
    prefix = 'rg'

    # Gemfix
    image_name = 'p' + prefix + sciimg + '.fits'
    if os.path.isfile(image_name):
        pipe.skipwarn(image_name)
    else:
        iraf.gemfix(prefix + sciimg,
                    out='p' + prefix + sciimg,
                    method='fit1d',
                    bitmask=65535,
                    axis=1)
    prefix = 'p' + prefix

    # LA Cosmic - cosmic ray removal
    if apply_lacos:
        image_name = 'l' + prefix + sciimg + '.fits'
        if os.path.isfile(image_name):
            pipe.skipwarn(image_name)
        else:
            iraf.gemcrspec(prefix + sciimg,
                           out='l' + prefix + sciimg,
                           sigfrac=0.5,
                           niter=4,
                           fl_vardq=vardq,
                           xorder=lacos_xorder,
                           yorder=lacos_yorder,
                           sigclip=lacos_sigclip,
                           objlim=lacos_objlim)
        prefix = 'l' + prefix

    if fl_gscrrej:
        image_name = 'ex' + prefix + sciimg + '.fits'
    else:
        image_name = 'e' + prefix + sciimg + '.fits'

    if os.path.isfile(image_name):
        pipe.skipwarn(image_name)
    else:
        iraf.gfreduce(prefix + sciimg,
                      slits='header',
                      rawpath='./',
                      fl_inter='no',
                      fl_addmdf='no',
                      key_mdf='MDF',
                      mdffile=mdffile,
                      fl_over='no',
                      fl_trim='no',
                      fl_bias='no',
                      trace='no',
                      recenter='no',
                      fl_flux='no',
                      fl_gscrrej=fl_gscrrej,
                      fl_extract='yes',
                      fl_gsappwave='yes',
                      fl_wavtran='no',
                      fl_novl='no',
                      fl_skysub='no',
                      grow=grow_gap,
                      reference='eprg' + flat,
                      weights='no',
                      wavtraname='eprg' + arc,
                      response='eprg' + flat + '_response.fits',
                      fl_vardq=vardq,
                      fl_fulldq='yes',
                      fl_fixgaps='yes')

    if fl_gscrrej:
        prefix = 'ex' + prefix
    else:
        prefix = 'e' + prefix

    # if wl2 > 7550.0:
    #     wl2 = 7550.0

    #
    #   Apply wavelength transformation
    #

    wl1, wl2 = wl_lims(prefix + sciimg + '.fits', wltrim_frac)

    image_name = 't' + prefix + sciimg + '.fits'
    if os.path.isfile(image_name):
        pipe.skipwarn(image_name)
    else:
        iraf.gftransform(
            prefix + sciimg,
            wavtraname='eprg' + arc,
            fl_vardq=vardq,
            w1=wl1,
            w2=wl2,
        )

    prefix = 't' + prefix
    #
    #   Sky subtraction
    #
    image_name = 's' + prefix + sciimg + '.fits'
    if os.path.isfile(image_name):
        pipe.skipwarn(image_name)
    else:
        iraf.gfskysub(
            prefix + sciimg,
            expr='default',
            combine='median',
            reject='avsigclip',
            scale='none',
            zero='none',
            weight='none',
            sepslits='yes',
            fl_inter='no',
            lsigma=1,
            hsigma=1,
        )

    prefix = 's' + prefix
    #
    #   Apply flux calibration to galaxy
    #
    image_name = 'c' + prefix + sciimg + '.fits'
    if os.path.isfile(image_name):
        pipe.skipwarn(image_name)
    else:
        iraf.gscalibrate(prefix + sciimg,
                         sfuncti=starimg,
                         extinct='onedstds$ctioextinct.dat',
                         observatory=observatory,
                         fluxsca=1,
                         fl_vardq=vardq)
    prefix = 'c' + prefix
    #
    # Remove spurious data with PCA
    #
    image_name = 'x' + prefix + sciimg + '.fits'
    print(os.getcwd())
    print(image_name)
    if os.path.isfile(image_name):
        pipe.skipwarn(image_name)
    else:
        t = pca.Tomography(prefix + sciimg + '.fits')
        t.decompose()
        t.remove_cosmic_rays(sigma_threshold=10.0)
        t.write(image_name)
    prefix = 'x' + prefix
    #
    #   Create data cubes
    #
    image_name = 'd' + prefix + sciimg + '.fits'
    if os.path.isfile(image_name):
        pipe.skipwarn(image_name)
    else:
        data_cube = CubeBuilder(prefix + sciimg + '.fits')
        data_cube.build_cube()
        data_cube.fit_refraction_function()
        data_cube.fix_atmospheric_refraction()
        data_cube.write(image_name)
Пример #4
0
# ---------- Trace reference ---------- #
iraf.imdelete('g@' + ic.lst_flat)
iraf.imdelete('rg@' + ic.lst_flat)
iraf.imdelete('erg@' + ic.lst_flat)

for flat in iraf.type(ic.lst_flat, Stdout=1):
    flat = flat.strip()
    iraf.gfreduce(flat,
                  rawpath=ic.rawdir,
                  fl_extract='yes',
                  bias=ic.bias,
                  fl_over='yes',
                  fl_trim='yes',
                  mdffile=ic.nmdf,
                  mdfdir='./',
                  slits='both',
                  line=1400,
                  fl_fluxcal='no',
                  fl_gscrrej='no',
                  fl_wavtran='no',
                  fl_skysub='no',
                  fl_inter='no',
                  fl_vardq='yes')

os.system('ds9 &')
iraf.sleep(5.0)
for flat in iraf.type(ic.lst_flat, Stdout=1):
    flat = flat.strip()
    iraf.gfdisplay('erg' + flat, 1)

# Printing the running time
Пример #5
0
def reduce_stdstar(rawdir,
                   rundir,
                   caldir,
                   starobj,
                   stdstar,
                   flat,
                   arc,
                   twilight,
                   twilight_flat,
                   starimg,
                   bias,
                   overscan,
                   vardq,
                   lacos,
                   observatory,
                   apply_lacos,
                   lacos_xorder,
                   lacos_yorder,
                   lacos_objlim,
                   lacos_sigclip,
                   bpm,
                   instrument,
                   slits,
                   fl_gscrrej,
                   wltrim_frac=0.03,
                   sens_order=6,
                   sens_function='spline3',
                   apsum_radius=1):
    """
    Reduction pipeline for standard star.

    Parameters
    ----------
    rawdir: string
        Directory containing raw images.
    rundi: string
        Directory where processed files are saved.
    caldir: string
        Directory containing standard star calibration files.
    starobj: string
        Object keyword for the star image.
    stdstar: string
        Star name in calibration file.
    flat: list
        Names of the files containing flat field images.
    arc: list
        Arc images.
    twilight: list
        Twilight flat images.
    starimg: string
        Name of the file containing the image to be reduced.
    bias: list
        Bias images.

    """

    iraf.set(stdimage='imtgmos')

    iraf.task(lacos_spec=lacos)

    iraf.gemini()
    iraf.unlearn('gemini')

    iraf.gmos()
    iraf.unlearn('gmos')

    iraf.gemtools()
    iraf.unlearn('gemtools')

    iraf.gmos.logfile = 'logfile.log'
    iraf.gemtools.gloginit.logfile = 'logfile.log'
    iraf.gfextract.verbose = 'no'

    # set directories
    iraf.set(caldir=rawdir)  #
    iraf.set(rawdir=rawdir)  # raw files
    iraf.set(procdir=rundir)  # processed files

    # os.path.isfile('arquivo')

    iraf.cd('procdir')

    flat = flat.strip('.fits')
    twilight = twilight.strip('.fits')
    twilight_flat = twilight_flat.strip('.fits')
    arc = arc.strip('.fits')
    starimg = starimg.strip('.fits')
    mdffile = 'mdf' + flat + '.fits'

    iraf.gfreduce.bias = 'rawdir$' + bias
    iraf.gfreduce.fl_fulldq = 'yes'
    iraf.gfreduce.fl_fixgaps = 'yes'
    iraf.gireduce.bpm = 'rawdir$' + bpm

    cal_reduction(rawdir=rawdir,
                  rundir=rundir,
                  flat=flat,
                  arc=arc,
                  twilight=twilight,
                  bias=bias,
                  bpm=bpm,
                  overscan=overscan,
                  vardq=vardq,
                  instrument=instrument,
                  slits=slits,
                  twilight_flat=twilight_flat)
    #
    #   Actually reduce star
    #
    imageName = 'rg' + starimg + '.fits'
    if os.path.isfile(imageName):
        skipwarn(imageName)
    else:

        imageName = 'g' + starimg + '.fits'
        if os.path.isfile(imageName):
            iraf.printlog(
                'GIREDS: WARNING: Removing file {:s}'.format(imageName),
                'logfile.log', 'yes')
            iraf.delete(imageName)

        iraf.gfreduce(starimg,
                      slits='header',
                      rawpath='rawdir$',
                      fl_inter='no',
                      fl_addmdf='yes',
                      key_mdf='MDF',
                      mdffile=mdffile,
                      weights='no',
                      fl_over=overscan,
                      fl_trim='yes',
                      fl_bias='yes',
                      trace='no',
                      recenter='no',
                      fl_flux='no',
                      fl_gscrrej='no',
                      fl_extract='no',
                      fl_gsappwave='no',
                      fl_wavtran='no',
                      fl_novl='yes',
                      fl_skysub='no',
                      fl_vardq=vardq,
                      mdfdir='procdir$')
    prefix = 'rg'
    #
    # Gemfix
    #
    imageName = 'p' + prefix + starimg + '.fits'
    if os.path.isfile(imageName):
        skipwarn(imageName)
    else:
        iraf.gemfix(prefix + starimg,
                    out='p' + prefix + starimg,
                    method='fit1d',
                    bitmask=1,
                    axis=1)
    prefix = 'p' + prefix
    #
    # LA Cosmic
    #
    if apply_lacos:

        imageName = 'l' + prefix + starimg + '.fits'
        if os.path.isfile(imageName):
            skipwarn(imageName)
        else:
            if apply_lacos:
                iraf.gemcrspec(prefix + starimg,
                               out='l' + prefix + starimg,
                               sigfrac=0.32,
                               niter=4,
                               fl_vardq=vardq,
                               xorder=lacos_xorder,
                               yorder=lacos_yorder,
                               objlim=lacos_objlim,
                               sigclip=lacos_sigclip)

        prefix = 'l' + prefix
    #
    # Extraction and Gemini's comsmic ray rejection
    #
    if fl_gscrrej:
        imageName = 'x' + prefix + starimg + '.fits'

        if os.path.isfile(imageName):
            skipwarn(imageName)
            fl_gscrrej = False
        else:
            imageName = 'ex' + prefix + starimg + '.fits'
            if os.path.isfile(imageName):
                skipwarn(imageName)
            else:
                iraf.gfreduce(prefix + starimg,
                              slits='header',
                              rawpath='./',
                              fl_inter='no',
                              fl_addmdf='no',
                              key_mdf='MDF',
                              mdffile=mdffile,
                              fl_over='no',
                              fl_trim='no',
                              fl_bias='no',
                              trace='no',
                              recenter='no',
                              fl_flux='no',
                              fl_gscrrej=fl_gscrrej,
                              fl_extract='yes',
                              fl_gsappwave='yes',
                              fl_wavtran='no',
                              fl_novl='no',
                              fl_skysub='no',
                              reference='eprg' + flat,
                              weights='no',
                              wavtraname='eprg' + arc,
                              response='eprg' + flat + '_response.fits',
                              fl_vardq=vardq)
        prefix = 'ex' + prefix
    else:
        imageName = 'e' + prefix + starimg + '.fits'

        if os.path.isfile(imageName):
            skipwarn(imageName)
        else:
            iraf.gfreduce(prefix + starimg,
                          slits='header',
                          rawpath='./',
                          fl_inter='no',
                          fl_addmdf='no',
                          key_mdf='MDF',
                          mdffile=mdffile,
                          fl_over='no',
                          fl_trim='no',
                          fl_bias='no',
                          trace='no',
                          recenter='no',
                          fl_flux='no',
                          fl_gscrrej=fl_gscrrej,
                          fl_extract='yes',
                          fl_gsappwave='yes',
                          fl_wavtran='no',
                          fl_novl='no',
                          fl_skysub='no',
                          reference='eprg' + flat,
                          weights='no',
                          wavtraname='eprg' + arc,
                          response='eprg' + flat + '_response.fits',
                          fl_vardq=vardq)
        prefix = 'e' + prefix
    #
    # Wavelength transform
    #
    wl1, wl2 = wl_lims(prefix + starimg + '.fits', wltrim_frac)
    imageName = 't' + prefix + starimg + '.fits'
    if os.path.isfile(imageName):
        skipwarn(imageName)
    else:
        iraf.gfreduce(prefix + starimg,
                      slits='header',
                      rawpath='./',
                      fl_inter='no',
                      fl_addmdf='no',
                      key_mdf='MDF',
                      mdffile=mdffile,
                      fl_over='no',
                      fl_trim='no',
                      fl_bias='no',
                      trace='no',
                      recenter='no',
                      fl_flux='no',
                      fl_gscrrej='no',
                      fl_extract='no',
                      fl_gsappwave='no',
                      fl_wavtran='yes',
                      fl_novl='no',
                      fl_skysub='no',
                      reference='eprg' + flat,
                      weights='no',
                      wavtraname='eprg' + arc,
                      response='eprg' + flat + '_response.fits',
                      fl_vardq=vardq,
                      w1=wl1,
                      w2=wl2)
    prefix = 't' + prefix

    #
    # Sky subtraction
    #
    imageName = 's' + prefix + starimg + '.fits'
    if os.path.isfile(imageName):
        skipwarn(imageName)
    else:
        iraf.gfreduce(prefix + starimg,
                      slits='header',
                      rawpath='./',
                      fl_inter='no',
                      fl_addmdf='no',
                      key_mdf='MDF',
                      mdffile=mdffile,
                      fl_over='no',
                      fl_trim='no',
                      fl_bias='no',
                      trace='no',
                      recenter='no',
                      fl_flux='no',
                      fl_gscrrej='no',
                      fl_extract='no',
                      fl_gsappwave='no',
                      fl_wavtran='no',
                      fl_novl='no',
                      fl_skysub='yes',
                      reference='eprg' + flat,
                      weights='no',
                      wavtraname='eprg' + arc,
                      response='eprg' + flat + '_response.fits',
                      fl_vardq=vardq,
                      w1=wl1,
                      w2=wl2)
    prefix = 's' + prefix
    #
    #   Apsumming the stellar spectra
    #
    xinst = pf.getdata(prefix + starimg + '.fits', ext=1)['XINST']
    if instrument == 'GMOS-N':
        x0 = np.average(xinst[xinst < 10])
    elif instrument == 'GMOS-S':
        x0 = np.average(xinst[xinst > 10])

    ap_expression = '((XINST-{:.2f})**2 + '\
        '(YINST-2.45)**2)**0.5 < {:.2f}'.format(x0, apsum_radius)

    imageName = 'a' + prefix + starimg + '.fits'
    if os.path.isfile(imageName):
        skipwarn(imageName)
    else:
        iraf.gfapsum(prefix + starimg,
                     fl_inter='no',
                     lthreshold='INDEF',
                     hthreshold='INDEF',
                     reject='avsigclip',
                     expr=ap_expression)
    #
    #   Building sensibility function
    #
    if os.path.isfile('std' + starimg)\
            and os.path.isfile('sens' + starimg + '.fits'):
        skipwarn('std{0:s} and sens{0:s}.fits'.format(starimg))
    else:

        imageName = 'std' + starimg
        if os.path.isfile(imageName):
            iraf.printlog(
                'GIREDS: WARNING: Removing file {:s}'.format(imageName),
                'logfile.log', 'yes')
            iraf.delete(imageName)

        imageName = 'sens' + starimg + '.fits'
        if os.path.isfile(imageName):
            iraf.printlog(
                'GIREDS: WARNING: Removing file {:s}'.format(imageName),
                'logfile.log', 'yes')
            iraf.delete(imageName)

        iraf.gsstandard('a' + prefix + starimg,
                        starname=stdstar,
                        observatory=observatory,
                        sfile='std' + starimg,
                        sfunction='sens' + starimg,
                        caldir=caldir,
                        order=sens_order,
                        function=sens_function)
    #
    #   Apply flux calibration to star
    #
    imageName = 'c' + prefix + starimg + '.fits'
    if os.path.isfile(imageName):
        skipwarn(imageName)
    else:
        iraf.gscalibrate(prefix + starimg,
                         sfuncti='sens' + starimg,
                         extinct='onedstds$ctioextinct.dat',
                         observatory=observatory,
                         fluxsca=1,
                         fl_vardq=vardq)
    #
    #   Create data cubes
    #
    imageName = 'dc' + prefix + starimg + '.fits'
    if os.path.isfile(imageName):
        skipwarn(imageName)
    else:
        data_cube = CubeBuilder('c' + prefix + starimg + '.fits')
        data_cube.build_cube()
        data_cube.fit_refraction_function()
        data_cube.fix_atmospheric_refraction()
        data_cube.write(imageName)

    #
    # Test calibration
    #
    iraf.cd(caldir)
    caldata = np.loadtxt(stdstar + '.dat', unpack=True)
    iraf.cd('procdir')
    calflux = mag2flux(caldata[0], caldata[1])

    imageName = 'ca' + prefix + starimg + '.fits'
    if os.path.isfile(imageName):
        skipwarn(imageName)
    else:
        iraf.gscalibrate('a' + prefix + starimg,
                         sfuncti='sens' + starimg,
                         extinct='onedstds$ctioextinct.dat',
                         observatory=observatory,
                         fluxsca=1)

    sumflux = pf.getdata('ca' + prefix + starimg + '.fits', ext=2)
    sumhead = pf.getheader('ca' + prefix + starimg + '.fits', ext=2)
    sumwl = sumhead['crval1'] + np.arange(
        sumhead['naxis1']) * sumhead['cdelt1']

    plt.close('all')
    plt.plot(sumwl, sumflux, 'b', lw=.5)
    plt.plot(caldata[0], calflux, 'r', lw=1.5)
    plt.xlim(sumwl[0] * .99, sumwl[-1] * 1.01)
    plt.ylim(min(calflux) * .8, max(calflux) * 1.2)
    plt.savefig('calib' + starimg + '.eps')
Пример #6
0
               cross='yes', fl_inter='no')

# os.system('ds9 &')
# iraf.sleep(5.0)
# for flat in iraf.type(ic.lst_flat, Stdout=1):
#     flat = flat.strip()
#     for i in np.arange(12):
#         iraf.imexamine('brg'+flat+'[sci,'+str(i+1)+']', 1)


# QE correction and extract
iraf.imdelete('qbrg@'+ic.lst_flat)
iraf.imdelete('eqbrg@'+ic.lst_flat)
iraf.gfreduce('brg@'+ic.lst_flat, recenter='no', reference='erg'+flat0,
              fl_extract='yes', fl_qecorr='yes', qe_refim='erg'+arc0,
              fl_addmdf='no', fl_bias='no', fl_over='no', fl_trim='no',
              mdffile=ic.nmdf, mdfdir='./',
              slits=ic.cslit, line=pk_line, fl_fluxcal='no', fl_gscrrej='no',
              fl_wavtran='no', fl_skysub='no', fl_inter='no', fl_vardq='yes')

if (ic.nslit == 1):
    vkw = '1'
if (ic.nslit == 2):
    vkw = '*'
os.system('ds9 &')
iraf.sleep(5.0)
iraf.gfdisplay('eqbrg'+flat0, 1, version=vkw)


# ---------- Response function ---------- #
iraf.imdelete(flat0+'_resp')
iraf.gfresponse('eqbrg'+flat0, outimage=flat0+'_resp', sky='', 
Пример #7
0

# ---------- Wavelength solution ---------- #

# Extract the arc
flatref = iraf.type(ic.lst_flat, Stdout=1)[0].strip()

iraf.imdelete('g@'+ic.lst_arc)
iraf.imdelete('rg@'+ic.lst_arc)
iraf.imdelete('erg@'+ic.lst_arc)

for arc in iraf.type(ic.lst_arc, Stdout=1):
	arc = arc.strip()
	iraf.gfreduce(arc, rawpath=ic.rawdir, fl_extract='yes', recenter='no',
	              trace='no', reference='erg'+flatref, fl_bias='no',
	              fl_over='yes', fl_trim='yes', mdffile=ic.nmdf, mdfdir='./',
	              slits='both', fl_fluxcal='no', fl_gscrrej='no',
	              fl_wavtran='no', fl_skysub='no', fl_inter='no')

iraf.sleep(10.0)

# ----- Measure the wavelength solution ----- #
for arc in iraf.type(ic.lst_arc, Stdout=1):
	arc = arc.strip()
	iraf.gswavelength('erg'+arc, fl_inter='yes',
	                  nlost=20, ntarget=15, threshold=25,
	                  coordlis='gmos$data/GCALcuar.dat')


# Printing the running time
print('--- %s seconds ---' %(time.time()-start_time))
Пример #8
0
def reduce_stdstar(rawdir, rundir, caldir, starobj, stdstar, flat,
    arc, twilight, starimg, bias, overscan, vardq):
    """
    Reduction pipeline for standard star.

    Parameters
    ----------
    rawdir: string
        Directory containing raw images.
    rundi: string
        Directory where processed files are saved.
    caldir: string
        Directory containing standard star calibration files.
    starobj: string
        Object keyword for the star image.
    stdstar: string
        Star name in calibration file.
    flat: list
        Names of the files containing flat field images.
    arc: list
        Arc images.
    twilight: list
        Twilight flat images.
    starimg: string
        Name of the file containing the image to be reduced.
    bias: list
        Bias images.
    
    """

    iraf.set(stdimage='imtgmos')
    
    iraf.gemini()
    iraf.gemtools()
    iraf.gmos()
    
    #iraf.unlearn('gemini')
    #iraf.unlearn('gmos')
    
    iraf.task(lacos_spec='/storage/work/gemini_pairs/lacos_spec.cl')
    
    tstart = time.time()
    
    #set directories
    iraf.set(caldir=rawdir)  # 
    iraf.set(rawdir=rawdir)  # raw files
    iraf.set(procdir=rundir)  # processed files
    
    iraf.gmos.logfile='logfile.log'
    
    iraf.cd('procdir')
    
    # building lists
    
    def range_string(l):
        return (len(l)*'{:4s},').format(*[i[-9:-5] for i in l])
    
    iraf.gemlist(range=range_string(flat), root=flat[0][:-9],
        Stdout='flat.list')
    iraf.gemlist(range=range_string(arc), root=arc[0][:-9],
        Stdout='arc.list')
    #iraf.gemlist(range=range_string(star), root=star[0][:-4],
    #    Stdout='star.list')
    iraf.gemlist(range=range_string(twilight),
        root=twilight[0][:-9], Stdout='twilight.list')
    
    iraf.gfreduce.bias = 'caldir$'+bias[0]
    
    #######################################################################
    #######################################################################
    ###   Star reduction                                                  #
    #######################################################################
    #######################################################################
    
    #
    #   Flat reduction
    #
    
    iraf.gfreduce(
        '@flat.list', slits='header', rawpath='rawdir$', fl_inter='no',
        fl_addmdf='yes', key_mdf='MDF', mdffile='default', weights='no',
        fl_over=overscan, fl_trim='yes', fl_bias='yes', trace='yes', t_order=4,
        fl_flux='no', fl_gscrrej='no', fl_extract='yes', fl_gsappwave='no',
        fl_wavtran='no', fl_novl='no', fl_skysub='no', reference='',
        recenter='yes', fl_vardq=vardq)
    
    iraf.gfreduce('@twilight.list', slits='header', rawpath='rawdir$',
        fl_inter='no', fl_addmdf='yes', key_mdf='MDF',
        mdffile='default', weights='no',
        fl_over=overscan, fl_trim='yes', fl_bias='yes', trace='yes',
        recenter='no',
        fl_flux='no', fl_gscrrej='no', fl_extract='yes', fl_gsappwave='no',
        fl_wavtran='no', fl_novl='no', fl_skysub='no',
        reference='erg'+flat[0], fl_vardq=vardq)
    #
    #   Response function
    #
    
    
    for i, j in enumerate(flat):

        j = j[:-5]
    
        iraf.imdelete(j+'_response')
        iraf.gfresponse('erg'+j+'.fits', out='erg'+j+'_response',
            skyimage='erg'+twilight[i], order=95, fl_inter='no',
            func='spline3',
            sample='*', verbose='yes')
    
    #   Arc reduction
    #
    
    iraf.gfreduce(
        '@arc.list', slits='header', rawpath='rawdir$', fl_inter='no',
        fl_addmdf='yes', key_mdf='MDF', mdffile='default', weights='no',
        fl_over=overscan, fl_trim='yes', fl_bias='yes', trace='no',
        recenter='no',
        fl_flux='no', fl_gscrrej='no', fl_extract='yes', fl_gsappwave='no',
        fl_wavtran='no', fl_novl='no', fl_skysub='no', reference='erg'+flat[0],
        fl_vardq=vardq)
    
    
    #   Finding wavelength solution
    #   Note: the automatic identification is very good
    #
    
    for i in arc:
        
        iraf.gswavelength('erg'+i, function='chebyshev', nsum=15, order=4,
            fl_inter='no', nlost=5, ntarget=20, aiddebug='s', threshold=5,
            section='middle line')
    
    #
    #   Apply wavelength solution to the lamp 2D spectra
    #
    
        iraf.gftransform('erg'+i, wavtran='erg'+i, outpref='t', fl_vardq=vardq)
    
    ##
    ##   Actually reduce star
    ##
    
    
    iraf.gfreduce(
        starimg, slits='header', rawpath='rawdir$', fl_inter='no',
        fl_addmdf='yes', key_mdf='MDF', mdffile='default', weights='no',
        fl_over=overscan, fl_trim='yes', fl_bias='yes', trace='no',
        recenter='no',
        fl_flux='no', fl_gscrrej='no', fl_extract='no', fl_gsappwave='no',
        fl_wavtran='no', fl_novl='yes', fl_skysub='no', fl_vardq=vardq)
    
    iraf.gemcrspec('rg{:s}'.format(starimg), out='lrg'+starimg, sigfrac=0.32, 
         niter=4, fl_vardq=vardq)
         
    iraf.gfreduce(
        'lrg'+starimg, slits='header', rawpath='./', fl_inter='no',
        fl_addmdf='no', key_mdf='MDF', mdffile='default',
        fl_over='no', fl_trim='no', fl_bias='no', trace='no',
        recenter='no',
        fl_flux='no', fl_gscrrej='no', fl_extract='yes',
        fl_gsappwave='yes',
        fl_wavtran='yes', fl_novl='no', fl_skysub='yes',
        reference='erg'+flat[0][:-5], weights='no',
        wavtraname='erg'+arc[0][:-5],
        response='erg'+flat[0][:-5]+'_response.fits',
        fl_vardq=vardq)
    #
    #   Apsumming the stellar spectra
    #
    iraf.gfapsum(
        'stexlrg'+starimg, fl_inter='no', lthreshold=400.,
        reject='avsigclip')
    #
    #   Building sensibility function
    #
    
    
    iraf.gsstandard(
        ('astexlrg{:s}').format(starimg), starname=stdstar,
        observatory='Gemini-South', sfile='std', sfunction='sens',
        caldir=caldir)
    #
    #   Apply flux calibration to galaxy
    #
    #
    ##iraf.imdelete('*****@*****.**')
    #
    ##iraf.gscalibrate('*****@*****.**',sfunction='sens.fits',fl_ext='yes',extinct='onedstds$ctioextinct.dat',observatory='Gemini-South',fluxsca=1)
    #
    ##
    ##   Create data cubes
    ##
    #
    #
    ##for i in objs:
    ##  iraf.imdelete('d0.1cstexlrg'+i+'.fits')
    ##  iraf.gfcube('cstexlrg'+i+'.fits',outpref='d0.1',ssample=0.1,fl_atmd='yes',fl_flux='yes')
    #
    ##
    ## Combine cubes
    ##
    #
    #
    ##iraf.imdelete('am2306-721r4_wcsoffsets.fits')
    ##iraf.imcombine('d0.1cstexlrgS20141113S00??.fits[1]',output='am2306-721r4_wcsoffsets.fits',combine='average',reject='sigclip',masktype='badvalue',lsigma=2,hsigma=2,offset='wcs',outlimits='2 67 2 48 100 1795')
    #
    
    tend = time.time()
    
    print('Elapsed time in reduction: {:.2f}'.format(tend - tstart))
Пример #9
0
#######################################################################

#
#   Flat reduction
#


for m in range(len(star)):
    for i in ['g', 'rg', 'erg']:
        iraf.imdelete(i+'@flat'+str(m)+'.list')

    # (B) - 'fl_over=no';
    iraf.gfreduce('@flat'+str(m)+'.list', slits='header', 
        rawpath='rawdir$', fl_inter='no',
        fl_addmdf='yes', key_mdf='MDF', mdffile='default', weights='no',
        fl_over='no', fl_trim='yes', fl_bias='yes', trace='yes', t_order=4,
        fl_flux='no', fl_gscrrej='no', fl_extract='yes', fl_gsappwave='no',
        fl_wavtran='no', fl_novl='no', fl_skysub='no', reference='',
        recenter='yes', fl_vardq='yes', bias='caldir$'+bias[m][0])


#
#   Twilight reduction
#
for m in range(len(star)):
    for i in ['g', 'rg', 'erg']:
        iraf.imdelete(i+'@twilight'+str(m)+'.list')

    # (B) - 'fl_over=no';
    iraf.gfreduce('@twilight'+str(m)+'.list', slits='header', rawpath='rawdir$',
        fl_inter='no', fl_addmdf='yes', key_mdf='MDF',