예제 #1
0
def time_calibration(input_file):
    """
    Obtain the calibration for time (hjd) by pyraf and the airmass for each image. Include in the header all information.
    """
    original_path = os.getcwd()
    save_path = input_file['save_path']
    #change to save data reduction directory
    os.chdir(save_path)
    print '\n Reading the list of images ....\n'
    planet = input_file['exoplanet'] #set exoplanet name
    images = sorted(glob.glob('AB'+planet+'*.fits'))
    print images
    #include de RA,DEC and epoch of the exoplanet
    RA,DEC,epoch = input_file['RA'],input_file['DEC'],input_file['epoch']
    #obtain ST JD using iraf task and introduce in the header
    for i in range(len(images)):
        hdr = fits.getheader(images[i])
        if int(split(hdr['UT'],':')[0]) < int(hdr['timezone']):
            new_date = use.yesterday(hdr['date-obs'])
            #print images[i], new_date
        else:
            new_date = hdr['date-obs']
        year,month,day = split(new_date,'-')
        iraf.asttimes(year=year,month=month,day=day,time=hdr['loctime'],obs=input_file['observatory'])
        JD = iraf.asttimes.jd #obtain julian date
        LMST = iraf.asttimes.lmst #obtain the sideral time
        LMST = use.sexagesimal_format(LMST) #convert sideral time in sexagesimal format
        iraf.hedit(images[i],'ST',LMST,add='yes',verify='no',show='no',update='yes') #create the ST keyword in the header
        iraf.ccdhedit(images[i],'LMST',LMST,type='string') #include the mean sideral time in the header
        iraf.ccdhedit(images[i],'JD',JD,type='string') #include de julian date in the header
        #include RA, and DEC of the object in your header
        iraf.ccdhedit(images[i],"RA",RA,type="string") #include right ascention in the header
        iraf.ccdhedit(images[i],"DEC",DEC,type="string")  #include declination in the header
        iraf.ccdhedit(images[i],"epoch",epoch,type="string") #include epoch in the header
        # use.update_progress((i+1.)/len(images))
    print '\n Setting airmass ....\n'
    for i in range(len(images)):
        print '# ',images[i]
        #iraf.hedit(images[i],'airmass',airmass,add='yes')
        #iraf.hedit(images[i],'HJD',HJD,add='yes')
        iraf.setairmass.observatory = input_file['observatory']
        iraf.setairmass(images[i])
        iraf.setjd.time = 'ut'
        iraf.setjd(images[i])
    print '\n.... done.\n'
    #export information
    hjd, jd, airmass, st = [],[],[],[]
    for i in range(len(images)):
        hdr = fits.getheader(images[i])
        hjd.append(hdr['HJD'])
        jd.append(hdr['JD'])
        airmass.append(hdr['airmass'])
        st.append(hdr['st'])
    #saving the data
    data = DataFrame([list(hjd),list(jd),list(st),list(airmass)]).T
    data.columns = ['HJD','JD','ST','Airmass']
    data.to_csv('results_iraf_calibrations.csv')
    #change to workings directory
    os.chdir(original_path)
    return
예제 #2
0
#obtain ST JD using iraf task and introduce in the header
for i in range(len(images)):
    hdr = fits.getheader(images[i])
    if int(split(hdr['UT'],':')[0]) < int(hdr['timezone']):
        new_date = use.yesterday(hdr['date-obs'])
        #print images[i], new_date
    else:
        new_date = hdr['date-obs']
    year,month,day = split(new_date,'-')
    iraf.asttimes(year=year,month=month,day=day,time=hdr['loctime'],obs=input_data['observatory'])
    JD = iraf.asttimes.jd #obtain julian date
    LMST = iraf.asttimes.lmst #obtain the sideral time
    LMST = use.sexagesimal_format(LMST) #convert sideral time in sexagesimal format
    iraf.hedit(images[i],'ST',LMST,add='yes',verify='no',show='no',update='yes') #create the ST keyword in the header
    iraf.ccdhedit(images[i],'LMST',LMST,type='string') #include the mean sideral time in the header
    iraf.ccdhedit(images[i],'JD',JD,type='string') #include de julian date in the header
    #include RA, and DEC of the object in your header
    iraf.ccdhedit(images[i],"RA",RA,type="string") #include right ascention in the header
    iraf.ccdhedit(images[i],"DEC",DEC,type="string")  #include declination in the header
    iraf.ccdhedit(images[i],"epoch",epoch,type="string") #include epoch in the header
    # use.update_progress((i+1.)/len(images))

