def vhelio_correct(WORK_DIR):
  print '\n + VHELIO correction\n'
    
  for obj in observations[WORK_DIR]['objects']:
    obj = obj+'.ec'

    utm = iraf.hselect(images=obj, fields='UTMIDDLE', Stdout=1, expr='yes')
    year = utm[0][:4]
    month = utm[0][5:7]
    day = utm[0][8:10]
    h = int(utm[0][11:13])
    m = int(utm[0][14:16])
    s = int(utm[0][17:19])

    ra = iraf.hselect(images=obj, fields='RA', Stdout=1, expr='yes')[0].split(':')
    dec = iraf.hselect(images=obj, fields='DEC', Stdout=1, expr='yes')[0].split(':')
    ra = float(ra[0])+int(ra[1])/60.+float(ra[2])/3600.
    dec = float(dec[0])+int(dec[1])/60.+float(dec[2])/3600.
    
    shutil.copy(obj+'.fits', obj+'.vh.fits')
    iraf.hedit(images=obj+'.vh', fields='UT', value=h+m/60.+s/3600., add='yes', verify='no')
    iraf.hedit(images=obj+'.vh', fields='EPOCH', value=year, add='yes', verify='no')
    iraf.rvcorrect(images=obj+'.vh', imupdat='yes', epoch=year, observa='ekar', year=year, month=month, day=day, ut=h+m/60.+s/3600., ra=ra, dec=dec)
    iraf.dopcor(input=obj+'.vh', redshift='-vhelio', isveloc='yes', dispers='yes')

    obj = obj+'.nosky'
    shutil.copy(obj+'.fits', obj+'.vh.fits')
    iraf.hedit(images=obj+'.vh', fields='UT', value=h+m/60.+s/3600., add='yes', verify='no')
    iraf.hedit(images=obj+'.vh', fields='EPOCH', value=year, add='yes', verify='no')
    iraf.rvcorrect(images=obj+'.vh', imupdat='yes', epoch=year, observa='ekar', year=year, month=month, day=day, ut=h+m/60.+s/3600., ra=ra, dec=dec)
    iraf.dopcor(input=obj+'.vh', redshift='-vhelio', isveloc='yes', dispers='yes')
def solar_velocity_shift(imagelist, restwave):
    """Opens the images of a data cube and shifts the wavelength planes
    so they are shifted to the solar frame. This is accomplished using the
    IRAF task 'rvcorrect'.

    It does it in a really really stupid way, which is to temporarily redirect
    IRAF's output to a string, because IRAF doesn't actually save the output
    anywhere (that I know of), it only prints it to the terminal. Then this
    routine searches through that string for the necessary value. It's a bit
    backwards, but it works!

    Note that the boost here is a Lorentz boost, not a Galilean boost, though
    values for either will be similar (i.e. the relativistic formula is used)

    Inputs:
    imagelist -> List of strings, the paths to wavelength images to be
                     updated.
    restwave -> The rest wavelength of the line you're interested in.

    """

    c = 299792.458  # in km/s

    for i in range(len(imagelist)):
        sys.stdout = iraf_output = StringIO()
        image = FPImage(imagelist[i], update=True)
        iraf.rvcorrect(header="N",
                       input="N",
                       imupdate="N",
                       observatory="SAAO",
                       year=float(image.datestring.split("-")[0]),
                       month=float(image.datestring.split("-")[1]),
                       day=float(image.datestring.split("-")[2]),
                       ut=image.ut,
                       ra=image.ra,
                       dec=image.dec,
                       vobs=0,
                       mode="a")
        image.solarvel = float(iraf_output.getvalue().split()[-6])
        iraf_output.close()
        beta_earth = (((image.wave/restwave)**2-1) /
                      ((image.wave/restwave)**2+1))
        beta_shift = image.solarvel/c
        beta_helio = (beta_earth+beta_shift)/(1+beta_earth*beta_shift)
        image.wave = restwave*(1+beta_helio)/np.sqrt(1-beta_helio**2)
        image.wave[np.isnan(image.wave)] = 0
        image.close()

    sys.stdout = sys.__stdout__

    return
