Skip to content

Commit

Permalink
Add copyWith method to VisitInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
fred3m committed Nov 23, 2022
1 parent abe93b2 commit 21c85d7
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
93 changes: 93 additions & 0 deletions python/lsst/afw/image/_visitInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,105 @@
"""

from lsst.utils.deprecated import deprecate_pybind11
from lsst.utils import continueClass
from ._imageLib import VisitInfo


__all__ = []


@continueClass
class VisitInfo: # noqa: F811
def copyWith(
self,
exposureId=None,
exposureTime=None,
darkTime=None,
date=None,
ut1=None,
era=None,
boresightRaDec=None,
boresightAzAlt=None,
boresightAirmass=None,
boresightRotAngle=None,
rotType=None,
observatory=None,
weather=None,
instrumentLabel=None,
id=None,
focusZ=None,
observationType=None,
scienceProgram=None,
observationReason=None,
object=None,
hasSimulatedContent=None,
):
if exposureTime is None:
exposureTime = self.exposureTime
if darkTime is None:
darkTime = self.darkTime
if date is None:
date = self.date
if ut1 is None:
ut1 = self.ut1
if era is None:
era = self.era
if boresightRaDec is None:
boresightRaDec = self.boresightRaDec
if boresightAzAlt is None:
boresightAzAlt = self.boresightAzAlt
if boresightAirmass is None:
boresightAirmass = self.boresightAirmass
if boresightRotAngle is None:
boresightRotAngle = self.boresightRotAngle
if rotType is None:
rotType = self.rotType
if observatory is None:
observatory = self.observatory
if weather is None:
weather = self.weather
if instrumentLabel is None:
instrumentLabel = self.instrumentLabel
if id is None:
id = self.id
if focusZ is None:
focusZ = self.focusZ
if observationType is None:
observationType = self.observationType
if scienceProgram is None:
scienceProgram = self.scienceProgram
if observationReason is None:
observationReason = self.observationReason
if object is None:
object = self.object
if hasSimulatedContent is None:
hasSimulatedContent = self.hasSimulatedContent

return VisitInfo(
exposureId=0,
exposureTime=exposureTime,
darkTime=darkTime,
date=date,
ut1=ut1,
era=era,
boresightRaDec=boresightRaDec,
boresightAzAlt=boresightAzAlt,
boresightAirmass=boresightAirmass,
boresightRotAngle=boresightRotAngle,
rotType=rotType,
observatory=observatory,
weather=weather,
instrumentLabel=instrumentLabel,
id=id,
focusZ=focusZ,
observationType=observationType,
scienceProgram=scienceProgram,
observationReason=observationReason,
object=object,
hasSimulatedContent=hasSimulatedContent,
)


VisitInfo.getExposureId = deprecate_pybind11(
VisitInfo.getExposureId,
reason="Replaced by VisitInfo.id for full focal plane identifiers and by ExposureInfo.id for "
Expand Down
46 changes: 46 additions & 0 deletions tests/test_visitInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,52 @@ def testValueConstructor_data2(self):
self._testValueConstructor(self.data2, self.localEra2, self.hourAngle2)
self._testProperties(self.data2, self.localEra2, self.hourAngle2)

def testCopyWith(self):
visitInfo1 = makeVisitInfo(self.data1)
visitInfo2 = makeVisitInfo(self.data2)

updateFields1 = [
"exposureTime",
"darkTime",
"date",
"ut1",
"era",
"boresightRaDec",
"boresightAzAlt",
"boresightAirmass",
"boresightRotAngle",
]

updateFields2 = [
"rotType",
"observatory",
"weather",
"instrumentLabel",
"id",
"focusZ",
"observationType",
"scienceProgram",
"observationReason",
"object",
"hasSimulatedContent",
]

kwargs1 = {k: getattr(visitInfo2, k) for k in updateFields1}
kwargs2 = {k: getattr(visitInfo2, k) for k in updateFields2}

newVisit1 = visitInfo1.copyWith(**kwargs1)
newVisit2 = visitInfo1.copyWith(**kwargs2)

print(newVisit1)

for field in updateFields1:
self.assertEqual(getattr(newVisit1, field), getattr(visitInfo2, field))
self.assertEqual(getattr(newVisit2, field), getattr(visitInfo1, field))

for field in updateFields2:
self.assertEqual(getattr(newVisit1, field), getattr(visitInfo1, field))
self.assertEqual(getattr(newVisit2, field), getattr(visitInfo2, field))

def testTablePersistence(self):
"""Test that VisitInfo can be round-tripped with current code.
"""
Expand Down

0 comments on commit 21c85d7

Please sign in to comment.