Esempio n. 1
0
def lacosmic(name, irafhome, la_iter):
    import time

    iraf.task(lacos_spec=irafhome + "lacos_spec.cl")
    outname = "la" + name
    pl = "mask" + name
    iraf.lacos_spec(
        input=name,
        output=outname,
        outmask=pl,
        gain=1.0,
        readn=2.89,
        xorder=9,
        yorder=0,
        sigclip=4.5,
        sigfrac=0.5,
        objlim=1.0,
        niter=la_iter,
        verbose="yes",
        mode="al",
    )
    old = time.time()
    pidds9 = subprocess.Popen(["ds9", pl, outname, "-zscale"]).pid
    os.system("mv %s history/" % (name))
    return pidds9
Esempio n. 2
0
def test_division(tmpdir):
    outfile = str(tmpdir.join('output.txt'))

    # First show straight Python
    case1 = 9 / 5
    case2 = 9 / 5.
    case3 = 9 // 5
    case4 = 9 // 5.
    iraf.printf('a: 9/5 ->   ' + str(case1) + '\n', StdoutAppend=outfile)
    iraf.printf('b: 9/5. ->  ' + str(case2) + '\n', StdoutAppend=outfile)
    iraf.printf('c: 9//5 ->  ' + str(case3) + '\n', StdoutAppend=outfile)
    iraf.printf('d: 9//5. -> ' + str(case4) + '\n', StdoutAppend=outfile)
    iraf.printf('\n', StdoutAppend=outfile)

    # Then show how a .cl script would be run
    iraf.task(xyz='print "e: " (9/5)\nprint "f: " (9/5.)\n'
              'print "g: " (9//5)\nprint "h: " (9//5.)', IsCmdString=1)
    iraf.xyz(StdoutAppend=outfile)
    iraf.printf('\n', StdoutAppend=outfile)

    # Then show how pyraf executes command-line instructions via cl2py
    iraf.clExecute('print "i: " (9/5)', StdoutAppend=outfile)
    iraf.clExecute('print "j: " (9/5.)', StdoutAppend=outfile)
    iraf.clExecute('print "k: " (9//5)', StdoutAppend=outfile)
    iraf.clExecute('print "l: " (9//5.)', StdoutAppend=outfile)

    # Quick step to strip whitespace from lines in output.
    # Much easier this way than messing with ancient comparator code.
    with open(outfile) as f_in:
        stripped = [l.replace('   ', ' ').replace('  ', ' ').strip()
                    for l in f_in.readlines()]

    diff_outputs(stripped, 'data/cli_div_output.ref')
Esempio n. 3
0
def lacosmic(name,irafhome):
	import time
	iraf.task(lacos_spec=irafhome+'lacos_spec.cl')
	outname = 'la'+name
	pl = 'mask'+name
	iraf.lacos_spec(input=name,output=outname,outmask=pl,gain=1.,readn=2.89,
				xorder=9,yorder=0,sigclip=4.5,sigfrac=0.5,objlim=1.,niter=7,verbose='yes',mode='al')
	old = time.time()
	os.system('ds9 %s -zscale %s -zscale -blink &' % (pl,name))
	os.system('ds9 %s -zscale &' % outname)
	return
Esempio n. 4
0
def define_lacosmic(path_to_lacos_im=''):
    """Moves to ``STSDAS`` package and defines ``LACOS_IM`` as an
    ``iraf`` task.

    Parameters
    -----------
    path_to_lacos_im : string
        Your path to ``lacos_im.cl``.
        If left blank, assume Current Working Directory.
        #By default, reads from lacos_setup

    Notes
    -----
    The IRAF way is
        
        task lacos_im = /path/lacos_im.cl
    """
    iraf.stsdas()
    iraf.task(lacos_im=path_to_lacos_im + 'lacos_im.cl')
Esempio n. 5
0
def lacosmic(name, irafhome, la_iter):
    import time
    iraf.task(lacos_spec=irafhome + 'lacos_spec.cl')
    outname = 'la' + name
    pl = 'mask' + name
    iraf.lacos_spec(input=name,
                    output=outname,
                    outmask=pl,
                    gain=1.,
                    readn=2.89,
                    xorder=9,
                    yorder=0,
                    sigclip=4.5,
                    sigfrac=0.5,
                    objlim=1.,
                    niter=la_iter,
                    verbose='yes',
                    mode='al')
    old = time.time()
    pidds9 = subprocess.Popen(['ds9', pl, outname, '-zscale']).pid
    os.system('mv %s history/' % (name))
    return pidds9
