Skip to content
Closed

Main #54

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ def pytest_addoption(parser: Parser) -> None:
default=False,
help="Run WEP pipeline before all tests.",
)
parser.addoption(
"--skip-pretest",
action="store_true",
default=False,
help="Skip pre-test WEP pipeline run.",
)


def pytest_configure(config: Config) -> None:
if config.getoption("--run-pretest"):
if config.getoption("--run-pretest") and not config.getoption("--skip-pretest"):
print("Running pre-test command...")

# Set up the butler repository config
Expand Down Expand Up @@ -80,7 +86,7 @@ def pytest_configure(config: Config) -> None:


def pytest_unconfigure(config: Config) -> None:
if config.getoption("--run-pretest"):
if config.getoption("--run-pretest") and not config.getoption("--skip-pretest"):
print("Running cleanup...")
for runName in [
config.testInfo["runNameCwfs"],
Expand Down
15 changes: 15 additions & 0 deletions doc/version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ Version History

.. towncrier release notes start

v16.5.0 (2025-12-16)
====================

New Features
------------

- Correctly handling FAM by shifting entire camera in batoid model. (`DM-53134 <https://rubinobs.atlassian.net//browse/DM-53134>`_)


Bug Fixes
---------

- Fixed bug with intrinsics in unpaired Zernike calculation task. (`DM-53632 <https://rubinobs.atlassian.net//browse/DM-53632>`_)


16.4.0 (2025-12-09)
===================

Expand Down
1 change: 1 addition & 0 deletions policy/instruments/LsstCam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ wavelength:
z: 866.8e-9
y: 973.9e-9
batoidModelName: LSST_{band} # name used to load the Batoid model
batoidOffsetOptic: Detector

maskParams: # center and radius are in meters, theta in degrees
M1:
Expand Down
8 changes: 4 additions & 4 deletions python/lsst/ts/wep/estimation/wfAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,16 @@ def estimateZk(
if startWithIntrinsic or returnWfDev:
zkIntrinsicI1 = instrument.getIntrinsicZernikes(
*I1.fieldAngle,
I1.bandLabel,
nollIndices,
band=I1.bandLabel,
nollIndices=nollIndices,
)
zkIntrinsicI2 = (
None
if I2 is None
else instrument.getIntrinsicZernikes(
*I2.fieldAngle,
I2.bandLabel,
nollIndices,
band=I2.bandLabel,
nollIndices=nollIndices,
)
)

Expand Down
10 changes: 5 additions & 5 deletions python/lsst/ts/wep/imageMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ def createImageMasks(
# Get the intrinsic Zernikes
zkCoeff = self.instrument.getIntrinsicZernikes(
*image.fieldAngle,
image.bandLabel,
band=image.bandLabel,
)

# Get the image grid inside the pupil
Expand Down Expand Up @@ -1376,7 +1376,7 @@ def getProjectionSize(
# Get the intrinsic Zernikes
zkCoeff = self.instrument.getIntrinsicZernikes(
*dummyImage.fieldAngle,
dummyImage.bandLabel,
band=dummyImage.bandLabel,
)

# Project the pupil onto the image plane
Expand Down Expand Up @@ -1445,7 +1445,7 @@ def centerOnProjection(
# Get the intrinsic Zernikes
zkCoeff = self.instrument.getIntrinsicZernikes(
*image.fieldAngle,
image.bandLabel,
band=image.bandLabel,
)

# Create the image template
Expand Down Expand Up @@ -1513,7 +1513,7 @@ def mapPupilToImage(
# Get the intrinsic Zernikes
zkCoeff = self.instrument.getIntrinsicZernikes(
*image.fieldAngle,
image.bandLabel,
band=image.bandLabel,
)

# Get the image grid inside the pupil
Expand Down Expand Up @@ -1606,7 +1606,7 @@ def mapImageToPupil(
# Get the intrinsic Zernikes
zkCoeff = self.instrument.getIntrinsicZernikes(
*image.fieldAngle,
image.bandLabel,
band=image.bandLabel,
)

# Construct the forward mapping
Expand Down
69 changes: 48 additions & 21 deletions python/lsst/ts/wep/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,11 @@ def batoidModelName(self, value: str | None) -> None:
@property
def batoidOffsetOptic(self) -> str | None:
"""The optic that is offset in the Batoid model."""
return self._batoidOffsetOptic
# Default to the detector if value not explicitly set
if self._batoidOffsetOptic is None and self.batoidModelName is not None:
return "Detector"
else:
return self._batoidOffsetOptic

@batoidOffsetOptic.setter
def batoidOffsetOptic(self, value: str | None) -> None:
Expand Down Expand Up @@ -734,6 +738,7 @@ def _getIntrinsicZernikesCached(
self,
xAngle: float,
yAngle: float,
defocalType: DefocalType | None,
band: BandLabel | str,
jmax: int,
) -> np.ndarray:
Expand All @@ -747,6 +752,9 @@ def _getIntrinsicZernikesCached(
The x-component of the field angle in degrees.
yAngle : float
The y-component of the field angle in degrees.
defocalType : DefocalType or str or None
The DefocalType Enum or corresponding string, specifying which side
of focus to model. If None, the model is not defocused.
band : BandLabel or str, optional
The BandLabel Enum or corresponding string, specifying which batoid
model to load. Only relevant if self.batoidModelName contains
Expand All @@ -769,6 +777,13 @@ def _getIntrinsicZernikesCached(
if batoidModel is None:
return np.zeros(jmax + 1)

# Offset the focal plane
if defocalType is not None:
defocalType = DefocalType(defocalType)
defocalSign = +1 if defocalType == DefocalType.Extra else -1
offset = [0, 0, defocalSign * self.defocalOffset]
batoidModel = batoidModel.withLocallyShiftedOptic(self.batoidOffsetOptic, offset)

# Get the wavelength
if len(self.wavelength) > 1:
wavelength = self.wavelength[band]
Expand All @@ -794,6 +809,7 @@ def getIntrinsicZernikes(
self,
xAngle: float,
yAngle: float,
defocalType: DefocalType | None = None,
band: BandLabel | str = BandLabel.REF,
nollIndices: Sequence[int] = tuple(np.arange(4, 79)),
) -> np.ndarray:
Expand All @@ -805,6 +821,9 @@ def getIntrinsicZernikes(
The x-component of the field angle in degrees.
yAngle : float
The y-component of the field angle in degrees.
defocalType : DefocalType or str or None
The DefocalType Enum or corresponding string, specifying which side
of focus to model. If None, the model is not defocused.
band : BandLabel or str, optional
The BandLabel Enum or corresponding string, specifying which batoid
model to load. Only relevant if self.batoidModelName contains
Expand All @@ -822,7 +841,13 @@ def getIntrinsicZernikes(
nollIndices = np.array(nollIndices)

# Retrieve cached Zernikes
zk = self._getIntrinsicZernikesCached(xAngle, yAngle, band, max(nollIndices))
zk = self._getIntrinsicZernikesCached(
xAngle=xAngle,
yAngle=yAngle,
defocalType=defocalType,
band=band,
jmax=max(nollIndices),
)

return zk[nollIndices]

Expand All @@ -831,7 +856,7 @@ def _getIntrinsicZernikesTACached(
self,
xAngle: float,
yAngle: float,
defocalType: DefocalType,
defocalType: DefocalType | None,
band: BandLabel | str,
jmax: int,
) -> np.ndarray:
Expand All @@ -843,9 +868,9 @@ def _getIntrinsicZernikesTACached(
The x-component of the field angle in degrees.
yAngle : float
The y-component of the field angle in degrees.
defocalType : DefocalType or str
defocalType : DefocalType or str or None
The DefocalType Enum or corresponding string, specifying which side
of focus to model.
of focus to model. If None, the model is not defocused.
band : BandLabel or str
The BandLabel Enum or corresponding string, specifying which
batoid model to load. Only relevant if self.batoidModelName
Expand Down Expand Up @@ -877,10 +902,11 @@ def _getIntrinsicZernikesTACached(
return np.zeros(jmax + 1)

# Offset the focal plane
defocalType = DefocalType(defocalType)
defocalSign = +1 if defocalType == DefocalType.Extra else -1
offset = [0, 0, defocalSign * self.defocalOffset]
batoidModel = batoidModel.withLocallyShiftedOptic("Detector", offset)
if defocalType is not None:
defocalType = DefocalType(defocalType)
defocalSign = +1 if defocalType == DefocalType.Extra else -1
offset = [0, 0, defocalSign * self.defocalOffset]
batoidModel = batoidModel.withLocallyShiftedOptic(self.batoidOffsetOptic, offset)

# Get the wavelength
if len(self.wavelength) > 1:
Expand Down Expand Up @@ -909,7 +935,7 @@ def getOffAxisCoeff(
self,
xAngle: float,
yAngle: float,
defocalType: DefocalType,
defocalType: DefocalType | None,
band: BandLabel | str = BandLabel.REF,
nollIndicesModel: Sequence = tuple(np.arange(4, 79)),
nollIndicesIntr: Sequence = tuple(np.arange(4, 79)),
Expand All @@ -922,9 +948,9 @@ def getOffAxisCoeff(
The x-component of the field angle in degrees.
yAngle : float
The y-component of the field angle in degrees.
defocalType : DefocalType or str
defocalType : DefocalType or str or None
The DefocalType Enum or corresponding string, specifying which side
of focus to model.
of focus to model. If None, the model is not defocused.
band : BandLabel or str, optional
The BandLabel Enum or corresponding string, specifying which
batoid model to load. Only relevant if self.batoidModelName
Expand Down Expand Up @@ -952,19 +978,20 @@ def getOffAxisCoeff(

# Get zernikeTA
zkTA = self._getIntrinsicZernikesTACached(
xAngle,
yAngle,
defocalType,
band,
max(nollIndicesModel),
xAngle=xAngle,
yAngle=yAngle,
defocalType=defocalType,
band=band,
jmax=max(nollIndicesModel),
)

# Get regular intrinsic zernikes
zk = self._getIntrinsicZernikesCached(
xAngle,
yAngle,
band,
max(nollIndicesIntr),
xAngle=xAngle,
yAngle=yAngle,
defocalType=None,
band=band,
jmax=max(nollIndicesIntr),
)

# Subtract intrinsics from zernikeTA
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ts/wep/task/calcZernikesTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def _unpackStampData(self, stamp: DonutStamp) -> tuple[u.Quantity, u.Quantity, u
if stamp is None:
fieldAngle = np.array(np.nan, dtype=pos2f_dtype) * u.deg
centroid = np.array((np.nan, np.nan), dtype=pos2f_dtype) * u.pixel
intrinsics = np.full_like(self.nollIndices, np.nan) * u.micron
intrinsics = np.full(len(self.nollIndices), np.nan) * u.micron
else:
fieldAngle = np.array(stamp.calcFieldXY(), dtype=pos2f_dtype) * u.deg
centroid = (
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ts/wep/utils/plotUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def plotMapperResiduals(
uImage, vImage, *_ = mapper._constructForwardMap(
uPupil,
vPupil,
mapper.instrument.getIntrinsicZernikes(*angle, band, jmax=22),
mapper.instrument.getIntrinsicZernikes(*angle, band=band, nollIndices=np.arange(4, 23)),
Image(np.zeros((1, 1)), angle, defocalType, band),
)

Expand Down
15 changes: 13 additions & 2 deletions tests/task/test_calcZernikesUnpairedTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ def testWithAndWithoutPairs(self) -> None:
collections=["LSSTCam/aos/intrinsic"],
)

# Modify the intrinsic table to allow explicit value testing below
intrinsicTable["Z4"] = 50e-9 # nm

# Loop over EstimateZernikes subtasks
for subtask in [EstimateZernikesTieTask, EstimateZernikesDanishTask]:
# Calculate Zernikes with stamps paired
Expand All @@ -145,14 +148,22 @@ def testWithAndWithoutPairs(self) -> None:
config.estimateZernikes.retarget(subtask)
unpairedTask = CalcZernikesUnpairedTask(config=config)

extraZk = unpairedTask.run(donutStampsExtra, intrinsicTable).outputZernikesAvg
intraZk = unpairedTask.run(donutStampsIntra, intrinsicTable).outputZernikesAvg
outputExtra = unpairedTask.run(donutStampsExtra, intrinsicTable)
outputIntra = unpairedTask.run(donutStampsIntra, intrinsicTable)
extraZk = outputExtra.outputZernikesAvg
intraZk = outputIntra.outputZernikesAvg
meanZk = np.mean([extraZk, intraZk], axis=0)

# Check that results are similar
diff = np.sqrt(np.sum((meanZk - pairedZk) ** 2))
self.assertLess(diff, 0.17)

# Check the stored intrinsic Z4 is close to modified value
for struct in [outputExtra, outputIntra]:
table = struct.zernikes
intrinsicZ4 = table[table["label"] == "average"]["Z4_intrinsic"][0]
self.assertTrue(np.isclose(intrinsicZ4.to_value("nm"), 50.0))

def testTable(self) -> None:
# Load data from butler
donutStampsExtra = self.butler.get(
Expand Down
4 changes: 2 additions & 2 deletions tests/task/test_cutOutDonutsBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,9 @@ def testCutOutStampsTaskRunNormal(self) -> None:
self.assertTrue(allowed_values.issuperset(unique_values))

# test the calculation of SN
sn_values = [2149.093503846915, 2160.668317852145, 2041.9917562475855]
sn_values = [2152.969905, 2574.566976, 2981.683746]
sn_calculated = donutStamps.metadata.getArray("SN")
np.testing.assert_allclose(np.sort(np.array(sn_values)), np.sort(np.array(sn_calculated)), rtol=1e-3)
np.testing.assert_allclose(np.sort(np.array(sn_calculated)), np.sort(np.array(sn_values)), rtol=1e-3)

def testFilterBadRecentering(self) -> None:
maxRecenter = 25
Expand Down
3 changes: 1 addition & 2 deletions tests/task/test_donutStampSelectorTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def testSelectStamps(self) -> None:
# test defaults
selection = self.task.selectStamps(donutStampsIntra)
donutsQuality = selection.donutsQuality
print(donutsQuality)

# by default, config.selectWithEntropy is False,
# so we select all donuts
Expand Down Expand Up @@ -196,7 +195,7 @@ def testSelectStamps(self) -> None:
task = DonutStampSelectorTask(config=self.config, name="SN Task")
selection = task.selectStamps(donutStampsIntra)
donutsQuality = selection.donutsQuality
self.assertEqual(np.sum(donutsQuality["SN_SELECT"]), 2)
self.assertEqual(np.sum(donutsQuality["SN_SELECT"]), 3)

# test that the SN of selected donuts is indeed above the threshold
for v in donutsQuality["SN"][donutsQuality["SN_SELECT"]]:
Expand Down
Loading