-
Notifications
You must be signed in to change notification settings - Fork 0
/
szkpan_lib.py
executable file
·284 lines (157 loc) · 7.29 KB
/
szkpan_lib.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
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
#! /usr/bin/env python
# |----------------------------------------------------------------------|
# |-----------------------------SZKPAN_LIB-------------------------------|
# |----------------------------------------------------------------------|
# A selection of useful SUZAKU-specific functions which are placed here to reduce clutter in the other
# files of PANTHEON. Supports .evt formatted FITS files.
#
# Contents:
#
# CHRANGE - clips a set of event data given to it to screen out photons outside of some energy range
# given by the user.
#
# DISCNEV - Discards non-photon events from a table of data
#
# GETBIN - gets the binning time of a FITS data table
#
# GETDAT - gets the data of a FITS data table
#
# GETGTI - gets the GTIs associated with a FITS data table
#
# GETINI - gets the start time of the observation associated with a FITS data table
#
# GETPCU - gets the number of PCUs that contributed events to a FITS data table
#
# MAXEN - returns the highest energy or channel valid for the instrument.
#
#-----Importing Modules------------------------------------------------------------------------------------------------
import pan_lib as pan
from numpy import array, ones
#-----ChRange----------------------------------------------------------------------------------------------------------
def chrange(data,low,high,header):
'''Channel Ranger
Description:
Takes raw event or GoodXenon data from PCA on RXTE and removes all photons outside of an energy
channel range given by the user.
Inputs:
data - FITS DATA: the event data; raw photon arrival times and data words.
low - INT: the lowest channel the user wants to consider.
high - INT: the highest channel the user wants to consider.
datamode - STRING: the datamode in which the data was taken.
Outputs:
ch_data - FITS DATA: the same as data, but with all photons outside of the given channel range
removed.
-J.M.Court, 2015'''
datamode=header['DATAMODE']
words=data.field('PI')
low=(low/3.65)
high=(high/3.65)
if low<=0 and high>=4095:
return data # Don't bother searching through if the user wants full range
mask1=(words>=low)
mask2=(words<=high)
ch_data=data[mask1&mask2]
return ch_data
#-----DiscNEv----------------------------------------------------------------------------------------------------------
def discnev(datas,datamode):
'''Discard Non-Events
Decription:
Given a FITS data table, discards all non-photon events from the table.
-J.M.Court, 2014'''
return datas # Nothing to discard in Suzaku data
#-----GetBin-----------------------------------------------------------------------------------------------------------
def getbin(event,datamode):
'''Get Bin
Description:
Returns the time binning of a given set of FITS data.
Inputs:
event - FITS OBJECT: The FITS file that has been opened.
Outputs:
bsz - FLOAT: The bin size of the observation (s).
-J.M.Court, 2014'''
bsz=event[1].header['TIMEDEL']
return bsz
#-----GetDat-----------------------------------------------------------------------------------------------------------
def getdat(event):
'''Get data
Description:
Returns the data table of a given set of FITS data.
Inputs:
event - FITS OBJECT: The FITS file that has been opened.
Outputs:
data - FITS TABLE: The data table from the FITS file.
-J.M.Court, 2014'''
data=event[1].data # Extract GTI indices
return data
#-----GetGTI-----------------------------------------------------------------------------------------------------------
def getgti(event):
'''Get GTI
Description:
Returns the GTI of a given set of FITS data.
Inputs:
event - FITS OBJECT: The FITS file that has been opened.
Outputs:
gti - 2D LIST: A list, each element of which contains the start and end point of a GTI.
-J.M.Court, 2014'''
gti=event[2].data # Extract GTI indices
return gti
#-----GetIni-----------------------------------------------------------------------------------------------------------
def getini(event):
'''Get Ini
Description:
Returns the initial (lowest) time of a given set of FITS data.
Inputs:
event - FITS OBJECT: The FITS file that has been opened.
Outputs:
ini - FLOAT: The starting time of the observation (s).
-J.M.Court, 2014'''
ini=event[1].header['TSTART']
return ini
#-----Get Obs----------------------------------------------------------------------------------------------------------
def getobs(event,datamode,filename):
'''Get Obs
Description:
Fetches a tuple consisting of the object and obs_id of the observation.'''
obsdata=(event[1].header['OBJECT'],event[1].header['OBS_ID'])
return obsdata
#-----Get PCU----------------------------------------------------------------------------------------------------------
def getpcu(words,header):
'''Get PCUs
Description:
If given a list of RXTE event words, and the data-mode in which their associated data is stored,
returns the number of PCUs that contributed photons to the dataset. Currently works for two
datamodes: GoodXenon_2s and E_125us_64M_0_1s with the intention to eventually generalise it to
any event data.
Inputs:
words - 2D ARRAY: The array of event words, each of which is an array of True/False statements.
datamode - STRING: The DATAMODE in which the data to be analysed is stored.
Outputs:
pcus - INT: The number of PCUs active when the data was taken. If a non-recognised event
word is given, 1 is returned instead along with an error message.
-J.M.Court, 2015'''
return 1 ########CHECK THIS IS OK############
#-----Get Tim----------------------------------------------------------------------------------------------------------
def gettim(data,event,tstart,res,datamode):
'''Get Times
Description: Returns the DATA Word or table column containing data on arrival times.
-J.M.Court, 2015'''
return data.field('TIME'),data
#-----Get Wrd----------------------------------------------------------------------------------------------------------
def getwrd(data,mask,datamode):
'''Get Words
Description: Returns the DATA Word or table column containing data on PCUs.
-J.M.Court, 2015'''
return ones(len(data.field(0)))
#-----Get Wrd Row------------------------------------------------------------------------------------------------------
def getwrdrow(words,datamode):
'''Get Word Rows
Description: Returns Data Words filtered by a mask, for data that has datawords.
-J.M.Court, 2015'''
return words[mask]
#-----MaxEn------------------------------------------------------------------------------------------------------------
def maxen(datamode):
'''Max Energy
Description:
Returns the highest energy or channel valid for the instrument.
-J.M.Court, 2015'''
return 4095*3.65