Esempio n. 6
0
def test_division(tmpdir):
    outfile = str(tmpdir.join('output.txt'))

    # First show straight Python
    case1 = 9 / 5
    case2 = 9 / 5.
    case3 = 9 // 5
    case4 = 9 // 5.
    iraf.printf('a: 9/5 ->   ' + str(case1) + '\n', StdoutAppend=outfile)
    iraf.printf('b: 9/5. ->  ' + str(case2) + '\n', StdoutAppend=outfile)
    iraf.printf('c: 9//5 ->  ' + str(case3) + '\n', StdoutAppend=outfile)
    iraf.printf('d: 9//5. -> ' + str(case4) + '\n', StdoutAppend=outfile)
    iraf.printf('\n', StdoutAppend=outfile)

    # Then show how a .cl script would be run
    iraf.task(xyz='print "e: " (9/5)\nprint "f: " (9/5.)\n'
              'print "g: " (9//5)\nprint "h: " (9//5.)',
              IsCmdString=1)
    iraf.xyz(StdoutAppend=outfile)
    iraf.printf('\n', StdoutAppend=outfile)

    # Then show how pyraf executes command-line instructions via cl2py
    iraf.clExecute('print "i: " (9/5)', StdoutAppend=outfile)
    iraf.clExecute('print "j: " (9/5.)', StdoutAppend=outfile)
    iraf.clExecute('print "k: " (9//5)', StdoutAppend=outfile)
    iraf.clExecute('print "l: " (9//5.)', StdoutAppend=outfile)

    # Quick step to strip whitespace from lines in output.
    # Much easier this way than messing with ancient comparator code.
    with open(outfile) as f_in:
        stripped = [
            l.replace('   ', ' ').replace('  ', ' ').strip()
            for l in f_in.readlines()
        ]

    diff_outputs(stripped, 'data/cli_div_output.ref')
Esempio n. 7
0
from pyraf import iraf
import os
import glob
import asciitable
import numpy as np
from scipy.interpolate import griddata
import matplotlib.pyplot as plt

#cargo paquetes
iraf.noao.rv()
iraf.task(fn2="find2c.cl")
iraf.task(spbina="spbina.cl")
iraf.task(scale="scale.cl")
iraf.noao.onedspec()
iraf.noao.imred()
iraf.noao.ccdred()
iraf.noao.echelle()


def f2c(res_tem="S", step_tem=100):  # es el programa en si, todo en iraf
    #valores para los template
    if res_tem == "h" or res_tem == "H":
        lit = "@template"
        print("Working with template spectra in hihg resolution")
    else:
        lit = "@template"
        print("Working with template spectra in low resolution")

    #parametros de entrada
    lio = "@objetos"
    lit = "@template"
Esempio n. 8
0
        np.loadtxt('shift.refimage', usecols=(0, ), dtype=str, unpack=True))
    # refImageSh = refImageShin[0]
    print "reference image: ", refImageSh

filesSh = glob.glob('msc_*.fits')
filesSh.pop(filesSh.index(refImageSh))
filesSh.append(refImageSh)
filesSh.reverse()

if not os.path.isfile('mscFilesSh.list'):
    with open('mscFilesSh.list', 'w+') as f1:
        for i, mfile in enumerate(filesSh):
            print >> f1, mfile

# import the getshfts task as a pyraf task
iraf.task(getshfts="home$scripts/getshfts.cl")

# then run getshfts
if not os.path.isfile('mscFilesSh.shft'):
    iraf.getshfts(images='@mscFilesSh.list', rootname='mscFilesSh')

if not os.path.isfile('sh' + refImageSh):
    iraf.immatch.imalign.setParam('input', '@mscFilesSh.list')
    iraf.immatch.imalign.setParam('reference', refImageSh)
    iraf.immatch.imalign.setParam('coords', 'mscFilesSh.reg')
    iraf.immatch.imalign.setParam('output', 'sh//@mscFilesSh.list')
    iraf.immatch.imalign.setParam('shifts', 'mscFilesSh.shft')
    iraf.immatch.imalign.setParam('niterate', 10)
    iraf.immatch.imalign.setParam('interp_type', 'poly5')
    iraf.immatch.imalign.setParam('boundary_type', 'constant')
    iraf.immatch.imalign.setParam('constant', 0.0)
Esempio n. 9
0
File: SCRIPT.py Progetto: dafh/stuff
             angle_rot_2 = hdu_aux[0].header['HIERARCH ESO INS RETA2 ROT']
             if angle_rot == angle_rot_2:
                out = wave_extraction(wave,im)
                w_image_ms.write(out + '\n')
                identify(out,ref_ID)
                w_image_ms.seek(0)
                break
    image_ms.close()
    w_image_ms.close()
    wave_list.close()
    return 'w.ms.' + list_image


if __name__ == '__main__':

  iraf.task(lacos_spec= "lacos_spec.cl")  #LACOSMIC
  abspath = os.path.abspath(__file__) #Definir main_directory
  dictionary, path = inputs(sys.argv)       #definir inputs
  #Setting variables and lacos_spec in directory
  wave = dictionary['wave']
  flat = dictionary['flat']
  std = dictionary['std']
  science = dictionary['science']
  flux = dictionary['flux']
  bias = dictionary['bias']
  #COSMIC REMOVAL
  c_wave = 'c' + wave
  c_flat = 'c' + flat
  c_science = 'c' + science
  c_flux = 'c' + flux
  #c_std = 'c' + std
Esempio n. 10
0
else:
    _iraf = ns._home + "/atwork/iraf/"

# Eventually, get all initializations from initobs:
print data
obs = ns.initobs(data, remote=(not local))
_proc = obs[1]
_raw = obs[8]
n_ap = obs[14]  #  number of apertures (i.e., echelle orders)
filter = obs[15]  # photometric band in which we're operating
prefn = obs[16]  # filename prefix
calnod = obs[17]  # whether A0V calibrators nod, or not

procData = processCal or processTarg
badval = 0
ir.task(bfixpix=_iraf + "bfixpix.cl")
ir.task(bfixpix_one=_iraf + "bfixpix_one.cl")
#ir.load('fitsutil')
ir.load('noao')
ir.load('astutil')
ir.load("imred")
ir.load('echelle')
ir.load('twodspec')
ir.load('apextract')

telluric_list = ns._home + '/proj/pcsa/data/atmo/telluric_hr_' + filter + '.dat'
if filter == 'K' or filter == 'H':
    horizsamp = "10:500 550:995"

elif filter == 'L':
    horizsamp = "10:270 440:500 550:980"
Esempio n. 11
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)
Esempio n. 12
0
    gain = 1.41
    readnoise = 4.64
elif teles == "LJT":
    print("Settings for LJT will be used.")
    gain = 3.20
    readnoise = 13.5
else:
    print("Error detected.")

objall = []
with open('objall.list') as file:
    for line in file:
        line = line.strip('.fits\n')
        objall.append(line)

iraf.task(lacos_im=lacos_im)
print('Loading IRAF packages ...')
iraf.stsdas()
iraf.lacos_im.gain = gain
iraf.lacos_im.readn = readnoise

iraf.images()
iraf.images.imutil()
iraf.images.imutil.imheader(images="@objall.list")
stdspecs = str(
    raw_input("Enter filenames of all standard star spectra, \n\
separated by comma (','): "))
stdlist = [x.strip('.fits') for x in stdspecs.split(',')]
stdlist = [x.strip() for x in stdlist]
for item in stdlist:
    objall.remove(item)
Esempio n. 13
0
        "No pyraf module -- did you forget to do `source activate geminiconda`?"
    )

import copy
import glob
import os
import shutil
import argparse

import matplotlib.pyplot as plt
from astropy.io import fits
from astropy.table import Table
from pyraf.iraf import gemini, gmos, gemtools, task

# this task allows us to skip bad slits in gswavelenght!
iraf.task(mgswavelength='/Users/mwilde/iraf/mgswavelength.cl')

path = os.path.abspath('.')

# Set colormap for plotting
cm = plt.get_cmap('Greys')

flatPrefix = 'MC' + 'gcalFlat'
combName = 'MC' + 'gcalFlat' + 'Comb'
biasName = 'MCbiasFull.fits'

# Read in user defined slit(s) to skip with mgswavelength
parser = argparse.ArgumentParser(
    description="run the iraf reduction on cgmsquared data.")
