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

Verify that we can reproduce the L3 WCS from the L3 metadata #1431

Open
schlafly opened this issue Oct 2, 2024 · 1 comment · May be fixed by #1585
Open

Verify that we can reproduce the L3 WCS from the L3 metadata #1431

schlafly opened this issue Oct 2, 2024 · 1 comment · May be fixed by #1585
Assignees

Comments

@schlafly
Copy link
Collaborator

schlafly commented Oct 2, 2024

We should verify that we can reproduce the L3 WCS from the L3 metadata, when creating L3 files on sky cells and on inferred projections (i.e., no explicit sky cell, letting resample pick what WCS it wants to resample onto).

@mairanteodoro found that this block of code

try:
l3_wcsinfo.rotation_matrix = transform[
"pc_rotation_matrix"
].matrix.value.tolist()
except Exception:
log.warning(
"WCS has no clear rotation matrix defined by pc_rotation_matrix. Calculating one."
)
rotation_matrix = utils.calc_rotation_matrix(l3_wcsinfo.orientat, 0.0)
l3_wcsinfo.rotation_matrix = utils.list_1d_to_2d(rotation_matrix, 2)

produces a different rotation matrix in the two blocks of the try statement, differing by the sign of rotation_matrix[0][0], which suggests to me that we may currently be encoding whether the RA direction increases to the +x or -x direction in the rotation matrix. That hadn't previously been obvious to me but doesn't seem crazy.

The goal is that we should be able to feed the L3 metadata to something like

def generate_tan_wcs(skycell_record):
# extract the wcs info from the record for generate_tan_wcs
# we need the scale, ra, dec, bounding_box
scale = float(skycell_record["pixel_scale"])
ra_center = float(skycell_record["ra_projection_center"])
dec_center = float(skycell_record["dec_projection_center"])
shiftx = float(skycell_record["x0_projection"])
shifty = float(skycell_record["y0_projection"])
bounding_box = (
(-0.5, -0.5 + skycell_record["nx"]),
(-0.5, -0.5 + skycell_record["ny"]),
)
# components of the model
# shift = models.Shift(shiftx) & models.Shift(shifty)
# select a scale for the skycell image, this will come from INS and may
# be optimized for the different survey programs
scale_x = scale
scale_y = scale
# set the pixelsscale to 0.1 arcsec/pixel
pixelscale = models.Scale(scale_x / 3600.0) & models.Scale(scale_y / 3600.0)
pixelshift = models.Shift(-1.0 * shiftx) & models.Shift(-1.0 * shifty)
tangent_projection = models.Pix2Sky_TAN()
celestial_rotation = models.RotateNative2Celestial(ra_center, dec_center, 180.0)
det2sky = pixelshift | pixelscale | tangent_projection | celestial_rotation
detector_frame = coordinate_frames.Frame2D(
name="detector", axes_names=("x", "y"), unit=(u.pix, u.pix)
)
sky_frame = coordinate_frames.CelestialFrame(
reference_frame=coordinates.ICRS(), name="icrs", unit=(u.deg, u.deg)
)
wcsobj = WCS([(detector_frame, det2sky), (sky_frame, None)])
wcsobj.bounding_box = bounding_box
return wcsobj

after appropriate translation of the metadata keywords into record keywords that that function expects, and get out a WCS that is a close match for the actual WCS.

@stscieisenhamer
Copy link
Collaborator

@schlafly I believe an executive decision will need to be made. The situation is as follows:

First, the routine generate_tan_wcs, when given the parameters of the skycell used from the patches table, creates a wcs that is equivalent to the MosaicModel.meta.wcs that is created by the resample task.

However, the information that is in MosaicModel.meta.wcsinfo cannot simply be passed into generate_tan_wcs. The wcsinfo has some dependency on how the resample's created wcs is defined. This is where the executive decision is needed.

If one desires the ability to provide the skycell information and generate the appropriate wcs, the skycell parameters, as used from the patches table, should be included in the MosaicModel.meta somewhere. Unless I have missed it, the only information about the skycell used by MosaicPipeline is meta.basic.location_name. The information found in the patches table for that location name should be placed in the meta.

If one desires a function to use the existing MosaicModel.meta.wcsinfo, a new function, such as wcs_from_mosaic_wcsinfo will need be created.

Or, both can be done. Note that wcsinfo should simply not be replaced by the skycell parameters since the wcsinfo is generated directly from the actual wcs created, which may have nothing to do with any skycell.

Until further notice, I am going to first create this wcs_from_mosaic_wcsinfo function. That seems like something that should simply exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants