-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLv0_nicer_housekeeping.py
287 lines (239 loc) · 13 KB
/
Lv0_nicer_housekeeping.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
282
283
284
285
286
287
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Thurs Jul 18 10:59am 2020
Generic script to open FITS files for NICER housekeeping data. It is objectively
redundant to have different functions for what is generally the same routine, but
it will help me keep track of things.
"""
from __future__ import division, print_function
import numpy as np
from astropy.io import fits
import Lv0_dirs
Lv0_dirs.global_par()
def get_att(eventfile,par_list):
"""
Getting data from the .att FITS file! Just provide a path to the event file.
I can also input the NICERsoft-output event files because this script will
just search for the ObsID and trawl through the NICER-data folder.
eventfile - path to the event file. Will extract ObsID from this for the NICER files.
par_list - A list of parameters we'd like to extract from the FITS file
(e.g., from eventcl, PI_FAST, TIME, PI)
"""
if type(eventfile) != str:
raise TypeError("eventfile should be a string!")
if type(par_list) != list and type(par_list) != np.ndarray:
raise TypeError("par_list should either be a list or an array!")
event = fits.open(eventfile)
obsid = event[0].header['OBS_ID']
att_file = fits.open(Lv0_dirs.NICER_DATADIR+obsid+'/auxil/ni'+obsid+'.att')
att_dict = {par_list[i]:att_file[1].data[par_list[i]] for i in range(len(par_list))}
#returns a dictionary in the form {'TIME':[array of TIME values],'QPARAM':[array of QPARAM values]}
return att_dict
def get_cat(eventfile,par_list):
"""
Getting data from the .cat FITS file! Just provide a path to the event file.
I can also input the NICERsoft-output event files because this script will
just search for the ObsID and trawl through the NICER-data folder.
eventfile - path to the event file. Will extract ObsID from this for the NICER files.
par_list - A list of parameters we'd like to extract from the FITS file
(e.g., from eventcl, PI_FAST, TIME, PI)
"""
if type(eventfile) != str:
raise TypeError("eventfile should be a string!")
if type(par_list) != list and type(par_list) != np.ndarray:
raise TypeError("par_list should either be a list or an array!")
event = fits.open(eventfile)
obsid = event[0].header['OBS_ID']
cat_file = fits.open(Lv0_dirs.NICER_DATADIR+obsid+'/auxil/ni'+obsid+'.cat')
cat_dict = {par_list[i]:cat_file[1].data[par_list[i]] for i in range(len(par_list))}
#returns a dictionary in the form {'FILENAME':[array of FILENAME values],'FORMAT':[array of FORMAT values]}
return cat_dict
def get_mkf(eventfile,par_list):
"""
Getting data from the .mkf FITS file! Just provide a path to the event file.
I can also input the NICERsoft-output event files because this script will
just search for the ObsID and trawl through the NICER-data folder.
eventfile - path to the event file. Will extract ObsID from this for the NICER files.
par_list - A list of parameters we'd like to extract from the FITS file
(e.g., from eventcl, PI_FAST, TIME, PI)
"""
if type(eventfile) != str:
raise TypeError("eventfile should be a string!")
if type(par_list) != list and type(par_list) != np.ndarray:
raise TypeError("par_list should either be a list or an array!")
event = fits.open(eventfile)
obsid = event[0].header['OBS_ID']
mkf_file = fits.open(Lv0_dirs.NICER_DATADIR+obsid+'/auxil/ni'+obsid+'.mkf')
mkf_dict = {par_list[i]:mkf_file[1].data[par_list[i]] for i in range(len(par_list))}
#returns a dictionary in the form {'TIME':[array of TIME values],'FPM_UNDERONLY_COUNT':[array of FPM_UNDERONLY_COUNT values]}
return mkf_dict
def get_orb(eventfile,par_list):
"""
Getting data from the .orb FITS file! Just provide a path to the event file.
I can also input the NICERsoft-output event files because this script will
just search for the ObsID and trawl through the NICER-data folder.
eventfile - path to the event file. Will extract ObsID from this for the NICER files.
par_list - A list of parameters we'd like to extract from the FITS file
(e.g., from eventcl, PI_FAST, TIME, PI)
"""
if type(eventfile) != str:
raise TypeError("eventfile should be a string!")
if type(par_list) != list and type(par_list) != np.ndarray:
raise TypeError("par_list should either be a list or an array!")
event = fits.open(eventfile)
obsid = event[0].header['OBS_ID']
orb_file = fits.open(Lv0_dirs.NICER_DATADIR+obsid+'/auxil/ni'+obsid+'.orb')
orb_dict = {par_list[i]:orb_file[1].data[par_list[i]] for i in range(len(par_list))}
#returns a dictionary in the form {'TIME':[array of TIME values],'Vx':[array of Vx values]}
return orb_dict
def get_hk(eventfile,mpu_no,par_list):
"""
Getting data from the .hk FITS file! Just provide a path to the event file.
I can also input the NICERsoft-output event files because this script will
just search for the ObsID and trawl through the NICER-data folder.
eventfile - path to the event file. Will extract ObsID from this for the NICER files.
mpu_no - MPU number, from 0 to 6 inclusive. For the 7 MPUs.
par_list - A list of parameters we'd like to extract from the FITS file
(e.g., from eventcl, PI_FAST, TIME, PI)
"""
if type(eventfile) != str:
raise TypeError("eventfile should be a string!")
if type(mpu_no) != str:
raise TypeError("mpu_no should be a string!")
if type(par_list) != list and type(par_list) != np.ndarray:
raise TypeError("par_list should either be a list or an array!")
event = fits.open(eventfile)
obsid = event[0].header['OBS_ID']
hk_file = fits.open(Lv0_dirs.NICER_DATADIR+obsid+'/xti/hk/ni'+obsid+'_0mpu'+mpu_no+'.hk')
hk_dict = {par_list[i]:hk_file[1].data[par_list[i]] for i in range(len(par_list))}
#returns a dictionary in the form {'TIME':[array of TIME values],'MPU_UNDER_COUNT':[array of MPU_UNDER_COUNT values]}
return hk_dict
def get_uf(eventfile,mpu_no,ext,par_list):
"""
Getting data from the .uf FITS file! Just provide a path to the event file.
I can also input the NICERsoft-output event files because this script will
just search for the ObsID and trawl through the NICER-data folder.
eventfile - path to the event file. Will extract ObsID from this for the NICER files.
mpu_no - MPU number, from 0 to 6 inclusive. For the 7 MPUs.
ext - which extension number; 1 for EVENTS, 2 for GTI, 3 for PPS_TREND
par_list - A list of parameters we'd like to extract from the FITS file
(e.g., from eventcl, PI_FAST, TIME, PI)
"""
if type(eventfile) != str:
raise TypeError("eventfile should be a string!")
if type(mpu_no) != str:
raise TypeError("mpu_no should be a string!")
if type(ext) != int:
raise TypeError("ext should be an integer!")
if type(par_list) != list and type(par_list) != np.ndarray:
raise TypeError("par_list should either be a list or an array!")
event = fits.open(eventfile)
obsid = event[0].header['OBS_ID']
uf_file = fits.open(Lv0_dirs.NICER_DATADIR+obsid+'/xti/event_uf/ni'+obsid+'_0mpu'+mpu_no+'_uf.evt')
uf_dict = {par_list[i]:uf_file[ext].data[par_list[i]] for i in range(len(par_list))}
#returns a dictionary in the form {'TIME':[array of TIME values],'DEADTIME':[array of DEADTIME values]}
return uf_dict
def get_ufa(eventfile,mpu_no,ext,par_list):
"""
Getting data from the .ufa FITS file! Just provide a path to the event file.
I can also input the NICERsoft-output event files because this script will
just search for the ObsID and trawl through the NICER-data folder.
eventfile - path to the event file. Will extract ObsID from this for the NICER files.
mpu_no - MPU number, from 0 to 6 inclusive. For the 7 MPUs.
MPU number 7 corresponds to the COMBINED file!
ext - which extension number; 1 for EVENTS, 2 for GTI
par_list - A list of parameters we'd like to extract from the FITS file
(e.g., from eventcl, PI_FAST, TIME, PI)
"""
if type(eventfile) != str:
raise TypeError("eventfile should be a string!")
if type(mpu_no) != str:
raise TypeError("mpu_no should be a string!")
if type(ext) != int:
raise TypeError("ext should be an integer!")
if type(par_list) != list and type(par_list) != np.ndarray:
raise TypeError("par_list should either be a list or an array!")
event = fits.open(eventfile)
obsid = event[0].header['OBS_ID']
ufa_file = fits.open(Lv0_dirs.NICER_DATADIR+obsid+'/xti/event_cl/ni'+obsid+'_0mpu'+mpu_no+'_ufa.evt')
ufa_dict = {par_list[i]:ufa_file[ext].data[par_list[i]] for i in range(len(par_list))}
#returns a dictionary in the form {'TIME':[array of TIME values],'MPU_UNDER_COUNT':[array of MPU_UNDER_COUNT values]}
return ufa_dict
if __name__ == "__main__":
eventfile = '/Volumes/Samsung_T5/NICER-data/1034070101/xti/event_cl/ni1034070101_0mpu7_cl.evt'
#print(get_att(eventfile,['TIME','QPARAM']))
#print(get_cat(eventfile,['FILENAME','FORMAT']))
#print(get_mkf(eventfile,['TIME','NICER_SAA','ANG_DIST']))
#print(get_orb(eventfile,['TIME','Vx','Vy']))
#print(get_hk(eventfile,'3',['TIME','GIT_HASH']))
#print(get_uf(eventfile,'2',1,['TIME','RAWX','DEADTIME']))
#print(get_ufa(eventfile,'7',1,['TIME','MPU_UNDER_COUNT','PI_RATIO']))
################################################################################
### RELEVANT PARAMETERS:
##### ATT file:
# Extension: ATTITUDE
# TIME, QPARAM, STATE, MODE, SUBMODE_AZ, SUBMODE_EL, ST_VALID, QUATSRC, FINEMEAS
# Extension: INST_ATTITUDE
# TIME, QPARAM, STATE, MODE, SUBMODE_AZ, SUBMODE_EL, ST_VALID, QUATSRC, FINEMEAS
##### CAT file:
# Extension: CATALOG
# FILENAME, FORMAT, TYPE, FILECLAS, DESCRIP, FILESIZE, ARCHSIZE, CHECKSUM, GZIP_CRC, CKSUM_B4
##### MKF file:
# Extension: ORIG_PREFILTER
# TIME, POSITION, VELOCITY, QUATERNION, PNTUNIT, POLAR, RA, DEC, ROLL, SAT_LAT,
# SAT_LON, SAT_ALT, ELV, BR_EARTH, SUNSHINE, FOV_FLAG, SUN_ANGLE, MOON_ANGLE,
# RAM_ANGLE, ANG_DIST, SAA, SAA_TIME, COR_ASCA, COR_SAX, MCILWAIN_L, SUN_RA, SUN_DEC,
# MOON_RA, MOON_DEC, EARTH_RA, EARTH_DEC, TIME_ADJ, ST_BBO, ST_VALID, ST_OBJECTS,
# ST_VIDEO_VDC, ATT_ANG_AZ, ATT_ANG_EL, RA_CMD, DEC_CMD, ATT_ERR_AZ, ATT_ERR_EL,
# ATT_STATE, ATT_MODE, ATT_SUBMODE_AZ, ATT_SUBMODE_EL, TARG_CMD, PPS_SOURCE,
# PPS_ERR_LOWPASS, GPS_INIT, GPS_CONVERGED, NICER_SAA, ST_STARS, ST_FAILCODE,
# MPU_ALL_COUNT, MPU_OVER_COUNT, MPU_UNDER_COUNT, MPU_XRAY_COUNT, TOT_ALL_COUNT,
# TOT_UNDER_COUNT, TOT_OVER_COUNT, TOT_XRAY_COUNT, FPM_ON, NUM_FPM_ON
# Extension: PREFILTER
# TIME, POSITION, VELOCITY, QUATERNION, PNTUNIT, POLAR, RA, DEC, ROLL, SAT_LAT,
# SAT_LON, SAT_ALT, ELV, BR_EARTH, SUNSHINE, FOV_FLAG, SUN_ANGLE, MOON_ANGLE,
# RAM_ANGLE, ANG_DIST, SAA, SAA_TIME, COR_ASCA, COR_SAX, MCILWAIN_L, SUN_RA, SUN_DEC,
# MOON_RA, MOON_DEC, EARTH_RA, EARTH_DEC, TIME_ADJ, ST_BBO, ST_VALID, ST_OBJECTS,
# ST_VIDEO_VDC, ATT_ANG_AZ, ATT_ANG_EL, RA_CMD, DEC_CMD, ATT_ERR_AZ, ATT_ERR_EL,
# ATT_STATE, ATT_MODE, ATT_SUBMODE_AZ, ATT_SUBMODE_EL, TARG_CMD, PPS_SOURCE,
# PPS_ERR_LOWPASS, GPS_INIT, GPS_CONVERGED, NICER_SAA, ST_STARS, ST_FAILCODE,
# MPU_ALL_COUNT, MPU_OVER_COUNT, MPU_UNDER_COUNT, MPU_XRAY_COUNT, TOT_ALL_COUNT,
# TOT_UNDER_COUNT, TOT_OVER_COUNT, TOT_XRAY_COUNT, FPM_ON, NUM_FPM_ON,
# FPM_RATIO_REJ_COUNT, FPM_XRAY_PI_0000_0025, FPM_XRAY_PI_0035_0200,
# FPM_XRAY_PI_0200_0800, FPM_XRAY_PI_0800_1200, FPM_XRAY_PI_1200_1500,
# FPM_XRAY_PI_1500_1700, FPM_XRAY_PI_COUNT, MPU_DEADTIME, MPU_DOUBLE_COUNT,
# MPU_FT_COUNT, MPU_NOISE25_COUNT, MPU_OVERONLY_COUNT, MPU_UNDERONLY_COUNT,
# FPM_DOUBLE_COUNT, FPM_OVERONLY_COUNT, FPM_UNDERONLY_COUNT, FPM_FT_COUNT,
# FPM_NOISE25_COUNT, MPU_FT_PI_AVG, MPU_FT_PI_ERR, MPU_FT_PI_FAST_AVG,
# MPU_FT_PI_FAST_ERR, MPU_NOISE25_PI_AVG, MPU_NOISE25_PI_ERR, ISS_ATT_STATE,
# ROBO_STATE, VEHICLE_SOYUZ_DC1, VEHICLE_SOYUZ_MRM1, VEHICLE_SOYUZ_MRM2,
# VEHICLE_SOYUZ_SM
##### ORB file:
# Extension: ORBIT
# TIME, X, Y, Z, Vx, Vy, Vz, GEONS_J2K_TIME_RAW0, GEONS_J2K_WEEK0, ORIG_TIME, QUALITY
# Extension: SPS_ORBIT
# TIME, X, Y, Z, Vx, Vy, Vz, TIME_VALID, QUALITY, SPS_SECS, SPS_WEEK, SDS_GDOP, ORIG_TIME
##### HK file:
# Extension: MPU_HK
#TIME, TICK_LOW32, MPU_P33D_VOLT, MPU_P5D_VOLT, MPU_M5D_VOLT, MPU_P33TEC_VOLT
# MPU_P33M_VOLT, MPU_GNDD_VOLT, MPU_HV_VOLT, MPU_D_TEMP, MPU_GNDA_VOLT,
# MPU_M5A_VOLT, MPU_P5A_VOLT, MPU_P25R_VOLT, MPU_P3R_VOLT, MPU_A_TEMP,
# MPU_PWRBRDG_TEMP, MPU_BAD_CSUM, MPU_INVALID_PKT, MPU_INVALID_ID, MPU_INVALID_MPU,
# MPU_LOWMEM_FIFO, MPU_LOWMEM,SCI, MPU_LOWMEM_OTHER, MPU_ALL_COUNT, MPU_OVER_COUNT,
# MPU_UNDER_COUNT, MPU_XRAY_COUNT, MPU_FPM_TEMP, MPU_PID_TEMP, MPU_HOTSIDE_TEMP,
# MPU_TEC_I, MPU_TEC_VOLT, MPU_BIAS_VOLT, MPU_FAST_LLD, MPU_SLOW_LLD, PACKET_FORMAT
# GIT_HASH, COMPILE_DATE
##### UF file:
# Extension: EVENTS
# TIME, RAWX, RAWY, PHA, PHA_FAST, DET_ID, DEADTIME, EVENT_FLAGS, TICK,
# Extension: GTI
# START, STOP
# Extension: PPS_TREND
# TIME, TICK, PKT_TICK
##### UFA file:
# Extension: EVENTS
# TIME, RAWX, RAWY, PHA, PHA_FAST, DET_ID, DEADTIME, EVENT_FLAGS, TICK, MPU_A_TEMP
# MPU_UNDER_COUNT, PI_FAST, PI, PI_RATIO
# Extension: GTI
# START, STOP