parser.add_argument("--skip_slit",
                    type=int,
Esempio n. 14
0
    refImageSh = str(np.loadtxt('shift.refimage', usecols=(0,), dtype=str, unpack=True))
    # refImageSh = refImageShin[0]
    print "reference image: ", refImageSh

filesSh = glob.glob('msc_*.fits')
filesSh.pop(filesSh.index(refImageSh))
filesSh.append(refImageSh)
filesSh.reverse()

if not os.path.isfile('mscFilesSh.list'):   
    with open('mscFilesSh.list','w+') as f1:
        for i,mfile in enumerate(filesSh):
            print >> f1, mfile  

# import the getshfts task as a pyraf task
iraf.task(getshfts = "home$scripts/getshfts.cl")

# then run getshfts
if not os.path.isfile('mscFilesSh.shft'):
    iraf.getshfts(images='@mscFilesSh.list', rootname='mscFilesSh')

if not os.path.isfile('sh'+refImageSh):    
    iraf.immatch.imalign.setParam('input','@mscFilesSh.list')
    iraf.immatch.imalign.setParam('reference',refImageSh)
    iraf.immatch.imalign.setParam('coords','mscFilesSh.reg')
    iraf.immatch.imalign.setParam('output','sh//@mscFilesSh.list')
    iraf.immatch.imalign.setParam('shifts','mscFilesSh.shft')
    iraf.immatch.imalign.setParam('niterate',10)
    iraf.immatch.imalign.setParam('interp_type','poly5')
    iraf.immatch.imalign.setParam('boundary_type','constant')
    iraf.immatch.imalign.setParam('constant',0.0)
Esempio n. 15
0
# print matched sources to a file suitable for marking
if os.path.isfile('ifirst_tol7.out') :
    mx,my = np.loadtxt('ifirst_tol7.out',usecols=(4,5),unpack=True)
    mfilter = np.loadtxt('ifirst_tol7.out',usecols=(1,),dtype=str,unpack=True)
    match_pos_file_g = open("tol7_g.pos", 'w+')
    match_pos_file_i = open("tol7_i.pos", 'w+')
    for i in range(len(mx)) :
        if mfilter[i]== 'g' :
            print >> match_pos_file_g, mx[i], my[i]
        if mfilter[i] == 'r' :
            print >> match_pos_file_i, mx[i], my[i]
    match_pos_file_g.close()
    match_pos_file_i.close()
    
# import the getfwhm task as a pyraf task
iraf.task(getfwhm = "home$scripts/getfwhm.cl")
# print iraf.getfwhm.getCode()

# you might want to remeasure the FWHMs to get a better global estimate now that we (should) only have good sources in the image
# use getfwhm, which is just a loop on imexam. (try to improve this with ralf's qr code)
if not os.path.isfile('getfwhm_g.log') :
    iraf.unlearn(iraf.imexamine, iraf.rimexam)
    iraf.getfwhm.setParam('images',fits_g)
    iraf.getfwhm.setParam('coordlist','tol7_g.pos')
    iraf.getfwhm.setParam('outfile','getfwhm_g.log')
    iraf.getfwhm.setParam('center','no')
    iraf.imexamine.setParam('frame',1)
    iraf.getfwhm()

if not os.path.isfile('getfwhm_i.log') :
    iraf.getfwhm.setParam('images',fits_i)
Esempio n. 16
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')
Esempio n. 17
0
    
Returns:
    --------
    Table with the distorted X,Y coordinates for all the stars 
    
"""

import os
import sys
import glob
from pyraf import iraf


#Getting access to Iraf
login = "******"
iraf.task(login = "******")
p = iraf.login.getCode()
eval('p')


def Geoxy(path):
    print "Starting Geoxy..."
    filename = path
    os.chdir(filename)   
    corrected = glob.glob("*.xy")
                   
    #Removing existing files    
    filelist = glob.glob("*.done")
    for f in filelist:
        os.remove(f)
    
from astropy.io import fits
from matplotlib import pyplot as plt
import shutil
import sys
from pyraf import iraf
iraf.noao(_doprint=0)
iraf.imred(_doprint=0)
iraf.ccdred(_doprint=0)
iraf.twodspec(_doprint=0)
iraf.longslit(_doprint=0)
iraf.kpnoslit(_doprint=0)
iraf.astutil(_doprint=0)
iraf.onedspec(_doprint=0)
iraf.twodspec.longslit.dispaxis = 2
iraf.module.load('stsdas', doprint=0, hush=1)
iraf.task(lacos_spec=irafhome + "lacos_spec.cl")

#read object keywords
for file in os.listdir(os.getcwd()):
    if file.endswith('.fits'):
        testfile = file
        shutil.copy(file, './original/.')

hduo = fits.open(testfile)

#name targets (science & standard)
target = hduo[0].header['OBJECT']
#target2 = 'SP0644p375'
#std = 'SP0305+261'

#create list of science files
Esempio n. 19
0
from pyraf import iraf
iraf.task(asgred = "home$asgred/asgred.cl")
iraf.task(copred = "home$copred/copred.cl")
Esempio n. 20
0
iraf.set(procdir='/home/eslamba/ic/reducao/NGC5728/procSTAR_15-01-16/')  # processed files
locrep = '/home/eslamba/Dropbox/ic/reducao/15-01-16/ctionewcal_flux/' # star flux files

iraf.cd('rawdir')

iraf.set(stdimage='imtgmos')

iraf.gemini()
iraf.gemtools()
iraf.gmos()

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

iraf.gmos.logfile='ltt7379.log'
iraf.task(lacos_spec='/home/eslamba/LAcosmic/lacos_spec.cl')

tstart = time.time()


#iraf.setjd('*fits[0]')

l = glob.glob('*.fits')
l.sort()
idx = np.arange(len(l))

headers = [pf.getheader(i, ext=0) for i in l]
jd = [pf.getheader(i, ext=1)['mjd-obs'] for i in l]


#   Define lists
Esempio n. 21
0
import re #importing regular expressions -- for a logfile issue later
import IPython
import sys
import os
import pyfits
import pyraf
from pyraf import iraf
import numpy as np

os.system('rm *.fits_cursor_file.dat')
os.system('rm *_continuum_fit')
os.system('rm *_continuum_fit_yoffset.dat')
os.system('rm *_scaling_factors.dat')

iraf.task(gscombine='/net/frigg/Users/inger/Gemini/Pipeline/Software/gmos/gscombine.cl')

iraf.unlearn('imexamine')
iraf.unlearn('kimexam') #this is the task I'm actually using when I call the 'k' keyword in imexamine
iraf.unlearn('gscombine')

#I was thinking of using INSTRES as way to code getting the line strengths and comparing them but after tinkering around and not getting too far (bc I couldn't get it to fit the lines I wanted) I figure I'll give imexamine a try. It'll allow me to us wavelength space instead of pixel space and I can use various tools on it; and I know how to code it without being interactive. But wait, I need to fit a gaussian to it so I can get the peak and width to calculate the area underneath. I can use the 'a' function with imexamine to get the peak and then use that as input for jimexamine with fits with a gaussian. Even though it is in pixel space it shouldn't make a difference if I'm comparing the same slits of different science frames of the same instrument setup? I can use the non-interactive version of imexamine to fit a gaussian to the peak line and have the output of the gaussian saved in a log file; I can read the log file and compute the area of the gaussian based on the peak and fwhm values -- I can script this for the other files of the same setup and compare their gaussian area values and therefore calculate their weight


#this is obsolete now since I'm no longer sampling emission lines but sampling a continuum area and I've specified the wavelengths already
def wavelength_to_pixel(fits, sample_ext, sample_wl):
	slit_header = pyfits.getheader(fits, sample_ext)	
	crpix1 = slit_header['CRPIX1']
	cd1_1 = slit_header['CD1_1']
	crval1 = slit_header['CRVAL1']
	sample_pixel = crpix1 + ((sample_wl - crval1) / cd1_1)
Esempio n. 22
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))
Esempio n. 23
0
from pyraf import iraf
import glob
import os 
import sys

file_list=glob.glob('IRCA*.fits')
file_list.sort()

###Left
#ch1='[1:256,1:1024]' 	#o
#ch2='[257:512,1:1024]' 	#e
###Right
ch1='[512:768,1:1024]'
ch2='[768:1024,1:1024]'

iraf.task(distcor = 'distcor.cl')
geomap='ircs+ao188_20mas_distmap_20131118.dbs'

flat='calflat.fits'
if os.path.isfile(flat):
  print('Using {}'.format(flat))
else:
  print('flat image not found!')
  sys.exit()

for filename in file_list:
  #flatfielding
  iraf.imar(filename,'/',flat,filename[:-5]+'f.fits')
  #geometric distortion correction
  iraf.distcor(filename,filename[:-5]+'fg.fits',geomap)
  a1=filename[:-5]+ch1
Esempio n. 24
0
except:
    import pyfits as pf
import logging

file_list = glob.glob('IRCA*.fits')
file_list.sort()

#logger
fname = pf.open(file_list[0])[0].header['FRAMEID'] + '_reduction.log'
logging.basicConfig(filename=fname, level=logging.INFO)

ch1 = '[1:256,1:1024]'  #o
ch2 = '[257:512,1:1024]'  #e

distcorr_file = 'distcor.cl'
iraf.task(distcor=distcorr_file)
geomap = 'ircs+ao188_20mas_distmap_20131118.dbs'
flat = 'calflat.fits'

#dark_folder = 'data/imaging/ircs_UH30B/CALIB/DARK'
dark_dir = '../CALIB/DARK/master_darks'
if not os.path.exists(dark_dir):
    print('Dark folder does is empty: {}'.format(dark_folder))
    logging.warning('dark file does not exist')
    sys.exit()

for filename in file_list:
    #get header
    hdr = pf.open(filename)[0].header
    #get specific dark
    #exptime='master_dark_'+str(hdr['EXP1TIME'])+'s.fits'