jaxspec 0.0.3__py3-none-any.whl → 0.0.5__py3-none-any.whl
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.
- jaxspec/__init__.py +1 -1
- jaxspec/analysis/compare.py +3 -3
- jaxspec/analysis/results.py +239 -110
- jaxspec/data/example_data/fakeit.pha +335 -1
- jaxspec/data/instrument.py +0 -2
- jaxspec/data/obsconf.py +101 -71
- jaxspec/data/observation.py +24 -6
- jaxspec/data/ogip.py +18 -0
- jaxspec/data/util.py +28 -34
- jaxspec/fit.py +166 -72
- jaxspec/model/_additive/__init__.py +0 -0
- jaxspec/model/_additive/apec.py +377 -0
- jaxspec/model/_additive/apec_loaders.py +90 -0
- jaxspec/model/abc.py +55 -7
- jaxspec/model/additive.py +6 -56
- jaxspec/tables/abundances.dat +31 -0
- jaxspec/tables/{apec.nc → new_apec.nc} +0 -0
- jaxspec/util/abundance.py +111 -0
- jaxspec/util/integrate.py +5 -4
- {jaxspec-0.0.3.dist-info → jaxspec-0.0.5.dist-info}/METADATA +8 -4
- {jaxspec-0.0.3.dist-info → jaxspec-0.0.5.dist-info}/RECORD +23 -17
- {jaxspec-0.0.3.dist-info → jaxspec-0.0.5.dist-info}/LICENSE.md +0 -0
- {jaxspec-0.0.3.dist-info → jaxspec-0.0.5.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
SIMPLE = T / file does conform to FITS standard BITPIX = 8 / number of bits per data pixel NAXIS = 0 / number of data axes EXTEND = T / FITS dataset may contain extensions COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H END XTENSION= 'BINTABLE' / binary table extension BITPIX = 8 / 8-bit bytes NAXIS = 2 / 2-dimensional binary table NAXIS1 = 12 / width of table in bytes NAXIS2 = 4096 / number of rows in table PCOUNT = 0 / size of special data area GCOUNT = 1 / one data group (required keyword) TFIELDS = 4 / number of fields in each row TTYPE1 = 'CHANNEL ' / label for field 1 TFORM1 = 'J ' / data format of field: 4-byte INTEGER TTYPE2 = 'COUNTS ' / label for field 2 TFORM2 = 'J ' / data format of field: 4-byte INTEGER TTYPE3 = 'QUALITY ' / label for field 3 TFORM3 = 'I ' / data format of field: 2-byte INTEGER TTYPE4 = 'GROUPING' / label for field 4 TFORM4 = 'I ' / data format of field: 2-byte INTEGER EXTNAME = 'SPECTRUM' / name of this binary table extension HDUCLASS= 'OGIP ' / format conforms to OGIP standard HDUCLAS1= 'SPECTRUM' / PHA dataset (OGIP memo OGIP-92-007) HDUVERS = '1.2.1 ' / Version of format (OGIP memo OGIP-92-007a) TELESCOP= 'XMM ' / mission/satellite name INSTRUME= 'EPN ' / instrument name DETNAM = 'UNKNOWN ' / detector name FILTER = 'Medium ' / filter name STOKESPR= 'UNKNOWN ' / Stokes parameter(s) STOKESWT= 'UNKNOWN ' / Stokes weighting CHANTYPE= 'PI ' / channel type (PHA, PI etc) DATE = '2024-03-20T11:51:55' / file creation date (YYYY-MM-DDThh:mm:ss UT) HISTORY Fake data file created by XSPEC version: 12.13.1 "fakeit" command FKSRC001= 'cutoffpl' FKRSP001= 'PN.rmf ' FKARF001= 'PN.arf ' RESPFILE= 'PN.rmf ' / associated redistrib matrix filename ANCRFILE= 'PN.arf ' / associated ancillary response filename CORRFILE= ' ' / associated correction filename CORRSCAL= 1. / correction file scaling factor BACKFILE= ' ' / associated background filename EXPOSURE= 10000. / exposure (in seconds) TLMIN1 = 0 / Lowest legal channel number TLMAX1 = 4095 / Highest legal channel number DETCHANS= 4096 / total number possible channels POISSERR= T / Pois. err assumed ? AREASCAL= 1. / area scaling factor BACKSCAL= 1. / background file scaling factor END �!�x�����a��$8 0�
|
|
2
|
+
;{D-L�
|
|
3
|
+
�����������8������<��H�����������~�������#��|�����n�����������������/�������X��"��_��i��-�������Z��������������������N�����q��<�����q��������������_��������������������A�����������a��������Y��2�����n�����d��������!���?�_�` ��
|
|
4
|
+
���+�+
|
|
5
|
+
&�'��(��)��*�+�<,�-�Q.��/��0��1�02�3�4�^5��6�[7�8�(9�a:�H;~�<�=~>}??|c@|A|8B{�C{mDy�E{�F{HGyHymIy�JxtKy�LyMx�Nw�Ow�PxRQw�RxSvTv�UvtVu�WuXXv4Yu�ZuY[u�\u�]t�^t�_t,`s�ar�bqNcr�drBeq�fp�gpxhn�im�jm�kk�ll�mk�ni
|
|
6
|
+
oipg�qgUre�sd�tc�ub�v`�wa�x`�y`Oz^�{]�|]�}] ~]_\��[��]�\(�[��[F�Z��[�Z��Zn�ZH�Y��Y��X��YK�Y.�W��X�V��W��X�WN�X��W`�U��U��U��V�V&�U�T��T��T��Ty�T0�S�S�Sl�R'�R*�R��QZ�Q3�QA�P}�O��O��N��NR�L��L��K��K}�JN�I��H+�G,�F=�EI�E��D��C)�B,�Ap�@��?Z�=��=��<L�:��:X�9(�9 �7t�7��5�6��4��4#�3��3b�2{�2��2$�1��1q�0�/��/��0M�/��/|�0n�/��/��/��/5�/��/�.��/x�0,�0 �/�/��.��/��/D�.��/5�.��0�.��0,�/I�/e�/�/2�/d�/
|
|
7
|
+
.4-�-�
|
|
8
|
+
� ��!
|
|
9
|
+
�!� �� �� �� �� ���� 1� �� >� x� � � u� �� 9� A� *� /��� �� �T� � �����_�v���i�q���n�v���'���:�'��������&��}�lm����Z �
|
|
10
|
+
.d�
|
|
11
|
+
I��
|
|
12
|
+
!
|
|
13
|
+
�q3r
|
|
14
|
+
�stu
|
|
15
|
+
�vw
|
|
16
|
+
�x$y z
|
|
17
|
+
�{
|
|
18
|
+
�|
|
|
19
|
+
�}(~
|
|
20
|
+
o
|
|
21
|
+
��
|
|
22
|
+
f�
|
|
23
|
+
��
|
|
24
|
+
��
|
|
25
|
+
��
|
|
26
|
+
���
|
|
27
|
+
��
|
|
28
|
+
��
|
|
29
|
+
Y�
|
|
30
|
+
��
|
|
31
|
+
x�
|
|
32
|
+
t�
|
|
33
|
+
,�
|
|
34
|
+
i�
|
|
35
|
+
H�
|
|
36
|
+
+�
|
|
37
|
+
��
|
|
38
|
+
b�
|
|
39
|
+
u�
|
|
40
|
+
�
|
|
41
|
+
n�
|
|
42
|
+
*�
|
|
43
|
+
� ��
|
|
44
|
+
h�
|
|
45
|
+
� ��
|
|
46
|
+
�
|
|
47
|
+
�
|
|
48
|
+
� �� �� �� �� �� �� �� ��
|
|
49
|
+
"� �� W� �� �� �� �� `� l� 1� o� N� x� g� � I� i� C� 5� � �� =� <� j� %� i��� D� M� 1� <��� F������� L��������� ��� �[�x�����U���v���������=���p�I�]�0����:�}�������D���D�(����E����p�������"�����|���������������}� �
|
|
50
|
+
�D�
|
|
51
|
+
0�1�2�3�45�6�7�8�9�:�;�<�=�>S?~@�A�B�C�DpE]FLGVHvI"JsK�L�MZN�O�P.Q_R'SST�UxVWX�YWZ�[�\R]�^�_R`9ab!cd�e�f�g�h�i�j�k:lm�n�o�p�q�r�s�t�u�v�w�x�y�z�{�|�}�~�����������~���g�������F�I�^�p�i�V�R�\�s�U�*�E�v�1�p� �=���E�����=���#����������8�'�.�M�������������������������������������������������������h�������������������o�u�r�p���S�w�9�j�G�i��������!��R����T��Z�7�>�-�i� �5�����+�
|
|
52
|
+
��S���.�����;�360�� �
|
|
53
|
+
��
|
|
54
|
+
���
|
|
55
|
+
� � �
|
|
56
|
+
*
|
|
57
|
+
+
|
|
58
|
+
-
|
|
59
|
+
+
|
|
60
|
+
&
|
|
61
|
+
3
|
|
62
|
+
'
|
|
63
|
+
&
|
|
64
|
+
1
|
|
65
|
+
-
|
|
66
|
+
|
|
67
|
+
1
|
|
68
|
+
&
|
|
69
|
+
-
|
|
70
|
+
|
|
71
|
+
!
|
|
72
|
+
|
|
73
|
+
*
|
|
74
|
+
|
|
75
|
+
*
|
|
76
|
+
|
|
77
|
+
,
|
|
78
|
+
'
|
|
79
|
+
,
|
|
80
|
+
!
|
|
81
|
+
"
|
|
82
|
+
1
|
|
83
|
+
(
|
|
84
|
+
)
|
|
85
|
+
*
|
|
86
|
+
%
|
|
87
|
+
'
|
|
88
|
+
/
|
|
89
|
+
|
|
90
|
+
!,
|
|
91
|
+
",
|
|
92
|
+
#0
|
|
93
|
+
$)
|
|
94
|
+
%#
|
|
95
|
+
&
|
|
96
|
+
'
|
|
97
|
+
(,
|
|
98
|
+
)
|
|
99
|
+
*
|
|
100
|
+
+,
|
|
101
|
+
,
|
|
102
|
+
-'
|
|
103
|
+
.
|
|
104
|
+
/!
|
|
105
|
+
0
|
|
106
|
+
1&
|
|
107
|
+
2
|
|
108
|
+
3
|
|
109
|
+
4%
|
|
110
|
+
5
|
|
111
|
+
6#
|
|
112
|
+
7
|
|
113
|
+
8
|
|
114
|
+
9&
|
|
115
|
+
:
|
|
116
|
+
;
|
|
117
|
+
<
|
|
118
|
+
=
|
|
119
|
+
>%
|
|
120
|
+
?/
|
|
121
|
+
@
|
|
122
|
+
A"
|
|
123
|
+
B'
|
|
124
|
+
C'
|
|
125
|
+
D%
|
|
126
|
+
E
|
|
127
|
+
F
|
|
128
|
+
G
|
|
129
|
+
H(
|
|
130
|
+
I
|
|
131
|
+
J#
|
|
132
|
+
K
|
|
133
|
+
L
|
|
134
|
+
M-
|
|
135
|
+
N
|
|
136
|
+
O#
|
|
137
|
+
P
|
|
138
|
+
Q
|
|
139
|
+
R
|
|
140
|
+
S!
|
|
141
|
+
T
|
|
142
|
+
U
|
|
143
|
+
V%
|
|
144
|
+
W
|
|
145
|
+
X"
|
|
146
|
+
Y
|
|
147
|
+
Z
|
|
148
|
+
[
|
|
149
|
+
\
|
|
150
|
+
]
|
|
151
|
+
^
|
|
152
|
+
_
|
|
153
|
+
`
|
|
154
|
+
a
|
|
155
|
+
b
|
|
156
|
+
c
|
|
157
|
+
d
|
|
158
|
+
e
|
|
159
|
+
f
|
|
160
|
+
g
|
|
161
|
+
h
|
|
162
|
+
i
|
|
163
|
+
j
|
|
164
|
+
k
|
|
165
|
+
l
|
|
166
|
+
m
|
|
167
|
+
n
|
|
168
|
+
o
|
|
169
|
+
p
|
|
170
|
+
q
|
|
171
|
+
r
|
|
172
|
+
s
|
|
173
|
+
t
|
|
174
|
+
u
|
|
175
|
+
v
|
|
176
|
+
w
|
|
177
|
+
x
|
|
178
|
+
y
|
|
179
|
+
z
|
|
180
|
+
{
|
|
181
|
+
|
|
|
182
|
+
}
|
|
183
|
+
~
|
|
184
|
+
|
|
185
|
+
�
|
|
186
|
+
�
|
|
187
|
+
�
|
|
188
|
+
�
|
|
189
|
+
�
|
|
190
|
+
�
|
|
191
|
+
�
|
|
192
|
+
�
|
|
193
|
+
�
|
|
194
|
+
�
|
|
195
|
+
�
|
|
196
|
+
�
|
|
197
|
+
�
|
|
198
|
+
�
|
|
199
|
+
�
|
|
200
|
+
�
|
|
201
|
+
�
|
|
202
|
+
�
|
|
203
|
+
�
|
|
204
|
+
�
|
|
205
|
+
�
|
|
206
|
+
�
|
|
207
|
+
�
|
|
208
|
+
�
|
|
209
|
+
�
|
|
210
|
+
�
|
|
211
|
+
�
|
|
212
|
+
�
|
|
213
|
+
�
|
|
214
|
+
�
|
|
215
|
+
�
|
|
216
|
+
�
|
|
217
|
+
�
|
|
218
|
+
�
|
|
219
|
+
�
|
|
220
|
+
�
|
|
221
|
+
�
|
|
222
|
+
�
|
|
223
|
+
�
|
|
224
|
+
�
|
|
225
|
+
�
|
|
226
|
+
�
|
|
227
|
+
�
|
|
228
|
+
�
|
|
229
|
+
�
|
|
230
|
+
�
|
|
231
|
+
�
|
|
232
|
+
�
|
|
233
|
+
�
|
|
234
|
+
�
|
|
235
|
+
|
|
236
|
+
�
|
|
237
|
+
�
|
|
238
|
+
�
|
|
239
|
+
�
|
|
240
|
+
�
|
|
241
|
+
�
|
|
242
|
+
�
|
|
243
|
+
�
|
|
244
|
+
�
|
|
245
|
+
�
|
|
246
|
+
�
|
|
247
|
+
�
|
|
248
|
+
�
|
|
249
|
+
�
|
|
250
|
+
�
|
|
251
|
+
�
|
|
252
|
+
�
|
|
253
|
+
�
|
|
254
|
+
�
|
|
255
|
+
�
|
|
256
|
+
�
|
|
257
|
+
|
|
258
|
+
�
|
|
259
|
+
�
|
|
260
|
+
�
|
|
261
|
+
�
|
|
262
|
+
�
|
|
263
|
+
�
|
|
264
|
+
�
|
|
265
|
+
�
|
|
266
|
+
�
|
|
267
|
+
�
|
|
268
|
+
�
|
|
269
|
+
�
|
|
270
|
+
�
|
|
271
|
+
�
|
|
272
|
+
�
|
|
273
|
+
�
|
|
274
|
+
�
|
|
275
|
+
�
|
|
276
|
+
�
|
|
277
|
+
�
|
|
278
|
+
�
|
|
279
|
+
|
|
280
|
+
�
|
|
281
|
+
�
|
|
282
|
+
�
|
|
283
|
+
�
|
|
284
|
+
�
|
|
285
|
+
�
|
|
286
|
+
�
|
|
287
|
+
�
|
|
288
|
+
�
|
|
289
|
+
�
|
|
290
|
+
�
|
|
291
|
+
|
|
292
|
+
�
|
|
293
|
+
�
|
|
294
|
+
�
|
|
295
|
+
�
|
|
296
|
+
�
|
|
297
|
+
�
|
|
298
|
+
�
|
|
299
|
+
�
|
|
300
|
+
�
|
|
301
|
+
�
|
|
302
|
+
|
|
303
|
+
�
|
|
304
|
+
�
|
|
305
|
+
�
|
|
306
|
+
�
|
|
307
|
+
�
|
|
308
|
+
�
|
|
309
|
+
�
|
|
310
|
+
�
|
|
311
|
+
�
|
|
312
|
+
�
|
|
313
|
+
�
|
|
314
|
+
�
|
|
315
|
+
�
|
|
316
|
+
�
|
|
317
|
+
�
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
!
|
|
325
|
+
+ , -./ 01234 5 6789:;<=>?@ABCD
|
|
326
|
+
EFGH
|
|
327
|
+
IJKLMN OPQR
|
|
328
|
+
STUVWXY
|
|
329
|
+
Z[\]^_`abcdefghijklmnopqrstu
|
|
330
|
+
vwxyz{|}~������������������������������������ ��������������������������������������������������������������������������������������������
|
|
331
|
+
|
|
332
|
+
|
|
333
|
|
|
334
|
+
|
|
1
|
-
|
|
335
|
+
|
|
336
|
+
|
jaxspec/data/instrument.py
CHANGED
jaxspec/data/obsconf.py
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
import xarray as xr
|
|
3
3
|
import sparse
|
|
4
|
+
import scipy
|
|
4
5
|
from .instrument import Instrument
|
|
5
6
|
from .observation import Observation
|
|
6
7
|
|
|
7
8
|
|
|
8
|
-
def densify_xarray(xarray):
|
|
9
|
-
return xr.DataArray(xarray.data.todense(), dims=xarray.dims, coords=xarray.coords, attrs=xarray.attrs, name=xarray.name)
|
|
10
|
-
|
|
11
|
-
|
|
12
9
|
class ObsConfiguration(xr.Dataset):
|
|
13
10
|
"""
|
|
14
11
|
Class to store the data of a folding model, which is the link between the unfolded and folded spectra.
|
|
@@ -56,8 +53,8 @@ class ObsConfiguration(xr.Dataset):
|
|
|
56
53
|
|
|
57
54
|
out_energies = np.stack(
|
|
58
55
|
(
|
|
59
|
-
np.asarray(self.coords["e_min_folded"].data
|
|
60
|
-
np.asarray(self.coords["e_max_folded"].data
|
|
56
|
+
np.asarray(self.coords["e_min_folded"].data, dtype=np.float64),
|
|
57
|
+
np.asarray(self.coords["e_max_folded"].data, dtype=np.float64),
|
|
61
58
|
)
|
|
62
59
|
)
|
|
63
60
|
|
|
@@ -67,34 +64,16 @@ class ObsConfiguration(xr.Dataset):
|
|
|
67
64
|
def from_pha_file(
|
|
68
65
|
cls, pha_path, rmf_path=None, arf_path=None, bkg_path=None, low_energy: float = 1e-20, high_energy: float = 1e20
|
|
69
66
|
):
|
|
70
|
-
from .util import
|
|
67
|
+
from .util import data_path_finder
|
|
71
68
|
|
|
72
|
-
|
|
69
|
+
arf_path_default, rmf_path_default, bkg_path_default = data_path_finder(pha_path)
|
|
73
70
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
rmf.energ_lo,
|
|
78
|
-
rmf.energ_hi,
|
|
79
|
-
rmf.e_min,
|
|
80
|
-
rmf.e_max,
|
|
81
|
-
)
|
|
71
|
+
arf_path = arf_path_default if arf_path is None else arf_path
|
|
72
|
+
rmf_path = rmf_path_default if rmf_path is None else rmf_path
|
|
73
|
+
bkg_path = bkg_path_default if bkg_path is None else bkg_path
|
|
82
74
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
else:
|
|
86
|
-
backratio = np.ones_like(pha.counts)
|
|
87
|
-
|
|
88
|
-
observation = Observation.from_matrix(
|
|
89
|
-
pha.counts,
|
|
90
|
-
pha.grouping,
|
|
91
|
-
pha.channel,
|
|
92
|
-
pha.quality,
|
|
93
|
-
pha.exposure,
|
|
94
|
-
background=bkg.counts if bkg is not None else None,
|
|
95
|
-
backratio=backratio,
|
|
96
|
-
attributes=metadata,
|
|
97
|
-
)
|
|
75
|
+
instrument = Instrument.from_ogip_file(rmf_path, arf_path=arf_path)
|
|
76
|
+
observation = Observation.from_pha_file(pha_path, bkg_path=bkg_path)
|
|
98
77
|
|
|
99
78
|
return cls.from_instrument(instrument, observation, low_energy=low_energy, high_energy=high_energy)
|
|
100
79
|
|
|
@@ -102,57 +81,108 @@ class ObsConfiguration(xr.Dataset):
|
|
|
102
81
|
def from_instrument(
|
|
103
82
|
cls, instrument: Instrument, observation: Observation, low_energy: float = 1e-20, high_energy: float = 1e20
|
|
104
83
|
):
|
|
105
|
-
#
|
|
106
|
-
|
|
107
|
-
|
|
84
|
+
# First we unpack all the xarray data to classical np array for efficiency
|
|
85
|
+
# We also exclude the bins that are flagged with bad quality on the instrument
|
|
86
|
+
quality_filter = observation.quality.data == 0
|
|
87
|
+
grouping = scipy.sparse.csr_array(observation.grouping.data.to_scipy_sparse()) * quality_filter
|
|
88
|
+
e_min_channel = instrument.coords["e_min_channel"].data
|
|
89
|
+
e_max_channel = instrument.coords["e_max_channel"].data
|
|
90
|
+
e_min_unfolded = instrument.coords["e_min_unfolded"].data
|
|
91
|
+
e_max_unfolded = instrument.coords["e_max_unfolded"].data
|
|
92
|
+
redistribution = scipy.sparse.csr_array(instrument.redistribution.data.to_scipy_sparse())
|
|
93
|
+
area = instrument.area.data
|
|
94
|
+
exposure = observation.exposure.data
|
|
108
95
|
|
|
109
96
|
# Computing the lower and upper energies of the bins after grouping
|
|
110
97
|
# This is just a trick to compute it without 10 lines of code
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
)
|
|
98
|
+
grouping_nan = observation.grouping.data * quality_filter
|
|
99
|
+
grouping_nan.fill_value = np.nan
|
|
100
|
+
e_min = sparse.nanmin(grouping_nan * e_min_channel, axis=1).todense()
|
|
101
|
+
e_max = sparse.nanmax(grouping_nan * e_max_channel, axis=1).todense()
|
|
114
102
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
transfer_matrix = grouping @ (instrument.redistribution * instrument.area * observation.exposure)
|
|
120
|
-
transfer_matrix = transfer_matrix.assign_coords({"e_min_folded": e_min, "e_max_folded": e_max})
|
|
103
|
+
# Compute the transfer matrix
|
|
104
|
+
transfer_matrix = grouping @ (redistribution * area * exposure)
|
|
121
105
|
|
|
122
106
|
# Exclude bins out of the considered energy range, and bins without contribution from the RMF
|
|
123
|
-
row_idx = densify_xarray(((e_min > low_energy) & (e_max < high_energy)) * (grouping.sum(dim="instrument_channel") > 0))
|
|
124
|
-
|
|
125
|
-
col_idx = densify_xarray(
|
|
126
|
-
(instrument.coords["e_min_unfolded"] > 0) * (instrument.redistribution.sum(dim="instrument_channel") > 0)
|
|
127
|
-
)
|
|
128
107
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
transfer_matrix_reduced = transfer_matrix_scipy[row_idx.data][:, col_idx.data]
|
|
132
|
-
transfer_matrix_reduced = sparse.COO.from_scipy_sparse(transfer_matrix_reduced)
|
|
108
|
+
row_idx = (e_min > low_energy) & (e_max < high_energy) & (grouping.sum(axis=1) > 0)
|
|
109
|
+
col_idx = (e_min_unfolded > 0) & (redistribution.sum(axis=0) > 0)
|
|
133
110
|
|
|
134
|
-
#
|
|
135
|
-
transfer_matrix
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
111
|
+
# Apply this reduction to all the relevant arrays
|
|
112
|
+
transfer_matrix = sparse.COO.from_scipy_sparse(transfer_matrix[row_idx][:, col_idx])
|
|
113
|
+
folded_counts = observation.folded_counts.data[row_idx]
|
|
114
|
+
folded_backratio = observation.folded_backratio.data[row_idx]
|
|
115
|
+
area = instrument.area.data[col_idx]
|
|
116
|
+
e_min_folded = e_min[row_idx]
|
|
117
|
+
e_max_folded = e_max[row_idx]
|
|
118
|
+
e_min_unfolded = e_min_unfolded[col_idx]
|
|
119
|
+
e_max_unfolded = e_max_unfolded[col_idx]
|
|
142
120
|
|
|
143
121
|
if observation.folded_background is not None:
|
|
144
|
-
folded_background = observation.folded_background.
|
|
145
|
-
|
|
122
|
+
folded_background = observation.folded_background.data[row_idx]
|
|
146
123
|
else:
|
|
147
|
-
folded_background =
|
|
124
|
+
folded_background = np.zeros_like(folded_counts)
|
|
125
|
+
|
|
126
|
+
data_dict = {
|
|
127
|
+
"transfer_matrix": (
|
|
128
|
+
["folded_channel", "unfolded_channel"],
|
|
129
|
+
transfer_matrix,
|
|
130
|
+
{
|
|
131
|
+
"description": "Transfer matrix to use to fold the incoming spectrum. It is built and restricted using the grouping, redistribution matrix, effective area, quality flags and energy bands defined by the user."
|
|
132
|
+
},
|
|
133
|
+
),
|
|
134
|
+
"area": (
|
|
135
|
+
["unfolded_channel"],
|
|
136
|
+
area,
|
|
137
|
+
{"description": "Effective area with the same restrictions as the transfer matrix.", "units": "cm^2"},
|
|
138
|
+
),
|
|
139
|
+
"exposure": ([], exposure, {"description": "Total exposure", "unit": "s"}),
|
|
140
|
+
"folded_counts": (
|
|
141
|
+
["folded_channel"],
|
|
142
|
+
folded_counts,
|
|
143
|
+
{
|
|
144
|
+
"description": "Folded counts after grouping, with the same restrictions as the transfer matrix.",
|
|
145
|
+
"unit": "photons",
|
|
146
|
+
},
|
|
147
|
+
),
|
|
148
|
+
"folded_backratio": (
|
|
149
|
+
["folded_channel"],
|
|
150
|
+
folded_backratio,
|
|
151
|
+
{"description": "Background scaling after grouping, with the same restrictions as the transfer matrix."},
|
|
152
|
+
),
|
|
153
|
+
"folded_background": (
|
|
154
|
+
["folded_channel"],
|
|
155
|
+
folded_background,
|
|
156
|
+
{
|
|
157
|
+
"description": "Folded background counts after grouping, with the same restrictions as the transfer matrix.",
|
|
158
|
+
"unit": "photons",
|
|
159
|
+
},
|
|
160
|
+
),
|
|
161
|
+
}
|
|
148
162
|
|
|
149
163
|
return cls(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
"
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
164
|
+
data_dict,
|
|
165
|
+
coords={
|
|
166
|
+
"e_min_folded": (
|
|
167
|
+
["folded_channel"],
|
|
168
|
+
e_min_folded,
|
|
169
|
+
{"description": "Low energy of folded channel"},
|
|
170
|
+
),
|
|
171
|
+
"e_max_folded": (
|
|
172
|
+
["folded_channel"],
|
|
173
|
+
e_max_folded,
|
|
174
|
+
{"description": "High energy of folded channel"},
|
|
175
|
+
),
|
|
176
|
+
"e_min_unfolded": (
|
|
177
|
+
["unfolded_channel"],
|
|
178
|
+
e_min_unfolded,
|
|
179
|
+
{"description": "Low energy of unfolded channel"},
|
|
180
|
+
),
|
|
181
|
+
"e_max_unfolded": (
|
|
182
|
+
["unfolded_channel"],
|
|
183
|
+
e_max_unfolded,
|
|
184
|
+
{"description": "High energy of unfolded channel"},
|
|
185
|
+
),
|
|
186
|
+
},
|
|
187
|
+
attrs=observation.attrs | instrument.attrs,
|
|
158
188
|
)
|
jaxspec/data/observation.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import os
|
|
2
1
|
import numpy as np
|
|
3
2
|
import xarray as xr
|
|
3
|
+
from .ogip import DataPHA
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class Observation(xr.Dataset):
|
|
@@ -95,11 +95,7 @@ class Observation(xr.Dataset):
|
|
|
95
95
|
)
|
|
96
96
|
|
|
97
97
|
@classmethod
|
|
98
|
-
def
|
|
99
|
-
from .util import data_loader
|
|
100
|
-
|
|
101
|
-
pha, arf, rmf, bkg, metadata = data_loader(pha_file)
|
|
102
|
-
|
|
98
|
+
def from_ogip_container(cls, pha: DataPHA, bkg: DataPHA | None = None, **metadata):
|
|
103
99
|
if bkg is not None:
|
|
104
100
|
backratio = np.nan_to_num((pha.backscal * pha.exposure * pha.areascal) / (bkg.backscal * bkg.exposure * bkg.areascal))
|
|
105
101
|
else:
|
|
@@ -116,6 +112,28 @@ class Observation(xr.Dataset):
|
|
|
116
112
|
attributes=metadata,
|
|
117
113
|
)
|
|
118
114
|
|
|
115
|
+
@classmethod
|
|
116
|
+
def from_pha_file(cls, pha_path: str, bkg_path: str | None = None, **metadata):
|
|
117
|
+
from .util import data_path_finder
|
|
118
|
+
|
|
119
|
+
arf_path, rmf_path, bkg_path_default = data_path_finder(pha_path)
|
|
120
|
+
bkg_path = bkg_path_default if bkg_path is None else bkg_path
|
|
121
|
+
|
|
122
|
+
pha = DataPHA.from_file(pha_path)
|
|
123
|
+
bkg = DataPHA.from_file(bkg_path) if bkg_path is not None else None
|
|
124
|
+
|
|
125
|
+
if metadata is None:
|
|
126
|
+
metadata = {}
|
|
127
|
+
|
|
128
|
+
metadata.update(
|
|
129
|
+
observation_file=pha_path,
|
|
130
|
+
background_file=bkg_path,
|
|
131
|
+
response_matrix_file=rmf_path,
|
|
132
|
+
ancillary_response_file=arf_path,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
return cls.from_ogip_container(pha, bkg=bkg, **metadata)
|
|
136
|
+
|
|
119
137
|
def plot_counts(self, **kwargs):
|
|
120
138
|
"""
|
|
121
139
|
Plot the counts
|
jaxspec/data/ogip.py
CHANGED
|
@@ -75,6 +75,24 @@ class DataPHA:
|
|
|
75
75
|
data = QTable.read(pha_file, "SPECTRUM")
|
|
76
76
|
header = fits.getheader(pha_file, "SPECTRUM")
|
|
77
77
|
|
|
78
|
+
if header.get("HDUCLAS2") == "NET":
|
|
79
|
+
raise ValueError(
|
|
80
|
+
f"The HDUCLAS2={header.get('HDUCLAS2')} keyword in the PHA file is not supported."
|
|
81
|
+
f"Please open an issue if this is required."
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
if header.get("HDUCLAS3") == "RATE":
|
|
85
|
+
raise ValueError(
|
|
86
|
+
f"The HDUCLAS3={header.get('HDUCLAS3')} keyword in the PHA file is not supported."
|
|
87
|
+
f"Please open an issue if this is required."
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
if header.get("HDUCLAS4") == "TYPE:II":
|
|
91
|
+
raise ValueError(
|
|
92
|
+
f"The HDUCLAS4={header.get('HDUCLAS4')} keyword in the PHA file is not supported."
|
|
93
|
+
f"Please open an issue if this is required."
|
|
94
|
+
)
|
|
95
|
+
|
|
78
96
|
if header.get("GROUPING") == 0:
|
|
79
97
|
grouping = None
|
|
80
98
|
elif "GROUPING" in data.colnames:
|