heapyx 0.1.7__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {heapyx-0.1.7 → heapyx-0.2.0}/PKG-INFO +1 -11
- {heapyx-0.1.7 → heapyx-0.2.0}/README.md +0 -10
- heapyx-0.2.0/heapy/__info__.py +1 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/auto/baseline.py +18 -9
- heapyx-0.2.0/heapy/auto/ggsignal.py +264 -0
- heapyx-0.2.0/heapy/auto/polybase.py +686 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/auto/polynomial.py +111 -86
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/auto/ppsignal.py +45 -24
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/data/retrieve.py +31 -11
- heapyx-0.2.0/heapy/docs/McIlwainL_coeffs/McIlwainL_Coeffs.npy +0 -0
- heapyx-0.2.0/heapy/geos/detector.py +68 -0
- heapyx-0.2.0/heapy/geos/geometry.py +347 -0
- heapyx-0.2.0/heapy/geos/localization.py +501 -0
- heapyx-0.2.0/heapy/geos/skymap.py +190 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/pipe/batpipe.py +198 -115
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/pipe/event.py +232 -100
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/pipe/filter.py +2 -3
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/pipe/image.py +80 -19
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/temp/lag.py +71 -74
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/temp/txx.py +414 -309
- heapyx-0.2.0/heapy/util/coord.py +444 -0
- heapyx-0.2.0/heapy/util/data.py +750 -0
- heapyx-0.2.0/heapy/util/file.py +308 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/util/significance.py +3 -32
- heapyx-0.2.0/heapy/util/time.py +368 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapyx.egg-info/PKG-INFO +1 -11
- {heapyx-0.1.7 → heapyx-0.2.0}/heapyx.egg-info/SOURCES.txt +6 -1
- heapyx-0.1.7/heapy/__info__.py +0 -1
- heapyx-0.1.7/heapy/auto/polybase.py +0 -437
- heapyx-0.1.7/heapy/geos/geometry.py +0 -140
- heapyx-0.1.7/heapy/geos/location.py +0 -65
- heapyx-0.1.7/heapy/util/data.py +0 -395
- heapyx-0.1.7/heapy/util/file.py +0 -324
- heapyx-0.1.7/heapy/util/time.py +0 -171
- {heapyx-0.1.7 → heapyx-0.2.0}/LICENSE +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/__init__.py +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/auto/__init__.py +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/data/__init__.py +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/data/filefinder.py +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/docs/psf_model/fxt_psf.cod +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/docs/psf_model/fxt_psf.dat +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/docs/psf_model/xrt_psf.cod +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/geos/__init__.py +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/pipe/__init__.py +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/temp/__init__.py +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapy/util/__init__.py +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapyx.egg-info/dependency_links.txt +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapyx.egg-info/requires.txt +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/heapyx.egg-info/top_level.txt +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/setup.cfg +0 -0
- {heapyx-0.1.7 → heapyx-0.2.0}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: heapyx
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: High-energy (X-ray and gamma-ray) astronomical data analysis tools
|
|
5
5
|
Home-page: https://github.com/jyangch/heapy
|
|
6
6
|
Author: Jun Yang
|
|
@@ -50,16 +50,6 @@ Dynamic: summary
|
|
|
50
50
|
|
|
51
51
|
_Heapy_ will invoke certain software and commands from HEASoft, such as `xselect` and `ximage`. Please ensure that [`HEASoft`](https://heasarc.gsfc.nasa.gov/docs/software/heasoft/#install) is correctly installed on your system, and that the [`Calibration Database`](https://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/install.html) (CALDB) for the mission (e.g., `Swift`) you are processing is also properly installed.
|
|
52
52
|
|
|
53
|
-
### Fermi GBM Data Tools
|
|
54
|
-
|
|
55
|
-
_Heapy_ obtains the orbital location and pointing information of `Fermi` by invoking `gbm_data_tools`. Therefore, if you require this functionality, please ensure that [`gbm_data_tools`](https://fermi.gsfc.nasa.gov/ssc/data/analysis/gbm/gbm_data_tools/gdt-docs/index.html#) is correctly installed in advance.
|
|
56
|
-
|
|
57
|
-
If you are using macOS with an Apple silicon chip, you may encounter difficulties compiling older versions of `matplotlib` (e.g., <= 3.2.1) when installing `gbm_data_tools`. One possible workaround is to first install a newer version of `matplotlib` (for example, version 3.8.4) and then install `gbm_data_tools` without performing dependency checks, using the following command:
|
|
58
|
-
```bash
|
|
59
|
-
$ pip3 install matplotlib==3.8.4
|
|
60
|
-
$ pip3 install --no-deps <path_to_tar>/gbm_data_tools-1.1.1.tar
|
|
61
|
-
```
|
|
62
|
-
|
|
63
53
|
### Fermi GBM Response Generator
|
|
64
54
|
|
|
65
55
|
_Heapy_ generates the response matrix files for Fermi GBM by invoking [`gbm_drm_gen`](https://github.com/grburgess/gbm_drm_gen). It is recommended to install my forked Python packages, which have been fine-tuned to resolve compatibility issues with newer versions of `numpy` and `astropy`, and to use TTE data instead of CSPEC data. The specific installation procedure is as follows:
|
|
@@ -12,16 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
_Heapy_ will invoke certain software and commands from HEASoft, such as `xselect` and `ximage`. Please ensure that [`HEASoft`](https://heasarc.gsfc.nasa.gov/docs/software/heasoft/#install) is correctly installed on your system, and that the [`Calibration Database`](https://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/install.html) (CALDB) for the mission (e.g., `Swift`) you are processing is also properly installed.
|
|
14
14
|
|
|
15
|
-
### Fermi GBM Data Tools
|
|
16
|
-
|
|
17
|
-
_Heapy_ obtains the orbital location and pointing information of `Fermi` by invoking `gbm_data_tools`. Therefore, if you require this functionality, please ensure that [`gbm_data_tools`](https://fermi.gsfc.nasa.gov/ssc/data/analysis/gbm/gbm_data_tools/gdt-docs/index.html#) is correctly installed in advance.
|
|
18
|
-
|
|
19
|
-
If you are using macOS with an Apple silicon chip, you may encounter difficulties compiling older versions of `matplotlib` (e.g., <= 3.2.1) when installing `gbm_data_tools`. One possible workaround is to first install a newer version of `matplotlib` (for example, version 3.8.4) and then install `gbm_data_tools` without performing dependency checks, using the following command:
|
|
20
|
-
```bash
|
|
21
|
-
$ pip3 install matplotlib==3.8.4
|
|
22
|
-
$ pip3 install --no-deps <path_to_tar>/gbm_data_tools-1.1.1.tar
|
|
23
|
-
```
|
|
24
|
-
|
|
25
15
|
### Fermi GBM Response Generator
|
|
26
16
|
|
|
27
17
|
_Heapy_ generates the response matrix files for Fermi GBM by invoking [`gbm_drm_gen`](https://github.com/grburgess/gbm_drm_gen). It is recommended to install my forked Python packages, which have been fine-tuned to resolve compatibility issues with newer versions of `numpy` and `astropy`, and to use TTE data instead of CSPEC data. The specific installation procedure is as follows:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '0.2.0'
|
|
@@ -12,28 +12,26 @@ from scipy.interpolate import interp1d, UnivariateSpline
|
|
|
12
12
|
class Baseline(object):
|
|
13
13
|
|
|
14
14
|
def __init__(self):
|
|
15
|
+
|
|
15
16
|
pass
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
@classmethod
|
|
19
20
|
def set_method(cls, method='drpls'):
|
|
21
|
+
|
|
20
22
|
if method == 'drpls':
|
|
21
23
|
pass
|
|
22
|
-
# print(
|
|
23
|
-
# '''
|
|
24
|
-
# +-----------------+-----------+
|
|
25
|
-
# | baseline method | drpls |
|
|
26
|
-
# +-----------------+-----------+
|
|
27
|
-
# ''')
|
|
28
24
|
else:
|
|
29
25
|
raise ValueError('invalid method')
|
|
30
26
|
|
|
31
27
|
cls_ = cls()
|
|
32
28
|
cls_.method = method
|
|
29
|
+
|
|
33
30
|
return cls_
|
|
34
31
|
|
|
35
32
|
|
|
36
33
|
def fit(self, x, y, w=None, lam=None, nk=None):
|
|
34
|
+
|
|
37
35
|
self.x = np.array(x).astype(float)
|
|
38
36
|
self.y = np.array(y).astype(float)
|
|
39
37
|
|
|
@@ -45,10 +43,10 @@ class Baseline(object):
|
|
|
45
43
|
nk = 2 * len(x) - 200
|
|
46
44
|
|
|
47
45
|
if self.method == 'snip':
|
|
48
|
-
mo = self.snip(y, x, w=w)
|
|
46
|
+
mo = self.snip(y, x, w=w)
|
|
49
47
|
|
|
50
48
|
elif self.method == 'isnip':
|
|
51
|
-
mo = self.isnip(y, x, w=w)
|
|
49
|
+
mo = self.isnip(y, x, w=w)
|
|
52
50
|
|
|
53
51
|
elif self.method == 'drpls':
|
|
54
52
|
mo = pybaselines.whittaker.drpls(y, lam=lam, eta=0.5, weights=w)[0]
|
|
@@ -69,6 +67,7 @@ class Baseline(object):
|
|
|
69
67
|
|
|
70
68
|
|
|
71
69
|
def val(self, x):
|
|
70
|
+
|
|
72
71
|
x = np.array(x)
|
|
73
72
|
|
|
74
73
|
if min(x) < min(self.x) or max(x) > max(self.x):
|
|
@@ -85,20 +84,24 @@ class Baseline(object):
|
|
|
85
84
|
|
|
86
85
|
@staticmethod
|
|
87
86
|
def speyediff(N, d, format='csc'):
|
|
87
|
+
|
|
88
88
|
assert not (d < 0)
|
|
89
|
+
|
|
89
90
|
shape = (N - d, N)
|
|
90
91
|
diagonals = np.zeros(2 * d + 1)
|
|
91
|
-
diagonals[d] = 1.
|
|
92
|
+
diagonals[d] = 1.0
|
|
92
93
|
for i in range(d):
|
|
93
94
|
diff = diagonals[:-1] - diagonals[1:]
|
|
94
95
|
diagonals = diff
|
|
95
96
|
offsets = np.arange(d + 1)
|
|
96
97
|
spmat = sparse.diags(diagonals, offsets, shape, format=format)
|
|
98
|
+
|
|
97
99
|
return spmat
|
|
98
100
|
|
|
99
101
|
|
|
100
102
|
@staticmethod
|
|
101
103
|
def whittaker_smooth(self, y, lmbd, d, w):
|
|
104
|
+
|
|
102
105
|
y = np.array(y)
|
|
103
106
|
m = len(y)
|
|
104
107
|
y = np.mat(y)
|
|
@@ -107,11 +110,13 @@ class Baseline(object):
|
|
|
107
110
|
W = sparse.diags(w, 0, shape=(m, m))
|
|
108
111
|
coefmat = W + lmbd * D.conj().T.dot(D)
|
|
109
112
|
z = spsolve(coefmat, W * y.T)
|
|
113
|
+
|
|
110
114
|
return coefmat, z
|
|
111
115
|
|
|
112
116
|
|
|
113
117
|
@staticmethod
|
|
114
118
|
def get_smooth(self, y, w=None, d=None, lmbd=None):
|
|
119
|
+
|
|
115
120
|
y = np.array(y)
|
|
116
121
|
m = len(y)
|
|
117
122
|
if w is None:
|
|
@@ -141,6 +146,7 @@ class Baseline(object):
|
|
|
141
146
|
#pr: peak ratio
|
|
142
147
|
#for same binsize
|
|
143
148
|
#--------------------------
|
|
149
|
+
|
|
144
150
|
y, x = np.array(y), np.array(x)
|
|
145
151
|
m = len(y)
|
|
146
152
|
if w is None:
|
|
@@ -206,6 +212,7 @@ class Baseline(object):
|
|
|
206
212
|
|
|
207
213
|
|
|
208
214
|
def isnip(self, y, x, w=None, d=None, lmbd=None, inte=None, pr=None, hwi=None, it=None):
|
|
215
|
+
|
|
209
216
|
#--------------------------
|
|
210
217
|
#lmbd: smooth hardness
|
|
211
218
|
#it: iterations
|
|
@@ -291,7 +298,9 @@ class Baseline(object):
|
|
|
291
298
|
|
|
292
299
|
|
|
293
300
|
class InterpWarning(UserWarning):
|
|
301
|
+
|
|
294
302
|
"""
|
|
295
303
|
Issued by self.val for External interpolation.
|
|
296
304
|
"""
|
|
305
|
+
|
|
297
306
|
pass
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import warnings
|
|
3
|
+
import numpy as np
|
|
4
|
+
import matplotlib.pyplot as plt
|
|
5
|
+
from matplotlib import rcParams
|
|
6
|
+
from astropy.stats import bayesian_blocks
|
|
7
|
+
|
|
8
|
+
from ..util.data import json_dump
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ggSignal(object):
|
|
13
|
+
|
|
14
|
+
"""
|
|
15
|
+
NOTE: only apply to gaussian data
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, cts, cts_err, bins, exp=None):
|
|
19
|
+
|
|
20
|
+
self.cts = np.array(cts)
|
|
21
|
+
self.cts_err = np.array(cts_err)
|
|
22
|
+
self.bins = np.array(bins).astype(float)
|
|
23
|
+
|
|
24
|
+
self.lbins = self.bins[:-1]
|
|
25
|
+
self.rbins = self.bins[1:]
|
|
26
|
+
self.binsize = self.bins[1:] - self.bins[:-1]
|
|
27
|
+
if exp is None:
|
|
28
|
+
self.exp = self.binsize
|
|
29
|
+
else:
|
|
30
|
+
self.exp = np.array(exp).astype(float)
|
|
31
|
+
|
|
32
|
+
if (self.exp.size + 1) != self.bins.size:
|
|
33
|
+
raise TypeError("expected size(exp) + 1 = size(bins)")
|
|
34
|
+
if not (self.exp <= self.binsize).all():
|
|
35
|
+
raise TypeError("expected exp <= binsize")
|
|
36
|
+
|
|
37
|
+
self.time = (self.lbins + self.rbins) / 2
|
|
38
|
+
self.rate = self.cts / self.exp
|
|
39
|
+
self.rate_err = self.cts_err / self.exp
|
|
40
|
+
|
|
41
|
+
self.ini_res = {'cts': self.cts, 'cts_err': self.cts_err,
|
|
42
|
+
'time': self.time, 'rate': self.rate,
|
|
43
|
+
'exp': self.exp, 'bins': self.bins}
|
|
44
|
+
|
|
45
|
+
# bblock method
|
|
46
|
+
self.block_res = None
|
|
47
|
+
|
|
48
|
+
# calsnr method
|
|
49
|
+
self.snr_res = None
|
|
50
|
+
|
|
51
|
+
# fetsig method
|
|
52
|
+
self.sort_res = None
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def bblock(self, p0=0.05):
|
|
56
|
+
|
|
57
|
+
edges_ = bayesian_blocks(self.time, self.rate, self.rate_err, fitness='measures', p0=p0)
|
|
58
|
+
|
|
59
|
+
edges_[0] = max(edges_[0], self.time[0])
|
|
60
|
+
edges_[-1] = min(edges_[-1], self.time[-1])
|
|
61
|
+
|
|
62
|
+
edges = [edges_[0], edges_[-1]]
|
|
63
|
+
for i in range(1, len(edges_) - 1, 1):
|
|
64
|
+
flag1 = (edges_[i] - edges_[i-1]) > np.min(self.binsize) / 1.8
|
|
65
|
+
flag2 = (edges_[i+1] - edges_[i]) > np.min(self.binsize) / 1.8
|
|
66
|
+
if flag1 and flag2:
|
|
67
|
+
edges.append(edges_[i])
|
|
68
|
+
self.edges = np.unique(edges)
|
|
69
|
+
self.nblock = len(self.edges) - 1
|
|
70
|
+
self.re_binsize = self.edges[1:] - self.edges[:-1]
|
|
71
|
+
|
|
72
|
+
self.block_res = {'edges': self.edges, 'nblock': self.nblock, 're_binsize': self.re_binsize}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def calsnr(self):
|
|
76
|
+
|
|
77
|
+
if self.block_res is None: self.bblock()
|
|
78
|
+
|
|
79
|
+
self.re_cts, self.re_cts_err = [], []
|
|
80
|
+
for t1, t2 in zip(self.edges[:-1], self.edges[1:]):
|
|
81
|
+
self.re_cts.append(np.sum(self.cts[(self.time >= t1) & (self.time < t2)]))
|
|
82
|
+
self.re_cts_err.append(np.sqrt(np.sum(self.cts_err[(self.time >= t1) & (self.time < t2)]**2)))
|
|
83
|
+
self.re_cts = np.array(self.re_cts)
|
|
84
|
+
self.re_cts_err = np.array(self.re_cts_err)
|
|
85
|
+
|
|
86
|
+
self.snr = np.zeros_like(self.binsize)
|
|
87
|
+
for i in range(len(self.binsize)):
|
|
88
|
+
cts_i = self.cts[i]
|
|
89
|
+
cts_err_i = self.cts_err[i]
|
|
90
|
+
|
|
91
|
+
if cts_err_i <= 0:
|
|
92
|
+
snr_i = -5 # bad events
|
|
93
|
+
else:
|
|
94
|
+
snr_i = cts_i / cts_err_i
|
|
95
|
+
|
|
96
|
+
self.snr[i] = snr_i
|
|
97
|
+
|
|
98
|
+
self.re_snr = np.zeros_like(self.re_binsize)
|
|
99
|
+
for i in range(len(self.re_binsize)):
|
|
100
|
+
cts_i = self.re_cts[i]
|
|
101
|
+
cts_err_i = self.re_cts_err[i]
|
|
102
|
+
|
|
103
|
+
if cts_err_i <= 0:
|
|
104
|
+
snr_i = -5 # bad events
|
|
105
|
+
else:
|
|
106
|
+
snr_i = cts_i / cts_err_i
|
|
107
|
+
|
|
108
|
+
self.re_snr[i] = snr_i
|
|
109
|
+
|
|
110
|
+
self.snr_res = {'snr': self.snr, 're_snr': self.re_snr,
|
|
111
|
+
're_cts': self.re_cts, 're_cts_err': self.re_cts_err}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def sorting(self, sigma=3):
|
|
115
|
+
|
|
116
|
+
if self.snr_res is None: self.calsnr()
|
|
117
|
+
|
|
118
|
+
self.sigma = sigma
|
|
119
|
+
self.re_bkg_idx, self.re_sig_idx, self.re_bad_idx = [], [], []
|
|
120
|
+
self.re_sig_int, self.re_bkg_int, self.re_bad_int = [], [], []
|
|
121
|
+
self.bkg_idx, self.sig_idx, self.bad_idx = [], [], []
|
|
122
|
+
self.sig_int, self.bkg_int, self.bad_int = [], [], []
|
|
123
|
+
|
|
124
|
+
for i, snr_i in enumerate(self.re_snr):
|
|
125
|
+
if snr_i > sigma:
|
|
126
|
+
self.re_sig_idx.append(i)
|
|
127
|
+
self.re_sig_int.append([self.edges[i], self.edges[i+1]])
|
|
128
|
+
elif -5 < snr_i <= sigma:
|
|
129
|
+
self.re_bkg_idx.append(i)
|
|
130
|
+
self.re_bkg_int.append([self.edges[i], self.edges[i+1]])
|
|
131
|
+
else:
|
|
132
|
+
self.re_bad_idx.append(i)
|
|
133
|
+
self.re_bad_int.append([self.edges[i], self.edges[i+1]])
|
|
134
|
+
|
|
135
|
+
for i, snr_i in enumerate(self.snr):
|
|
136
|
+
if snr_i > sigma:
|
|
137
|
+
self.sig_idx.append(i)
|
|
138
|
+
self.sig_int.append([self.lbins[i], self.rbins[i]])
|
|
139
|
+
elif -5 < snr_i <= sigma:
|
|
140
|
+
self.bkg_idx.append(i)
|
|
141
|
+
self.bkg_int.append([self.lbins[i], self.rbins[i]])
|
|
142
|
+
else:
|
|
143
|
+
self.bad_idx.append(i)
|
|
144
|
+
self.bad_int.append([self.lbins[i], self.rbins[i]])
|
|
145
|
+
|
|
146
|
+
self.re_bkg_idx = np.array(self.re_bkg_idx, dtype=int)
|
|
147
|
+
self.re_sig_idx = np.array(self.re_sig_idx, dtype=int)
|
|
148
|
+
self.re_bad_idx = np.array(self.re_bad_idx, dtype=int)
|
|
149
|
+
|
|
150
|
+
self.bkg_idx = np.array(self.bkg_idx, dtype=int)
|
|
151
|
+
self.sig_idx = np.array(self.sig_idx, dtype=int)
|
|
152
|
+
self.bad_idx = np.array(self.bad_idx, dtype=int)
|
|
153
|
+
|
|
154
|
+
self.re_bad_index = []
|
|
155
|
+
for i, (l, u) in enumerate(zip(self.lbins, self.rbins)):
|
|
156
|
+
for low, upp in self.re_bad_int:
|
|
157
|
+
if not (u <= low or l >= upp):
|
|
158
|
+
self.re_bad_index.append(i)
|
|
159
|
+
self.re_bad_index = np.unique(self.re_bad_index).astype(int)
|
|
160
|
+
|
|
161
|
+
self.re_sig_index = []
|
|
162
|
+
for i, (l, u) in enumerate(zip(self.lbins, self.rbins)):
|
|
163
|
+
for low, upp in self.re_sig_int:
|
|
164
|
+
if not (u <= low or l >= upp):
|
|
165
|
+
self.re_sig_index.append(i)
|
|
166
|
+
self.re_sig_index = np.unique(self.re_sig_index).astype(int)
|
|
167
|
+
|
|
168
|
+
self.sort_res = {'sigma': self.sigma,
|
|
169
|
+
're_bkg': (self.re_bkg_int, self.re_bkg_idx),
|
|
170
|
+
're_sig': (self.re_sig_int, self.re_sig_idx, self.re_sig_index),
|
|
171
|
+
're_bad': (self.re_bad_int, self.re_bad_idx, self.re_bad_index)}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def loop(self, p0=0.05, sigma=3):
|
|
175
|
+
|
|
176
|
+
self.bblock(p0)
|
|
177
|
+
self.calsnr()
|
|
178
|
+
self.sorting(sigma)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def save(self, savepath, suffix=''):
|
|
182
|
+
|
|
183
|
+
if not os.path.exists(savepath):
|
|
184
|
+
os.makedirs(savepath)
|
|
185
|
+
|
|
186
|
+
json_dump(self.ini_res, savepath + '/ini_res%s.json'%suffix)
|
|
187
|
+
json_dump(self.block_res, savepath + '/block_res%s.json'%suffix)
|
|
188
|
+
json_dump(self.snr_res, savepath + '/snr_res%s.json'%suffix)
|
|
189
|
+
json_dump(self.sort_res, savepath + '/sort_res%s.json'%suffix)
|
|
190
|
+
|
|
191
|
+
rcParams['font.family'] = 'serif'
|
|
192
|
+
rcParams['font.sans-serif'] = 'Georgia'
|
|
193
|
+
rcParams['font.size'] = 12
|
|
194
|
+
rcParams['pdf.fonttype'] = 42
|
|
195
|
+
|
|
196
|
+
fig, ax = plt.subplots(1, 1, figsize=(8, 5))
|
|
197
|
+
ax.plot(self.time, self.rate, lw=1.0, c='b', label='Light curve')
|
|
198
|
+
ax.plot(self.edges, np.append(self.re_cts/self.re_binsize, [(self.re_cts/self.re_binsize)[-1]]),
|
|
199
|
+
lw=1.0, c='c', drawstyle='steps-post', label='Bayesian block')
|
|
200
|
+
ax.set_xlim([min(self.time), max(self.time)])
|
|
201
|
+
ax.set_xlabel('Time')
|
|
202
|
+
ax.set_ylabel('Rate')
|
|
203
|
+
ax.minorticks_on()
|
|
204
|
+
ax.tick_params(axis='x', which='both', direction='in', labelcolor='k', colors='k')
|
|
205
|
+
ax.tick_params(axis='y', which='both', direction='in', labelcolor='k', colors='k')
|
|
206
|
+
ax.tick_params(which='major', width=1.0, length=5)
|
|
207
|
+
ax.tick_params(which='minor', width=1.0, length=3)
|
|
208
|
+
ax.xaxis.set_ticks_position('both')
|
|
209
|
+
ax.yaxis.set_ticks_position('both')
|
|
210
|
+
ax.legend(frameon=False)
|
|
211
|
+
fig.savefig(savepath + '/bs%s.pdf'%suffix, bbox_inches='tight', pad_inches=0.1, dpi=300)
|
|
212
|
+
plt.close(fig)
|
|
213
|
+
|
|
214
|
+
fig, ax = plt.subplots(1, 1, figsize=(8, 5))
|
|
215
|
+
p1, = ax.plot(self.time, self.rate, lw=1.0, c='k', label='light curve')
|
|
216
|
+
ax.set_xlim([min(self.time), max(self.time)])
|
|
217
|
+
ax.set_xlabel('Time')
|
|
218
|
+
ax.set_ylabel('Rate')
|
|
219
|
+
ax.minorticks_on()
|
|
220
|
+
ax.tick_params(axis='x', which='both', direction='in', labelcolor='k', colors='k')
|
|
221
|
+
ax.tick_params(axis='y', which='both', direction='in', labelcolor='k', colors='k')
|
|
222
|
+
ax.tick_params(which='major', width=1.0, length=5)
|
|
223
|
+
ax.tick_params(which='minor', width=1.0, length=3)
|
|
224
|
+
ax.xaxis.set_ticks_position('both')
|
|
225
|
+
ax.yaxis.set_ticks_position('both')
|
|
226
|
+
|
|
227
|
+
ax1 = ax.twinx()
|
|
228
|
+
p2, = ax1.plot(self.time, self.snr, lw=1.0, c='b', label='SNR', drawstyle='steps-mid')
|
|
229
|
+
p3, = ax1.plot(self.edges, np.append(self.re_snr, [self.re_snr[-1]]), lw=1.0, c='c',
|
|
230
|
+
label='Baysian block SNR', drawstyle='steps-post')
|
|
231
|
+
p4 = ax1.axhline(self.sigma, lw=1.0, c='grey', ls='--', label='%.1f$\\sigma$' % self.sigma)
|
|
232
|
+
ax1.set_xlim([min(self.time), max(self.time)])
|
|
233
|
+
ax1.set_ylabel('SNR')
|
|
234
|
+
|
|
235
|
+
ratio = np.max(self.rate) / np.max(self.re_snr)
|
|
236
|
+
ax_ylim = [1.5 * np.min(self.rate), 1.1 * np.max(self.rate)]
|
|
237
|
+
ax1_ylim = [lim / ratio for lim in ax_ylim]
|
|
238
|
+
ax.set_ylim(ax_ylim)
|
|
239
|
+
ax1.set_ylim(ax1_ylim)
|
|
240
|
+
|
|
241
|
+
plt.legend(handles=[p1, p2, p3, p4], frameon=False)
|
|
242
|
+
fig.savefig(savepath + '/snr%s.pdf'%suffix, bbox_inches='tight', pad_inches=0.1, dpi=300)
|
|
243
|
+
plt.close(fig)
|
|
244
|
+
|
|
245
|
+
fig, ax = plt.subplots(1, 1, figsize=(8, 5))
|
|
246
|
+
colors = []
|
|
247
|
+
for i in range(len(self.re_binsize)):
|
|
248
|
+
if i in self.re_sig_idx: colors.append('m')
|
|
249
|
+
if i in self.re_bkg_idx: colors.append('b')
|
|
250
|
+
if i in self.re_bad_idx: colors.append('k')
|
|
251
|
+
ax.bar((self.edges[:-1]+self.edges[1:])/2, self.re_cts/self.re_binsize, bottom=0, width=self.re_binsize, color=colors)
|
|
252
|
+
ax.plot(self.time, self.rate, lw=1.0, c='b', label='Light curve')
|
|
253
|
+
ax.set_xlim([min(self.time), max(self.time)])
|
|
254
|
+
ax.set_xlabel('Time')
|
|
255
|
+
ax.set_ylabel('Rate')
|
|
256
|
+
ax.minorticks_on()
|
|
257
|
+
ax.tick_params(axis='x', which='both', direction='in', labelcolor='k', colors='k')
|
|
258
|
+
ax.tick_params(axis='y', which='both', direction='in', labelcolor='k', colors='k')
|
|
259
|
+
ax.tick_params(which='major', width=1.0, length=5)
|
|
260
|
+
ax.tick_params(which='minor', width=1.0, length=3)
|
|
261
|
+
ax.xaxis.set_ticks_position('both')
|
|
262
|
+
ax.yaxis.set_ticks_position('both')
|
|
263
|
+
fig.savefig(savepath + '/sort%s.pdf'%suffix, bbox_inches='tight', pad_inches=0.1, dpi=300)
|
|
264
|
+
plt.close(fig)
|