Skip to content

Commit

Permalink
Update test data and tests with rotated DonutStamps.
Browse files Browse the repository at this point in the history
Quick fix to get WEP pipeline running on macOS.
Update docs.
  • Loading branch information
jbkalmbach committed Oct 10, 2023
1 parent c996ee0 commit cd54490
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 72 deletions.
10 changes: 9 additions & 1 deletion doc/versionHistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
Version History
##################

.. _lsst.ts.wep-7.1.0:

-------------
7.1.0
-------------

* Save all DonutStamps with images aligned with focal plane science sensors.

.. _lsst.ts.wep-7.0.0:

-------------
Expand All @@ -20,7 +28,7 @@ Version History
6.4.12
-------------

* Update ts_pre_commit_config with ruff.
* Update ts_pre_commit_config with ruff.

.. _lsst.ts.wep-6.4.11:

Expand Down
21 changes: 8 additions & 13 deletions python/lsst/ts/wep/task/cutOutDonutsBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import lsst.afw.cameraGeom
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import lsst.obs.lsst as obs_lsst
import numpy as np
from lsst.daf.base import PropertyList
from lsst.fgcmcal.utilities import lookupStaticCalibrations
Expand All @@ -40,10 +39,10 @@
from lsst.ts.wep.utils import (
DonutTemplateType,
createInstDictFromConfig,
getCamTypeFromButlerName,
getCameraFromButlerName,
getCamTypeFromButlerName,
)
from scipy.ndimage import binary_dilation, shift, rotate
from scipy.ndimage import binary_dilation, rotate, shift
from scipy.signal import correlate


Expand Down Expand Up @@ -156,6 +155,7 @@ class CutOutDonutsBaseTaskConfig(
optional=True,
)


