# Licensed under a 3-clause BSD style license - see LICENSE.rstfromtypingimportClassVar,Literal,OptionalfrompydanticimportFieldfromgammapy.utils.fitsimportearth_location_from_dictfromgammapy.utils.metadataimport(METADATA_FITS_KEYS,CreatorMetaData,MetaData,ObsInfoMetaData,PointingInfoMetaData,TargetMetaData,TimeInfoMetaData,)fromgammapy.utils.typesimportEarthLocationType,TimeType__all__=["ObservationMetaData","GTIMetaData","EventListMetaData"]OBSERVATION_METADATA_FITS_KEYS={"location":{"input":lambdav:earth_location_from_dict(v),"output":lambdav:{"GEOLON":v.lon.deg,"GEOLAT":v.lat.deg,"ALTITUDE":v.height.to_value("m"),},},"deadtime_fraction":{"input":lambdav:1-v["DEADC"],"output":lambdav:{"DEADC":1-v},},}METADATA_FITS_KEYS["observation"]=OBSERVATION_METADATA_FITS_KEYSEVENTLIST_METADATA_FITS_KEYS={"event_class":"EV_CLASS",}METADATA_FITS_KEYS["eventlist"]=EVENTLIST_METADATA_FITS_KEYSclassObservationMetaData(MetaData):"""Metadata containing information about the Observation. Parameters ---------- obs_info : `~gammapy.utils.ObsInfoMetaData` The general observation information. pointing : `~gammapy.utils.PointingInfoMetaData The pointing metadata. target : `~gammapy.utils.TargetMetaData The target metadata. creation : `~gammapy.utils.CreatorMetaData` The creation metadata. location : `~astropy.coordinates.EarthLocation` or str, optional The observatory location. deadtime_fraction : float The observation deadtime fraction. Default is 0. optional : dict, optional Additional optional metadata. """_tag:ClassVar[Literal["observation"]]="observation"obs_info:Optional[ObsInfoMetaData]=Nonepointing:Optional[PointingInfoMetaData]=Nonetarget:Optional[TargetMetaData]=Nonelocation:Optional[EarthLocationType]=Nonedeadtime_fraction:float=Field(0.0,ge=0,le=1.0)time_info:Optional[TimeInfoMetaData]=Nonecreation:Optional[CreatorMetaData]=Noneoptional:Optional[dict]=None@classmethoddeffrom_header(cls,header,format="gadf"):"""Create and fill the observation metadata from the event list metadata. Parameters ---------- header : dict Input FITS header. format : str The header data format. Default is gadf. """meta=super().from_header(header,format)meta.creation=CreatorMetaData()# Include additional gadf keywords not specified as ObservationMetaData attributesoptional_keywords=["OBSERVER","EV_CLASS","TELAPSE","TELLIST","N_TELS","TASSIGN","DST_VER","ANA_VER","CAL_VER","CONV_DEP","CONV_RA","CONV_DEC","TRGRATE","ZTRGRATE","MUONEFF","BROKPIX","AIRTEMP","PRESSURE","RELHUM","NSBLEVEL",]optional=dict()forkeyinoptional_keywords:ifkeyinheader.keys():optional[key]=header[key]meta.optional=optionalreturnmetaclassGTIMetaData(MetaData):"""Metadata containing information about the GTI. Parameters ---------- reference_time : Time, str The GTI reference time. """_tag:ClassVar[Literal["GTI"]]="GTI"reference_time:Optional[TimeType]=Nonedeffrom_header(cls,header,format="gadf"):meta=super().from_header(header,format)returnmeta
[docs]classEventListMetaData(MetaData):"""Metadata containing information about the EventList. Parameters ---------- """_tag:ClassVar[Literal["EventList"]]="eventlist"event_class:Optional[str]=Nonecreation:Optional[CreatorMetaData]=Noneoptional:Optional[dict]=None
[docs]@classmethoddeffrom_header(cls,header,format="gadf"):meta=super().from_header(header,format)# Include additional gadf keywordsoptional_keywords=["DST_VER","ANA_VER","CAL_VER",]optional=dict()forkeyinoptional_keywords:ifkeyinheader.keys():optional[key]=header[key]meta.optional=optionalreturnmeta