Beispiel #1
0
def airmass(img,overwrite=True,_observatory='lasilla'):
   import lsc
   from lsc.util import readhdr,readkey3, delete, updateheader
   from pyraf import iraf
   iraf.astutil(_doprint=0)
   hdr=readhdr(img)
   if readkey3(hdr,'UTC'):    
      _UT=(readkey3(hdr,'UTC')+(readkey3(hdr,'exptime')/2))/3600
      _date=readkey3(hdr,'date-obs')
      _date=_date[0:4]+'-'+_date[4:6]+'-'+_date[6:8]
      _RA=readkey3(hdr,'RA')/15
      _DEC=readkey3(hdr,'DEC')
      f = file('airmass.txt','w')
      f.write('mst = mst ("'+str(_date)+'",'+str(_UT)+', obsdb ("'+str(_observatory)+'", "longitude"))\n')
      f.write('air = airmass ('+str(_RA)+','+str(_DEC)+',mst, obsdb ("'+str(_observatory)+'", "latitude"))\n')
      f.write('print(air)\n')
      f.close()
      _air=iraf.astcalc(image=img, command="airmass.txt",Stdout=1)[0]
      try: _air=float(_air)
      except: _air=999
      delete('airmass.txt')
      if overwrite and _air<99.:
         updateheader(img,0,{'AIRMASS':(_air,'mean airmass computed with astcalc')})
   else:   _air=''
   return _air
Beispiel #2
0
def airmass(img, overwrite=True, _observatory='lasilla'):
    import lsc
    from lsc.util import readhdr, readkey3, delete, updateheader
    from pyraf import iraf
    iraf.astutil(_doprint=0)
    hdr = readhdr(img)
    if readkey3(hdr, 'UTC'):
        _UT = (readkey3(hdr, 'UTC') + (readkey3(hdr, 'exptime') / 2)) / 3600
        _date = readkey3(hdr, 'date-obs')
        _date = _date[0:4] + '-' + _date[4:6] + '-' + _date[6:8]
        _RA = readkey3(hdr, 'RA') / 15
        _DEC = readkey3(hdr, 'DEC')
        f = file('airmass.txt', 'w')
        f.write('mst = mst ("' + str(_date) + '",' + str(_UT) + ', obsdb ("' +
                str(_observatory) + '", "longitude"))\n')
        f.write('air = airmass (' + str(_RA) + ',' + str(_DEC) +
                ',mst, obsdb ("' + str(_observatory) + '", "latitude"))\n')
        f.write('print(air)\n')
        f.close()
        _air = iraf.astcalc(image=img, command="airmass.txt", Stdout=1)[0]
        try:
            _air = float(_air)
        except:
            _air = 999
        delete('airmass.txt')
        if overwrite and _air < 99.:
            updateheader(
                img, 0,
                {'AIRMASS': (_air, 'mean airmass computed with astcalc')})
    else:
        _air = ''
    return _air
Beispiel #3
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')
Beispiel #4
0
def ImportPackages():
	iraf.noao(_doprint=0)
	iraf.rv(_doprint=0)
	iraf.imred(_doprint=0)
	iraf.kpnoslit(_doprint=0)	
	iraf.ccdred(_doprint=0)
	iraf.astutil(_doprint=0)
	
	iraf.keywpars.setParam('ra','CAT-RA') 
	iraf.keywpars.setParam('dec','CAT-DEC')
	iraf.keywpars.setParam('ut','UT')
	iraf.keywpars.setParam('utmiddl','UT-M_E')
	iraf.keywpars.setParam('exptime','EXPTIME')
	iraf.keywpars.setParam('epoch','CAT-EPOC')
	iraf.keywpars.setParam('date_ob','DATE-OBS')
	iraf.keywpars.setParam('hjd','HJD')
	iraf.keywpars.setParam('mjd_obs','MJD-OBS')
	iraf.keywpars.setParam('vobs','VOBS')
	iraf.keywpars.setParam('vrel','VREL')
	iraf.keywpars.setParam('vhelio','VHELIO')
	iraf.keywpars.setParam('vlsr','VLSR')
	iraf.keywpars.setParam('vsun','VSUN')
	iraf.keywpars.setParam('mode','ql')
	iraf.fxcor.setParam('continu','both')
	iraf.fxcor.setParam('filter','none')
	iraf.fxcor.setParam('rebin','smallest')
	iraf.fxcor.setParam('pixcorr','no')
	iraf.fxcor.setParam('apodize','0.2')
	iraf.fxcor.setParam('function','gaussian')
	iraf.fxcor.setParam('width','INDEF')
	iraf.fxcor.setParam('height','0.')
	iraf.fxcor.setParam('peak','no')
	iraf.fxcor.setParam('minwidt','3.')
	iraf.fxcor.setParam('maxwidt','21.')
	iraf.fxcor.setParam('weights','1.')
	iraf.fxcor.setParam('backgro','0.')
	iraf.fxcor.setParam('window','INDEF')
	iraf.fxcor.setParam('wincent','INDEF')
	iraf.fxcor.setParam('verbose','long')
	iraf.fxcor.setParam('imupdat','no')
	iraf.fxcor.setParam('graphic','stdgraph')
	iraf.fxcor.setParam('interac','yes')
	iraf.fxcor.setParam('autowri','yes')
	iraf.fxcor.setParam('autodra','yes')
	iraf.fxcor.setParam('ccftype','image')
	iraf.fxcor.setParam('observa','lapalma')
	iraf.fxcor.setParam('mode','ql')
	return 0