print '\n Setting airmass ....\n'
for i in range(len(images)):
    print '# ',images[i]
    #iraf.hedit(images[i],'airmass',airmass,add='yes')
    #iraf.hedit(images[i],'HJD',HJD,add='yes')
    iraf.setairmass.observatory = input_data['observatory']
    iraf.setairmass(images[i])
    iraf.setjd.time = 'ut'
예제 #3
0
def changeHeaderFormat(imageList, imageType):
    imageString = getIrafString(imageList)
    iraf.ccdhedit(imageString, parameter="IMAGETYP", value=imageType)
예제 #4
0
def preprocess(path):  #, mode='EABA'):
    """ Pipeline that applies the basic CCD reduction tasks.
    Asks for the path were all files are present, and
    performs Bias combination, Dark combination, Flat
    combination and the inherent substractions
    Works in TORITOS mode, and EABA mode, the latter using UBVRI
    filters.

    Pipeline que aplica una reducción básica a imágenes de tipo CCD
    Realiza combinación de Bias, de Darks, y Flats.
    Luego realiza las restas inherentes
    Funciona en dos modos, TORITOS y EABA, el último usando filtros UBVRI
    """
    bornpath = os.path.abspath('.')
    workdir = os.path.abspath(path)
    biasdir = os.path.join(workdir, "bias")
    flatdir = os.path.join(workdir, "flat")
    darkdir = os.path.join(workdir, "dark")
    scidir = os.path.join(workdir, "science")
    for x in [biasdir, flatdir, darkdir, scidir]:
        print "creating {} directory".format(str(x))
        mkdir(x)
    cd(workdir)
    #-------------------------------------------------------------------------#
    fitslist = []
    for root, dirs, files in os.walk(path, topdown=True):
        for name in fnmatch.filter(files, '*.fit*'):
            fitslist.append(os.path.join(root, name))
    #fitslist = glob.glob('*.fits') + glob.glob('*.fit')
    #load_ccdred()
    #-------------------------------------------------------------------------#
    imagetypes = {}
    for img in fitslist:
        imghead = fits.getheader(img)
        imgty = imghead['IMAGETYP']
        imagetypes[str(img)] = imgty
    #-------------------------------------------------------------------------#
    # now we get the image types in the dictionary imagetypes
    # now we make different lists for different image types
    #-------------------------------------------------------------------------#
    biaslist = []
    sciencelist = []
    flatlist = []
    darklist = []
    #-------------------------------------------------------------------------#
    for k, v in imagetypes.iteritems():
        print k, v
        if v.upper() == 'LIGHT' or v.upper() == 'OBJECT' or v.upper(
        ) == 'LIGHT FRAME':
            #            print str(k)+' is a '+str(v)+' file'
            sciencelist.append(str(k))
        elif v.upper() == 'BIAS' or v.upper() == 'ZERO' or v.upper(
        ) == 'BIAS FRAME':
            #            print str(k)+' is a '+str(v)+' file'
            biaslist.append(str(k))
        elif v.upper() == 'FLAT' or v.upper() == 'FLAT FRAME' or v.upper(
        ) == 'FLAT FIELD':
            #           print str(k)+' is a '+str(v)+' file'
            flatlist.append(str(k))
        elif v.upper() == 'DARK' or v.upper() == 'DARK FRAME':
            #           print str(k)+' is a '+str(v)+' file'
            darklist.append(str(k))
    #-------------------------------------------------------------------------#
    insp = raw_input("Inspeccionar imagenes de correccion con ds9? (si/NO)\n")
    if insp.upper() in ('S', 'Y', 'SI', 'YES'):
        print('\n')
        print(u"""Comienza la inspeccion visual de bias
            ante cualquier anomalia en alguna imagen se la vetará
              Starting visual inspection of Bias frames. If there exists any
              anomalies image will be discarded""")
        for idx, img in enumerate(list(biaslist)):
            I = raw_input("inspeccionar {} mediante ds9? (si/NO)\n".format(
                str(img)))
            if I.upper() in ('S', 'Y', 'SI', 'YES'):
                print(""" inspeccionando {} mediante ds9""".format(str(img)))
                print("\n")
                command = shlex.split('ds9 {}'.format(str(img)))
                subprocess.call(command)
                V = raw_input(" Vetar la imagen? (si/NO)")
                print("\n")
                if V.upper() in ('S', 'Y', 'SI', 'YES'):
                    S = raw_input('Es una imagen de ciencia? (LIGHT)  (SI/no)')
                    print("\n")
                    if S.upper() in ('S', 'Y', 'SI', 'YES'):
                        hdu = fits.open(img, mode='update')
                        hdr = hdu[0].header
                        hdr.set('IMAGETYP', 'LIGHT')
                        hdu.close()
                        sciencelist.append(img)
                    elif S.upper() in ('N', 'NO'):
                        os.rename(img, img + '.vet')
                    biaslist.remove(img)
        #-------------------------------------------------------------------------#
        print('\n')
        print(u"""Comienza la inspeccion visual de flats
            ante cualquier anomalia en alguna imagen se la vetará \n""")
        for idx, img in enumerate(list(flatlist)):
            I = raw_input("inspeccionar {} mediante ds9? (si/NO)\n".format(
                str(img)))
            if I.upper() in ('S', 'Y', 'SI', 'YES'):
                print(""" inspeccionando {} mediante ds9""".format(str(img)))
                print("\n")
                command = shlex.split('ds9 {}'.format(str(img)))
                subprocess.call(command)
                V = raw_input(" Vetar la imagen? (si/NO) ")
                print("\n")
                if V.upper() in ('S', 'Y', 'SI', 'YES'):
                    S = raw_input(
                        'Es una imagen de ciencia? (LIGHT)  (SI/no) ')
                    print("\n")
                    if S.upper() in ('S', 'Y', 'SI', 'YES'):
                        hdu = fits.open(img, mode='update')
                        hdr = hdu[0].header
                        hdr.set('IMAGETYP', 'LIGHT')
                        hdu.close()
                        sciencelist.append(img)
                    elif S.upper() in ('N', 'NO'):
                        os.rename(img, img + '.vet')
                    flatlist.remove(img)
        #-------------------------------------------------------------------------#
        print("\n")
        print(u"""Comienza la inspeccion visual de darks
            ante cualquier anomalia en alguna imagen se la vetará \n""")
        for idx, img in enumerate(list(darklist)):
            I = raw_input("inspeccionar {} mediante ds9? (si/NO)\n".format(
                str(img)))
            if I.upper() in ('S', 'Y', 'SI', 'YES'):
                print(""" inspeccionando {} mediante ds9""".format(str(img)))
                print("\n")
                command = shlex.split('ds9 {}'.format(str(img)))
                subprocess.call(command)
                V = raw_input(" Vetar la imagen? (si/NO)")
                print("\n")
                if V.upper() in ('S', 'Y', 'SI', 'YES'):
                    S = raw_input('Es una imagen de ciencia? (LIGHT)  (SI/no)')
                    print("\n")
                    if S.upper() in ('S', 'Y', 'SI', 'YES'):
                        hdu = fits.open(img, mode='update')
                        hdr = hdu[0].header
                        hdr.set('IMAGETYP', 'LIGHT')
                        hdu.close()
                        sciencelist.append(img)
                    elif S.upper() in ('N', 'NO'):
                        os.rename(img, img + '.vet')
                    darklist.remove(img)
    #-------------------------------------------------------------------------#
    #posee listas de todos los files.
    #comienzo por los bias:
    #primero creo una lista (file) para darle a zerocombine
    write_tolist(biaslist, 'lbias', biasdir)  #, workdir)
    #-------------------------------------------------------------------------#
    iraf.ccdhedit('@lbias', parameter='imagetype', value='zero')
    iraf.zerocombine.unlearn()
    iraf.zerocombine('@lbias', output='Zero.fits')
    #baseflat = [os.path.basename(x) for x  in flatlist]
    #basesci  = [os.path.basename(x) for x  in sciencelist]
    #basedark = [os.path.basename(x) for x  in darklist]
    #-------------------------------------------------------------------------#
    #ahora corrijo las imagenes de flat, dark y objetos por bias.
    load_ccdproc()
    iraf.ccdproc.zero = 'Zero.fits'
    for names in flatlist:
        iraf.ccdproc(names,
                     output=os.path.join(flatdir,
                                         'fz' + os.path.basename(names)))
    for names in darklist:
        iraf.ccdproc(names,
                     output=os.path.join(darkdir,
                                         'dz' + os.path.basename(names)))
    #-------------------------------------------------------------------------#
    #recreate lists of new corrected objects
    flatlist = []
    darklist = []
    for root, dirs, files in os.walk(path, topdown=True):
        for name in fnmatch.filter(files, 'fz*'):
            flatlist.append(os.path.join(flatdir, name))
    for root, dirs, files in os.walk(path, topdown=True):
        for name in fnmatch.filter(files, 'dz*'):
            darklist.append(os.path.join(darkdir, name))
    #-------------------------------------------------------------------------#
    #combino darks tal como hice con los bias
    #-------------------------------------------------------------------------#
    write_tolist(darklist, 'ldark')
    #write_tolist(sciencelist, 'lsci')
    iraf.darkcombine.unlearn()
    iraf.ccdhedit('@ldark', parameter='imagetype', value='dark')
    iraf.darkcombine('@ldark', output='Dark.fits')
    #-------------------------------------------------------------------------#
    # discrimino por filtro los datos. es importante esta parte!
    #.------------------------------------------------------------------------#
    #SE USARON FILTROS?
    filteruse = True
    for v in flatlist:
        try:
            hdr = fits.getheader(v)
            FILTER = hdr['FILTER']
            print 'FILTROS HALLADOS'
        except KeyError:
            filteruse = False
            print 'NO SE USARON FILTROS'
    #---------------------------IF FILTERS USED ------------------------------#
    if filteruse:
        FD = {'U': [], 'B': [], 'V': [], 'R': [], 'I': []}
        for idx, img in enumerate(list(flatlist)):
            hdr = fits.getheader(img)
            FR = hdr['FILTER']
            #creo un diccionario de filtros
            FD[str(FR)].append(img)
        print(FD)
        #-------------------------------------------------------------------------#
        #combino los flats
        #-------------------------------------------------------------------------#
        for k, v in FD.iteritems():
            if not v == []:
                print('writing to list for {} filter'.format(k))
                print(v)
                lname = str(k) + 'flat'
                #print(lname)
                write_tolist(v, lname)
                iraf.flatcombine.unlearn()
                iraf.flatcombine.combine = 'median'
                iraf.ccdhedit('@' + lname, parameter='imagetype', value='flat')
                iraf.flatcombine('@' + lname, output='Flat' + k + '.fits')
        #-------------------------------------------------------------------------#
        SD = {'U': [], 'B': [], 'V': [], 'R': [], 'I': []}
        for idx, img in enumerate(list(sciencelist)):
            hdr = fits.getheader(img)
            FR = hdr['FILTER']
            #creo un diccionario de filtros
            SD[str(FR)].append(img)
        print(SD)
        #-------------------------------------------------------------------------#
        for k, v in SD.iteritems():
            iraf.ccdproc.flatcor = 'yes'
            iraf.ccdproc.darkcor = 'yes'
            iraf.ccdproc.dark = 'Dark.fits'
            for img in v:
                if os.path.isfile('Flat' + k + '.fits'):
                    iraf.ccdproc.flat = 'Flat' + k + '.fits'
                    iraf.ccdproc(img, output='reduced_' + img)
    #----------------------IF NO FILTERS--------------------------------------#
    else:
        lname = 'flist'
        write_tolist(flatlist, lname)
        iraf.flatcombine.unlearn()
        iraf.flatcombine.combine = 'median'
        iraf.ccdhedit('@' + lname, parameter='imagetype', value='flat')
        iraf.flatcombine('@' + lname, output='Flat.fits')
        iraf.ccdproc.flatcor = 'yes'
        iraf.ccdproc.darkcor = 'yes'
        iraf.ccdproc.dark = 'Dark.fits'
        iraf.ccdproc.flat = 'Flat.fits'
        iraf.ccdproc.ccdtype = ''
        for sciname in sciencelist:
            print 'ccdproc of ', sciname, '\n', os.path.join(
                scidir, 'reduced_' + os.path.basename(sciname))
            iraf.ccdproc(sciname, output=os.path.join(scidir,\
                            'reduced_'+os.path.basename(sciname)))
    #[os.remove(x) for x in fitslist]
    aux = glob.glob('sz*.fits') + glob.glob('dz*.fits') + glob.glob('fz*.fits')
    [os.remove(x) for x in aux]
    aux = glob.glob('reduced*.fits')
    [os.rename(x, x[10:-4].upper() + x[-4:].lower()) for x in aux]
    #-------------------------------------------------------------------------#
    print(u""" Imágenes reducidas exitosamente APARENTEMENTE,
            chequea todo obsesivamente, porque ni el desarrollador de
            esto confia en que ande bien \n
            """)
    #-------------------------------------------------------------------------#
    cd(bornpath)
    #print sys.argv[:]
    return ()
예제 #5
0
else:
    print "So using", len(drk), "dark,", len(flt), "flat and", len(
        obj), "objects images, with object's rootname:", rname

getout = raw_input(
    "Is everything ok? Press 'enter' to continue, 'e' to exit.\t")
# option to exit
if getout == 'e' or getout == 'E':
    print "\nexiting then... Bye!\n"
    raise SystemExit

# preparing header fields (input of imagetyp, exptime/darktime)
print "> preparing the image headers"
#l.write("\n> preparing the image headers")
unlearn(iraf.ccdhedit)
iraf.ccdhedit("Dark*.fit", parameter="imagetyp", value="dark")
iraf.ccdhedit("Flat*.fit", parameter="imagetyp", value="flat")
iraf.ccdhedit(rname + "_*.fit", parameter="imagetyp", value="object")
for im in glob.glob('*.fit*'):
    unlearn(iraf.imgets)
    iraf.imgets(im, param="inttime")
    iraf.hedit(im,
               fields="exptime",
               value=iraf.imgets.value,
               add="no",
               addonly="yes",
               delete="no",
               verify="no",
               show="no",
               update="yes")
for im in glob.glob("Dark*.fit"):
예제 #6
0
def changeHeaderFormat(imageList, imageType):
    imageString = getIrafString(imageList)
    iraf.ccdhedit(imageString, parameter="IMAGETYP",value=imageType)
