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