Exemple #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
Exemple #2
0
def setairmass(inim, obs, ra, dec):
    """
    setairmass -- update image headers with the effective airmass
    obs   -- SAO1-m : "sao" 
    ra    -- target ra hh:mm:ss
    dec   -- target dec dd:mm:ss
    location -- Put your observatory information.
    *** Hourly airmass for Feige 56 ***

    Epoch 2000.00: RA  12 06 47.3, dec  11 40 13
    Epoch 2019.35: RA  12 07 46.6, dec  11 33 45

    At midnight: UT date 2019 May 10, Moon 0.33 illum,  59 degr from obj

    Local      UT      LMST      HA     secz   par.angl. SunAlt MoonAlt

    22 00    11 00    10 40    -1 28    1.186   -33.6     -6.3    52.1
    23 00    12 00    11 40    -0 28    1.119   -12.4    -16.3    40.7
    0 00    13 00    12 40     0 32    1.121    14.2     ...     29.1
    1 00    14 00    13 40     1 32    1.194    34.7     ...     17.7
    2 00    15 00    14 40     2 33    1.363    46.2     ...      6.6
    3 00    16 00    15 40     3 33    1.701    51.8     ...     ... 
    4 00    17 00    16 41     4 33    2.436    53.9     ...     ... 
    5 00    18 00    17 41     5 33    4.691    53.8     ...     ... 
    6 00    19 00    18 41     6 33  (v.low)    51.8    -15.8    ... 
    7 00    20 00    19 41     7 33   (down)    47.9     -5.7    ... 
    """
    import glob
    import os, sys
    from pyraf import iraf
    from astropy.time import Time
    from astropy.io import fits
    from astropy import units as u
    hdr = fits.getheader(inim)
    t = Time(hdr['date-obs'],
             format='isot',
             scale='utc',
             location=(126.95333299999999 * u.deg, 37.45704167 * u.deg,
                       190 * u.m))
    st = t.sidereal_time('apparent')  # in hourangle
    set_observatory(obs)
    st_hms = str(int(st.hms.h)).zfill(2) + ':' + str(int(
        st.hms.m)).zfill(2) + ':' + str(int(st.hms.s)).zfill(2)
    iraf.hedit(images=inim, fields='st', value=st_hms, add='yes', verify='yes')
    iraf.hedit(images=inim, fields='ra', value=ra, add='yes', verify='yes')
    iraf.hedit(images=inim, fields='dec', value=dec, add='yes')
    print('OK.')
    iraf.astutil()
    iraf.setairmass(images=inim,
                    observatory=obs,
                    equinox='epoch',
                    date="date-obs",
                    exposure="exptime",
                    airmass="airmass",
                    show='yes',
                    ut="date-obs",
                    override='yes')