예제 #7
0
print '\nThis is the list of local time: \n'
print '\nImage ** Local Time (isot format) ** Sideral Time (hours min seg)\n'
for i in range(len(images)):
    print images[i], ' ** ', local_time[i], ' ** ', sideraltime[i]

print '\nSetting coordinates to our ' + planet + ': \n'
RA = Angle(file['RA'] + file['u.RA'])
DEC = Angle(file['DEC'] + file['u.DEC'])
coordinates = SkyCoord(RA, DEC, frame=file['frame'])
print '\nCoordinates: ', coordinates

print '\nIncluding RA,DEC,epoch in the header of the images ....\n'
#RA in hours
for i in range(len(images)):
    iraf.ccdhedit(images[i], 'RA', coordinates.ra.hour, type='string')
    iraf.ccdhedit(images[i], 'DEC', coordinates.dec.deg, type='string')
    iraf.ccdhedit(images[i], 'epoch', file['epoch'], type='string')
    iraf.ccdhedit(images[i], 'st', sideraltime[i].hour, type='string')
    update_progress((i + 1.) / len(images))

print '\nCalibrating your airmass correction: \n'
print 'Setting observatory: ', file['observatory']
iraf.setairmass('AB' + planet + '*.fits')
iraf.setairmass.observatory = file['observatory']
print '\n.... done.\n'

