示例#1
0
def loadtemplatespectrum(filename, resolution, telluric_linelist, ccf_mask, velocity_step, wavemask):
    
    spc = Spectrum(filename)
    
    if wavemask :
        spc.applyMask(wavemask)

    barycentricTime = spc.barycentricTime()
    barycentric_vel = barycentric_velocity(spc)
    
    spc.continuumOrderByOrder(binsize = 30, overlap = 10)
    spc.normalizeByContinuum(constant=10.0)
    
    spc.binningOrderByOrder(rvsampling_kps=2.4, median=False)
    spc.sortByWavelength()

    ispectrum = ispec.create_spectrum_structure(spc.wl,spc.flux)

    smoothed_spectrum = ispec.convolve_spectrum(ispectrum, resolution)

    tel_models, tel_ccf = ispec.cross_correlate_with_mask(smoothed_spectrum, telluric_linelist, \
                                                        lower_velocity_limit=-10, upper_velocity_limit=10, \
                                                        velocity_step=0.1, mask_depth=0.01, \
                                                        fourier = False, only_one_peak = True)
    tel_rv = tel_models[0].mu()
    
    min_vel = -30.0
    max_vel = +30.0
    # Only the 25% of the deepest ones:
    dfilter = telluric_linelist['depth'] > np.percentile(telluric_linelist['depth'], 75)
    tfilter = ispec.create_filter_for_regions_affected_by_tellurics(smoothed_spectrum['waveobs'], \
                                                                    telluric_linelist[dfilter], min_velocity=-tel_rv+min_vel, \
                                                                    max_velocity=-tel_rv+max_vel)
    
    
    clean_spectrum = smoothed_spectrum[~tfilter]


    corrected_spectrum = ispec.correct_velocity(clean_spectrum, tel_rv - barycentric_vel)

    models, ccf = ispec.cross_correlate_with_mask(clean_spectrum, ccf_mask, \
                                                  lower_velocity_limit=-100, upper_velocity_limit=100, \
                                                  velocity_step=velocity_step, mask_depth=0.01, \
                                                  fourier=False)
    rv = models[0].mu()

    clean_corrected_spectrum = ispec.correct_velocity(corrected_spectrum, rv)

    return clean_corrected_spectrum
示例#2
0
try:
    options,args = parser.parse_args(sys.argv[1:])
except:
    print "Error: check usage with extract.py -h "; sys.exit(1);

if options.verbose:
    print 'Input spectrum: ', options.input
    print 'Output wavelength range: ', options.wlrange
    print 'Spectrum type: ', options.spectype
    print 'Polar option: ', options.polar
    print 'Telluric correction: ', options.telluric
    print 'Heliocentric correction: ', options.helio

wl0, wlf = options.wlrange.split()

spc = Spectrum(options.input, options.spectype, options.polar, options.telluric, options.helio)

#spc.info()
wl,flux,fluxerr = spc.extractChunk(float(wl0), float(wlf))

chunk = SpectrumChunk(wl,flux,fluxerr)

chunk.snrfilter(15.0)

chunk.removeBackground(2.0)

#chunk.binning(0.5, median=True)

#chunk.fft_filter()

init_guess = [656.270,2500, 0.5]
parser.add_option("-r", action="store_true", dest="helio", help="heliocentric correction", default=False)

try:
    options,args = parser.parse_args(sys.argv[1:])
except:
    print "Error: check usage with App_normalizeFcal.py -h "; sys.exit(1);

if options.verbose:
    print 'Input spectrum: ', options.input
    print 'Output spectrum file: ', options.output
    print 'Output spectrum file: ', options.outputcontinuum
    print 'RV sampling for output spectrum in km/s: ', options.rvsampling
    print 'Polar option: ', options.polar
    print 'Telluric correction: ', options.telluric
    print 'Heliocentric correction: ', options.helio

spc = Spectrum(options.input, 'fcal', options.polar, options.telluric, options.helio)

spc.applyMask()

spc.binning(float(options.rvsampling), median=True)

spc.continuum(binsize=200, overlap=100, sigmaclip=3.0, window=3)

spc.normalizeByContinuum()

spc.saveToFile(options.output)

if options.outputcontinuum :
    spc.saveContinuumToFile(options.outputcontinuum)
示例#4
0
                  dest="helio",
                  help="heliocentric correction",
                  default=False)

