Rotating DP0.2 `exposures` with WCS

Hi, I have a doubt related to this topic, so I’ll revive it. I read the previous answers and the DP02_03a_Image_Display_and_Manipulation notebook.
I wanted to rotate the images to have North up and East to the left (so RA along x-axis and DEC along y-axis, with RA increasing to the left and Dec increasing towards the top).
I found a function to rotate images in DP02_14_Injecting_Synthetic_Sources (a modified version of this code).
I successfully rotated the image and the coordinates grid as expected, but the coordinates of the grid seem to be wrong.
I attach the original frame (with a marker on a big galaxy)


the rotated one

and an image showing the two frames side by side with the marker that does not fall on the galaxy in the rotated images (but falls at the right galaxy coordinates).

Maybe the function I used rotates in pixel but does not handle wcs?
Or maybe I’m missing something or I’m doing something wrong…
Thanks for any suggestion.

This is the function I used:

def rotate_exposure(exp, n_degrees):
    """Rotate an exposure by nDegrees clockwise.

    Parameters
    ----------
    exp : `lsst.afw.image.exposure.Exposure`
        The exposure to rotate
    n_degrees : `float`
        Number of degrees clockwise to rotate by

    Returns
    -------
    rotated_exp : `lsst.afw.image.exposure.Exposure`
        A copy of the input exposure, rotated by nDegrees
    """
    n_degrees = n_degrees % 360

    wcs = exp.getWcs()

    warper = afwMath.Warper('lanczos4')

    affine_rot_transform = geom.AffineTransform.makeRotation(n_degrees*geom.degrees)
    transform_p2top2 = afwGeom.makeTransform(affine_rot_transform)
    rotated_wcs = afwGeom.makeModifiedWcs(transform_p2top2, wcs, False)

    rotated_exp = warper.warpExposure(rotated_wcs, exp)
    return rotated_exp
1 Like

Thank you, @altavilla, for your questions! I’ve moved this to a new topic under the support category (original topic where this was posted: Calexps displayed with imshow seem offset from WCS center). Thank you for sharing the function you used. To reproduce the error, would you mind sharing all the code you used to produce the images you posted, including the part that calls this function? Additionally, could you please share the LSST Science Pipelines version you were using when spawning the notebook in the data.lsst.cloud RSP? Thanks!

Hi, I used the RSP selecting the following options:

  • Recommended (Weekly 2025_17)
  • Large (4.0 CPU, 16Gi RAM)
    In attachment the notebook I created, maybe there is a mistake…
    testRotation.ipynb (3.0 MB)
    Thanks for the reply!

Hi, indeed there were some mistakes in my notebook, here the revised version and result
testRotationCorr.ipynb (897.7 KB)

original_corr

rotated_1corr
Sorry for bothering

No problem at all! It seems that the addition of extent=image_rotated_extent in the last call to imshow helped fix the issue. The extent keyword should always be used. I’ll mark your post as the solution (thank you for sharing your corrected code!), but feel free to open a new topic in the support category if you have any other questions.