Пример #3
0
def barycor(filelist_new):
    iraf.reset(obsdb='home$obsdb.dat')
    for i in range(len(filelist_new)):
        hdulist = fits.open(filelist_new[i])
        header_time_of_observation = hdulist[0].header['DATE-OBS']
        year_of_observation = int(header_time_of_observation[:4])
        month_of_observation = int(header_time_of_observation[5:7])
        day_of_observation = int(header_time_of_observation[8:10])
        right_ascension = hdulist[0].header['RA']
        declination = hdulist[0].header['DEC']

        try:
            ut_of_observation = hdulist[0].header['UT']
        except KeyError:
            ut_of_observation = int(header_time_of_observation[11:13]) + int(
                header_time_of_observation[14:16]) / 60 + int(
                    header_time_of_observation[17:19]) / 3600
        exposure_time = hdulist[0].header['EXP_TIME']

        output_filename_dummy = filelist_new[i].replace("norm.", "norm.dummy.")
        output_filename_dummyI = output_filename_dummy.replace(
            "norm-1", "norm-1.dummy.")
        output_filename = output_filename_dummyI.replace(
            "merged", "merged.dummy.")

        iraf.scopy(filelist_new[i], output_filename)
        iraf.hedit(images=output_filename,
                   fields="UT",
                   value=ut_of_observation)
        iraf.hedit(images=output_filename, fields="EPOCH", value="2000")
        iraf.hedit(images=output_filename,
                   fields="EXP-TIME",
                   value=exposure_time)
        iraf.rvcorrect(images=output_filename,
                       year=year_of_observation,
                       month=month_of_observation,
                       day=day_of_observation,
                       ut=ut_of_observation,
                       ra=right_ascension,
                       dec=declination)

        output_filename_final = output_filename.replace("dummy.", "rvcorrect.")
        print(output_filename, output_filename_final)
        iraf.dopcor(output_filename,
                    output_filename_final,
                    redshift="-VHELIO",
                    isvelocity="yes")

        os.remove(output_filename)
        hdulist.close()
Пример #4
0
def rv_correct(hdu):
    date_obs = hdu[0].header['DATE-OBS'].split('-') 
    iraf.rvcorrect(header="N", input="N",
                   imupdate="N",
                   observatory="SAAO",
                   year=float(date_obs[0]),
                   month=float(date_obs[1]),
                   day=float(date_obs[2]),
                   ut=hdu[0].header['TIME-OBS'],
                   ra=hdu[0].header['RA'],
                   dec=hdu[0].header['DEC'],
                   vobs=0,
                   mode="a")
    return iraf.rvcorrect.vlsr
Пример #5
0
def rv_correct(img):
    hdu = fits.open(img)
    date_obs = hdu[0].header['DATE-OBS'].split('-')
    iraf.rvcorrect(header="N", input="N",
                   imupdate="N",
                   observatory="SAAO",
                   year=float(date_obs[0]),
                   month=float(date_obs[1]),
                   day=float(date_obs[2]),
                   ut=hdu[0].header['TIME-OBS'],
                   ra=hdu[0].header['RA'],
                   dec=hdu[0].header['DEC'],
                   vobs=0,
                   mode="a")
    return iraf.rvcorrect.vlsr
Пример #6
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
Пример #7
0

def ImportPackages():
    iraf.noao(_doprint=0)
    iraf.rv(_doprint=0)
    iraf.keywpars.setParam("ra", "CAT-RA")
    iraf.keywpars.setParam("dec", "CAT-DEC")
    # must use UT as UT mid exposure for RV correct or it
    # messes up the HJD values by a lot
    iraf.keywpars.setParam("ut", "UT-M_E")
    iraf.keywpars.setParam("utmiddl", "")
    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.rvcorrect.setParam("imupdat", "yes")
    iraf.rvcorrect.setParam("observa", "lapalma")

    return 0


ImportPackages()
iraf.rvcorrect(images="*.fits")