24__all__ = [
"plantSources",
"makeRandomTransmissionCurve",
"makeDefectList",
25 "MockReferenceObjectLoaderFromFiles"]
32from lsst
import sphgeom
33from .
import SingleGaussianPsf
36from .
import ReferenceObjectLoader
41 """Make an exposure with stars (modelled as Gaussians)
46 Parent bbox of exposure
48 Kernal width (and height; kernal
is square)
50 Amount of sky background (counts)
51 coordList : `list [tuple]`
52 A list of [x, y, counts, sigma] where:
53 * x,y are relative to exposure origin
54 * counts
is the integrated counts
for the star
55 * sigma
is the Gaussian sigma
in pixels
56 addPoissonNoise : `bool`
57 If
True: add Poisson noise to the exposure
60 img = afwImage.ImageD(bbox)
62 for coord
in coordList:
63 x, y, counts, sigma = coord
67 psf = SingleGaussianPsf(kwid, kwid, sigma)
74 psfBox = thisPsfImg.getBBox()
76 if psfBox != thisPsfImg.getBBox():
77 thisPsfImg = thisPsfImg[psfBox, afwImage.PARENT]
78 imgSeg = img[psfBox, afwImage.PARENT]
80 meanSigma /= len(coordList)
86 np.random.seed(seed=1)
87 imgArr = img.getArray()
88 imgArr[:] = np.random.poisson(imgArr)
92 var = img.convertFloat()
94 mimg = afwImage.MaskedImageF(img.convertFloat(), mask, var)
98 psf = SingleGaussianPsf(kwid, kwid, meanSigma)
105 maxRadius=80.0, nRadii=30, perturb=0.05):
106 """Create a random TransmissionCurve with nontrivial spatial and
107 wavelength variation.
111 rng : numpy.random.RandomState
112 Random number generator.
113 minWavelength : float
114 Average minimum wavelength for generated TransmissionCurves (will be
116 maxWavelength : float
117 Average maximum wavelength
for generated TransmissionCurves (will be
120 Number of samples
in the wavelength dimension.
122 Average maximum radius
for spatial variation (will be perturbed).
124 Number of samples
in the radial dimension.
126 Fraction by which wavelength
and radius bounds should be randomly
129 dWavelength = maxWavelength - minWavelength
131 def perturbed(x, s=perturb*dWavelength):
132 return x + 2.0*s*(rng.rand() - 0.5)
134 wavelengths = np.linspace(perturbed(minWavelength), perturbed(maxWavelength), nWavelengths)
135 radii = np.linspace(0.0, perturbed(maxRadius, perturb*maxRadius), nRadii)
136 throughput = np.zeros(wavelengths.shape + radii.shape, dtype=float)
139 peak0 = perturbed(0.9, 0.05)
140 start0 = perturbed(minWavelength + 0.25*dWavelength)
141 stop0 = perturbed(minWavelength + 0.75*dWavelength)
142 for i, r
in enumerate(radii):
143 mask = np.logical_and(wavelengths >= start0 + r, wavelengths <= stop0 + r)
144 throughput[mask, i] = peak0*(1.0 - r/1000.0)
145 return afwImage.TransmissionCurve.makeRadial(throughput, wavelengths, radii)
149 """Create a list of defects that can be used for testing.
190 """Mock reference catalog dataId.
192 The reference catalog dataId is only used to retrieve a region property.
202 self.
_region = pixelization.pixel(index)
210 """Mock reference catalog dataset handle.
212 The mock handle needs a get() and a name
for logging.
219 Name of reference catalog.
250 """A simple mock of ReferenceObjectLoader.
252 This mock ReferenceObjectLoader uses a set of files on disk to create
253 mock dataIds and data reference handles that can be accessed
254 without a butler. The files must be afw catalog files
in the reference
255 catalog format, sharded
with HTM pixelization.
259 filenames : `list` [`str`]
260 Names of files to use.
261 config : `lsst.meas.astrom.LoadReferenceObjectsConfig`, optional
262 Configuration object
if necessary to override defaults.
263 htmLevel : `int`, optional
264 HTM level to use
for the loader.
266 def __init__(self, filenames, name='cal_ref_cat', config=None, htmLevel=4):
269 super().
__init__(dataIds, refCats, name=name, config=config)
271 def _createDataIdsAndRefcats(self, filenames, htmLevel, name):
272 """Create mock dataIds and refcat handles.
276 filenames : `list` [`str`]
277 Names of files to use.
279 HTM level to use for the loader.
281 Name of reference catalog (
for logging).
285 dataIds : `list` [`MockRefcatDataId`]
286 List of mock dataIds.
287 refCats : `list` [`MockRefcatDeferredDatasetHandle`]
288 List of mock deferred dataset handles.
292 RuntimeError
if any file contains sources that cover more than one HTM
293 pixel at level ``htmLevel``.
296 htm = esutil.htm.HTM(htmLevel)
301 for filename
in filenames:
302 cat = afwTable.BaseCatalog.readFits(filename)
304 ids = htm.lookup_id(np.rad2deg(cat[
'coord_ra']), np.rad2deg(cat[
'coord_dec']))
306 if len(np.unique(ids)) != 1:
307 raise RuntimeError(f
"File {filename} contains more than one pixel at level {htmLevel}")
312 return dataIds, refCats
table::Key< std::string > name
Represent a 2-dimensional array of bitmask pixels.
An integer coordinate rectangle.
Encapsulate information about a bad portion of a detector.
def __init__(self, pixelization, index)
def __init__(self, catalog, name)
def _createDataIdsAndRefcats(self, filenames, htmLevel, name)
def __init__(self, filenames, name='cal_ref_cat', config=None, htmLevel=4)
HtmPixelization provides HTM indexing of points and regions.
A Pixelization (or partitioning) of the sphere is a mapping between points on the sphere and a set of...
std::shared_ptr< Exposure< ImagePixelT, MaskPixelT, VariancePixelT > > makeExposure(MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > &mimage, std::shared_ptr< geom::SkyWcs const > wcs=std::shared_ptr< geom::SkyWcs const >())
A function to return an Exposure of the correct type (cf.
def plantSources(bbox, kwid, sky, coordList, addPoissonNoise=True)
def makeRandomTransmissionCurve(rng, minWavelength=4000.0, maxWavelength=7000.0, nWavelengths=200, maxRadius=80.0, nRadii=30, perturb=0.05)