Handling Good Time Intervals
[1]:
from astropy.time import Time
from cosipy.event_selection import GoodTimeInterval
11:21:24 WARNING The naima package is not available. Models that depend on it will not be functions.py:48 available
WARNING The GSL library or the pygsl wrapper cannot be loaded. Models that depend on it functions.py:69 will not be available.
WARNING The ebltable package is not available. Models that depend on it will not be absorption.py:33 available
INFO Starting 3ML! __init__.py:39
WARNING WARNINGs here are NOT errors __init__.py:40
WARNING but are inform you about optional packages that can be installed __init__.py:41
WARNING to disable these messages, turn off start_warning in your config file __init__.py:44
11:21:24 WARNING ROOT minimizer not available minimization.py:1345
WARNING Multinest minimizer not available minimization.py:1357
WARNING PyGMO is not available minimization.py:1369
WARNING The cthreeML package is not installed. You will not be able to use plugins which __init__.py:94 require the C/C++ interface (currently HAWC)
WARNING Could not import plugin HAWCLike.py. Do you have the relative instrument __init__.py:144 software installed and configured?
WARNING Could not import plugin FermiLATLike.py. Do you have the relative instrument __init__.py:144 software installed and configured?
WARNING No fermitools installed lat_transient_builder.py:44
11:21:25 WARNING Env. variable OMP_NUM_THREADS is not set. Please set it to 1 for optimal __init__.py:387 performances in 3ML
WARNING Env. variable MKL_NUM_THREADS is not set. Please set it to 1 for optimal __init__.py:387 performances in 3ML
WARNING Env. variable NUMEXPR_NUM_THREADS is not set. Please set it to 1 for optimal __init__.py:387 performances in 3ML
Instantiation
Here, a good time interval (GTI) instance for the periods from 2025-10-22 to 2025-10-27 and from 2025-11-01 to 2025-11-06 is generated.
[2]:
tstarts = Time([60970.0, 60980.0], format='mjd', scale = 'utc')
tstops = Time([60975.0, 60985.0], format='mjd', scale = 'utc')
tstarts.iso, tstops.iso
[2]:
(array(['2025-10-22 00:00:00.000', '2025-11-01 00:00:00.000'], dtype='<U23'),
array(['2025-10-27 00:00:00.000', '2025-11-06 00:00:00.000'], dtype='<U23'))
[3]:
gti = GoodTimeInterval(tstarts, tstops)
[4]:
n_range = len(gti)
for i, (tstart, tstop) in enumerate(gti):
print(tstart.iso, '-', tstop.iso)
2025-10-22 00:00:00.000 - 2025-10-27 00:00:00.000
2025-11-01 00:00:00.000 - 2025-11-06 00:00:00.000
Save GTI as a fits file
[5]:
gti.save_as_fits('gti.fits')
WARNING: VerifyWarning: Keyword name 'TIMEFORMAT' is greater than 8 characters or contains characters not allowed by the FITS standard; a HIERARCH card will be created. [astropy.io.fits.card]
[6]:
# open the save fits file
gti_from_fits = GoodTimeInterval.from_fits('gti.fits')
Calculate the intersection of several GTIs
Considering that we have several GTIs, for instance, GTI from the SAA cut and GTI where a source is in the FoV of COSI, etc., we can calculate the final GTI as an intersection of these GTIs as follows.
[7]:
#GTI1
tstarts_1 = Time([60970.0, 60980.0], format='mjd', scale = 'utc')
tstops_1 = Time([60975.0, 60985.0], format='mjd', scale = 'utc')
gti1 = GoodTimeInterval(tstarts_1, tstops_1)
#GTI2
tstarts_2 = Time([60972.0, 60979.0], format='mjd', scale = 'utc')
tstops_2 = Time([60977.0, 60983.0], format='mjd', scale = 'utc')
gti2 = GoodTimeInterval(tstarts_2, tstops_2)
#GTI3
tstarts_3 = Time([60970.0], format='mjd', scale = 'utc')
tstops_3 = Time([60990.0], format='mjd', scale = 'utc')
gti3 = GoodTimeInterval(tstarts_3, tstops_3)
[8]:
for i, _gti in enumerate([gti1, gti2, gti3]):
n_range = len(_gti)
for (tstart, tstop) in _gti:
print(f'GTI {i}: ', tstart.iso, '-', tstop.iso)
print()
GTI 0: 2025-10-22 00:00:00.000 - 2025-10-27 00:00:00.000
GTI 0: 2025-11-01 00:00:00.000 - 2025-11-06 00:00:00.000
GTI 1: 2025-10-24 00:00:00.000 - 2025-10-29 00:00:00.000
GTI 1: 2025-10-31 00:00:00.000 - 2025-11-04 00:00:00.000
GTI 2: 2025-10-22 00:00:00.000 - 2025-11-11 00:00:00.000
[9]:
# intersection
gti_intersection = GoodTimeInterval.intersection(gti1, gti2, gti3)
[10]:
n_range = len(gti_intersection)
for i, (tstart, tstop) in enumerate(gti_intersection):
print(f'GTI {i+1}/{n_range}: ', tstart.iso, '-', tstop.iso)
GTI 1/2: 2025-10-24 00:00:00.000 - 2025-10-27 00:00:00.000
GTI 2/2: 2025-11-01 00:00:00.000 - 2025-11-04 00:00:00.000