Skip to content

Commit

Permalink
Respond to reviewer comments v2
Browse files Browse the repository at this point in the history
  • Loading branch information
isullivan committed Jul 13, 2020
1 parent de93100 commit ebe61ba
Showing 1 changed file with 40 additions and 34 deletions.
74 changes: 40 additions & 34 deletions tests/assembleCoaddTestUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ class MockGen2WarpReference:
Unique identifier for an observation,
potentially consisting of multiple ccds.
"""
datasetTypes = None
"List of the names of exposures that can be retrieved."
metadataTypes = None
"List of the names of metadata objects that can be retrieved."
dataLookup = None
"Stores the data and metadata that can be retrieved."

def __init__(self, exposure, exposurePsfMatched=None, coaddName='deep',
patch="2,3", tract=0, visit=100):
Expand All @@ -82,19 +88,16 @@ def __init__(self, exposure, exposurePsfMatched=None, coaddName='deep',

self.datasetTypes = (f"{coaddName}Coadd_directWarp", f"{coaddName}Coadd_psfMatchedWarp",
f"{coaddName}Coadd_directWarp_sub", f"{coaddName}Coadd_psfMatchedWarp_sub")
"List of the names of exposures that can be retrieved."

self.metadataTypes = (f"{coaddName}Coadd_directWarp_visitInfo",
f"{coaddName}Coadd_psfMatchedWarp_visitInfo")
"List of the names of metadata objects that can be retrieved."

self.dataLookup = {f"{coaddName}Coadd_directWarp": exposure,
f"{coaddName}Coadd_psfMatchedWarp": exposurePsfMatched,
f"{coaddName}Coadd_directWarp_sub": exposure,
f"{coaddName}Coadd_psfMatchedWarp_sub": exposurePsfMatched,
f"{coaddName}Coadd_directWarp_visitInfo": visitInfo,
f"{coaddName}Coadd_psfMatchedWarp_visitInfo": visitInfo}
"Stores the data and metadata that can be retrieved."

def get(self, datasetType, bbox=None, **kwargs):
"""Retrieve the specified dataset using the API of the Gen 2 Butler.
Expand All @@ -117,15 +120,17 @@ def get(self, datasetType, bbox=None, **kwargs):
Raises
------
KeyError
If a bounding box is specified incorrectly for the datasetType.
ValueError
If an unknown datasetType is supplied.
"""
if "_sub" in datasetType:
if bbox is None:
raise ValueError(f"A bbox must be supplied for dataset {datasetType}")
raise KeyError(f"A bbox must be supplied for dataset {datasetType}")
else:
if bbox is not None:
raise ValueError(f"A bbox cannot be supplied for dataset {datasetType}")
raise KeyError(f"A bbox cannot be supplied for dataset {datasetType}")
if datasetType in self.datasetTypes:
exp = self.dataLookup[datasetType].clone()
if "_sub" in datasetType:
Expand Down Expand Up @@ -314,6 +319,35 @@ class MockCoaddTestData:
This is due to `GaussianPsf` that is used by `lsst.meas.algorithms.testUtils.plantSources`
lacking the option to specify the pixel origin.
"""
rotAngle = 0.*degrees
"Rotation of the pixel grid on the sky, East from North (`lsst.geom.Angle`)."
filterInfo = None
"""The filter definition, usually set in the current instruments' obs package.
For these tests, a simple filter is defined without using an obs package (`lsst.afw.image.Filter`).
"""
rngData = None
"""Pre-initialized random number generator for constructing the test images
repeatably (`numpy.random.Generator`).
"""
rngMods = None
"""Pre-initialized random number generator for applying modifications to
the test images for only some test cases (`numpy.random.Generator`).
"""
kernelSize = None
"Width of the kernel used for simulating sources, in pixels."
exposures = {}
"The simulated test data, with variable PSF sizes (`dict` of `lsst.afw.image.Exposure`)"
matchedExposures = {}
"""The simulated exposures, all with PSF width set to `maxPsfSize`
(`dict` of `lsst.afw.image.Exposure`).
"""
photoCalib = afwImage.makePhotoCalibFromCalibZeroPoint(27, 10)
"The photometric zero point to use for converting counts to flux units (`lsst.afw.image.PhotoCalib`)."
badMaskPlanes = ["NO_DATA", "BAD"]
"Mask planes that, if set, the associated pixel should not be included in the coaddTempExp."
detector = None
"Properties of the CCD for the exposure (`lsst.afw.cameraGeom.Detector`)."

def __init__(self, shape=geom.Extent2I(201, 301), offset=geom.Point2I(-123, -45),
backgroundLevel=314.592, seed=42, nSrc=37,
fluxRange=2., noiseLevel=5, sourceSigma=200.,
Expand All @@ -322,63 +356,35 @@ def __init__(self, shape=geom.Extent2I(201, 301), offset=geom.Point2I(-123, -45)
ccd=37, patch=42, patchGen2="2,3", tract=0):
self.ra = ra
self.dec = dec
self.rotAngle = 0.*degrees
"Rotation of the pixel grid on the sky, East from North (`lsst.geom.Angle`)."
self.pixelScale = pixelScale
self.patch = patch
self.patchGen2 = patchGen2
self.tract = tract
self.filterInfo = self.defineFilter()
"""The filter definition, usually set in the current instruments' obs package.
For these tests, a simple filter is defined without using an obs package (`lsst.afw.image.Filter`).
"""
self.rngData = np.random.default_rng(seed)
"""Pre-initialized random number generator for constructing the test images
repeatably (`numpy.random.Generator`).
"""
self.rngMods = np.random.default_rng(seed + 1)
"""Pre-initialized random number generator for applying modifications to
the test images for only some test cases (`numpy.random.Generator`).
"""
self.bbox = geom.Box2I(offset, shape)
"Outer bounding box of the simulated exposures (`lsst.geom.Box2I`)."
if not self.bbox.contains(0, 0):
raise ValueError(f"The bounding box must contain the coordinate (0, 0). {repr(self.bbox)}")
self.wcs = self.makeDummyWcs()
"Coordinate system definition (wcs) for the exposure (`lsst.afw.geom.SkyWcs`)."

# Set up properties of the simulations
nSigmaForKernel = 5
self.kernelSize = (int(maxPsfSize*nSigmaForKernel + 0.5)//2)*2 + 1 # make sure it is odd
"Width of the kernel used for simulating sources, in pixels."

bufferSize = self.kernelSize//2
x0, y0 = self.bbox.getBegin()
xSize, ySize = self.bbox.getDimensions()
# Set the pixel coordinates and fluxes of the simulated sources.
self.xLoc = self.rngData.random(nSrc)*(xSize - 2*bufferSize) + bufferSize + x0
self.yLoc = self.rngData.random(nSrc)*(ySize - 2*bufferSize) + bufferSize + y0
"Pixel coordinates of the simulated sources."
self.flux = (self.rngData.random(nSrc)*(fluxRange - 1.) + 1.)*sourceSigma*noiseLevel
"Flux values of the simulated sources."

self.backgroundLevel = backgroundLevel
self.noiseLevel = noiseLevel
self.minPsfSize = minPsfSize
self.maxPsfSize = maxPsfSize

self.exposures = {}
"The simulated test data, with variable PSF sizes (`dict` of `lsst.afw.image.Exposure`)"
self.matchedExposures = {}
"""The simulated exposures, all with PSF width set to `maxPsfSize`
(`dict` of `lsst.afw.image.Exposure`).
"""
self.photoCalib = afwImage.makePhotoCalibFromCalibZeroPoint(27, 10)
"The photometric zero point to use for converting counts to flux units (`lsst.afw.image.PhotoCalib`)."

self.badMaskPlanes = ["NO_DATA", "BAD"]
"Mask planes that, if set, the associated pixel should not be included in the coaddTempExp."
self.detector = DetectorWrapper(name=f"detector {ccd}", id=ccd).detector
"Properties of the CCD for the exposure (`lsst.afw.cameraGeom.Detector`)."

def setDummyCoaddInputs(self, exposure, expId):
"""Generate an `ExposureCatalog` as though the exposures had been
Expand Down

0 comments on commit ebe61ba

Please sign in to comment.