LSSTApplications  20.0.0
LSSTDataManagementBasePackage
Classes | Functions
lsst.obs.base.cameraMapper Namespace Reference

Classes

class  CameraMapper
 

Functions

def exposureFromImage (image, dataId=None, mapper=None, logger=None, setVisitInfo=True)
 
def validateRecipeFitsStorage (recipes)
 

Function Documentation

◆ exposureFromImage()

def lsst.obs.base.cameraMapper.exposureFromImage (   image,
  dataId = None,
  mapper = None,
  logger = None,
  setVisitInfo = True 
)
Generate an Exposure from an image-like object

If the image is a DecoratedImage then also set its WCS and metadata
(Image and MaskedImage are missing the necessary metadata
and Exposure already has those set)

Parameters
----------
image : Image-like object
    Can be one of lsst.afw.image.DecoratedImage, Image, MaskedImage or
    Exposure.

Returns
-------
`lsst.afw.image.Exposure`
    Exposure containing input image.

Definition at line 1286 of file cameraMapper.py.

1286 def exposureFromImage(image, dataId=None, mapper=None, logger=None, setVisitInfo=True):
1287  """Generate an Exposure from an image-like object
1288 
1289  If the image is a DecoratedImage then also set its WCS and metadata
1290  (Image and MaskedImage are missing the necessary metadata
1291  and Exposure already has those set)
1292 
1293  Parameters
1294  ----------
1295  image : Image-like object
1296  Can be one of lsst.afw.image.DecoratedImage, Image, MaskedImage or
1297  Exposure.
1298 
1299  Returns
1300  -------
1301  `lsst.afw.image.Exposure`
1302  Exposure containing input image.
1303  """
1304  translatorClass = None
1305  if mapper is not None:
1306  translatorClass = mapper.translatorClass
1307 
1308  metadata = None
1309  if isinstance(image, afwImage.MaskedImage):
1310  exposure = afwImage.makeExposure(image)
1311  elif isinstance(image, afwImage.DecoratedImage):
1312  exposure = afwImage.makeExposure(afwImage.makeMaskedImage(image.getImage()))
1313  metadata = image.getMetadata()
1314  fix_header(metadata, translator_class=translatorClass)
1315  exposure.setMetadata(metadata)
1316  elif isinstance(image, afwImage.Exposure):
1317  exposure = image
1318  metadata = exposure.getMetadata()
1319  fix_header(metadata, translator_class=translatorClass)
1320  else: # Image
1322 
1323  # set VisitInfo if we can
1324  if setVisitInfo and exposure.getInfo().getVisitInfo() is None:
1325  if metadata is not None:
1326  if mapper is None:
1327  if not logger:
1328  logger = lsstLog.Log.getLogger("CameraMapper")
1329  logger.warn("I can only set the VisitInfo if you provide a mapper")
1330  else:
1331  exposureId = mapper._computeCcdExposureId(dataId)
1332  visitInfo = mapper.makeRawVisitInfo(md=metadata, exposureId=exposureId)
1333 
1334  exposure.getInfo().setVisitInfo(visitInfo)
1335 
1336  return exposure
1337 
1338 

◆ validateRecipeFitsStorage()

def lsst.obs.base.cameraMapper.validateRecipeFitsStorage (   recipes)
Validate recipes for FitsStorage

The recipes are supplemented with default values where appropriate.

TODO: replace this custom validation code with Cerberus (DM-11846)

Parameters
----------
recipes : `lsst.daf.persistence.Policy`
    FitsStorage recipes to validate.

Returns
-------
validated : `lsst.daf.base.PropertySet`
    Validated FitsStorage recipe.

Raises
------
`RuntimeError`
    If validation fails.

Definition at line 1339 of file cameraMapper.py.

