juanep97 / iop4

IOP4, the Interactive Optical Photo-Polarimetric Python Pipeline.
https://juanep97.github.io/iop4/
BSD 3-Clause "New" or "Revised" License
5 stars 2 forks source link

Fix quad matching #149

Closed juanep97 closed 2 weeks ago

juanep97 commented 2 weeks ago

The quad hash is purposely invariant to flips and permutations. This results sometimes in a bad mapping from the sources in the photometry field and the ones in the polarimetry field. This can be observed in these two images of the same source, where one is correctly mapped, and the other one is not.

ReducedFit 242884 OSN-T090/2024-10-23/J0211_R_IAR-0371_DIPOL.fts

ReducedFit 242883 OSN-T090/2024-10-23/J0211_R_IAR-0370_DIPOL.fts

To resolve this ambiguity, this PR introduces a check of the flip status (sometimes introduced by MaximDL during data taking) and finds the linear transform that correctly takes into account this possible flip.

The new procedure correctly identifies the target source in both images above, both of which have a flip present. It also correctly identifies the source in images where no flip is present:

ReducedFit 242959 OSN-T090/2024-10-23/J0217_R_IAR-0074_DIPOL.fts

morcuended commented 2 weeks ago

Thanks @juanep97. Please briefly explain the changes in the PR's first entry.

juanep97 commented 2 weeks ago

We need to implement this change already in the production installation. There should be a better way to reconstruct the WCS than what we do now,

pix_array_2 = np.array(list(zip(*[(x+x_start,y+y_start) for x,y in (np.dot(R, np.array(quads_1[best_i]).T).T + t)])))

# fit the WCS so the pixel arrays in 1 correspond to the ra/dec of the pixel array in 2
wcs1 = fit_wcs_from_points(pix_array_1,  redf_phot.wcs1.pixel_to_world(*pix_array_2), projection=pre_wcs)
wcs2 = fit_wcs_from_points(pix_array_1,  redf_phot.wcs2.pixel_to_world(*pix_array_2), projection=pre_wcs)

by just concatenating the found transformation to the WCS. But since this method works and we need it now, we can open an issue and make these improvements, and others, later.