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
def get_jd(fn): try: val = pyfits.getval(fn, 'JD') return val except KeyError: from pyraf import iraf iraf.hedit(images=fn, fields='OBSERVAT', value='ca', add='Yes', addonly='Yes', delete='No', verify='No', show='Yes', update='Yes') iraf.setjd(images=fn, observatory='ca', date='date-obs', time='date-obs', exposure='exptime', ra='ra', dec='dec', epoch='EQUINOX', utdate='Yes', uttime='Yes') val = pyfits.getval(fn, 'JD') return val
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 data.columns = ['HJD','JD','ST','Airmass'] data.to_csv('results_iraf_calibrations.csv')
iraf.hedit(ifile, 'UTMIDDLE', value=utmiddle.strftime('%H:%M:%S.%f'), add=yes, delete=no, addonly=no, verify=no) flist.close() print 'Setting Julian Date Keywords' iraf.setjd('@targets_extracted', 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,
VHELIO = retrieve_RV(object_name, RV_standard_dat) append_VHELIO(file_location, str(VHELIO)) ############################ ### Apply header changes ### ############################ ### Apply setJD to both images iraf.setjd( images="normspec_" + file_name + "," + RV_Standards, observatory=")_.observatory", date="date-obs", time="ut", exposure="exptime", ra="ra", dec="dec", epoch="equinox", jd="jd", hjd="hjd", ljd="ljd", utdate=1, uttime=1, listonly=0, ) ### Add required header information to both images ### Add EPOCH keyward to fits header iraf.hedit( images="normspec_" + file_name + "," + RV_Standards, fields="EPOCH", value="2000.0", add=1,
os.system("mv -f n_synthetic.fits synthetic.fits") ################# ### Run fxcor ### ################# ### Apply setJD to object image iraf.setjd( images = "normspec_" + file_name,\ observatory = ")_.observatory",\ date = "date-obs",\ time = "ut",\ exposure = "exptime",\ ra = "ra",\ dec = "dec",\ epoch = "equinox",\ jd = "jd",\ hjd = "hjd",\ ljd = "ljd",\ utdate = 1,\ uttime = 1,\ listonly = 0) ### Add required header information to object image ### Add EPOCH keyward to fits header iraf.hedit( images = "normspec_" + file_name,\ fields = "EPOCH",\ value = "2000.0",\ add = 1,\
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'
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'
def Rename(im,FLAG_END=False): #FLAG_END = False BIN1X1 = '1 1' BIN2X2 = '2 2' BIN3X3 = '3 3' BIN4X4 = '4 4' while True: oldname = im.name.split('.') newname = os.path.join(im.path,oldname[1] + '.' + oldname[0] + '.' + oldname[2]) acqnewname = os.path.join(im.path,oldname[1] + 'acq.' + oldname[0] + '.' + oldname[2]) # acqnewname = oldname[1] + '.' + oldname[0] + '.' + oldname[2] if os.path.isfile(newname): print "Goodname already exist!" pass else: if os.path.isfile(im.fname): if PYRAF: fimg = pyfits.open(im.fname,ignore_missing_end=True) imhdr = fimg[0].header CCDSUM = imhdr['CCDSUM'] IMTITLE = imhdr['OBJECT'] if 'acq' in IMTITLE: newname = acqnewname i.imcopy(im.fname+'[*,*,1]',newname) elif 'HgAr' in IMTITLE: i.imcopy(im.fname+'[*,*,1]',newname) i.hedit(newname,fields='OBSTYPE',value='COMP', update='yes',addonly='no',delete='no',verify='no') elif 'Quartz' in IMTITLE: i.imcopy(im.fname+'[*,*,1]',newname) i.hedit(newname,fields='OBSTYPE',value='FLAT', update='yes',addonly='no',delete='no',verify='no') else: i.imcopy(im.fname+'[*,*,1]',newname) i.astutil(_doprint=0) i.hedit(newname,fields='OBSERVAT',value='SOAR',add='yes',verify='no') i.hedit(newname,fields='EPOCH',value='2000',add='yes',verify='no') i.setjd.setParam('time','UT') i.setjd(newname) if CCDSUM == BIN1X1: i.hedit(newname,fields='DETSIZE',value='[1:4069,1:1896]', update='yes',addonly='no',delete='no',verify='no') i.hedit(newname,fields='DATASEC',value='[28:4096,1:1896]',update='yes',addonly='no',delete='no',verify='no') i.hedit(newname,fields='TRIMSEC',value='[28:4096,1:1896]',update='yes',addonly='no',delete='no',verify='no') i.hedit(newname,fields='DETSEC', value='[1:4069,1:1896]', update='yes',addonly='no',delete='no',verify='no') i.hedit(newname,fields='CCDSEC', value='[1:4069,1:1896]', update='yes',addonly='no',delete='no',verify='no') i.hedit(newname,fields='CCDSIZE',value='[1:4069,1:1896]', update='yes',addonly='no',delete='no',verify='no') i.hedit(newname,fields='BIASSEC',value='[5:15,40:1860]', update='yes',addonly='no',delete='no',verify='no') elif CCDSUM == BIN2X2: print "2x2" i.hedit(newname,fields='DETSIZE',value='[1:2071,1:948]', update='yes',addonly='no',delete='no',verify='no') i.hedit(newname,fields='TRIMSEC',value='[12:2054,1:948]',update='yes',addonly='no',delete='no',verify='no') i.hedit(newname,fields='CCDSIZE',value='[1:2071,1:948]', update='yes',addonly='no',delete='no',verify='no') i.hedit(newname,fields='DETSEC', value='[1:2071,1:948]', update='yes',addonly='yes',delete='no',verify='no') i.hedit(newname,fields='BIASSEC',value='[2:8,20:930]', update='yes',addonly='yes',delete='no',verify='no') i.hedit(newname,fields='CCDSEC', value='[1:2071,1:948]', update='yes',addonly='yes',delete='no',verify='no') elif CCDSUM == BIN3X3: print "3x3" i.hedit(newname,fields='DETSIZE',value='[1:1356,1:632]', update='yes',addonly='no',delete='no',verify='no') i.hedit(newname,fields='TRIMSEC',value='[10:1365,1:632]',update='yes',addonly='no',delete='no',verify='no') i.hedit(newname,fields='CCDSIZE',value='[1:1356,1:632]', update='yes',addonly='no',delete='no',verify='no') i.hedit(newname,fields='DETSEC', value='[1:1356,1:632]', update='yes',addonly='yes',delete='no',verify='no') i.hedit(newname,fields='BIASSEC',value='[3:5,13:629]', update='yes',addonly='yes',delete='no',verify='no') i.hedit(newname,fields='CCDSEC', value='[1:1356,1:632]', update='yes',addonly='yes',delete='no',verify='no') elif CCDSUM == BIN4X4: print "4x4" i.hedit(newname,fields='DETSIZE',value='[1:1036,1:474]', update='yes',addonly='no',delete='no',verify='no') i.hedit(newname,fields='TRIMSEC',value='[6:1028,1:474]', update='yes',addonly='no',delete='no',verify='no') i.hedit(newname,fields='CCDSIZE',value='[1:1036,1:474]', update='yes',addonly='no',delete='no',verify='no') i.hedit(newname,fields='DETSEC', value='[1:1036,1:474]', update='yes',addonly='yes',delete='no',verify='no') i.hedit(newname,fields='BIASSEC',value='[1:4,10:465]', update='yes',addonly='yes',delete='no',verify='no') i.hedit(newname,fields='CCDSEC', value='[1:1036,1:474]', update='yes',addonly='yes',delete='no',verify='no') else: print "ERROR: It's neither 1x1, 2x2, 3x3 or 4x4." return -1 #sys.exit(1) if not im.next: return newname #sys.exit(1) if FLAG_END: return newname break else: im.add()