1339 def validateRecipeFitsStorage(recipes):
1340  """Validate recipes for FitsStorage
1341 
1342  The recipes are supplemented with default values where appropriate.
1343 
1344  TODO: replace this custom validation code with Cerberus (DM-11846)
1345 
1346  Parameters
1347  ----------
1348  recipes : `lsst.daf.persistence.Policy`
1349  FitsStorage recipes to validate.
1350 
1351  Returns
1352  -------
1353  validated : `lsst.daf.base.PropertySet`
1354  Validated FitsStorage recipe.
1355 
1356  Raises
1357  ------
1358  `RuntimeError`
1359  If validation fails.
1360  """
1361  # Schemas define what should be there, and the default values (and by the default
1362  # value, the expected type).
1363  compressionSchema = {
1364  "algorithm": "NONE",
1365  "rows": 1,
1366  "columns": 0,
1367  "quantizeLevel": 0.0,
1368  }
1369  scalingSchema = {
1370  "algorithm": "NONE",
1371  "bitpix": 0,
1372  "maskPlanes": ["NO_DATA"],
1373  "seed": 0,
1374  "quantizeLevel": 4.0,
1375  "quantizePad": 5.0,
1376  "fuzz": True,
1377  "bscale": 1.0,
1378  "bzero": 0.0,
1379  }
1380 
1381  def checkUnrecognized(entry, allowed, description):
1382  """Check to see if the entry contains unrecognised keywords"""
1383  unrecognized = set(entry.keys()) - set(allowed)
1384  if unrecognized:
1385  raise RuntimeError(
1386  "Unrecognized entries when parsing image compression recipe %s: %s" %
1387  (description, unrecognized))
1388 
1389  validated = {}
1390  for name in recipes.names(True):
1391  checkUnrecognized(recipes[name], ["image", "mask", "variance"], name)
1392  rr = dafBase.PropertySet()
1393  validated[name] = rr
1394  for plane in ("image", "mask", "variance"):
1395  checkUnrecognized(recipes[name][plane], ["compression", "scaling"],
1396  name + "->" + plane)
1397 
1398  for settings, schema in (("compression", compressionSchema),
1399  ("scaling", scalingSchema)):
1400  prefix = plane + "." + settings
1401  if settings not in recipes[name][plane]:
1402  for key in schema:
1403  rr.set(prefix + "." + key, schema[key])
1404  continue
1405  entry = recipes[name][plane][settings]
1406  checkUnrecognized(entry, schema.keys(), name + "->" + plane + "->" + settings)
1407  for key in schema:
1408  value = type(schema[key])(entry[key]) if key in entry else schema[key]
1409  rr.set(prefix + "." + key, value)
1410  return validated
lsst::afw::image::DecoratedImage
A container for an Image and its associated metadata.
Definition: Image.h:404
lsst::afw::image::Exposure
A class to contain the data, WCS, and other information needed to describe an image of the sky.
Definition: Exposure.h:72
lsst::afw::image::makeExposure
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.
Definition: Exposure.h:442
lsst::afw::image::MaskedImage
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:73
lsst.obs.base.cameraMapper.exposureFromImage
def exposureFromImage(image, dataId=None, mapper=None, logger=None, setVisitInfo=True)
Definition: cameraMapper.py:1286
lsst.obs.base.cameraMapper.validateRecipeFitsStorage
def validateRecipeFitsStorage(recipes)
Definition: cameraMapper.py:1339
type
table::Key< int > type
Definition: Detector.cc:163
lsst::daf::base::PropertySet
Class for storing generic metadata.
Definition: PropertySet.h:67
lsst::afw::image::makeMaskedImage
MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > * makeMaskedImage(typename std::shared_ptr< Image< ImagePixelT >> image, typename std::shared_ptr< Mask< MaskPixelT >> mask=Mask< MaskPixelT >(), typename std::shared_ptr< Image< VariancePixelT >> variance=Image< VariancePixelT >())
A function to return a MaskedImage of the correct type (cf.
Definition: MaskedImage.h:1279
set
daf::base::PropertySet * set
Definition: fits.cc:912