24__all__ = [
"plantSources",
"makeRandomTransmissionCurve",
"makeDefectList",
25 "MockReferenceObjectLoaderFromFiles",
"MockRefcatDataId"]
33from lsst
import sphgeom
34from .
import SingleGaussianPsf
37from .
import ReferenceObjectLoader
42 """Make an exposure with stars (modelled as Gaussians)
47 Parent bbox of exposure
49 Kernal width (and height; kernal
is square)
51 Amount of sky background (counts)
52 coordList : `list [tuple]`
53 A list of [x, y, counts, sigma] where:
54 * x,y are relative to exposure origin
55 * counts
is the integrated counts
for the star
56 * sigma
is the Gaussian sigma
in pixels
57 addPoissonNoise : `bool`
58 If
True: add Poisson noise to the exposure
61 img = afwImage.ImageD(bbox)
63 for coord
in coordList:
64 x, y, counts, sigma = coord
68 psf = SingleGaussianPsf(kwid, kwid, sigma)
75 psfBox = thisPsfImg.getBBox()
77 if psfBox != thisPsfImg.getBBox():
78 thisPsfImg = thisPsfImg[psfBox, afwImage.PARENT]
79 imgSeg = img[psfBox, afwImage.PARENT]
81 meanSigma /= len(coordList)
87 np.random.seed(seed=1)
88 imgArr = img.getArray()
89 imgArr[:] = np.random.poisson(imgArr)
92 mask = afwImage.Mask(bbox)
93 var = img.convertFloat()
95 mimg = afwImage.MaskedImageF(img.convertFloat(), mask, var)
96 exposure = afwImage.makeExposure(mimg)
99 psf = SingleGaussianPsf(kwid, kwid, meanSigma)
106 maxRadius=80.0, nRadii=30, perturb=0.05):
107 """Create a random TransmissionCurve with nontrivial spatial and
108 wavelength variation.
112 rng : numpy.random.RandomState
113 Random number generator.
114 minWavelength : float
115 Average minimum wavelength for generated TransmissionCurves (will be
117 maxWavelength : float
118 Average maximum wavelength
for generated TransmissionCurves (will be
121 Number of samples
in the wavelength dimension.
123 Average maximum radius
for spatial variation (will be perturbed).
125 Number of samples
in the radial dimension.
127 Fraction by which wavelength
and radius bounds should be randomly
130 dWavelength = maxWavelength - minWavelength
132 def perturbed(x, s=perturb*dWavelength):
133 return x + 2.0*s*(rng.rand() - 0.5)
135 wavelengths = np.linspace(perturbed(minWavelength), perturbed(maxWavelength), nWavelengths)
136 radii = np.linspace(0.0, perturbed(maxRadius, perturb*maxRadius), nRadii)
137 throughput = np.zeros(wavelengths.shape + radii.shape, dtype=float)
140 peak0 = perturbed(0.9, 0.05)
141 start0 = perturbed(minWavelength + 0.25*dWavelength)
142 stop0 = perturbed(minWavelength + 0.75*dWavelength)
143 for i, r
in enumerate(radii):
144 mask = np.logical_and(wavelengths >= start0 + r, wavelengths <= stop0 + r)
145 throughput[mask, i] = peak0*(1.0 - r/1000.0)
146 return afwImage.TransmissionCurve.makeRadial(throughput, wavelengths, radii)
150 """Create a list of defects that can be used for testing.
191 """Mock reference catalog dataId.
193 The reference catalog dataId is only used to retrieve a region property.
198 The region associated
with this mock dataId.
209 """A simple mock of ReferenceObjectLoader.
211 This mock ReferenceObjectLoader uses a set of files on disk to create
212 mock dataIds and data reference handles that can be accessed
213 without a butler. The files must be afw catalog files
in the reference
214 catalog format, sharded
with HTM pixelization.
218 filenames : `list` [`str`]
219 Names of files to use.
220 config : `lsst.meas.astrom.LoadReferenceObjectsConfig`, optional
221 Configuration object
if necessary to override defaults.
222 htmLevel : `int`, optional
223 HTM level to use
for the loader.
225 def __init__(self, filenames, name='cal_ref_cat', config=None, htmLevel=4):
228 super().
__init__(dataIds, refCats, name=name, config=config)
231 """Create mock dataIds and refcat handles.
235 filenames : `list` [`str`]
236 Names of files to use.
238 HTM level to use for the loader.
240 Name of reference catalog (
for logging).
244 dataIds : `list` [`MockRefcatDataId`]
245 List of mock dataIds.
246 refCats : `list` [`lsst.pipe.base.InMemoryDatasetHandle`]
247 List of mock deferred dataset handles.
251 RuntimeError
if any file contains sources that cover more than one HTM
252 pixel at level ``htmLevel``.
255 htm = esutil.htm.HTM(htmLevel)
260 for filename
in filenames:
261 cat = afwTable.BaseCatalog.readFits(filename)
263 ids = htm.lookup_id(np.rad2deg(cat[
'coord_ra']), np.rad2deg(cat[
'coord_dec']))
265 if len(np.unique(ids)) != 1:
266 raise RuntimeError(f
"File {filename} contains more than one pixel at level {htmLevel}")
269 refCats.append(InMemoryDatasetHandle(cat, name=name))
271 return dataIds, refCats
Encapsulate information about a bad portion of a detector.
_createDataIdsAndRefcats(self, filenames, htmLevel, name)
__init__(self, filenames, name='cal_ref_cat', config=None, htmLevel=4)
makeRandomTransmissionCurve(rng, minWavelength=4000.0, maxWavelength=7000.0, nWavelengths=200, maxRadius=80.0, nRadii=30, perturb=0.05)
plantSources(bbox, kwid, sky, coordList, addPoissonNoise=True)