Skip to content

Commit

Permalink
Merge pull request #694 from dirac-institute/standardizers/wcs_fix2
Browse files Browse the repository at this point in the history
Fix the wrongly oriented BBox in IC.
  • Loading branch information
DinoBektesevic authored Sep 9, 2024
2 parents f6770b7 + 26fa49b commit 2869f17
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
25 changes: 20 additions & 5 deletions src/kbmod/standardizers/butler_standardizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
22 changes: 17 additions & 5 deletions src/kbmod/standardizers/standardizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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)
Expand Down Expand Up @@ -682,17 +694,17 @@ 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]

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

Expand Down

0 comments on commit 2869f17

Please sign in to comment.