Beispiel #1
0
        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,
                                                nc=3)
            ratio = np.polyval(ccoef, spec[0, order])
            L = np.where(spec[1, order, :] != 0)
Beispiel #2
0
        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
Beispiel #3
0
 # 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,
                                             lu=5,
Beispiel #4
0
	"""
        if rms_ms / np.sqrt(float(len(G_wav))) < 10:
            good_arcs.append(thars[index])

        equis = np.arange(thar_S.shape[1])
        for order in range(n_useful):
            m = order + 37
            chebs = GLOBALutils.Calculate_chebs(equis,
                                                m,
                                                npix=thar_S.shape[1],
                                                order0=37,
                                                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.writeto(thar_out)

        pdict = {'p1':p1,'mjd':mjd, 'G_pix':G_pix, 'G_ord':G_ord, 'G_wav':G_wav, 'II':II, 'rms_ms':rms_ms,\
                     'G_res':G_res, 'All_Centroids':All_Centroids, 'All_Orders':All_Orders, 'All_Sigmas':All_Sigmas}
        pickle.dump(pdict, open(wavsol_pkl, 'w'))

    else:
        print "\t\tUsing previously computed wavelength solution in file", wavsol_pkl
        pdict = pickle.load(open(wavsol_pkl, 'r'))
        if pdict['rms_ms'] / np.sqrt(float(len(pdict['G_wav']))) < 10:
Beispiel #5
0
                                                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):
        #   I = np.where(G_ord == orde)[0]
        #   plot(G_wav[I],G_res[I],'o')
        #show()

        pdict = {'p1':p1,'mjd':mjd, 'G_pix':G_pix, 'G_ord':G_ord, 'G_wav':G_wav, 'II':II, 'rms_ms':rms_ms,\
Beispiel #6
0
        # 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)
	    #plot(spec[0,order],sflat[order])
	    #show()
	    #cv = np.vstack((x,y)).T
	    #x_i,y_i = HIRESutils.bspline(cv, n=1000, degree=3, periodic=False)
	    #plot(x_i,y_i)
Beispiel #7
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 = {
            'p1': p1,
Beispiel #8
0
        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.
            final[6,order,:] = final[4,order,:]*(ratio**2)
Beispiel #9
0
        hdu = GLOBALutils.update_header(hdu,'HIERARCH DEC BARY',dec)
        hdu = GLOBALutils.update_header(hdu,'HIERARCH EQUINOX',h[ih].header['EQUINOX'])
        hdu = GLOBALutils.update_header(hdu,'HIERARCH OBS LATITUDE',h[ih].header['SITELAT'])
        hdu = GLOBALutils.update_header(hdu,'HIERARCH OBS LONGITUDE',h[ih].header['SITELONG'])
        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
	    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,lu=5,nc=3)
	    ratio = np.polyval(cont_coef, spec[0,order,:])
            L  = np.where( spec[1,order,:] != 0 )[0]
            spec[5,order,:][L] = spec[3,order,:][L] / ratio[L]
            spec[6,order,:][L] = spec[4,order,:][L] * (ratio[L] ** 2 )
            spec[7,order,:][L] = ratio[L]
Beispiel #10
0
        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)