From 26fa49b25161edd0d34eabd5eb619e6fe21d4cec Mon Sep 17 00:00:00 2001 From: DinoBektesevic Date: Wed, 4 Sep 2024 12:03:40 -0700 Subject: [PATCH] Flip the corners back, fix astropy BBox calculator. --- .../standardizers/butler_standardizer.py | 25 +++++++++++++++---- src/kbmod/standardizers/standardizer.py | 22 ++++++++++++---- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/kbmod/standardizers/butler_standardizer.py b/src/kbmod/standardizers/butler_standardizer.py index 33ec29775..50c366afd 100644 --- a/src/kbmod/standardizers/butler_standardizer.py +++ b/src/kbmod/standardizers/butler_standardizer.py @@ -208,14 +208,26 @@ def _computeSkyBBox(self, wcs, dimX, dimY): calculates the values of world coordinates image center and image corners. + The corners are given by the following indices: + + topleft topright + (0, dimX) ---------- (dimY, dimX) + | | + | x | + | (dimY/2, dimX/2) | + | center | + | | + (0, 0) ---------- (dimY, 0) + botleft botright + Parameters ---------- wcs : `object` World coordinate system object, must support standard WCS API. dimX : `int` - Image dimension in x-axis. + Maximal index in the NumPy convention x-axis, a "height". dimY : `int` - Image dimension in y-axis. + Maximal index in the NumPy convention y-axis, a "width" return_type : `str`, optional A 'dict' or an 'array', the type the result is returned as. @@ -313,17 +325,20 @@ def _fetch_meta(self): self._naxis1 = bbox.getWidth() self._naxis2 = bbox.getHeight() + # If the standardizer is re-used, many generators will be + # depleted, returning None as values. Cast to dict to make + # a copy. wcs_ref = self.ref.makeComponentRef("wcs") wcs = self.butler.get(wcs_ref) - meta = wcs.getFitsMetadata() + meta = dict(wcs.getFitsMetadata()) meta["NAXIS1"] = self._naxis1 meta["NAXIS2"] = self._naxis2 self._wcs = WCS(meta) # calculate the WCS "error" (max difference between edge coordinates # from Rubin's more powerful SkyWCS and Atropy's Fits-WCS) - skyBBox = self._computeSkyBBox(wcs, self._naxis1, self._naxis2) - apyBBox = self._computeBBoxArray(self._wcs, self._naxis1, self._naxis2) + skyBBox = self._computeSkyBBox(wcs, self._naxis2, self._naxis1) + apyBBox = self._computeBBoxArray(self._wcs, self._naxis2, self._naxis1) self._metadata["wcs_err"] = (skyBBox - apyBBox).max() # TODO: see issue #666 diff --git a/src/kbmod/standardizers/standardizer.py b/src/kbmod/standardizers/standardizer.py index 56c8b33ed..61f33b3de 100644 --- a/src/kbmod/standardizers/standardizer.py +++ b/src/kbmod/standardizers/standardizer.py @@ -616,6 +616,18 @@ def _computeBBoxArray(self, wcs, dimX, dimY): calculates the values of world coordinates image center and image corners. + The corners are given by the following indices: + + topleft topright + (0, dimX) ---------- (dimY, dimX) + | | + | x | + | (dimY/2, dimX/2) | + | center | + | | + (0, 0) ---------- (dimY, 0) + botleft botright + Parameters ---------- wcs : `object` @@ -639,7 +651,7 @@ def _computeBBoxArray(self, wcs, dimX, dimY): Bottom left corner is taken to be the (0,0)-th pixel and image lies in the first quadrant of a unit circle to match Astropy's convention. """ - center = wcs.pixel_to_world(dimY, dimX) + center = wcs.pixel_to_world(int(dimY // 2), int(dimX // 2)) botleft = wcs.pixel_to_world(0, 0) topleft = wcs.pixel_to_world(0, dimX) topright = wcs.pixel_to_world(dimY, dimX) @@ -682,8 +694,8 @@ def _bboxArrayToDict(self, stdBBoxArr): standardizedBBox["ra"] = center[0] standardizedBBox["dec"] = center[1] - standardizedBBox["ra_bl"] = botright[0] - standardizedBBox["dec_bl"] = botright[1] + standardizedBBox["ra_bl"] = botleft[0] + standardizedBBox["dec_bl"] = botleft[1] standardizedBBox["ra_tl"] = topleft[0] standardizedBBox["dec_tl"] = topleft[1] @@ -691,8 +703,8 @@ def _bboxArrayToDict(self, stdBBoxArr): standardizedBBox["ra_tr"] = topright[0] standardizedBBox["dec_tr"] = topright[1] - standardizedBBox["ra_br"] = botleft[0] - standardizedBBox["dec_br"] = botleft[1] + standardizedBBox["ra_br"] = botright[0] + standardizedBBox["dec_br"] = botright[1] return standardizedBBox