Skip to content

Commit

Permalink
Merge pull request #5262 from meeseeksmachine/auto-backport-of-pr-525…
Browse files Browse the repository at this point in the history
…7-on-v1.2.x

Backport PR #5257 on branch v1.2.x (Pass `events.time_ref` to `observation.pointing.to_fits_header`in `observation.write`)
  • Loading branch information
registerrier committed May 16, 2024
2 parents 96422f5 + 2ceb0a7 commit f57f84a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gammapy/data/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,9 @@ def write(
events = self.events
if events is not None:
events_hdu = events.to_table_hdu(format=format)
events_hdu.header.update(self.pointing.to_fits_header())
events_hdu.header.update(
self.pointing.to_fits_header(time_ref=events.time_ref)
)
hdul.append(events_hdu)

gti = self.gti
Expand Down
5 changes: 5 additions & 0 deletions gammapy/data/tests/test_observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ def test_observation_write(tmp_path):
obs = Observation.read(
"$GAMMAPY_DATA/hess-dl3-dr1/data/hess_dl3_dr1_obs_id_023523.fits.gz"
)
mjdreff = obs.events.table.meta["MJDREFF"]
mjdrefi = obs.events.table.meta["MJDREFI"]
path = tmp_path / "obs.fits.gz"

obs.meta.creation.origin = "test"
Expand All @@ -393,6 +395,9 @@ def test_observation_write(tmp_path):
assert obs_read.obs_id == 23523
assert_allclose(obs_read.observatory_earth_location.lat.deg, -23.271778)

assert_allclose(obs_read.events.table.meta["MJDREFF"], mjdreff)
assert_allclose(obs_read.events.table.meta["MJDREFI"], mjdrefi)

# unsupported format
with pytest.raises(ValueError):
obs.write(tmp_path / "foo.fits.gz", format="cool-new-format")
Expand Down

0 comments on commit f57f84a

Please sign in to comment.