try:
    options, args = parser.parse_args(sys.argv[1:])
except:
    print "Error: check usage with App_lsd.py -h "
    sys.exit(1)

if options.verbose:
    print 'Input spectrum: ', options.input
    print 'Output spectrum file: ', options.output
    print 'Lines mask: ', options.linesmask
    print 'File with wavelength ranges: ', options.wavemask
    print 'Spectrum type: ', options.spectype
    print 'RV sampling for output spectrum in km/s: ', options.rvsampling
    print 'Plot output spectrum: ', options.plot
    print 'Telluric correction: ', options.telluric
    print 'Heliocentric correction: ', options.helio

if options.verbose:
    print "Loading spectrum"

spc = Spectrum(options.input,
               options.spectype,
               False,
               options.telluric,
               options.helio,
               Sort=False)
示例#5
0
    print 'Input directory: ', options.inputdir
    print 'Object name: ', options.object
    print 'Spectrum type: ', options.spectype
    print 'Polar option: ', options.polar
    print 'Telluric correction: ', options.telluric
    print 'Heliocentric correction: ', options.helio


heliumlines = [447.148, 492.193, 501.568, 587.561, 667.815, 706.518]

delta_wl = 0.5

filelist = espectrolib.generateList(options.inputdir, options.object)

for filepath in filelist :
    spc = Spectrum(filepath, options.spectype, options.polar, options.telluric, options.helio)

    rvvalues = []
    for line in heliumlines :
        wl_line = line
        wl0, wlf = wl_line-delta_wl, wl_line+delta_wl
    
        wl,flux,fluxerr = spc.extractChunk(float(wl0), float(wlf))
        chunk = SpectrumChunk(wl,flux,fluxerr)
        chunk.removeBackground(0.1)
        init_guess = [wl_line,-0.1, 0.3]
        wlcen, amp, sigma = chunk.fitgaussian(init_guess)
        rv = (wlcen[0] - wl_line)*constants.c/wl_line
        rvvalues.append(rv)
    
    median_rv = np.median(rvvalues)
示例#6
0
if options.verbose:
    print 'Input sample file: ', options.inputsample
    print 'Data directory: ', options.datadir
    print 'Output calibration matrix: ', options.outputcalibmatrix

listOfStarSpectra = mcallib.get_spectrafilepaths(options.datadir)

twomassid, id, teff, feh = mcallib.loadSampleOfCalibrators(options.inputsample)

Tcal = []
FeHcal = []
ewcal = []

for file in listOfStarSpectra:

    spc = Spectrum(file)
    objname = spc.object.replace(" ", "").upper()

    if options.verbose:
        print "Processing spectrum: ", file, objname

    if spc.instrument == 'ESPaDOnS' or spc.instrument == 'NARVAL':
        spc.resampling(0.01, 4000, 10400)

    for i in range(len(id)):
        if objname in id[i].upper() or objname in twomassid[i].upper():
            spc.equivalentWidths(override=False, verbose=options.verbose)
            ewcal_tmp = spc.eqwidths
            if not np.any(np.isnan(ewcal_tmp)):
                ewcal.append(ewcal_tmp)
                Tcal.append(teff[i])
示例#7
0
if options.verbose:
    print 'Input spectrum: ', options.input

lines = [
    402.619, 412.082, 447.148, 471.315, 492.193, 501.568, 587.562, 667.815,
    706.519
]

#lines = [447.148, 471.315, 492.193, 501.568, 587.562, 667.815, 706.519]

delta_rv_kps = 400

gaussian = lambda x, a, c, w: a * np.exp(-((x - c) / w)**2)
gaussfunc = np.vectorize(gaussian)

spc = Spectrum(options.input, Sort=False)

shift = 0.0
dshift = 0.015

for line in lines:
    wl_line = line

    delta_wl = 1000.0 * delta_rv_kps * wl_line / constants.c

    wl0, wlf = wl_line - delta_wl, wl_line + delta_wl

    wl, flux, fluxerr = spc.extractChunk(float(wl0), float(wlf))
    chunk = SpectrumChunk(wl, flux, fluxerr)
    chunk.removeBackground(0.1)
    init_guess = [wl_line, -0.1, 0.3]
示例#8
0
    print 'File with wavelength ranges: ', options.wavemask
    print 'Spectrum type: ', options.spectype
    print 'Polar option: ', options.polar
    print 'Telluric correction: ', options.telluric
    print 'Heliocentric correction: ', options.helio

useMedian = True  # method to bin data (if False -> use Mean)
outputRVSampling = 10.0  # in km/s

filelist, rvfilelist = espectrolib.generateListWithRVs(options.inputdir,
                                                       options.object)

sourceRVs = espectrolib.loadSourceRVs(rvfilelist)
stackspc = Spectrum(filelist[0],
                    "raw",
                    options.polar,
                    options.telluric,
                    options.helio,
                    SourceRV=sourceRVs[0] / 1000.0)

stackspc.setAllFluxesToZero()

spc = []

for i in range(len(filelist)):
    print filelist[i]
    spc.append(
        Spectrum(filelist[i],
                 options.spectype,
                 options.polar,
                 options.telluric,
                 options.helio,
示例#9
0
parser.add_option("-i", "--input", dest="input", help="Input spectrum file",type='string',default="")
parser.add_option("-w", "--wlrange", dest="wlrange", help="Output wavelength range (nm)",type='string',default="")
parser.add_option("-p", action="store_true", dest="polar", help="polar",default=False)
parser.add_option("-v", action="store_true", dest="verbose", help="verbose",default=False)

try:
    options,args = parser.parse_args(sys.argv[1:])
except:
    print "Error: check usage with espectro.py -h "; sys.exit(1);

if options.verbose:
    print 'Input spectrum: ', options.input
    print 'Output wavelength range: ', options.wlrange
    print 'Polar? ', options.polar

wl0, wlf = options.wlrange.split()

spc = Spectrum(options.input, polar=options.polar)

#spc.info()
wl,flux = spc.extractChunk(float(wl0), float(wlf))

dl = 2.0
wlranges = [(float(wl0),float(wl0)+dl),(float(wlf)-dl,float(wlf))]
wl,flux = espectrolib.removeBackground(wl,flux,wlranges)

for i in range(len(wl)) :
    print wl[i], flux[i]

#spc.printdata()
示例#10
0
#templatefile = "/Users/edermartioli/Desktop/51Peg/testdata/1603681o.m.fits.gz"
templatefile = "/Users/edermartioli/Desktop/51Peg/testdata/1604052o.m.fits.gz"

if options.template :
    templatefile = options.template
    templatespectrum = loadtemplatespectrum(templatefile, resolution, telluric_linelist, ccf_mask, velocity_step, options.wavemask)
#---------------

output = []

for filepath in filelist :
    head, filename = os.path.split(filepath)
    
    if options.verbose: print "Loading spectrum file: ", filename

    spc = Spectrum(filepath, options.spectype)
    
    if options.wavemask :
        spc.applyMask(options.wavemask)

    snrmask = np.where(spc.fluxerr > 1.0)
    snr = np.mean(spc.flux[snrmask] / spc.fluxerr[snrmask])
    if options.verbose: print "Mean SNR: ",snr

    barycentricTime = spc.barycentricTime()
    if options.verbose: print "Barycentric Time: ",barycentricTime

    barycentric_vel = barycentric_velocity(spc)
    if options.verbose: print "Barycentric velocity correction: ",barycentric_vel

    if options.spectype != "norm" :
示例#11
0
if options.verbose:
    print 'Data directory: ', options.datadir
    print 'Calibration matrix: ', options.calibmatrix

listOfStarSpectra = mcallib.get_spectrafilepaths(options.datadir)

print "--------------------------------------------------"
print "File","Object","[Fe/H]_corr","[Fe/H]","e[Fe/H]","Teff_corr","Teff","eTeff","H-alpha", "RV(km/s)"
print "--------------------------------------------------"

for file in listOfStarSpectra :

    if options.verbose :
        print "Processing spectrum: ", file

    spc = Spectrum(file, FFT=options.fft)

    if spc.instrument == 'ESPaDOnS' :
        spc.resampling(0.01,4000,10400)
    elif spc.instrument == 'NARVAL' :
        spc.resampling(0.01,4000,10400)

    spc.equivalentWidths(override=True,verbose=options.verbose)

    spc.calculateTeffAndFeH(options.calibmatrix, verbose=options.verbose)

    spc.halphaActivity(verbose=options.verbose)

    #spc.info()
    #spc.printdata()