class CutOutDonutsBaseTask(pipeBase.PipelineTask):
"""
Base class for CutOutDonuts tasks.
Expand Down Expand Up @@ -533,17 +533,12 @@ def cutOutStamps(self, exposure, donutCatalog, defocalType, cameraName):
camera = getCameraFromButlerName(cameraName)
detectorInfo = camera.get(detectorName)

# Rotate any sensors that are not lined up with the focal plane.
# Mostly just for the corner wavefront sensors. The negative sign
# creates the correct rotation based upon closed loop tests
# with R04 and R40 corner sensors.
# Rotate sensors to line up with the science sensors in the
# focal plane.
eulerZ = -detectorInfo.getOrientation().getYaw().asDegrees()
donutStamp.stamp_im.image.array = rotate(donutStamp.stamp_im.image.array, eulerZ)

# NOTE: TS_WEP expects these images to be transposed
# TODO: Look into this
# if self.transposeImages:
# finalStamp.image.array = finalStamp.image.array.T
donutStamp.stamp_im.image.array = rotate(
donutStamp.stamp_im.image.array, eulerZ
)

donutStamp.stamp_im.setMask(donutStamp.mask_comp)

Expand Down
8 changes: 6 additions & 2 deletions python/lsst/ts/wep/task/donutStamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@
import lsst.afw.image as afwImage
import lsst.afw.table as afwTable
import lsst.geom
import lsst.obs.lsst as obs_lsst
import numpy as np
from lsst.afw.cameraGeom import FIELD_ANGLE, PIXELS
from lsst.meas.algorithms.stamps import AbstractStamp
from lsst.ts.wep.cwfs.compensableImage import CompensableImage
from lsst.ts.wep.utils import DefocalType, FilterType, getFilterTypeFromBandLabel, getCameraFromButlerName
from lsst.ts.wep.utils import (
DefocalType,
FilterType,
getCameraFromButlerName,
getFilterTypeFromBandLabel,
)


@dataclass
Expand Down
85 changes: 38 additions & 47 deletions tests/task/test_calcZernikesTaskCwfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import lsst.utils.tests
import numpy as np
from scipy.ndimage import rotate
from lsst.daf import butler as dafButler
from lsst.ts.wep.task.calcZernikesTask import CalcZernikesTask, CalcZernikesTaskConfig
from lsst.ts.wep.task.combineZernikesMeanTask import CombineZernikesMeanTask
Expand Down Expand Up @@ -150,38 +149,34 @@ def testEstimateCornerZernikes(self):
donutStampsExtra = DonutStamps.readFits(
os.path.join(donutStampDir, "R04_SW0_donutStamps.fits")
)
for stamp in donutStampsExtra:
stamp.stamp_im.image.array = rotate(stamp.stamp_im.image.array, 90).T
donutStampsIntra = DonutStamps.readFits(
os.path.join(donutStampDir, "R04_SW1_donutStamps.fits")
)
for stamp in donutStampsIntra:
stamp.stamp_im.image.array = rotate(stamp.stamp_im.image.array, -90).T
zernCoeffAllR04 = self.task.estimateZernikes(donutStampsExtra, donutStampsIntra)
zernCoeffAvgR04 = self.task.combineZernikes.run(
zernCoeffAllR04
).combinedZernikes
trueZernCoeffR04 = np.array(
[
-0.71201408,
1.12248525,
0.77794367,
-0.04085477,
-0.05272933,
0.16054277,
0.081405,
-0.04382461,
-0.04830676,
-0.06218882,
0.10246469,
0.0197683,
0.007953,
0.00668697,
-0.03570788,
-0.03020376,
0.0039522,
0.04793133,
-0.00804605,
-0.35353452,
-0.07365128,
0.62222451,
-0.06206281,
-0.09065757,
0.21722746,
-0.20491936,
0.00849322,
-0.01150489,
0.02599147,
-0.00150702,
-0.14100845,
0.02294787,
0.02284791,
0.02116483,
-0.02537743,
0.01866772,
0.01653037,
-0.00552862,
]
)
# Make sure the total rms error is less than 0.35 microns off
Expand All @@ -194,38 +189,34 @@ def testEstimateCornerZernikes(self):
donutStampsExtra = DonutStamps.readFits(
os.path.join(donutStampDir, "R40_SW0_donutStamps.fits")
)
for stamp in donutStampsExtra:
stamp.stamp_im.image.array = rotate(stamp.stamp_im.image.array, -90).T
donutStampsIntra = DonutStamps.readFits(
os.path.join(donutStampDir, "R40_SW1_donutStamps.fits")
)
for stamp in donutStampsIntra:
stamp.stamp_im.image.array = rotate(stamp.stamp_im.image.array, 90).T
zernCoeffAllR40 = self.task.estimateZernikes(donutStampsExtra, donutStampsIntra)
zernCoeffAvgR40 = self.task.combineZernikes.run(
zernCoeffAllR40
).combinedZernikes
trueZernCoeffR40 = np.array(
[
-0.6535694,
1.00838499,
0.55968811,
-0.08899825,
0.00173607,
0.04133107,
-0.10913093,
-0.04363778,
-0.03149601,
-0.04941225,
0.09980538,
0.03704486,
-0.00210766,
0.01737253,
0.01727539,
0.01278011,
0.01212878,
0.03876888,
-0.00559142,
-3.83610201e-01,
-2.06528254e-01,
5.42893431e-01,
7.74255848e-02,
3.40529812e-02,
5.45565149e-02,
8.65849308e-02,
1.75029212e-02,
-1.40149246e-04,
4.11223127e-02,
-2.42644902e-03,
-1.52392233e-01,
-1.24547354e-02,
-2.33075716e-02,
7.35477674e-04,
1.93518814e-02,
-3.65768735e-03,
4.12718699e-02,
-6.93386734e-03,
]
)
# Make sure the total rms error is less than 0.35 microns off
Expand Down
4 changes: 3 additions & 1 deletion tests/task/test_cutOutDonutsBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ def testCutOutStamps(self):
lsst.geom.Extent2I(160),
)
expCutOut = exposure[stampBBox].image.array
np.testing.assert_array_equal(donutStamps[0].stamp_im.image.array, expCutOut)
np.testing.assert_array_almost_equal(
donutStamps[0].stamp_im.image.array, expCutOut
)

def testCutOutStampsBlended(self):
exposure = self.butler.get(
Expand Down
4 changes: 2 additions & 2 deletions tests/testData/donutImg/donutStamps/R04_SW0_donutStamps.fits
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testData/donutImg/donutStamps/R04_SW1_donutStamps.fits
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testData/donutImg/donutStamps/R40_SW0_donutStamps.fits
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/testData/donutImg/donutStamps/R40_SW1_donutStamps.fits
Git LFS file not shown

0 comments on commit cd54490

Please sign in to comment.