Source code for gdt.missions.gifts.tcat

#
# Copyright 2026 by University College Dublin. All rights reserved.
#
# Developed by: Derek O'Callaghan
#               University College Dublin
#               https://www.ucd.ie/
#
# Builds on:
#               Gamma-ray Data Tools - Core Components (https://github.com/USRA-STI/gdt-core)
#               Gamma-ray Data Tools - Fermi mission components (https://github.com/USRA-STI/gdt-fermi/)
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing permissions and limitations under the
# License.
#
import astropy.io.fits as fits
from astropy.coordinates import Latitude, Longitude
from gdt.core.file import FitsFileContextManager
from gdt.missions.fermi.gbm.tcat import Tcat as GbmTcat
from .headers import TcatHeaders

__all__ = ['Tcat']

[docs] class Tcat(GbmTcat): """TCAT (Trigger CATalog) file class. """ @property def gifts_location(self): """(astropy.coordinates.Longitude, astropy.coordinates.Latitude): GIFT's orbital longitude and latitude""" return self.fermi_location
[docs] @classmethod def open(cls, file_path, **kwargs): """Open a TCAT FITS file and return the Tcat object Args: file_path (str): The file path of the FITS file Returns: (:class:`Tcat`) """ # Currently impossible to access the FITS HDUs without opening twice, not ideal # This could be avoided if the original HDUs were retained during opening, but # they're rebuilt by each FITS subclass that uses its own headers obj = FitsFileContextManager.open(file_path, **kwargs) hdrs = [hdu.header for hdu in obj.hdulist] # This is the reason why GbmTcat.open() can't solely be used, # need to explicitly specify the header classes tcat_headers = TcatHeaders.from_headers(hdrs) obj.close() tcat = super().open(file_path, **kwargs) tcat._headers = tcat_headers return tcat
def _build_hdulist(self): """ Fixes bug in GbmTcat._build_hdulist() """ hdulist = fits.HDUList() # Bug fix: self['PRIMARY'] -> self.headers['PRIMARY'] primary_header = self.headers["PRIMARY"] primary_hdu = fits.PrimaryHDU(header=primary_header) hflag = 0 # Bug fix: self['PRIMARY'] -> self.headers['PRIMARY'] for key, val in primary_header.items(): if key == 'HISTORY': primary_hdu.header['HISTORY'][hflag] = val hflag += 1 else: primary_hdu.header[key] = val hdulist.append(primary_hdu) return hdulist