Exemple #3
0
def cor_airmass(lstfile):
    f = open(lstfile)
    l = f.readlines()
    f.close()
    l = [tmp.split('\n')[0] for tmp in l]
    fitlst = ['awftbo' + tmp for tmp in l]
    for fitname in fitlst:
        if os.path.isfile(fitname):
            fit = pyfits.open(fitname)
            objname = fit[0].header['object'].replace('_', ' ').split()[0]
            print(fitname + ' ' + objname)
            objname_new = find_normal_objname(objname)
            if len(objname_new) == 0:
                objname_new = raw_input('please input object name:')
            radec = findradec(objname_new)
            if len(radec) == 0:
                radec = raw_input('please input ra dec of objname:')
                radec = radec.split()
            fitextnum = len(fit)
            fit.close()
            for lay in range(fitextnum):
                airold = iraf.hselect(images = fitname + '[%i]' % lay, fields = 'airmass', expr = 'yes', Stdout = 1)
                airold = float(airold[0])
                print(fitname + ' ' + objname + ' ' + str(lay) + ' airmass old: ' + str(airold))
                fitnamelay = fitname + '[%i]' % lay
                iraf.hedit(images = fitnamelay, fields = 'airold', 
                    value = airold, add = 'yes', addonly = 'yes', delete = 'no', 
                    verify = 'no', show = 'yes', update = 'yes')
                iraf.hedit(images = fitnamelay, fields = 'sname', 
                    value = objname_new, add = 'yes', addonly = 'yes', delete = 'no', 
                    verify = 'no', show = 'yes', update = 'yes')
                iraf.hedit(images = fitnamelay, fields = 'RA', 
                    value = radec[0], add = 'yes', addonly = 'yes', delete = 'no', 
                    verify = 'no', show = 'yes', update = 'yes')
                iraf.hedit(images = fitnamelay, fields = 'DEC', 
                    value = radec[1], add = 'yes', addonly = 'yes', delete = 'no', 
                    verify = 'no', show = 'yes', update = 'yes')
                iraf.twodspec()
                stdpath = os.path.split(os.path.realpath(__file__))[0] + os.sep + 'standarddir' + os.sep
                iraf.longslit(dispaxis = 2, nsum = 1, observatory = 'Lijiang', 
                    extinction = 'onedstds$LJextinct.dat', caldir = stdpath)
                iraf.setairmass(images = fitnamelay,
                    observatory = 'Lijiang', intype = 'beginning', 
                    outtype = 'effective', ra = 'ra', dec = 'dec', 
                    equinox = 'epoch', st = 'lst', ut = 'date-obs', 
                    date = 'date-obs', exposure = 'exptime', airmass = 'airmass', 
                    utmiddle = 'utmiddle', scale = 750.0, show = 'yes', 
                    override = 'yes', update = 'yes')
                print('name airmass_new airmass_old')
                iraf.hselect(fitnamelay, fields = '$I,airmass,airold', 
                             expr = 'yes')
Exemple #4
0
def set_airmass(fn):

    fit = pyfits.open(fn)
    size = len(fit)
    for i, hdu in enumerate(fit):
        if 'AIRMASS' in hdu.header:
            airmassold = hdu.header['AIRMASS']
            print('%s[%d] airmassold = %f' % (fn, i, airmassold), )
            if 'AIROLD' in hdu.header:
                airold = hdu.header['AIROLD']
                print('%s[%d] AIROLD = %f' % (fn, i, airold))
                print(
                    'AIROLD keyword alreay exist, the airmass old will not saved'
                )
            else:
                iraf.hedit(images=fn + '[%d]' % i,
                           fields='AIROLD',
                           value=airmassold,
                           add='Yes',
                           addonly='Yes',
                           delete='No',
                           verify='No',
                           show='Yes',
                           update='Yes')
    fit.close()
    ra, dec = get_ra_dec(fn)
    set_ra_dec(fn, ra, dec)

    iraf.twodspec()
    iraf.longslit(dispaxis=2, nsum=1, observatory='ca', caldir=stdpath)

    for i in range(size):
        iraf.setairmass(images=fn,
                        observatory='ca',
                        intype='beginning',
                        outtype='effective',
                        ra='ra',
                        dec='dec',
                        equinox='epoch',
                        st='lst',
                        ut='date-obs',
                        date='date-obs',
                        exposure='exptime',
                        airmass='airmass',
                        utmiddle='utmiddle',
                        scale=750.0,
                        show='yes',
                        override='yes',
                        update='yes')
