Thursday, February 23, 2017

Barycentric velocity correction for wavelengths

Astropy has all the infrastructure needed to calculate the barycentric correction needed to correct the wavelengths of a spectrum, but hasn't made a wrapper yet.  Still an open ticket.

(Gloss: by barycentric velocity correction, I mean removing the radial velocity of the observatory toward the target with respect to the barycenter of the solar system.  Affects spectra by up to +-30 km/s, so relevant for moderate or high resolution spectra.)

So, I adapted this gist by Stuart Littlefair.  I wrote a small module that computes the barycentric correction and applies it to a spectrum.   I tested that it agrees within 0.01 km/s with the correction computed by Jskycalc.  Good enough for extragalactic purposes; dunno if safe for exoplanets.

Here's a code snippet that reads in a bunch of spectra and applies the barycentric correction:
def get_the_spectra(filenames, obslog, colwav='obswave') :
    df = {}
    for thisfile in filenames :
        print "loading file ", thisfile
        df[thisfile] = pandas.read_table(thisfile, delim_whitespace=True, comment="#")
        # Apply the Barycentric correction
        thisobs = obslog.loc[thisfile]
        keck = EarthLocation.of_site('keck')
        my_target = SkyCoord(thisobs['RA'], thisobs['DEC'], unit=(units.hourangle, units.deg), frame='icrs')
        my_start_time = Time( thisobs['DATE-OBS'] + "T" + thisobs['UT_START'] , format='isot', scale='utc')
        midpt = TimeDelta(thisobs['EXPTIME'] / 2.0, format='sec')
        my_time = my_start_time + midpt  # time at middle of observation
        barycor_vel = jrr.barycen.compute_barycentric_correction(my_time, my_target, location=keck)
        print "FYI, the barycentric correction factor for", thisfile,  "was", barycor_vel
        jrr.barycen.apply_barycentric_correction(df[thisfile], barycor_vel, colwav='obswave', colwavnew='wave') #  
        df[thisfile]['Nfiles'] = 1 # N of exposures that went into this spectrum
    return(df)  # return a dictionary of dataframes of spectra

No comments:

Post a Comment