#Setting Julian Date
print '\n Setting Julian Date\n'
iraf.setjd.time = "ut"
iraf.setjd('AB' + planet + '*.fist')
예제 #8
0
print '\nThis is the list of local time: \n'
print '\nImage ** Local Time (isot format) ** Sideral Time (hours min seg)\n'
for i in range(len(images)):
    print images[i],' ** ',local_time[i],' ** ',sideraltime[i]

print '\nSetting coordinates to our '+planet+': \n'
RA = Angle(file['RA']+file['u.RA'])
DEC = Angle(file['DEC']+file['u.DEC'])
coordinates = SkyCoord(RA,DEC,frame=file['frame'])
print '\nCoordinates: ',coordinates


print '\nIncluding RA,DEC,epoch in the header of the images ....\n'
#RA in hours
for i in range(len(images)):
    iraf.ccdhedit(images[i],'RA',coordinates.ra.hour,type='string')
    iraf.ccdhedit(images[i],'DEC',coordinates.dec.deg,type='string')
    iraf.ccdhedit(images[i],'epoch',file['epoch'],type='string')
    iraf.ccdhedit(images[i],'st',sideraltime[i].hour,type='string')
    update_progress((i+1.)/len(images))
 
print '\nCalibrating your airmass correction: \n'
print 'Setting observatory: ',file['observatory']
iraf.setairmass('AB'+planet+'*.fits')
iraf.setairmass.observatory = file['observatory']
print '\n.... done.\n'

#Setting Julian Date
print '\n Setting Julian Date\n'
iraf.setjd.time = "ut"
iraf.setjd('AB'+planet+'*.fist')
예제 #9
0
파일: iraf.py 프로젝트: Hofmaier/wintermute
 def setFitsHeader(self, headerType):
     iraf.ccdhedit(self.inputFolder, parameter="IMAGETYP", value = headerType)