Exemple #5
0
def correct_airmass():
    stdout = os.popen("ls Y*otbfmsw.fits").readlines()
    namelst = [i.split('\n')[0] for i in stdout]
    for i in xrange(len(namelst)):
        fits = pyfits.open(namelst[i])
        extnum = len(fits)
        objname = fits[0].header['object']
        fits.close()
        print '#' * 50
        print namelst[i], objname
        name = raw_input('please input the name of object:')
        ra, dec = findradec(name)
        print name, ra, dec
        for j in xrange(extnum):
            stdout = iraf.hselect(images=namelst[i] + '[%i]' % j,
                                  fields='airmass',
                                  expr='yes',
                                  Stdout=1)
            airold = float(stdout[0])
            print '+' * 5, namelst[i], 'ext:', j, 'airmass_old:', airold
            iraf.hedit(images=namelst[i] + '[%i]' % j,
                       fields='airold',
                       value=airold,
                       add='yes',
                       addonly='yes',
                       delete='no',
                       verify='no',
                       show='yes',
                       update='yes')
            iraf.hedit(images=namelst[i] + '[%i]' % j,
                       fields='sname',
                       value=name,
                       add='yes',
                       addonly='yes',
                       delete='no',
                       verify='no',
                       show='yes',
                       update='yes')
            iraf.hedit(images=namelst[i] + '[%i]' % j,
                       fields='sname',
                       value=name,
                       add='yes',
                       addonly='yes',
                       delete='no',
                       verify='no',
                       show='yes',
                       update='yes')
            iraf.hedit(images=namelst[i] + '[%i]' % j,
                       fields='ra',
                       value=ra,
                       add='yes',
                       addonly='yes',
                       delete='no',
                       verify='no',
                       show='yes',
                       update='yes')
            iraf.hedit(images=namelst[i] + '[%i]' % j,
                       fields='dec',
                       value=dec,
                       add='yes',
                       addonly='yes',
                       delete='no',
                       verify='no',
                       show='yes',
                       update='yes')
            iraf.twodspec()
            iraf.longslit(dispaxis=2,
                          nsum=1,
                          observatory='Lijiang',
                          extinction='onedstds$LJextinct.dat',
                          caldir='onedstds$spec50cal/')
            iraf.setairmass(images=namelst[i] + '[%i]' % j,
                            observatory='Lijiang',
                            intype='beginning',
                            outtype='effective',
                            ra='ra',
                            dec='dec',
                            equinox='epoch',
                            st='lst',
                            ut='date-obs',
                            date='date-obs',
                            exposure='exptime',
                            airmass='airmass',
                            utmiddle='utmiddle',
                            scale=750.0,
                            show='yes',
                            override='yes',
                            update='yes')
            print 'name                            airmass_new     airmass_old'
            iraf.hselect(images=namelst[i] + '[%i]' % j,
                         fields='$I,airmass,airold',
                         expr='yes')
Exemple #6
0
    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'
    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
Exemple #7
0
           date='date-obs',
           exposure='exptime',
           ra='ra',
           dec='dec',
           epoch='equinox',
           utdate=yes,
           uttime=yes,
           listonly=no)
iraf.setairmass('@targets_extracted',
                date='date-obs',
                exposure='exptime',
                ra='ra',
                dec='dec',
                equinox='equinox',
                utmiddle='utmiddle',
                st='lst',
                airmass='airmass',
                show=yes,
                update=yes,
                override=yes,
                intype='beginning',
                outtype='middle',
                ut='date-obs')

