'/')[-1][:-4] + 'spec.wavsolpars.pkl' print "\t\tUnpickling wavelength solution from", pkl_wsol, " ..." wsol_dict = pickle.load(open(pkl_wsol, 'r')) # Apply new wavelength solution including barycentric correction equis = np.arange(data.shape[0]) for order in range(nord1): #order = 16 #print order m = order + ro0 chebs = GLOBALutils.Calculate_chebs(equis, m, npix=data.shape[0],\ order0=ro0, ntotal=nord1, Inverse=Inverse_m,nx=ncoef_x,nm=ncoef_m) WavSol = lbary_ltopo * ( 1.0 / m) * GLOBALutils.Joint_Polynomial_Cheby( wsol_dict['p1'], chebs, ncoef_x, ncoef_m) spec[0, order, :] = GLOBALutils.ToVacuum(WavSol) spec[1, order, :] = sci_S['chip1'][order, 1, :] #spec[1,order,:300] = 0. spec[2, order, :] = sci_S['chip1'][order, 2, :] spec[3, order, :] = spec[1, order, :] / sflat['chip1'][order][::-1] spec[4, order, :] = spec[2, order, :] * sflat['chip1'][order][::-1]**2 ccoef = GLOBALutils.get_cont_single(spec[0, order], spec[3, order], spec[4, order], ll=1.5, lu=5, nc=3) ratio = np.polyval(ccoef, spec[0, order]) L = np.where(spec[1, order, :] != 0) spec[5, order, :][L] = spec[3, order, :][L] / ratio[L]
# Apply new wavelength solution including barycentric correction equis = np.arange(data.shape[1]) del_vels = [] for order in range(n_useful): m = order + 37 chebs = GLOBALutils.Calculate_chebs(equis, m, npix=data.shape[1], order0=37, ntotal=n_useful, Inverse=Inverse_m, nx=ncoef_x, nm=ncoef_m) WavSol = GLOBALutils.ToVacuum( ((1. + 1.0e-6 * psh) / float(m)) * GLOBALutils.Joint_Polynomial_Cheby(pref, chebs, ncoef_x, ncoef_m) * lbary_ltopo) spec[0, order, :] = WavSol spec[1, order, :] = sci_S[order, 1, :] if len(np.where(np.isnan(spec[1, order, :]))[0]) > 0: spec[1, order, :] = sci_Ss[order, :] spec[2, order, :] = 1. / (spec[1, order, :] / gain + (ronoise / gain)**2) blaze = flat_S_n[order] #scipy.signal.medfilt(flat_S[order],21) spec[3, order, :] = spec[1, order, :] / blaze spec[4, order, :] = spec[2, order, :] * blaze**2 #cont_coef = continuum.NORM_single(spec[0,order,:],scipy.signal.medfilt(spec[3,order,:],7),orden=3) cont_coef = GLOBALutils.get_cont_single(spec[0, order], spec[3, order], spec[4, order], ll=1.5,
print('\t\tWavelength calibration:') print("\t\t\tInstrumental drift:",(1e-6*p_shift)*299792458.0) # Apply new wavelength solution including barycentric correction equis = np.arange( data.shape[1] ) if len(mjds_thar) > 1: p_shift = scipy.interpolate.splev(mjd,tck_shift) else: p_shift = 0. order = ro0 ind = 0 while order < ro0 + n_useful: oss = order - difo m = order chebs = GLOBALutils.Calculate_chebs(equis, m, npix=data.shape[1], order0=ro0, ntotal=n_useful, Inverse=Inverse_m,nx=ncoef_x,nm=ncoef_m) WavSol = GLOBALutils.ToVacuum( lbary_ltopo * (1.0 + 1.0e-6*p_shift) * (1.0/float(m)) * \ GLOBALutils.Joint_Polynomial_Cheby(p_ref,chebs,ncoef_x,ncoef_m) ) spec[0,ind,:] = WavSol spec[1,ind,:] = sci_S[oss,1] spec[2,ind,:] = sci_S[oss,2] fn = S_flat[oss,1,:] L = np.where( fn == 0 )[0] spec[3,ind,:] = spec[1,ind,:] / S_flat[oss,1,:] spec[4,ind,:] = spec[2,ind] * ( S_flat_n[oss,1,:] ** 2 ) spec[3,ind,L] = 0. spec[4,ind,L] = 0. ind+=1 order+=1 ccoefs = GLOBALutils.get_cont(spec[0,:,:],spec[3,:,:]) order = ro0 ind = 0
equis = np.arange(np.shape(thar_wav_Ss)[2]) order = orwa orre = 0 while orre < nup: m = order + oro0 chebs = GLOBALutils.Calculate_chebs(equis, m, order0=oro0, ntotal=nup, npix=len(thar_order), Inverse=Inverse_m, nx=ncoef_x, nm=ncoef_m) thar_wav_Ss[0, orre, :] = GLOBALutils.ToVacuum( (1.0 / m) * GLOBALutils.Joint_Polynomial_Cheby( p1, chebs, ncoef_x, ncoef_m))[::-1] thar_wav_Ss[1, orre, :] = thar_Ss[orre][::-1] orre += 1 order += 1 if (os.access(thar_fits_simple_wav, os.F_OK)): os.remove(thar_fits_simple_wav) hdu = pyfits.PrimaryHDU(thar_wav_Ss) hdu.writeto(thar_fits_simple_wav) #if rms_ms/np.sqrt(NL)<50: nThAr_ref.append(thar) nthtimes.append(thtime) pdict = {
for i in range(spec.shape[1]): if spec[0,i,0]<6500: first_o = i break last_o = spec.shape[1] for i in range(spec.shape[1]): if spec[0,i,0]<4300: last_o = i break spec1 = spec[:,first_o:last_o+1,:] # Read in mask ml, mh, weight = np.loadtxt(mask,unpack=True) ml_v = GLOBALutils.ToVacuum( ml ) mh_v = GLOBALutils.ToVacuum( mh ) # make mask larger accounting for factor ~3 lower res in DUPONT w/r to HARPS av_m = 0.5*( ml_v + mh_v ) ml_v -= 1.5*(av_m - ml_v) mh_v += 1.5*(mh_v - av_m) mask_hw_kms = (GLOBALutils.Constants.c/1e3) * 0.5*(mh_v - ml_v) / av_m disp = GLOBALutils.get_disp(obname, reffile=reffile) if disp == 0: known_sigma = False if vsini != -999 and vsini != 0.: disp = vsini else:
pdict1 = pickle.load(open(wavsol_pkl1,'r')) global1 = pdict1['p1'] or01 = pdict1['or0'] orwa1 = pdict1['orwa'] oro0 = pdict1['oro0'] final = np.zeros( [3, n_last-orwa1, np.shape(obj_S)[1]] ) equis = np.arange( np.shape(obj_S)[1] ) order = orwa1 orre = or01 final2 = np.zeros( [nn, np.shape(obj_S)[1]] ) while order < n_last: m = order + oro0 chebs = GLOBALutils.Calculate_chebs(equis, m, order0=oro0, ntotal=ntotal, npix=obj_S.shape[1], Inverse=Inverse_m, nx=ncoef_x,nm=ncoef_m ) WavSol = lbary_ltopo*(1.0/m) * GLOBALutils.Joint_Polynomial_Cheby(global1,chebs,ncoef_x,ncoef_m) final[0,orre,:] = GLOBALutils.ToVacuum(WavSol[::-1]) final[1,orre,:] = obj_S[orre,:][::-1] order += 1 orre += 1 final[2,:,:] = dupontutils.get_blaze(final[0,:,:],final[1,:,:]) blaze = np.zeros((2,final.shape[1],final.shape[2])) blaze[0] = final[0] blaze[1] = dupontutils.get_blaze(final[0,:,:],final[1,:,:]) if (os.access(dirout+'blaze_f.fits',os.F_OK)): os.remove( dirout+'blaze_f.fits' ) hdu = pyfits.PrimaryHDU( blaze ) hdu.writeto(dirout+'blaze_f.fits' ) else: