hdu = GLOBALutils.update_header(hdu, 'HIERARCH OBS ALTITUDE', h[ih].header['SITEALT']) hdu = GLOBALutils.update_header(hdu, 'HIERARCH TARG AIRMASS', h[ih].header['AIRMASS']) psh = scipy.interpolate.splev(mjd, tck_sh) # 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
models_path = base + "data/COELHO_MODELS/R_40000b/" ref_RES = 60000. # get ThAr closest in time im = np.argmin(np.absolute(np.array(ThAr_ref_dates) - mjd)) pkl_wsol = dirout + ThAr_ref[im].split( '/')[-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,
ref_RES = -999 # get ThAr closest in time im = np.argmin(np.absolute(np.array(ThAr_ref_dates) - mjd)) pkl_wsol = dirout + ThAr_ref[im].split('/')[-1][:-4] + 'spec_' + str( int(chip)) + '.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[1]) for order in range(nord): #order = 16 #print order m = order + ro0 chebs = GLOBALutils.Calculate_chebs(equis, m, npix=data.shape[1],\ order0=ro0, ntotal=nord, 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[order, 1, :] #spec[1,order,-100:] = 0. spec[2, order, :] = sci_S[order, 2, :] spec[3, order, :] = spec[1, order, :] / sflat[order] spec[4, order, :] = spec[2, order, :] * sflat[order]**2 I = np.where(spec[1, order] != 0)[0] cont_coef, x, y = hiresutils.get_cont(spec[0, order, I], scipy.signal.medfilt( spec[3, order, I], 11), n=3)
#show() p0 = np.zeros(npar_wsol) p0[0] = (32 + 93) * Global_ZP p1, G_pix, G_ord, G_wav, II, rms_ms, G_res = \ GLOBALutils.Fit_Global_Wav_Solution(All_Pixel_Centers, All_Wavelengths, All_Orders,\ np.ones(All_Intensities.shape), p0, Cheby=use_cheby,\ maxrms=50, Inv=Inverse_m,minlines=minlines_glob,order0=93, \ ntotal=n_useful,npix=len(thar_order),nx=ncoef_x,nm=ncoef_m) equis = np.arange(thar_S.shape[2]) for order in range(n_useful): m = order + 93 chebs = GLOBALutils.Calculate_chebs(equis, m, npix=thar_S.shape[2], order0=93, ntotal=n_useful, Inverse=Inverse_m, nx=ncoef_x, nm=ncoef_m) WavSol = (1.0 / m) * GLOBALutils.Joint_Polynomial_Cheby( p1, chebs, ncoef_x, ncoef_m) thar_data[0, order, :] = WavSol if (os.access(thar_out, os.F_OK)): os.remove(thar_out) hdu = pyfits.PrimaryHDU(thar_data) hdu = GLOBALutils.update_header(hdu, 'SLITNAME', hd['SLITNAME']) hdu.writeto(thar_out) #for orde in np.unique(G_ord):
#for odd in np.unique(G_ord): # Io = np.where(G_ord == odd)[0] # plot(G_wav[Io], G_res[Io],'.') #show() #print gfd thar_wav_Ss = np.zeros((2, nup, dthar.shape[1])) 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)
orders_offset = pdict['orders_offset'] orderi = 0 if orders_offset < 0: orderi = - orders_offset orderf = nord - 1 if orderf + orders_offset >= n_useful: orderf = n_useful - orders_offset - 1 final = np.zeros( [11, orderf - orderi + 1, np.shape(obj_S)[2]] ) equis = np.arange( obj_S.shape[2] ) for order in range(orderi,orderf+1): m = order + oro0 chebs = GLOBALutils.Calculate_chebs(equis, m, order0=oro0, ntotal=n_useful, npix=obj_S.shape[2], 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,order,:] = WavSol final[1,order,:] = obj_S[order,1,:] final[2,order,:] = obj_S[order,2,:] final[3,order,:] = final[1,order,:]/flat[order,1] final[4,order,:] = final[2,order,:]*(flat[order,1]**2) ccoef = GLOBALutils.get_cont_single(final[0,order],final[3,order],final[4,order],ll=1.5,lu=5,nc=3) L = np.where( final[1,order] != 0 ) ratio = np.polyval(ccoef,final[0,order]) final[5,order,:] = final[3,order,:]/ratio Inan = np.where( np.isnan(final[1,order,:]) == True )[0] final[5,order,Inan] = 1.
p0[0] = (25 + 49) * Global_ZP p1, G_pix, G_ord, G_wav, II, rms_ms, G_res = \ GLOBALutils.Fit_Global_Wav_Solution(All_Pixel_Centers, All_Wavelengths, All_Orders,\ np.ones(All_Intensities.shape), p0, Cheby=True,\ maxrms=MRMS, Inv=Inverse_m,minlines=400,order0=49, \ ntotal=nord_ob,npix=len(thar_order),nx=ncoef_x,nm=ncoef_m) thar_out = np.zeros((2, nord_ob, lines_thar_ob.shape[1])) equis = np.arange(lines_thar_ob.shape[1]) order = 0 while order < nord_ob: m = order + 49 chebs = GLOBALutils.Calculate_chebs(equis, m, Inverse=Inverse_m, order0=49, ntotal=nord_ob, npix=len(thar_order), nx=ncoef_x, nm=ncoef_m) WavSol = (1.0 / m) * GLOBALutils.Joint_Polynomial_Cheby( p1, chebs, ncoef_x, ncoef_m) thar_out[0, order, :] = WavSol thar_out[1, order, :] = lines_thar_ob[order] order += 1 if os.access(thar_spec_ob, os.F_OK): os.system('rm ' + thar_spec_ob) hdu = pyfits.PrimaryHDU(thar_out) hdu.writeto(thar_spec_ob) for order in range(nord_co):