Skip to content

Commit

Permalink
nollIndices configurable from tasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfcrenshaw committed Nov 11, 2024
1 parent 2d35f34 commit 1536ae0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 22 deletions.
16 changes: 8 additions & 8 deletions python/lsst/ts/wep/task/calcZernikesTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __init__(self, **kwargs) -> None:
# Create subtasks
self.estimateZernikes = self.config.estimateZernikes
self.makeSubtask("estimateZernikes")
self.maxNollIndex = self.estimateZernikes.config.maxNollIndex
self.nollIndices = self.estimateZernikes.config.nollIndices

self.combineZernikes = self.config.combineZernikes
self.makeSubtask("combineZernikes")
Expand Down Expand Up @@ -165,7 +165,7 @@ def initZkTable(self) -> QTable:
("intra_frac_bad_pix", "<f4"),
("extra_frac_bad_pix", "<f4"),
]
for j in range(4, self.maxNollIndex + 1):
for j in self.nollIndices:
dtype.append((f"Z{j}", "<f4"))

table = QTable(dtype=dtype)
Expand All @@ -175,7 +175,7 @@ def initZkTable(self) -> QTable:
table["extra_field"].unit = u.deg
table["intra_centroid"].unit = u.pixel
table["extra_centroid"].unit = u.pixel
for j in range(4, self.maxNollIndex + 1):
for j in self.nollIndices:
table[f"Z{j}"].unit = u.nm

return table
Expand Down Expand Up @@ -215,8 +215,8 @@ def createZkTable(
"label": "average",
"used": True,
**{
f"Z{j}": zkCoeffCombined.combinedZernikes[j - 4] * u.micron
for j in range(4, self.maxNollIndex + 1)
f"Z{j}": zkCoeffCombined.combinedZernikes[i] * u.micron
for i, j in enumerate(self.nollIndices)
},
"intra_field": np.nan,
"extra_field": np.nan,
Expand Down Expand Up @@ -248,7 +248,7 @@ def createZkTable(
row["label"] = f"pair{i+1}"
row["used"] = not flag
row.update(
{f"Z{j}": zk[j - 4] * u.micron for j in range(4, self.maxNollIndex + 1)}
{f"Z{j}": zk[i] * u.micron for i, j in enumerate(self.nollIndices)}
)
row["intra_field"] = (
(np.array(np.nan, dtype=pos2f_dtype) * u.deg)
Expand Down Expand Up @@ -357,8 +357,8 @@ def empty(self) -> pipeBase.Struct:
"DEFOCAL_TYPE",
]
return pipeBase.Struct(
outputZernikesRaw=np.atleast_2d(np.full(self.maxNollIndex - 3, np.nan)),
outputZernikesAvg=np.atleast_2d(np.full(self.maxNollIndex - 3, np.nan)),
outputZernikesRaw=np.atleast_2d(np.full(len(self.nollIndices), np.nan)),
outputZernikesAvg=np.atleast_2d(np.full(len(self.nollIndices), np.nan)),
zernikes=self.initZkTable(),
donutQualityTable=QTable({name: [] for name in qualityTableCols}),
)
Expand Down
19 changes: 5 additions & 14 deletions python/lsst/ts/wep/task/estimateZernikesBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ class EstimateZernikesBaseConfig(pexConfig.Config):
dtype=str,
optional=True,
)
maxNollIndex = pexConfig.Field(
nollIndices = pexConfig.ListField(
dtype=int,
default=28,
doc="The maximum Zernike Noll index estimated.",
default=tuple(range(4, 29)),
doc="Noll indices for which you wish to estimate Zernike coefficients. "
+ "Note these values must be unique, ascending, and >= 4.",
)
startWithIntrinsic = pexConfig.Field(
dtype=bool,
Expand All @@ -60,15 +61,6 @@ class EstimateZernikesBaseConfig(pexConfig.Config):
default=False,
doc="If True, returns wavefront deviation. If False, returns full OPD.",
)
return4Up = pexConfig.Field(
dtype=bool,
default=True,
doc="If True, the returned Zernike coefficients start with Noll index 4. "
+ "If False, they follow the Galsim convention of starting with index 0 "
+ "(which is meaningless), so the array index of the output corresponds "
+ "to the Noll index. In this case, indices 0-3 are always set to zero, "
+ "because they are not estimated by our pipeline.",
)
binning = pexConfig.Field(
dtype=int,
default=1,
Expand Down Expand Up @@ -260,10 +252,9 @@ def run(
algoName=self.wfAlgoName,
algoConfig=self.wfAlgoConfig,
instConfig=instrument,
jmax=self.config.maxNollIndex,
nollIndices=self.config.nollIndices,
startWithIntrinsic=self.config.startWithIntrinsic,
returnWfDev=self.config.returnWfDev,
return4Up=self.config.return4Up,
units="um",
saveHistory=self.config.saveHistory,
)
Expand Down
29 changes: 29 additions & 0 deletions tests/task/test_calcZernikesTieTaskCwfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,32 @@ def testUnevenPairs(self):

# Now estimate Zernikes
self.task.run(stampsExtra, stampsIntra)

def testNollIndices(self):
# Load the stamps
donutStampDir = os.path.join(self.testDataDir, "donutImg", "donutStamps")
donutStampsExtra = DonutStamps.readFits(
os.path.join(donutStampDir, "R04_SW0_donutStamps.fits")
)
donutStampsIntra = DonutStamps.readFits(
os.path.join(donutStampDir, "R04_SW1_donutStamps.fits")
)

# Estimate Zernikes 4, 5, 6
self.task.config.estimateZernikes.nollIndices = [4, 5, 6]
zk0 = self.task.estimateZernikes.run(
donutStampsExtra, donutStampsIntra
).zernikes[0]

# Estimate Zernikes 4, 5, 6, 10, 11
self.task.config.estimateZernikes.nollIndices = [4, 5, 6, 10, 11]
zk1 = self.task.estimateZernikes.run(
donutStampsExtra, donutStampsIntra
).zernikes[0]

# Check lengths
self.assertEqual(len(zk0), 3)
self.assertEqual(len(zk1), 5)

# Check that 4, 5, 6 are independent of 10, 11
self.assertTrue(np.all(np.abs(zk1[:3] - zk0) < 0.035))

0 comments on commit 1536ae0

Please sign in to comment.