23 """Mapper and cameraGeom definition for extremely simple mock data.
25 SimpleMapper inherits directly from Mapper, not CameraMapper. This means
26 we can avoid any problems with paf files at the expense of reimplementing
27 some parts of CameraMapper here. Jim is not sure this was the best
28 possible approach, but it gave him an opportunity to play around with
29 prototyping a future paf-free mapper class, and it does everything it
30 needs to do right now.
42 __all__ = (
"SimpleMapper",
"makeSimpleCamera",
"makeDataRepo")
46 """Base class of a hierarchy used by SimpleMapper to defined different kinds of types of objects
49 PersistenceType objects are never instantiated; only the type objects are used (we needed a
50 simple singleton struct that could be inherited, which is exactly what a Python type is).
60 """Method called by SimpleMapping to implement a map_ method."""
70 """Persistence type for things that don't actually use daf_persistence.
73 python =
"lsst.daf.base.PropertySet"
77 """Method called by SimpleMapping to implement a map_ method; overridden to not use the path."""
79 mapper=mapper, storage=storage)
83 """Persistence type of Exposure images.
86 python =
"lsst.afw.image.ExposureF"
88 storage =
"FitsStorage"
94 """Method called by SimpleMapping to implement a map_ method; overridden to support subimages."""
96 loc = super(ExposurePersistenceType, cls).
makeButlerLocation(path, dataId, mapper, suffix=
None,
104 "compression.algorithm":
"NONE",
105 "compression.columns": 0,
106 "compression.rows": 0,
107 "compression.quantizeLevel": 0.0,
108 "scaling.algorithm":
"NONE",
109 "scaling.bzero": 0.0,
110 "scaling.bscale": 0.0,
112 "scaling.quantizeLevel": 0.0,
113 "scaling.quantizePad": 0.0,
114 "scaling.fuzz":
False,
117 for prefix
in (
"image",
"mask",
"variance"):
118 for k, v
in options.items():
119 loc.additionalData.set(
"{}.{}".
format(prefix, k), v)
120 elif suffix ==
"_sub":
121 subId = dataId.copy()
122 bbox = subId.pop(
'bbox')
123 loc = super(ExposurePersistenceType, cls).
makeButlerLocation(path, subId, mapper, suffix=
None,
125 loc.additionalData.set(
'llcX', bbox.getMinX())
126 loc.additionalData.set(
'llcY', bbox.getMinY())
127 loc.additionalData.set(
'width', bbox.getWidth())
128 loc.additionalData.set(
'height', bbox.getHeight())
129 if 'imageOrigin' in dataId:
130 loc.additionalData.set(
'imageOrigin',
131 dataId[
'imageOrigin'])
136 python =
"lsst.skymap.BaseSkyMap"
137 storage =
"PickleStorage"
142 python =
"lsst.afw.table.BaseCatalog"
144 storage =
"FitsCatalogStorage"
149 python =
"lsst.afw.table.SimpleCatalog"
150 cpp =
"SimpleCatalog"
154 python =
"lsst.afw.table.SourceCatalog"
155 cpp =
"SourceCatalog"
159 python =
"lsst.afw.table.ExposureCatalog"
160 cpp =
"ExposureCatalog"
164 python =
"lsst.afw.detection.PeakCatalog"
169 """Mapping object used to implement SimpleMapper, similar in intent to lsst.daf.peristence.Mapping.
175 def __init__(self, persistence, template=None, keys=None):
177 if template
is not None:
182 def map(self, dataset, root, dataId, mapper, suffix=None, storage=None):
183 if self.
templatetemplate
is not None:
187 return self.
persistencepersistence.makeButlerLocation(path, dataId, suffix=suffix, mapper=mapper,
192 """Mapping for dataset types that are organized the same way as raw data (i.e. by CCD)."""
194 template =
"{dataset}-{visit:04d}-{ccd:01d}{ext}"
195 keys = dict(visit=int, ccd=int)
197 def query(self, dataset, index, level, format, dataId):
198 dictList = index[dataset][level]
199 results = [
list(d.values())
for d
in dictList[dataId.get(level,
None)]]
204 """Mapping for dataset types that are organized according to a SkyMap subdivision of the sky."""
206 template =
"{dataset}-{filter}-{tract:02d}-{patch}{ext}"
207 keys = dict(filter=str, tract=int, patch=str)
211 """Mapping for CoaddTempExp datasets."""
213 template =
"{dataset}-{tract:02d}-{patch}-{visit:04d}{ext}"
214 keys = dict(tract=int, patch=str, visit=int)
218 """Mapping for forced_src datasets."""
220 template =
"{dataset}-{tract:02d}-{visit:04d}-{ccd:01d}{ext}"
221 keys = dict(tract=int, ccd=int, visit=int)
225 """Metaclass for SimpleMapper that creates map_ and query_ methods for everything found in the
226 'mappings' class variable.
230 def _makeMapClosure(dataset, mapping, suffix=None):
231 def mapClosure(self, dataId, write=False):
232 return mapping.map(dataset, self.root, dataId, self, suffix=suffix, storage=self.storage)
236 def _makeQueryClosure(dataset, mapping):
237 def queryClosure(self, level, format, dataId):
238 return mapping.query(dataset, self.index, level, format, dataId)
242 type.__init__(cls, name, bases, dict_)
244 for dataset, mapping
in cls.mappings.
items():
245 setattr(cls,
"map_" + dataset, MapperMeta._makeMapClosure(dataset, mapping, suffix=
None))
246 for suffix
in mapping.persistence.suffixes:
247 setattr(cls,
"map_" + dataset + suffix,
248 MapperMeta._makeMapClosure(dataset, mapping, suffix=suffix))
249 if hasattr(mapping,
"query"):
250 setattr(cls,
"query_" + dataset, MapperMeta._makeQueryClosure(dataset, mapping))
251 cls.
keyDictkeyDict.update(mapping.keys)
256 An extremely simple mapper for an imaginary camera for use in integration tests.
258 As SimpleMapper does not inherit from obs.base.CameraMapper, it does not
259 use a policy file to set mappings or a registry; all the information is here
260 (in the map_* and query_* methods).
262 The imaginary camera's raw data format has only 'visit' and 'ccd' keys, with
263 two CCDs per visit (by default).
269 forced_src_schema=
SimpleMapping(SourceCatalogPersistenceType,
270 template=
"{dataset}{ext}", keys={}),
271 truth=
SimpleMapping(SimpleCatalogPersistenceType, template=
"{dataset}-{tract:02d}{ext}",
272 keys={
"tract": int}),
273 simsrc=
RawMapping(SimpleCatalogPersistenceType, template=
"{dataset}-{tract:02d}{ext}",
274 keys={
"tract": int}),
275 observations=
SimpleMapping(ExposureCatalogPersistenceType, template=
"{dataset}-{tract:02d}{ext}",
276 keys={
"tract": int}),
277 ccdExposureId=
RawMapping(BypassPersistenceType),
279 deepCoaddId=
SkyMapping(BypassPersistenceType),
281 deepMergedCoaddId=
SkyMapping(BypassPersistenceType),
283 deepCoadd_skyMap=
SimpleMapping(SkyMapPersistenceType, template=
"{dataset}{ext}", keys={}),
284 deepCoadd=
SkyMapping(ExposurePersistenceType),
285 deepCoadd_filterLabel=
SkyMapping(ExposurePersistenceType),
286 deepCoaddPsfMatched=
SkyMapping(ExposurePersistenceType),
287 deepCoadd_calexp=
SkyMapping(ExposurePersistenceType),
288 deepCoadd_calexp_background=
SkyMapping(CatalogPersistenceType),
289 deepCoadd_icSrc=
SkyMapping(SourceCatalogPersistenceType),
290 deepCoadd_icSrc_schema=
SimpleMapping(SourceCatalogPersistenceType,
291 template=
"{dataset}{ext}", keys={}),
292 deepCoadd_src=
SkyMapping(SourceCatalogPersistenceType),
293 deepCoadd_src_schema=
SimpleMapping(SourceCatalogPersistenceType,
294 template=
"{dataset}{ext}", keys={}),
295 deepCoadd_peak_schema=
SimpleMapping(PeakCatalogPersistenceType,
296 template=
"{dataset}{ext}", keys={}),
297 deepCoadd_ref=
SkyMapping(SourceCatalogPersistenceType),
298 deepCoadd_ref_schema=
SimpleMapping(SourceCatalogPersistenceType,
299 template=
"{dataset}{ext}", keys={}),
300 deepCoadd_det=
SkyMapping(SourceCatalogPersistenceType),
301 deepCoadd_det_schema=
SimpleMapping(SourceCatalogPersistenceType,
302 template=
"{dataset}{ext}", keys={}),
303 deepCoadd_mergeDet=
SkyMapping(SourceCatalogPersistenceType),
304 deepCoadd_mergeDet_schema=
SimpleMapping(SourceCatalogPersistenceType,
305 template=
"{dataset}{ext}", keys={}),
306 deepCoadd_deblendedFlux=
SkyMapping(SourceCatalogPersistenceType),
307 deepCoadd_deblendedFlux_schema=
SimpleMapping(SourceCatalogPersistenceType,
308 template=
"{dataset}{ext}", keys={}),
309 deepCoadd_deblendedModel=
SkyMapping(SourceCatalogPersistenceType),
310 deepCoadd_deblendedModel_schema=
SimpleMapping(SourceCatalogPersistenceType,
311 template=
"{dataset}{ext}", keys={}),
312 deepCoadd_meas=
SkyMapping(SourceCatalogPersistenceType),
313 deepCoadd_meas_schema=
SimpleMapping(SourceCatalogPersistenceType,
314 template=
"{dataset}{ext}", keys={}),
315 deepCoadd_forced_src=
SkyMapping(SourceCatalogPersistenceType),
316 deepCoadd_forced_src_schema=
SimpleMapping(SourceCatalogPersistenceType,
317 template=
"{dataset}{ext}", keys={}),
318 deepCoadd_mock=
SkyMapping(ExposurePersistenceType),
319 deepCoaddPsfMatched_mock=
SkyMapping(ExposurePersistenceType),
321 deepCoadd_directWarp_mock=
TempExpMapping(ExposurePersistenceType),
323 deepCoadd_psfMatchedWarp_mock=
TempExpMapping(ExposurePersistenceType),
332 self.
storagestorage = lsst.daf.persistence.Storage.makeFromURI(root)
333 super(SimpleMapper, self).
__init__(**kwargs)
348 if datasetType
is None:
351 keyDict = self.
mappingsmappings[datasetType].keys
352 if level
is not None and level
in self.
levelslevels:
353 keyDict = dict(keyDict)
354 for lev
in self.
levelslevels[level]:
360 filenames = os.listdir(self.
rootroot)
361 rawRegex = re.compile(
r"(?P<dataset>\w+)-(?P<visit>\d+)-(?P<ccd>\d).*")
363 for filename
in filenames:
364 m = rawRegex.match(filename)
367 index = self.
indexindex.setdefault(m.group(
'dataset'), dict(ccd={
None: []}, visit={
None: []}))
368 visit = int(m.group(
'visit'))
369 ccd = int(m.group(
'ccd'))
370 d1 = dict(visit=visit, ccd=ccd)
371 d2 = dict(visit=visit)
372 index[
'ccd'].setdefault(visit, []).
append(d1)
373 index[
'ccd'][
None].
append(d1)
374 index[
'visit'][visit] = [d2]
375 index[
'visit'][
None].
append(d1)
385 "lsst.afw.cameraGeom.Camera",
"Camera",
None, [], dataId, mapper=self, storage=self.
storagestorage
389 detectorId = dataId[
"ccd"]
390 detector = self.
cameracamera[detectorId]
391 item.setDetector(detector)
395 def _computeCcdExposureId(self, dataId):
396 return int(dataId[
"visit"]) * 10 + int(dataId[
"ccd"])
398 def _computeCoaddId(self, dataId):
401 tract = int(dataId[
'tract'])
402 if tract < 0
or tract >= 128:
403 raise RuntimeError(
'tract not in range [0,128)')
404 patchX, patchY = (int(c)
for c
in dataId[
'patch'].split(
','))
405 for p
in (patchX, patchY):
406 if p < 0
or p >= 2**13:
407 raise RuntimeError(
'patch component not in range [0, 8192)')
408 return (tract * 2**13 + patchX) * 2**13 + patchY
412 return dict(visit=(int(ccdExposureId) // 10), ccd=(int(ccdExposureId) % 10))
424 return 1 + 7 + 13*2 + 3
430 return 1 + 7 + 13*2 + 3
433 """To return a useful filterLabel for MergeDetectionsTask."""
443 radialDistortion=0.925,
447 @param[in] nx: number of detectors in x
448 @param[in] ny: number of detectors in y
449 @param[in] sizeX: detector size in x (pixels)
450 @param[in] sizeY: detector size in y (pixels)
451 @param[in] gapX: gap between detectors in x (mm)
452 @param[in] gapY: gap between detectors in y (mm)
453 @param[in] pixelSize: pixel size (mm) (a float)
454 @param[in] plateScale: plate scale in arcsec/mm; 20.0 is for LSST
455 @param[in] radialDistortion: radial distortion, in mm/rad^2
456 (the r^3 coefficient of the radial distortion polynomial
457 that converts FIELD_ANGLE in radians to FOCAL_PLANE in mm);
458 0.925 is the value Dave Monet measured for lsstSim data
460 Each detector will have one amplifier (with no raw information).
463 radialDistortCoeffs = [0.0, 1.0/pScaleRad, 0.0, radialDistortion/pScaleRad]
472 cY = (iY - 0.5 * (nY - 1)) * (pixelSize * sizeY + gapY)
474 cX = (iX - 0.5 * (nX - 1)) * (pixelSize * sizeY + gapX)
476 detectorName =
"detector %d,%d" % (iX, iY)
478 detectorBuilder = cameraBuilder.add(detectorName, detectorId)
479 detectorBuilder.setSerial(detectorName +
" serial")
480 detectorBuilder.setBBox(ccdBBox)
486 ampBuilder.setName(ampName)
487 ampBuilder.setBBox(ccdBBox)
488 ampBuilder.setGain(1.0)
489 ampBuilder.setReadNoise(5.0)
491 detectorBuilder.append(ampBuilder)
495 cameraBuilder.setTransformFromFocalPlaneTo(lsst.afw.cameraGeom.FIELD_ANGLE, focalPlaneToFieldAngle)
496 return cameraBuilder.finish()
501 Create a data repository for SimpleMapper and return a butler for it.
503 Clobbers anything already in the given path.
505 if os.path.exists(root):
508 with open(os.path.join(root,
"_mapper"),
"w")
as f:
509 f.write(
"lsst.pipe.tasks.mocks.SimpleMapper\n")
std::vector< SchemaItem< Flag > > * items
A mutable Amplifier subclass class that can be used to incrementally construct or modify Amplifiers.
A helper class for creating and modifying cameras.
Describe a detector's orientation in the focal plane.
A group of labels for a filter in an exposure or coadd.
An integer coordinate rectangle.
def makeButlerLocation(cls, path, dataId, mapper, suffix=None, storage=None)
def makeButlerLocation(cls, path, dataId, mapper, suffix=None, storage=None)
def makeButlerLocation(cls, path, dataId, mapper, suffix=None, storage=None)
def canStandardize(self, datasetType)
def query(self, dataset, index, level, format, dataId)
def bypass_deepMergedCoaddId_bits(self, datasetType, pythonType, location, dataId)
def bypass_deepMergedCoaddId(self, datasetType, pythonType, location, dataId)
def getDefaultLevel(self)
def bypass_ccdExposureId(self, datasetType, pythonType, location, dataId)
def _computeCcdExposureId(self, dataId)
def bypass_deepCoadd_filterLabel(self, *args, **kwargs)
def getKeys(self, datasetType, level)
def std_calexp(self, item, dataId)
def map_camera(self, dataId, write=False)
def __init__(self, root, **kwargs)
def bypass_camera(self, datasetType, pythonType, location, dataId)
def splitCcdExposureId(ccdExposureId)
def bypass_deepCoaddId_bits(self, datasetType, pythonType, location, dataId)
def bypass_ccdExposureId_bits(self, datasetType, pythonType, location, dataId)
def bypass_deepCoaddId(self, datasetType, pythonType, location, dataId)
def _computeCoaddId(self, dataId)
def map(self, dataset, root, dataId, mapper, suffix=None, storage=None)
def __init__(self, persistence, template=None, keys=None)
daf::base::PropertyList * list
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
std::shared_ptr< TransformPoint2ToPoint2 > makeRadialTransform(std::vector< double > const &coeffs)
A purely radial polynomial distortion.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
constexpr double arcsecToRad(double x) noexcept
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
def makeSimpleCamera(nX, nY, sizeX, sizeY, gapX, gapY, pixelSize=1.0, plateScale=20.0, radialDistortion=0.925)