Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass events.time_ref to observation.pointing.to_fits_headerin observation.write #5257

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion gammapy/data/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,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
Loading