LSSTApplications  18.1.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 1322 of file cameraMapper.py.

1322 def exposureFromImage(image, dataId=None, mapper=None, logger=None, setVisitInfo=True):
1323  """Generate an Exposure from an image-like object
1324 
1325  If the image is a DecoratedImage then also set its WCS and metadata
1326  (Image and MaskedImage are missing the necessary metadata
1327  and Exposure already has those set)
1328 
1329  Parameters
1330  ----------
1331  image : Image-like object
1332  Can be one of lsst.afw.image.DecoratedImage, Image, MaskedImage or
1333  Exposure.
1334 
1335  Returns
1336  -------
1337  `lsst.afw.image.Exposure`
1338  Exposure containing input image.
1339  """
1340  metadata = None
1341  if isinstance(image, afwImage.MaskedImage):
1342  exposure = afwImage.makeExposure(image)
1343  elif isinstance(image, afwImage.DecoratedImage):
1344  exposure = afwImage.makeExposure(afwImage.makeMaskedImage(image.getImage()))
1345  metadata = image.getMetadata()
1346  try:
1347  wcs = afwGeom.makeSkyWcs(metadata, strip=True)
1348  exposure.setWcs(wcs)
1349  except pexExcept.TypeError as e:
1350  # raised on failure to create a wcs (and possibly others)
1351  if logger is None:
1352  logger = lsstLog.Log.getLogger("CameraMapper")
1353  logger.debug("wcs set to None; insufficient information found in metadata to create a valid wcs:"
1354  " %s", e.args[0])
1355 
1356  exposure.setMetadata(metadata)
1357  elif isinstance(image, afwImage.Exposure):
1358  # Exposure
1359  exposure = image
1360  metadata = exposure.getMetadata()
1361  else:
1362  # Image
1364  #
1365  # set VisitInfo if we can
1366  #
1367  if setVisitInfo and exposure.getInfo().getVisitInfo() is None:
1368  if metadata is not None:
1369  if mapper is None:
1370  if not logger:
1371  logger = lsstLog.Log.getLogger("CameraMapper")
1372  logger.warn("I can only set the VisitInfo if you provide a mapper")
1373  else:
1374  exposureId = mapper._computeCcdExposureId(dataId)
1375  visitInfo = mapper.makeRawVisitInfo(md=metadata, exposureId=exposureId)
1376 
1377  exposure.getInfo().setVisitInfo(visitInfo)
1378 
1379  return exposure
1380 
1381 
A class to contain the data, WCS, and other information needed to describe an image of the sky...
Definition: Exposure.h:72
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:1280
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:457
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:74
std::shared_ptr< SkyWcs > makeSkyWcs(TransformPoint2ToPoint2 const &pixelsToFieldAngle, lsst::geom::Angle const &orientation, bool flipX, lsst::geom::SpherePoint const &boresight, std::string const &projection="TAN")
Construct a FITS SkyWcs from camera geometry.
Definition: SkyWcs.cc:496
Reports errors from accepting an object of an unexpected or inappropriate type.
Definition: Runtime.h:167
def exposureFromImage(image, dataId=None, mapper=None, logger=None, setVisitInfo=True)
A container for an Image and its associated metadata.
Definition: Image.h:407

◆ 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 1382 of file cameraMapper.py.

1382 def validateRecipeFitsStorage(recipes):
1383  """Validate recipes for FitsStorage
1384 
1385  The recipes are supplemented with default values where appropriate.
1386 
1387  TODO: replace this custom validation code with Cerberus (DM-11846)
1388 
1389  Parameters
1390  ----------
1391  recipes : `lsst.daf.persistence.Policy`
1392  FitsStorage recipes to validate.
1393 
1394  Returns
1395  -------
1396  validated : `lsst.daf.base.PropertySet`
1397  Validated FitsStorage recipe.
1398 
1399  Raises
1400  ------
1401  `RuntimeError`
1402  If validation fails.
1403  """
1404  # Schemas define what should be there, and the default values (and by the default
1405  # value, the expected type).
1406  compressionSchema = {
1407  "algorithm": "NONE",
1408  "rows": 1,
1409  "columns": 0,
1410  "quantizeLevel": 0.0,
1411  }
1412  scalingSchema = {
1413  "algorithm": "NONE",
1414  "bitpix": 0,
1415  "maskPlanes": ["NO_DATA"],
1416  "seed": 0,
1417  "quantizeLevel": 4.0,
1418  "quantizePad": 5.0,
1419  "fuzz": True,
1420  "bscale": 1.0,
1421  "bzero": 0.0,
1422  }
1423 
1424  def checkUnrecognized(entry, allowed, description):
1425  """Check to see if the entry contains unrecognised keywords"""
1426  unrecognized = set(entry.keys()) - set(allowed)
1427  if unrecognized:
1428  raise RuntimeError(
1429  "Unrecognized entries when parsing image compression recipe %s: %s" %
1430  (description, unrecognized))
1431 
1432  validated = {}
1433  for name in recipes.names(True):
1434  checkUnrecognized(recipes[name], ["image", "mask", "variance"], name)
1435  rr = dafBase.PropertySet()
1436  validated[name] = rr
1437  for plane in ("image", "mask", "variance"):
1438  checkUnrecognized(recipes[name][plane], ["compression", "scaling"],
1439  name + "->" + plane)
1440 
1441  for settings, schema in (("compression", compressionSchema),
1442  ("scaling", scalingSchema)):
1443  prefix = plane + "." + settings
1444  if settings not in recipes[name][plane]:
1445  for key in schema:
1446  rr.set(prefix + "." + key, schema[key])
1447  continue
1448  entry = recipes[name][plane][settings]
1449  checkUnrecognized(entry, schema.keys(), name + "->" + plane + "->" + settings)
1450  for key in schema:
1451  value = type(schema[key])(entry[key]) if key in entry else schema[key]
1452  rr.set(prefix + "." + key, value)
1453  return validated
1454 
def validateRecipeFitsStorage(recipes)
daf::base::PropertySet * set
Definition: fits.cc:884
table::Key< int > type
Definition: Detector.cc:167
Class for storing generic metadata.
Definition: PropertySet.h:68