Beispiel #5
0
def rvcorrect(infile='rv.obs', observatory='Palomar'):
    from pyraf import iraf
    iraf.astutil(_doprint=0)
    iraf.unlearn('rvcorrect')

    iraf.rvcorrect.files = infile
    iraf.rvcorrect.observatory = observatory
    corr = iraf.rvcorrect(Stdout=1)

    hjds = []
    vlsrs = []
    for line in corr:
        if not line.startswith('#'):
            tok = line.split()
            hjds.append(tok[0])
            vlsrs.append(tok[3])

    return hjds, vlsrs
Beispiel #6
0
def precess_coords(file, epoch=2000.0):
    '''This function takes a file, accesses its header keywords (RA,DEC and
      EPOCH), precesses the coordinates to the proviced epoch and returns
      the RA and DEC as a tuple of string representations.'''

    iraf.noao()
    iraf.astutil()
    if not iraf.imaccess(file):
        print "Error:  can't open image frame %s" % (file)
        return None

    ra = get_header(file, 'RA', str)[file]
    dec = get_header(file, 'DEC', str)[file]
    in_epoch = get_header(file, 'EPOCH', str)[file]

    f = open('iraf.tempfile', 'w')
    f.write('%s %s %s %.1f\n' % (ra, dec, in_epoch, epoch))
    f.close()
    result = iraf.precess(input='iraf.tempfile',
                          startyear=1950,
                          endyear=2000,
                          Stdout=1)
    #os.unlink('iraf.tempfile')
    return string.split(result[0])[0:2]
Beispiel #7
0
try:
    print 'Trying /home/lemoen/'
    os.chdir('/home/lemoen/')
except:
    print 'We must be on corvus then... trying /home/ezietsman/'
    os.chdir('/home/ezietsman/')
    
from pyraf import iraf
os.chdir(cd)
try:
    os.remove('splot.log')
except:
    pass
# load NOAO package
iraf.noao()
iraf.astutil()
iraf.onedspec()


times = []
results = []
fwhm = []

for i in range(61,395):
    print i
    
    # open spectrum and calculate continuum level near Ha line then write to cursor file
    data = pf.getdata('fec2117_%04d.fits'%i)
    head = pf.getheader('fec2117_%04d.fits'%i)
    start = head['CRVAL1']
    step = head['CDELT1']
folderroot = '/Users/lucaizzo/Documents/NOT/test/'
os.chdir(folderroot)
import numpy as np
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

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


hduo = fits.open(testfile)

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

	# As we will tweak the database, do a backup first
backupfile(imgdb, dbbudir, "hjd")

db = KirbyBase()
images = db.select(imgdb, ['gogogo'], [True], ['recno','imgname','mjd','date'], sortFields=['imgname'], returnType='dict')

if db.getFieldNames(imgdb).count("hjd") == 0 :
	db.addFields(imgdb, ['hjd:str'])
if db.getFieldNames(imgdb).count("jd") == 0 :
	db.addFields(imgdb, ['jd:str'])

print "Number of images :", len(images)

iraf.astutil()
iraf.unlearn(iraf.astutil.setjd)
	
	# header keyworkds
iraf.astutil.setjd.observa = "lapalma"
iraf.astutil.setjd.date = "date"
iraf.astutil.setjd.time = "utstart"
iraf.astutil.setjd.exposure = "exptime"
iraf.astutil.setjd.ra = "ra"
iraf.astutil.setjd.dec = "dec"
iraf.astutil.setjd.epoch = "epoch"

