Skip to content

Commit 4a28822

Browse files
Merge pull request #575 from StingraySoftware/fix_missing_header_keys
Use header 1 when header 0 has missing keys
2 parents 97ecea0 + 921cf17 commit 4a28822

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

stingray/io.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,19 +574,25 @@ def load_events_and_gtis(
574574
from astropy.io import fits as pf
575575

576576
hdulist = pf.open(fits_file)
577+
probe_header = hdulist[0].header
578+
# Let's look for TELESCOP here. This is the most common keyword to be
579+
# found in well-behaved headers. If it is not in header 0, I take this key
580+
# and the remaining information from header 1.
581+
if "TELESCOP" not in probe_header:
582+
probe_header = hdulist[1].header
577583
mission_key = "MISSION"
578-
if mission_key not in hdulist[0].header:
584+
if mission_key not in probe_header:
579585
mission_key = "TELESCOP"
580-
mission = hdulist[0].header[mission_key].lower()
586+
mission = probe_header[mission_key].lower()
581587
db = read_mission_info(mission)
582588
instkey = get_key_from_mission_info(db, "instkey", "INSTRUME")
583589
instr = mode = None
584-
if instkey in hdulist[0].header:
585-
instr = hdulist[0].header[instkey].strip()
590+
if instkey in probe_header:
591+
instr = probe_header[instkey].strip()
586592

587593
modekey = get_key_from_mission_info(db, "dmodekey", None, instr)
588-
if modekey is not None and modekey in hdulist[0].header:
589-
mode = hdulist[0].header[modekey].strip()
594+
if modekey is not None and modekey in probe_header:
595+
mode = probe_header[modekey].strip()
590596

591597
gtistring = get_key_from_mission_info(db, "gti", "GTI,STDGTI", instr, mode)
592598
if hduname is None:

0 commit comments

Comments
 (0)