hdu = pyfits.PrimaryHDU( thar_S ) hdu.writeto( thar_fits ) hdu = pyfits.PrimaryHDU( thar_Ss ) hdu.writeto( thar_simple_fits ) else: print("\t\tThAr file", fsim, "all ready extracted, loading...") or50 = 50 or502 = 50 maxxc = 0. maxxc2 = 0. thar_fits = dirout + ThAr_ref[0].split('/')[-1][:-4]+'spec.simple.fits.S' thar_Ss = pyfits.getdata(thar_fits) for i in range(40,60,1): ccf_max, shift = GLOBALutils.cor_thar(thar_Ss[i],span=40,filename=order_dir+'order_103.iwdat') if ccf_max > maxxc: maxxc = ccf_max rough_shift = shift or50 = i difo = 103 - or50 #show() #print gfds print("\n\tWavelength solution of ThAr calibration spectra:") for i in range(len(ThAr_ref_dates)): wavsol_pkl = dirout + ThAr_ref[i].split('/')[-1][:-4]+'wavsolpars.pkl' hd = pyfits.getheader(ThAr_ref[i]) gain,ron = float(hd['CCDGAIN']),float(hd['CCDRON']) #force_thar_wavcal = True if ( os.access(wavsol_pkl,os.F_OK) == False ) or (force_thar_wavcal):
All_Orders = np.array([]) All_Centroids = np.array([]) All_Sigmas = np.array([]) All_Intensities = np.array([]) for order in range(n_useful): order_s = str(order) if (order < 10): order_s = '0' + str(order) thar_order_orig = lines_thar[order, :] #bkg = PFSutils.Lines_mBack(thar_order_orig, IV, thres_rel=3) thar_order = thar_order_orig - scipy.signal.medfilt( thar_order_orig, 21) wei = np.ones(len(thar_order)) ccf_max, rshift = GLOBALutils.cor_thar(lines_thar[order],filename=order_dir+'order_'+\ order_s+'.iwdat',span=20,binning=binx) coeffs_pix2wav, coeffs_pix2sigma, pixel_centers, wavelengths,\ rms_ms, residuals, centroids, sigmas, intensities =\ GLOBALutils.Initial_Wav_Calibration(order_dir+'order_'+\ order_s+'.iwdat', thar_order, order, wei, rmsmax=100, \ minlines=30,FixEnds=False,Dump_Argon=dumpargon,\ Dump_AllLines=True, Cheby=use_cheby,porder=5,del_width=4.0,\ binning=binx,rough_shift=rshift,line_width=6) fwhms_lns = sigmas * 2.355 inis_lns = pixel_centers - fwhms_lns * 0.5 fins_lns = pixel_centers + fwhms_lns * 0.5 inis_wvs = GLOBALutils.Cheby_eval(coeffs_pix2wav, inis_lns, float(len(thar_order))) fins_wvs = GLOBALutils.Cheby_eval(coeffs_pix2wav, fins_lns,
lines_thar = thar_S.copy() All_Pixel_Centers = np.array([]) All_Wavelengths = np.array([]) All_Orders = np.array([]) All_Centroids = np.array([]) All_Sigmas = np.array([]) All_Intensities = np.array([]) force_corr = True if os.access(dirout + 'id_orders.pkl', os.F_OK) == False or force_corr: maxes = 0 or41 = 0 for order in range(len(lines_thar)): ccf_max, shift = GLOBALutils.cor_thar(lines_thar[order], span=10, filename=order_dir + 'arces_order41.dat') if ccf_max > maxes: maxes = ccf_max rough_shift = shift or41 = order print '\t\t\tThe real echelle order 41 is order', or41 print '\t\t\tShift in pixels:', rough_shift or0 = or41 - 41 or10 = 10 + or0 if or0 >= 0: orwa = 0 else: orwa = -or0 or0 = 0
#force_thar_wavcal = True if (os.access(wavsol_pkl, os.F_OK) == False) or (force_thar_wavcal): thar_Ss = pyfits.getdata(thar_fits_simple) print "\t\tWorking on ThAr file", thar lines_thar = thar_Ss.copy() force_ofind = True if numt == 0: if os.access(dirout + 'order_find.pkl', os.F_OK) == False or force_ofind: maxes = 0 or14 = 0 for order in range(len(lines_thar)): ccf_max, deltar = GLOBALutils.cor_thar(lines_thar[order], span=15, filename=order_dir + 'gorder14.dat') #print order, ccf_max if ccf_max > maxes: maxes = ccf_max or14 = order delta = deltar or0 = or14 - 14 or40 = or14 + 26 #print or14 if or0 >= 0: orwa = 0 else: orwa = -or0 or0 = 0
hth['UT-TIME'][3:5]+'-'+hth['UT-TIME'][6:]+'.wavsolpars.pkl' thar_Ss = pyfits.getdata(thar_fits_simple) if ( os.access(wavsol_pkl,os.F_OK) == False ) or (force_thar_wavcal): print " \t\tWorking on ThAr file", thar RON = hth['ENOISE'] GAIN = hth['EGAIN'] lines_thar = thar_Ss[:,:] if os.access(dirout+'id_orders.pkl',os.F_OK) == False or force_corr: maxes = 0 or32 = 0 for order in range(len(lines_thar)): ccf_max, shift = GLOBALutils.cor_thar(lines_thar[order],filename=order_dir+'order_32o.iwdat',span=50) if ccf_max > maxes: maxes = ccf_max rough_shift = shift or32 = order or0 = or32 - 32 if or0 >= 0: orwa = 0 else: orwa = - or0 or0 = 0 #print 'n_lasts',n_last,or0 + nord if n_last > or0 + nord: n_last = or0 + nord if or32-32 >0: