コード例 #1
0
from astroquery.simbad import Simbad

S = Simbad()
S.add_votable_fields('rv_value')

dir = sys.argv[1]
files = glob.glob(dir + '/*p08.fits')
templates = glob.glob('/home/rajikak/tools/RV_standards/*')

print("*************")

for file in files:
    a = pyfits.open(file)
    object_name = a[1].header['OBJNAME']

    #get RV data on the standard:
    #From Vizier table:
    result = Vizier.query_object(object_name)
    interesting_table = result['J/ApJS/141/503/table1']
    object_RV = float(interesting_table[0]['__RV_']) / 1000.

    flux_stamp, wave = ps.read_and_find_star_p08(file)
    spectrum, sig = ps.weighted_extract_spectrum(flux_stamp)
    rv, rv_sig = ps.calc_rv_template(spectrum, wave, sig, templates,
                                     ([0, 5400], [6870, 6890]))
    rv += a[1].header['RADVEL']

    print("object_name: " + object_name)
    print("object RV: " + str(object_RV) + "km/s")
    print("Retrieved RV from standards: " + str(rv) + "km/s")
    print("*************")
コード例 #2
0
                        else:
                            sptype = Temp_sptype[ind]
                    else:
                        templates = glob.glob(templates_dir + '/*.fits')
                        Temp_sptype[ind] = ' '

                    if args.correct_sky == 'True':
                        #Calculating RV from skylines
                        if args.absorption == 'False':
                            spectrum, sig = ps.weighted_extract_spectrum(
                                sky, var)
                            snr_val = np.max(spectrum) / np.median(spectrum)
                            SNR.append(snr_val)
                            rv_sky, rv_sky_sig, temp_used = ps.calc_rv_template(
                                spectrum,
                                wave,
                                sig,
                                sky_temp, (sky_intervals),
                                heliocentric_correction=0.0)
                            temp_hdu = fits.open('/Users/rajikak/tools/' +
                                                 temp_used)
                            spectrum_interp = np.interp(
                                wave_template, wave * (1 - (rv_sky) / 2.998e5),
                                spectrum)

                            print("Skyline offset=  " + str(rv_sky) + ',    ' +
                                  str(rv_sky_sig))

                            if np.isnan(rv_sky) or np.isnan(
                                    rv_sky_sig) or np.abs(rv_sky) > 50.:
                                print("Could not get reliable sky RV")
                                rv_sky = 0.0
コード例 #3
0
    ccd = hdu[0].header['CCDTEMP']
    CCD_Temp.append(ccd)
    cam = hdu[0].header['CAMTEMPB']
    Cam_Temp.append(cam)

    for slit in range(slits):
        print("DOING SLIT:", slit)
        if args.weight_direction != 'hor':
            flux_stamp = flux[:, slit, :]
        else:
            flux_stamp = flux[slit]
        flux_stamp =  np.nan_to_num(flux_stamp)
        flux_stamp = np.array([flux_stamp])
        spectrum,sig = ps.weighted_extract_spectrum(flux_stamp)
        template = ['templates/slit_'+str(slit)+'.fits']
        rv,rv_sig, temp_used = ps.calc_rv_template(spectrum,wave,sig,template, ([0,5400],[6870,6890]), save_figures=False, save_dir='Images/', heliocentric_correction=0.0)
        RV[slit].append(rv)
        print('rv =', rv)


RV = np.array(RV)
RV_med = []
RV_std = []
for obs in range(len(RV[0])):
    RV_med.append(np.median(RV[np.where(np.isnan(RV[:,obs])==False)[0],obs]))
    RV_std.append(np.std(RV[np.where(np.isnan(RV[:,obs])==False)[0],obs]))



print("NOW THAT WE'VE GONE THROUGH ALL THE FILES, LETS PLOT THIS!")
plt.clf()
コード例 #4
0
            full_file_path = reduced_dir + file_dir + '/' + file

            if os.path.isfile(full_file_path):
                hdu = pyfits.open(full_file_path)
                h_corr = hdu[0].header['RADVEL']
                Hcorr.append(h_corr)

                flux, wave, var, sky = ps.read_and_find_star_p08(
                    full_file_path, sky_rad=5, return_sky=True)
                spectrum, sig = ps.weighted_extract_spectrum(flux, var)

                if args.absorption != 'False':
                    if args.all_spectral_types != 'False':
                        rv_abs, rv_abs_sig, temp_used = ps.calc_rv_template(
                            spectrum,
                            wave,
                            sig,
                            abs_temps, (abs_bad_ints),
                            heliocentric_correction=0.0)
                        print(("ABSORPTION OFFSET= " + str(rv_abs) + ', ' +
                               str(rv_abs_sig)))
                    else:
                        if RV_standard_data[ind][1][0] in abs_corr_spt:
                            rv_abs, rv_abs_sig, temp_used = ps.calc_rv_template(
                                spectrum,
                                wave,
                                sig,
                                abs_temps, (abs_bad_ints),
                                heliocentric_correction=0.0)
                            print(("ABSORPTION OFFSET= " + str(rv_abs) + ', ' +
                                   str(rv_abs_sig)))
                        else:
コード例 #5
0
            interesting_table = result['J/ApJS/141/503/table1']
            object_RV = float(interesting_table[0]['__RV_']) / 1000.
        except:
            object_RV = float(data['RV_VALUE'])
        Actual_RV.append(object_RV)
    else:
        h_corr = hdu[0].header['RADVEL']
        ind = RV_standard.index(Obj_name)
        pref_temp = Temp_to_use[ind]

        flux, wave = ps.read_and_find_star_p08(file)
        spectrum, sig = ps.weighted_extract_spectrum(flux)

        rv, rv_sig, temp_used = ps.calc_rv_template(
            spectrum,
            wave,
            sig, [pref_temp], ([0, 5400], [6870, 6890]),
            save_figures=False,
            heliocentric_correction=h_corr)

        Delta_RV = Actual_RV[ind] - rv

        Time_line[ind].append(MJD)
        RV_variation[ind].append(Delta_RV)

for sit in range(len(RV_standard)):
    plt.clf()
    plt.plot(Time_line[sit], RV_variation[sit], 'o')
    plt.axhline(y=0.0)
    plt.xlabel('MJD')
    plt.ylabel('RV Variation')
    plt.title(RV_standard[sit] + '_RV_' + str(Actual_RV[sit]))
コード例 #6
0
"""
Determine radial velocities
How is template determined?
"""

import process_stellar as ps

ps.calc_rv_template(spect,wave,sig, template_dir,bad_intervals,smooth_distance=101, \
    gaussian_offset=1e-4,nwave_log=1e4,oversamp=1,fig_fn='',convolve_template=True,\
    starnumber=0, plotit=False, save_figures=False, save_dir='./', heliocentric_correction=0.)


    """Compute a radial velocity based on an best fitting template spectrum.
    Teff is estimated at the same time.
    
    Parameters
    ----------
    spect: array-like
        The reduced WiFeS spectrum
        
    wave: array-like
        The wavelengths corresponding to the reduced WiFeS spectrum
        
    template_conv_dir: string
        The directory containing template spectra convolved to 0.1 Angstrom resolution
        
    bad_intervals: 
        List of wavelength intervals where e.g. telluric absorption is bad.
        
    smooth_distance: float
        Distance to smooth for "continuum" correction
コード例 #7
0
     SNR.append(snr_val)
     if snr_val >= 3.0:
         rv,rv_sig, temp_used = ps.calc_rv_template(spectrum,wave,sig,templates, (bad_intervals), save_figures=False, save_dir='Images/', heliocentric_correction=0.0, fig_fn='Images/xcorr_slit_'+str(slit))
     else:
         rv = np.nan
     RV_slits[slit].append(rv)
 '''
 spectrum, sig = ps.weighted_extract_spectrum(sky)
 snr_val = np.max(spectrum) / np.median(spectrum)
 SNR.append(snr_val)
 if snr_val >= 5.0:
     rv, rv_sig, temp_used = ps.calc_rv_template(
         spectrum,
         wave,
         sig,
         templates, (bad_intervals),
         save_figures=True,
         save_dir='Images/',
         heliocentric_correction=0.0,
         fig_fn='Images/xcorr_' + file.split('-')[-1].split('.')[0])
     '''
     spectrum_interp = np.interp(wave_template,wave[100:-100]*(1 - (0.0 - 0.0)/2.998e5),spectrum[100:-100])
     sky_templates.append(spectrum_interp)
     '''
     #ps.make_wifes_p08_template(file, 'templates/', rv=0.0, )
 else:
     print("SNR TOO LOW")
     rv = np.nan
     rv_sig = np.nan
 RV.append(rv)
 RV_sig.append(rv_sig)
コード例 #8
0
    spectrum,sig = ps.weighted_extract_spectrum(flux)

    templates = glob.glob('/Users/rajikak/tools/templates/*') + glob.glob('/Users/rajikak/tools/self_templates/*')
    for temp in templates:
        if Obj_name in temp and ''.join(Obs_date.split('-')) not in temp and use_self == True:
            templates = [temp]
            print("Observed before so will compare with itself")
            break
        else:
            templates = glob.glob('/Users/rajikak/tools/templates/*')
    if len(templates) >1:
        print("Using RV standards")
    #templates = glob.glob('/Users/rajikak/tools/self_templates/*')
    #templates = glob.glob('/Users/rajikak/Observational_Data/Reduced_Wifes_Obs/20140622/*-0030*')
    '''
    for temp in templates:
        if Obj_name in temp and ''.join(Obs_date.split('-')) in temp:
            templates.remove(temp)
            print "removed template:", temp
    '''

    #PLOT TEMPLATE SPECTRA VS REAL DATA AND PLOT CROSS_CORRELATION FUNCTIONS WITH RV
    rv,rv_sig, temp_used = ps.calc_rv_template(spectrum,wave,sig,templates, ([0,5400],[6870,6890]), save_figures=True, save_dir=temp_dir, heliocentric_correction=h_corr)

    write_string = Obj_name+','+RA+','+DEC+','+str(Obs_date)+','+str(rv)+','+str(rv_sig)+','+str(h_corr)+','+str(temp_used)+'\n'
    print(write_string)
    f.write(write_string)
    f.close()
    #MAKE LATEX

f.close()