def lightcurve(self): """Lightcurve (`~gammapy.time.LightCurve`).""" flux = self.data["Flux_History"] # Flux error is given as asymmetric high/low flux_errn = -self.data["Unc_Flux_History"][:, 0] flux_errp = self.data["Unc_Flux_History"][:, 1] # Really the time binning is stored in a separate HDU in the FITS # catalog file called `Hist_Start`, with a single column `Hist_Start` # giving the time binning in MET (mission elapsed time) # This is not available here for now. # TODO: read that info in `SourceCatalog3FGL` and pass it down to the # `SourceCatalogObject3FGL` object somehow. # For now, we just hard-code the start and stop time and assume # equally-spaced time intervals. This is roughly correct, # for plotting the difference doesn't matter, only for analysis time_start = Time("2008-08-02T00:33:19") time_end = Time("2012-07-31T22:45:47") n_points = len(flux) time_step = (time_end - time_start) / n_points time_bounds = time_start + np.arange(n_points + 1) * time_step table = Table([ Column(time_bounds[:-1].utc.mjd, "time_min"), Column(time_bounds[1:].utc.mjd, "time_max"), Column(flux, "flux"), Column(flux_errp, "flux_errp"), Column(flux_errn, "flux_errn"), ]) return LightCurve(table)
def test_lightcurve_read_write(tmp_path, lc, format): lc.write(tmp_path / "tmp", format=format) lc = LightCurve.read(tmp_path / "tmp", format=format) # Check if time-related info round-trips time = lc.time assert time.scale == "utc" assert time.format == "mjd" assert_allclose(time.mjd, [55198, 55202.5])
def lightcurve(self, interval="1-year"): """Lightcurve (`~gammapy.estimators.LightCurve`). Parameters ---------- interval : {'1-year', '2-month'} Time interval of the lightcurve. Default is '1-year'. Note that '2-month' is not available for all catalogue version. """ if interval == "1-year": tag = "Flux_History" elif interval == "2-month": tag = "Flux2_History" if tag not in self.data: raise ValueError( "Only '1-year' interval is available for this catalogue version" ) else: raise ValueError("Time intervals available are '1-year' or '2-month'") flux = self.data[tag] # Flux error is given as asymmetric high/low flux_errn = -self.data[f"Unc_{tag}"][:, 0] flux_errp = self.data[f"Unc_{tag}"][:, 1] # Really the time binning is stored in a separate HDU in the FITS # catalog file called `Hist_Start`, with a single column `Hist_Start` # giving the time binning in MET (mission elapsed time) # This is not available here for now. # TODO: read that info in `SourceCatalog3FGL` and pass it down to the # `SourceCatalogObject3FGL` object somehow. # For now, we just hard-code the start and stop time and assume # equally-spaced time intervals. This is roughly correct, # for plotting the difference doesn't matter, only for analysis time_start = Time("2008-08-04T15:43:36.0000") n_points = len(flux) if n_points in [8, 48]: # 8 = 1/years * 8 years # 48 = (12 month/year / 2month) * 8 years time_end = Time("2016-08-02T05:44:11.9999") else: time_end = Time("2018-08-02T05:44:11.9999") time_step = (time_end - time_start) / n_points time_bounds = time_start + np.arange(n_points + 1) * time_step table = Table( [ Column(time_bounds[:-1].utc.mjd, "time_min"), Column(time_bounds[1:].utc.mjd, "time_max"), Column(flux, "flux"), Column(flux_errp, "flux_errp"), Column(flux_errn, "flux_errn"), ] ) return LightCurve(table)
def lc(): meta = dict(TIMESYS="utc") table = Table( meta=meta, data=[ Column(Time(["2010-01-01", "2010-01-03"]).mjd, "time_min"), Column(Time(["2010-01-03", "2010-01-10"]).mjd, "time_max"), Column([1e-11, 3e-11], "flux", unit="cm-2 s-1"), Column([0.1e-11, 0.3e-11], "flux_err", unit="cm-2 s-1"), Column([np.nan, 3.6e-11], "flux_ul", unit="cm-2 s-1"), Column([False, True], "is_ul"), ], ) return LightCurve(table=table)
def lc_2d(): meta = dict(TIMESYS="utc") table = Table( meta=meta, data=[ Column(Time(["2010-01-01", "2010-01-03"]).mjd, "time_min"), Column(Time(["2010-01-03", "2010-01-10"]).mjd, "time_max"), Column([[1.0, 2.0], [1.0, 2.0]], "e_min", unit="TeV"), Column([[2.0, 4.0], [2.0, 4.0]], "e_max", unit="TeV"), Column([[1e-11, 1e-12], [3e-11, 3e-12]], "flux", unit="cm-2 s-1"), Column([[0.1e-11, 1e-13], [0.3e-11, 3e-13]], "flux_err", unit="cm-2 s-1"), Column([[np.nan, np.nan], [3.6e-11, 3.6e-12]], "flux_ul", unit="cm-2 s-1"), Column([[False, False], [True, True]], "is_ul"), ], ) return LightCurve(table=table)