iraf.setjd('sig_//@targets_extracted',
           date='date-obs',
           exposure='exptime',
           ra='ra',
           dec='dec',
           epoch='equinox',
           utdate=yes,
Exemple #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')
print '\n.... done.\n'
Exemple #9
0
def set_airmass(fn):
    """
    Set airmass of fits fn. If keyword 'AIRMASS' already exist, the old airmass
    value will saved by keyword 'AIROLD'. If keyword 'AIROLD' also exist, the
    old airmass value will just overwritten. If the fits fn have more than one
    hdu or more than one star, this function assume they have same ra, dec and
    observed in same time.
    fn : fits name
    type : string
    """
    fit = pyfits.open(fn)
    size = len(fit)
    for i, hdu in enumerate(fit):
        if 'AIRMASS' in hdu.header:
            airmassold = hdu.header['AIRMASS']
            print(
                colored('%s[%d] airmassold = %f' % (fn, i, airmassold),
                        'blue'))
            if 'AIROLD' in hdu.header:
                airold = hdu.header['AIROLD']
                print(colored('%s[%d] AIROLD = %f' % (fn, i, airold),
                              'yellow'))
                print(
                    colored(('\'AIROLD\' keyword alreay exist, the airmass '
                             'old will not saved'), 'yellow'))
            else:
                iraf.hedit(images=fn + '[%d]' % i,
                           fields='AIROLD',
                           value=airmassold,
                           add='Yes',
                           addonly='Yes',
                           delete='No',
                           verify='No',
                           show='Yes',
                           update='Yes')
    fit.close()
    ra, dec = get_ra_dec(fn)
    set_ra_dec(fn, ra, dec)
    iraf.twodspec()
    stdpath = std_path + os.sep
    extfile = config_path + os.sep + 'LJextinct.dat'
    iraf.longslit(dispaxis=2,
                  nsum=1,
                  observatory='Lijiang',
                  extinction=extfile,
                  caldir=stdpath)
    for i in range(size):
        iraf.setairmass(images=fn + '[%d]' % i,
                        observatory=obs.name,
                        intype='beginning',
                        outtype='effective',
                        ra='ra',
                        dec='dec',
                        equinox='epoch',
                        st='lst',
                        ut='date-obs',
                        date='date-obs',
                        exposure='exptime',
                        airmass='airmass',
                        utmiddle='utmiddle',
                        scale=750.0,
                        show='yes',
                        override='yes',
                        update='yes')
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')
print '\n.... done.\n'
it = 0
for j in range(len(file_list[3])):
    if file_list[3][j] == '_':
        it += 1
    if it == 2 and file_list[3][j] != '_':
        date = date + file_list[3][j]
print('Date = ' + date)

if flux_calibrate != 'n':
    ## begin IRAFing

    print('\n' + 'Setting airmass...')
    iraf.setairmass('@speclist',
                    observ='lapalma',
                    ra='cat-ra',
                    dec='cat-dec',
                    equi='cat-equi',
                    st='lst',
                    ut='utstart')

    print('\n' + 'Combining spectra...')
    iraf.scombine(input='@speclist',
                  output='allspec',
                  group='all',
                  combine='median',
                  gain=2.45,
                  reject='crreject',
                  lthresh=1e-30,
                  hthresh=hthresh2)

    print('\n' + 'Applying flux calibration to sensitivity function...')
		utme_old=hdr['UT-M_E']
		print "[HJD] Old: %s --> New: %.6f" % (hjd_old,HJD[i])
		print "[JD_E] Old: %s --> New: %.6f" % (jde_old,JD_e[i])
		print "[UT-M_E] Old: %s --> New: %s" % (utme_old,mid_times[i].iso.replace(' ','T'))
	elif args.action == 'updatedb':
		qry="SELECT hjd_mid FROM %s WHERE image_id='%s'" % (table,t[i])
		print qry
		with db.cursor() as cur:
			count=cur.execute(qry)
			if count == 1:
				qry2="UPDATE %s SET hjd_mid = %.8f WHERE image_id = '%s'" % (table, HJD[i], t[i])
				print qry2
				for row in cur:
					print "%f --> %f" % (row[0],HJD[i])
				with db.cursor() as cur2:
					cur2.execute(qry2)
					db.commit()
			elif count == 0:
				print "Image is not logged in %s" % (table)
			else:
				print "DUPLICATE ENTRIES IN %s FOR image_id='%s'" % (table,t[i])
				raise Exception
	else:
		print "I'm lost..."
	print "\n"

if args.action == 'update':		
	# ensure the airmass is ok now that utmiddle etc are fixed	
	iraf.setairmass(images="*.fits", ra="cat-ra", dec="cat-dec", equinox="cat-epoc", st="st", ut="utstart", date="date-obs", exposur="exptime", airmass="airmass", utmiddl="ut-mid", show="yes", update="yes", overrid="yes",mode="ql")	

Exemple #13
0
### Run setairmass to make sure the airmass parameter is correct
iraf.hedit(
    images = file_path + file_name,\
    fields = "EPOCH",\
    value = 2000,\
    add = 1,\
    addonly = 0,\
    delete = 0,\
    verify = 0,\
    show = 1,\
    update = 1)

iraf.setairmass(
    images = file_path + file_name,\
    observatory = "SSO",\
    intype = "beginning",\
    outtype = "effective",\
    ra = "RA",\
    dec = "DEC",\
    equinox = "EPOCH",\
    st = "LST-OBS",\
    ut = "UTC-OBS",\
    date = "DATE-OBS",\
    exposure = "EXPTIME",\
    airmass = "AIRMASS",\
    utmiddle = "UTCMID",\
    scale = 750.0,\
    show = 1,\
    update = 1,\
    override = 1)