-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBB.py
executable file
·71 lines (59 loc) · 1.96 KB
/
BB.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 30 17:59:59 2020
@author: asif
"""
import numpy as np
from astropy.stats import bayesian_blocks
def Read_lc_qdp(qdp_file_name):
with open(qdp_file_name,'r') as reader:
lines=reader.readlines()
modes=[]
data=[]
b=iter(lines[9:])
data=[]
block=[]
for line in b:
if line[0].isalpha():
data.append(block)
block=[]
line=next(b)
modes.append(line.strip().split(' ')[1])
line=next(b)
line=next(b)
block.append(line.strip().split('\t'))
# print(line)
data.append(block)
data.pop(0)
return [modes,data]
def CreateBinFile(t_bin,out_file_name="tbin.txt"):
"""Takes bin times as input and create a text file used for time splicing in xrt site"""
n=len(t_bin)
f=open(out_file_name,'x')
for i in range(n-1):
tstart=t_bin[i]
tstop=t_bin[i+1]
line="spec"+str(i)+" "+str(tstart)+"-"+str(tstop)
f.write(line+"\n")
f.close()
lc_filename="curve_mod.qdp"
bin_textfile="tbin_bb.txt"
modes,data=Read_lc_qdp(lc_filename)
PC_data=np.array(data[-1],dtype=np.float32)
t=PC_data[:,0]
x=PC_data[:,3]
del_t=np.diff(t)
s=(PC_data[:,4]-PC_data[:,5])/2
# edges = bayesian_blocks(t, fitness='events')
# edges = bayesian_blocks(t, x,fitness='measures')
# edges1 = bayesian_blocks(t, x,sigma=s,fitness='measures')
edges = bayesian_blocks(t, x,sigma=s,fitness='measures',p0=0.01)
CreateBinFile(edges,bin_textfile)
# plt.scatter(range(len(edges)),edges)
# Out[19]: <matplotlib.collections.PathCollection at 0x7f303bb3c250>
# plt.scatter(range(len(edges1)),edges1)
# Out[20]: <matplotlib.collections.PathCollection at 0x7f30380653d0>
# plt.scatter(range(len(edges2)),edges2)
# Out[21]: <matplotlib.collections.PathCollection at 0x7f303806c760>
# plt.yscale("log")