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
options,args = parser.parse_args(sys.argv[1:]) except: print "Error: check usage with App_iSpecTest.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 spc = Spectrum(options.input, options.spectype, options.polar, options.telluric, options.helio) spc.continuumOrderByOrder(binsize = 30, overlap = 10) spc.normalizeByContinuum(constant=10.0) spc.binningOrderByOrder(rvsampling_kps=2.5, median=False) spc.sortByWavelength() ispectrum = ispec.create_spectrum_structure(spc.wl,spc.flux) resolution = 80000 smoothed_star_spectrum = ispec.convolve_spectrum(ispectrum, resolution) mask_file = ispec_dir + "input/linelists/CCF/Narval.Sun.370_1048nm/mask.lst" ccf_mask = ispec.read_cross_correlation_mask(mask_file) models, ccf = ispec.cross_correlate_with_mask(smoothed_star_spectrum, ccf_mask, \ lower_velocity_limit=-50, upper_velocity_limit=50, \ velocity_step=0.05, mask_depth=0.01, \ fourier=False) components = len(models)
False, options.telluric, options.helio, Sort=False) if options.verbose: print "Calculating continuum" spc.continuumOrderByOrder(binsize=30, overlap=10, linesmask=options.linesmask) if options.verbose: print "Normalizing by the continuum" spc.normalizeByContinuum(constant=10.0) if options.verbose: print "Binning data" spc.binningOrderByOrder(rvsampling_kps=float(options.rvsampling), median=False) if options.verbose: print "Applying mask" spc.applyMask(options.wavemask) if options.verbose: print "Sorting data by wavelength" spc.sortByWavelength() if options.plot: plt.plot(spc.wl, spc.flux) plt.show() if options.output == 'print' or options.output == '': spc.info()
for i in range(len(filelist)): x.append((spc[i].flux)[j]) if useMedian: stackspc.flux[j] = np.median(x) stackspc.fluxerr[j] = np.std(x) else: stackspc.flux[j] = np.mean(x) stackspc.fluxerr[j] = np.std(x) stackspc.continuumOrderByOrder(binsize=30, overlap=10, linesmask=options.linesmask) #stackspc_copy1 = copy.deepcopy(stackspc) stackspc.normalizeByContinuum(constant=10.0) stackspc.binningOrderByOrder(rvsampling_kps=outputRVSampling, median=True) stackspc.applyMask(options.wavemask) #stackspc.binning(rvsampling_kps=outputRVSampling, median=True) """ #for o in range(22,55) : for o in range(45,52) : print o #continuum = stackspc.extractOrderContinuum(o) #plt.plot(orderwl, continuum) #orderwlc, orderfluxc, orderfluxerrc = stackspc_copy1.extractOrder(o) #continuum = stackspc_copy1.extractOrderContinuum(o) #plt.plot(orderwlc, orderfluxc) #plt.plot(orderwlc, continuum)