Skip to content

Commit dc00a50

Browse files
committed
Wrap average RA to 0-360
1 parent 7c18ede commit dc00a50

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

changes/10456.cube_build.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Wrap average RA values to the 0-360 degree range, to fix negative CRVAL1 values in output cubes.

jwst/cube_build/ifu_cube.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def set_geometry(self, corner_a, corner_b, lambda_min, lambda_max):
340340

341341
# astropy circmean assumes angles are in radians,
342342
# we have angles in degrees
343-
ra_ave = circmean(ravalues * u.deg).value
343+
ra_ave = circmean(ravalues * u.deg).value % 360
344344

345345
if self.ra_center is not None:
346346
self.crval1 = self.ra_center

jwst/cube_build/tests/test_cube_build_step.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy as np
88
import pytest
99
from astropy.io import fits
10+
from astropy.modeling.models import Identity, Shift
1011
from stdatamodels.jwst.datamodels import IFUImageModel
1112

1213
from jwst.adaptive_trace_model import AdaptiveTraceModelStep
@@ -271,3 +272,22 @@ def test_cube_build_oversampled(request, oversample, dataset, output_shape):
271272

272273
# Input data is flat, so output data should have the same mean value
273274
np.testing.assert_allclose(np.nanmean(cube.data), np.nanmean(model.data))
275+
276+
277+
@pytest.mark.parametrize("shift_ra", [True, False])
278+
def test_output_crval1_positive(miri_data, shift_ra):
279+
model = miri_data.copy()
280+
281+
expected_ra = 164
282+
if shift_ra:
283+
# Shift RA by 100 degrees to make it > 180
284+
model.meta.wcs.pipeline[-2].transform |= Shift(100) & Identity(2)
285+
model.meta.wcsinfo.ra_ref += 100
286+
model.meta.wcsinfo.s_region = model.meta.wcsinfo.s_region.replace("164", "264")
287+
expected_ra += 100
288+
289+
result = CubeBuildStep.call(model)
290+
291+
# Output RA should be between 0 and 360
292+
for cube in result:
293+
assert np.isclose(cube.meta.wcsinfo.crval1, expected_ra, atol=1)

0 commit comments

Comments
 (0)