iraf.astutil.setjd.jd = "jd"
iraf.astutil.setjd.hjd = "hjd"
iraf.astutil.setjd.ljd = "ljd"
from lmfit import minimize, Parameters, report_fit

#import cosmics

iraf.noao(_doprint=0,Stdout="/dev/null")
iraf.rv(_doprint=0,Stdout="/dev/null")
iraf.imred(_doprint=0,Stdout="/dev/null")
iraf.ccdred(_doprint=0,Stdout="/dev/null")
iraf.images(_doprint=0,Stdout="/dev/null")
iraf.immatch(_doprint=0,Stdout="/dev/null")
iraf.onedspec(_doprint=0,Stdout="/dev/null")
iraf.twodspec(_doprint=0,Stdout="/dev/null")
iraf.apextract(_doprint=0,Stdout="/dev/null")
iraf.imutil(_doprint=0,Stdout="/dev/null")
iraf.echelle(_doprint=0,Stdout="/dev/null")
iraf.astutil(_doprint=0,Stdout="/dev/null")
iraf.apextract.dispaxi=1
iraf.echelle.dispaxi=1
#fixes a bug with latest versions of iraf
iraf.ccdred.instrum='blank.txt'


os.environ['PYRAF_BETA_STATUS'] = '1'

# REFS NEW: ecEC59550 ecEC59758 ecEC59795 ecEC59842 ecEC59844 ecEC59864 ecEC59866 ecEC59881 ecEC59883 ecEC59885

observations = {
  'cemp_cand': {'ORIG_DIR':'/home/nandir/IRAF_Echelle_Asiago/CEMP_obs/201712/',
    'biases':['EC60040', 'EC60041', 'EC60042', 'EC60043', 'EC60044'], 
    'flats':['EC60046', 'EC60047', 'EC60048'], 
    'objects': ['EC60089'], 
Beispiel #11
0
# toggles
make_lcs = 0
run_pdm_vik = 0
get_pdm_err = 0

# use this one!
run_pdm_iraf = 1

name,period=GetPDMInputs()

# make boot strapped lcs
if make_lcs > 0:
	made=MakeBootStrapLCs(name)

# run pdm
if run_pdm_vik > 0:
	for i in range(0,1):
		ran=RunPDM(name[i],period[i])
		
	if get_pdm_err > 0:
		periods,pdm_stats=GetPDMError()

if run_pdm_iraf > 0:
	iraf=LoadIRAF()
	
	iraf.noao(_doprint=0)
	iraf.astutil(_doprint=0)
	
	for i in range(4,5):
		periods=PDM_IRAF(name[i],period[i])
Beispiel #12
0
                shutil.copy(os.path.join(self.pars.wdir, self.dataset.masterdir, 'master.final'),
                            os.path.join(self.pars.wdir, self.irafphotdir, basename + '.coord'))
                f2.write(os.path.join(self.pars.wdir, self.irafphotdir, basename + '.phot') + '\n')
                f3.write(os.path.join(self.pars.wdir, self.irafphotdir, basename + '.coord') + '\n')
            f2.close()
            f3.close()

            logging.info('Photometry will be performed using the following apertures: %s' % self. apsizestr)

            # initialize IRAF
            iraf.noao(Stdout=1)
            iraf.digiphot(Stdout=1)
            iraf.daophot(Stdout=1, verify='no')
            iraf.tables(Stdout=1)
            iraf.ttools(Stdout=1)
            iraf.astutil(Stdout=1)

            # set some parameters for iraf photometry
            iraf.fitskypars.setParam('salgori', self.pars.iraf_phot['salgori'])
            iraf.fitskypars.setParam('annulus', self.pars.iraf_phot['annulus'])
            iraf.fitskypars.setParam('dannulu', self.pars.iraf_phot['dannulu'])
            iraf.centerpars.setParam('calgori', self.pars.iraf_phot['calgori'])
            iraf.centerpars.setParam('cbox',    self.pars.iraf_phot['cbox'])
            iraf.centerpars.setParam('maxshif', self.pars.iraf_phot['maxshif'])
            iraf.photpars.setParam('apertur', self.apsizestr)

            o = iraf.phot(image='@'+os.path.join(self.pars.wdir, self.dataset.framesdir, 'imagelist'), wcsin='world',
                          coords='@'+os.path.join(self.pars.wdir, self.irafphotdir, 'coordlist'),
                          output='@'+os.path.join(self.pars.wdir, self.irafphotdir, 'outputlist'),
                          interactive='no', verify='no', Stdout=1)
Beispiel #13
0
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()