def main_process(): dataname='186' bin_len = 2000 (src_evt_use,epoch_info_use)=load_data(dataname=dataname,ecf=90) # lc=get_lc_frombkgimg(int(dataname),src_evt_use,epoch_info_use,ecf=90,bin_len=bin_len) figurepath = '/Users/baotong/Desktop/aas/pXS_Tuc/figure/' period =49504.9505 net_p = 0.77 time = src_evt_use[:, 0] time=hawk.filter_energy(src_evt_use[:,0],src_evt_use[:,1],[500,8000]) hawk.plot_longT_V(src_evt=src_evt_use, bkg_file=None,epoch_info=epoch_info_use,iffold=True,p_test=period,shift=0.0) # plt.close() hawk.phase_fold(time=time,epoch_info=epoch_info_use,net_percent=net_p,p_test=period,outpath=figurepath,bin=30,shift=0., label=dataname,text='Seq.232 (W37)',save=0,show=1) # plt.hist(time,bins=300,histtype='step') # plt.show() lc=hawk.get_hist(time,len_bin=bin_len,tstart=epoch_info_use[:,0][0],tstop=epoch_info_use[:,1][-1]) T_tot=epoch_info_use[:,1][-1]-epoch_info_use[:,0][0] freq = np.arange(1 / T_tot, 0.5/ bin_len, 1 / (10* T_tot)) freq = freq[np.where(freq > 1 / 40000.)] figurepath='/Users/baotong/Desktop/aas/pXS_Tuc/figure/'
def write_result(data_file, epoch_file, w_range, dataname='1', if_filter=False): epoch_info = np.loadtxt(epoch_file) epoch_info = epoch_info if epoch_info.ndim == 1: epoch_info = np.array([epoch_info]) src_evt = np.loadtxt(data_file) if src_evt.ndim < 2: return None if if_filter: CR = hawk.plot_longT_V(src_evt=src_evt, bkg_file=None, epoch_info=epoch_info, show=False) plt.close() print(CR) (useid, epoch_info_use) = hawk.choose_obs(epoch_info, flux_info=CR, flux_filter=6e-3, expT_filter=1000, if_flux_high=1, if_expT_high=True, obsID=[2668, 2669]) epoch_info = epoch_info_use ##这里随意改 src_evt_use = hawk.filter_obs(src_evt, useid) src_evt = src_evt_use time = src_evt[:, 0] energy = src_evt[:, 1] starttime = datetime.datetime.now() time = hawk.filter_energy(time, energy, [500, 8000]) counts = len(time) print('counts=', counts) GL_R = compute_GL(time, epoch_info=epoch_info, w_range=w_range, m_max=12, parallel=True) endtime = datetime.datetime.now() srcid = dataname runtime = (endtime - starttime).seconds Prob = GL_R[1] wpeak = GL_R[5] wmean = GL_R[6] mopt = GL_R[2] wconf_lo = GL_R[7][0] wconf_hi = GL_R[7][1] period = 2 * np.pi / wpeak return [ int(srcid), runtime, Prob, period, wpeak, wmean, mopt, wconf_lo, wconf_hi, counts ]
def plot_HR_lc(): (src_evt_use, epoch_info_use) = load_data(dataname='211', ecf=90) len_bin = 1000 expT = epoch_info_use[:, -1] tstart = epoch_info_use[:, 0][0] tstop = epoch_info_use[:, 1][0] time = src_evt_use[:, 0] time_s = hawk.filter_energy(src_evt_use[:, 0], src_evt_use[:, 1], [500, 2000]) time_h = hawk.filter_energy(src_evt_use[:, 0], src_evt_use[:, 1], [2000, 8000]) lc_s = hawk.get_hist(time_s, len_bin, tstart=tstart, tstop=tstop) lc_h = hawk.get_hist(time_h, len_bin, tstart=tstart, tstop=tstop) plt.plot(lc_s.time, lc_s.counts) plt.show() plt.plot(lc_h.time, lc_h.counts) plt.show() HR = (lc_h.counts - lc_s.counts) / (lc_s.counts + lc_h.counts) print(HR) plt.scatter(lc_s.time, HR) plt.show()
def write_result(dataname): #path = '/Users/baotong/xmm/M28_LMXB/0701981501/txt/' data_file=path + str(dataname) + '.txt' epoch_file = path + 'epoch_src_{0}.txt'.format(dataname) # epoch_file = path + 'epoch_src_' + str(dataname) + '.txt' epoch_info=np.loadtxt(epoch_file) epoch_info=epoch_info if epoch_info.ndim == 1: epoch_info=np.array([epoch_info]) src_evt=np.loadtxt(data_file) if src_evt.ndim==1: src_evt=np.array([src_evt]) CR=hawk.plot_longT_V(src_evt=src_evt, bkg_file=None,epoch_info=epoch_info,show=False) plt.close() print(CR) (useid, epoch_info_use)=hawk.choose_obs(epoch_info,flux_info=CR, flux_filter=100,expT_filter=1000, if_flux_high=0, if_expT_high=True,obsID=None) epoch_info = epoch_info_use ##这里随意改 src_evt_use =hawk.filter_obs(src_evt, useid) src_evt=src_evt_use time=src_evt[:,0] energy=src_evt[:,1] time = hawk.filter_energy(time, energy, [500, 8000]) counts=len(time) w_range=2*np.pi*np.arange(1./3000,1./100,1.e-6) starttime = datetime.datetime.now() GL_R=compute_GL(time,epoch_info=epoch_info,w_range=w_range,m_max=20,parallel=True) endtime = datetime.datetime.now() srcid=dataname runtime=(endtime - starttime).seconds Prob=GL_R[1] wpeak=GL_R[5] wmean=GL_R[6] mopt=GL_R[2] wconf_lo=GL_R[7][0] wconf_hi=GL_R[7][1] return [srcid,runtime,Prob,wpeak,wmean,mopt,wconf_lo,wconf_hi,counts]
def get_HR(softband, hardband, src_evt): time_soft = hawk.filter_energy(src_evt[:, 0], src_evt[:, 1], softband) time_hard = hawk.filter_energy(src_evt[:, 0], src_evt[:, 1], hardband) cts_soft = len(time_soft) cts_hard = len(time_hard) return (cts_soft, cts_hard)