From 8c310e2f9c17a558b888a7e53a4594af0f48396a Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Mon, 17 May 2021 12:04:00 +0200 Subject: [PATCH 1/3] Use header 1 when header 0 has missing keys --- stingray/io.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/stingray/io.py b/stingray/io.py index d8551b491..06a966d6f 100644 --- a/stingray/io.py +++ b/stingray/io.py @@ -574,19 +574,22 @@ def load_events_and_gtis( from astropy.io import fits as pf hdulist = pf.open(fits_file) + probe_header = hdulist[0].header + if "TELESCOP" not in probe_header: + probe_header = hdulist[1].header mission_key = "MISSION" - if mission_key not in hdulist[0].header: + if mission_key not in probe_header: mission_key = "TELESCOP" - mission = hdulist[0].header[mission_key].lower() + mission = probe_header[mission_key].lower() db = read_mission_info(mission) instkey = get_key_from_mission_info(db, "instkey", "INSTRUME") instr = mode = None - if instkey in hdulist[0].header: - instr = hdulist[0].header[instkey].strip() + if instkey in probe_header: + instr = probe_header[instkey].strip() modekey = get_key_from_mission_info(db, "dmodekey", None, instr) - if modekey is not None and modekey in hdulist[0].header: - mode = hdulist[0].header[modekey].strip() + if modekey is not None and modekey in probe_header: + mode = probe_header[modekey].strip() gtistring = get_key_from_mission_info(db, "gti", "GTI,STDGTI", instr, mode) if hduname is None: From e83e14700e689a680aeac3f7a13fa541a1bd19be Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Mon, 17 May 2021 12:34:52 +0200 Subject: [PATCH 2/3] Test case with missing TELESCOP key in header 0 --- stingray/tests/data/nomission.evt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stingray/tests/data/nomission.evt b/stingray/tests/data/nomission.evt index c1dd94073..a514643c5 100644 --- a/stingray/tests/data/nomission.evt +++ b/stingray/tests/data/nomission.evt @@ -1,4 +1,4 @@ -SIMPLE = T / conforms to FITS standard BITPIX = 8 / array data type NAXIS = 0 / number of array dimensions EXTEND = T OBSERVER= 'Edwige Bubble' TELESCOP= 'babasone ' / Telescope (mission) name INSTRUME= 'INSTRUMO' / Instrument name HISTORY File modified by user 'meo' with fv on 2020-11-13T17:08:07 END XTENSION= 'BINTABLE' / binary table extension BITPIX = 8 / array data type NAXIS = 2 / number of array dimensions NAXIS1 = 12 / length of dimension 1 NAXIS2 = 1000 / length of dimension 2 PCOUNT = 0 / number of group parameters GCOUNT = 1 / number of groups TFIELDS = 2 / number of table fields TTYPE1 = 'TIME ' TFORM1 = '1D ' TTYPE2 = 'PI ' TFORM2 = '1J ' EXTNAME = 'EVENTS ' / extension name OBSERVER= 'Edwige Bubble' TELESCOP= 'babasone ' / Telescope (mission) name INSTRUME= 'INSTRUMO ' / Instrument name OBS_ID = '00000000001' / Observation ID TARG_ID = 0 / Target ID OBJECT = 'Fake X-1' / Name of observed object RA_OBJ = 0.0 / [deg] R.A. Object DEC_OBJ = 0.0 / [deg] Dec Object RA_NOM = 0.0 / Right Ascension used for barycenter correctionsDEC_NOM = 0.0 / Declination used for barycenter corrections RA_PNT = 0.0 / [deg] RA pointing DEC_PNT = 0.0 / [deg] Dec pointing PA_PNT = 0.0 / [deg] Position angle (roll) EQUINOX = 2000.0 / Equinox of celestial coord system RADECSYS= 'FK5 ' / Coordinate Reference System TASSIGN = 'SATELLITE' / Time assigned by onboard clock TIMESYS = 'TDB ' / All times in this file are TDB MJDREFI = 55197 / TDB time reference; Modified Julian Day (int) MJDREFF = 0.00076601852 / TDB time reference; Modified Julian Day (frac) TIMEREF = 'SOLARSYSTEM' / Times are pathlength-corrected to barycenter CLOCKAPP= F / TRUE if timestamps corrected by gnd sware TIMEUNIT= 's ' / unit for time keywords TSTART = 80000000.0 / Elapsed seconds since MJDREF at start of file TSTOP = 80001025.0 / Elapsed seconds since MJDREF at end of file LIVETIME= 1025.0 / On-source time TIMEZERO= 0.0 / Time Zero COMMENT FITS (Flexible Image Transport System) format is defined in 'Astronomy aCOMMENT nd Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT MJDREFI+MJDREFF = epoch of Jan 1, 2010, in TT time system. HISTORY File modified by user 'meo' with fv on 2015-08-17T14:10:02 HISTORY File modified by user 'meo' with fv on 2015-08-17T14:48:52 HISTORY File modified by user 'meo' with fv on 2020-11-13T17:07:43 END A٤KAՄHoAv>A ]KA|dA'AzCg"Aڻ?'AʷRACWAAͬAB'A![YANzA`Ӏ9A%wAիVAA{*CAՈ-A]AM"&tA|8ARJ!'A>-cA$0A[(zjAؚhAb5,A,OA&"A߬xA9 +SIMPLE = T / conforms to FITS standard BITPIX = 8 / array data type NAXIS = 0 / number of array dimensions EXTEND = T OBSERVER= 'Edwige Bubble' INSTRUME= 'INSTRUMO' / Instrument name HISTORY File modified by user 'meo' with fv on 2020-11-13T17:08:07 HISTORY File modified by user 'meo' with fv on 2021-05-17T12:34:22 END XTENSION= 'BINTABLE' / binary table extension BITPIX = 8 / array data type NAXIS = 2 / number of array dimensions NAXIS1 = 12 / length of dimension 1 NAXIS2 = 1000 / length of dimension 2 PCOUNT = 0 / number of group parameters GCOUNT = 1 / number of groups TFIELDS = 2 / number of table fields TTYPE1 = 'TIME ' TFORM1 = '1D ' TTYPE2 = 'PI ' TFORM2 = '1J ' EXTNAME = 'EVENTS ' / extension name OBSERVER= 'Edwige Bubble' TELESCOP= 'babasone ' / Telescope (mission) name INSTRUME= 'INSTRUMO ' / Instrument name OBS_ID = '00000000001' / Observation ID TARG_ID = 0 / Target ID OBJECT = 'Fake X-1' / Name of observed object RA_OBJ = 0.0 / [deg] R.A. Object DEC_OBJ = 0.0 / [deg] Dec Object RA_NOM = 0.0 / Right Ascension used for barycenter correctionsDEC_NOM = 0.0 / Declination used for barycenter corrections RA_PNT = 0.0 / [deg] RA pointing DEC_PNT = 0.0 / [deg] Dec pointing PA_PNT = 0.0 / [deg] Position angle (roll) EQUINOX = 2000.0 / Equinox of celestial coord system RADECSYS= 'FK5 ' / Coordinate Reference System TASSIGN = 'SATELLITE' / Time assigned by onboard clock TIMESYS = 'TDB ' / All times in this file are TDB MJDREFI = 55197 / TDB time reference; Modified Julian Day (int) MJDREFF = 0.00076601852 / TDB time reference; Modified Julian Day (frac) TIMEREF = 'SOLARSYSTEM' / Times are pathlength-corrected to barycenter CLOCKAPP= F / TRUE if timestamps corrected by gnd sware TIMEUNIT= 's ' / unit for time keywords TSTART = 80000000.0 / Elapsed seconds since MJDREF at start of file TSTOP = 80001025.0 / Elapsed seconds since MJDREF at end of file LIVETIME= 1025.0 / On-source time TIMEZERO= 0.0 / Time Zero COMMENT FITS (Flexible Image Transport System) format is defined in 'Astronomy aCOMMENT nd Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT MJDREFI+MJDREFF = epoch of Jan 1, 2010, in TT time system. HISTORY File modified by user 'meo' with fv on 2015-08-17T14:10:02 HISTORY File modified by user 'meo' with fv on 2015-08-17T14:48:52 HISTORY File modified by user 'meo' with fv on 2020-11-13T17:07:43 END A٤KAՄHoAv>A ]KA|dA'AzCg"Aڻ?'AʷRACWAAͬAB'A![YANzA`Ӏ9A%wAիVAA{*CAՈ-A]AM"&tA|8ARJ!'A>-cA$0A[(zjAؚhAb5,A,OA&"A߬xA9 1A rLA3ݴAֲ-/A&M{Aެ[?sAPFAۉ( AgAכfA"8A񈩤ATAĽ٪*AP(AZA^Aߒ;IArc;AֵA{ ."AҐ'eA(AЙH,A`nA'+ A&AR AY|A#k6AS aOAӂסAEaEA~eAE 5sAVteA[{QA֪^#AdA՜b?A=,$A0,DA02A)AwAܡ#AٗbA> >OA$uAtAf<AٿnKLA:Aܕ0AL<AOw'A[VVAoA#iUAT!L{AOGB A݈V Am^Anl':A۟cwAFApZAAݚc5Aד9+Aa.=Ai\A?AIZAmFAҸ|Ao%WAdneAUAa@Aׄ=]KAC8AںAЇg7oAʘA%AQ!8,Aߔ鱰A؋\sDAڋ/Aڰo~FAf"AoR#A/~R|A^A9|82AZ A[1 AۚV(AX@ From 921cf179be99c301377e9f587448aa6d6b9c093c Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Mon, 17 May 2021 15:51:29 +0200 Subject: [PATCH 3/3] Add comment --- stingray/io.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stingray/io.py b/stingray/io.py index 06a966d6f..3bf2785e5 100644 --- a/stingray/io.py +++ b/stingray/io.py @@ -575,6 +575,9 @@ def load_events_and_gtis( hdulist = pf.open(fits_file) probe_header = hdulist[0].header + # Let's look for TELESCOP here. This is the most common keyword to be + # found in well-behaved headers. If it is not in header 0, I take this key + # and the remaining information from header 1. if "TELESCOP" not in probe_header: probe_header = hdulist[1].header mission_key = "MISSION"