46template <
typename T, std::
size_t N>
48 for (T
const&
element : array) {
98 if (
name == DEFAULT) {
119 return std::make_shared<FilterLabel>(_AFW_NAMES.
at(
name));
132 if (primaryMetadata->exists(versionName)) {
133 version = primaryMetadata->getAsInt(versionName);
134 primaryMetadata->remove(versionName);
140 str(boost::format(
"Cannot read Exposure FITS version > %i") %
146 wcs = afw::geom::makeSkyWcs(*imageMetadata,
true);
148 LOGLS_DEBUG(_log,
"No WCS found in FITS metadata");
155 imageMetadata->remove(
"LTV1");
156 imageMetadata->remove(
"LTV2");
158 if (!imageMetadata->exists(
"INHERIT")) {
176 size_t end =
name.find_last_not_of(
' ');
246 _hdu = popInt(
"AR_HDU");
248 _state = ArchiveState::MISSING;
251 _state = ArchiveState::PRESENT;
254 _ids[
PSF] = popInt(
"PSF_ID");
255 _ids[
WCS] = popInt(
"SKYWCS_ID");
260 _ids[
DETECTOR] = popInt(
"DETECTOR_ID");
267 if (headerKey.substr(0, PREFIX.
size()) == PREFIX) {
269 int archiveId = metadata.
get<
int>(headerKey);
270 _genericIds.
emplace(componentName, archiveId);
271 if (!_contains(_ids, archiveId)) {
272 _extraIds.
emplace(componentName);
275 toStrip.
push_back(componentName +
"_ID");
292 template <
typename T>
294 if (!_ensureLoaded(fitsFile)) {
297 return _archive.
get<T>(_ids[c]);
319 template <
typename T>
321 if (!_ensureLoaded(fitsFile)) {
325 if (_genericIds.
count(c) > 0) {
326 int archiveId = _genericIds.
at(c);
327 return _archive.
get<T>(archiveId);
346 if (!_ensureLoaded(fitsFile)) {
352 for (
std::string const& componentName : _extraIds) {
354 result.emplace(componentName, readComponent<table::io::Persistable>(fitsFile, componentName));
357 "Could not read component " << componentName <<
"; skipping: " << err.
what());
365 if (_state == ArchiveState::MISSING) {
368 if (_state == ArchiveState::PRESENT) {
371 _state = ArchiveState::LOADED;
373 assert(_state == ArchiveState::LOADED);
377 enum class ArchiveState { UNKNOWN, MISSING, PRESENT, LOADED };
380 ArchiveState _state = ArchiveState::UNKNOWN;
381 table::io::InputArchive _archive;
396 return _maskedImageReader.
readBBox(origin);
405 return _metadataReader->version;
416 return _metadataReader->metadata;
421 return _metadataReader->exposureId;
428 r = _metadataReader->wcs;
435 if (_metadataReader->version < 2) {
436 return _metadataReader->filterLabel;
444 if (_metadataReader->version == 0) {
445 return _metadataReader->photoCalib;
474 return _metadataReader->visitInfo;
495 return _archiveReader->readExtraComponents(_getFitsFile());
499 auto result = std::make_shared<ExposureInfo>();
515 LOGLS_WARN(_log,
"Could not read PSF; setting to null: " << err.
what());
520 LOGLS_WARN(_log,
"Could not read CoaddInputs; setting to null: " << err.
what());
525 LOGLS_WARN(_log,
"Could not read ApCorrMap; setting to null: " << err.
what());
530 LOGLS_WARN(_log,
"Could not read ValidPolygon; setting to null: " << err.
what());
535 LOGLS_WARN(_log,
"Could not read TransmissionCurve; setting to null: " << err.
what());
540 LOGLS_WARN(_log,
"Could not read Detector; setting to null: " << err.
what());
545 result->setWcs(_metadataReader->wcs);
554 auto msg =
str(boost::format(
"Could not read WCS extension; setting to null: %s") % err.
what());
556 msg +=
" ; using WCS from FITS header";
563 StorablePtr
object = std::dynamic_pointer_cast<StorablePtr::element_type>(keyValue.second);
565 if (
object.use_count() > 0) {
566 result->setComponent(typehandling::makeKey<StorablePtr>(key),
object);
568 LOGLS_WARN(_log,
"Data corruption: generic component " << key <<
" is not a Storable; skipping.");
573 if (_metadataReader->version < 2 && !
result->hasFilter()) {
579template <
typename ImagePixelT>
582 return _maskedImageReader.
readImage<ImagePixelT>(
bbox, origin, allowUnsafe);
585template <
typename ImagePixelT>
591template <
typename MaskPixelT>
593 bool conformMasks,
bool allowUnsafe) {
594 return _maskedImageReader.
readMask<MaskPixelT>(
bbox, origin, conformMasks, allowUnsafe);
597template <
typename MaskPixelT>
603template <
typename VariancePixelT>
606 return _maskedImageReader.
readVariance<VariancePixelT>(
bbox, origin, allowUnsafe);
609template <
typename VariancePixelT>
616template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
619 return _maskedImageReader.
read<ImagePixelT, MaskPixelT, VariancePixelT>(
bbox, origin, conformMasks,
624template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
630 readMaskedImage<ImagePixelT, MaskPixelT, VariancePixelT>(
bbox, origin, conformMasks, allowUnsafe);
634void ExposureFitsReader::_ensureReaders() {
635 if (!_metadataReader) {
636 auto metadataReader = std::make_unique<MetadataReader>(_maskedImageReader.
readPrimaryMetadata(),
639 _archiveReader = std::make_unique<ArchiveReader>(*metadataReader->metadata);
640 _metadataReader =
std::move(metadataReader);
642 assert(_archiveReader);
645#define INSTANTIATE(ImagePixelT) \
646 template Exposure<ImagePixelT, MaskPixel, VariancePixel> ExposureFitsReader::read( \
647 lsst::geom::Box2I const&, ImageOrigin, bool, bool); \
648 template Image<ImagePixelT> ExposureFitsReader::readImage(lsst::geom::Box2I const&, ImageOrigin, bool); \
649 template ndarray::Array<ImagePixelT, 2, 2> ExposureFitsReader::readImageArray(lsst::geom::Box2I const&, \
650 ImageOrigin, bool); \
651 template MaskedImage<ImagePixelT, MaskPixel, VariancePixel> ExposureFitsReader::readMaskedImage( \
652 lsst::geom::Box2I const&, ImageOrigin, bool, bool)
table::Key< std::string > name
#define INSTANTIATE(FROMSYS, TOSYS)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
LSST DM logging module built on log4cxx.
#define LOGLS_WARN(logger, message)
Log a warn-level message using an iostream-based interface.
#define LOG_GET(logger)
Returns a Log object associated with logger.
#define LOGLS_DEBUG(logger, message)
Log a debug-level message using an iostream-based interface.
Implementation of the Photometric Calibration class.
table::Key< table::Array< std::uint8_t > > wcs
table::Key< table::RecordId > exposureId
A representation of a detector in a mosaic camera.
A polymorphic base class for representing an image's Point Spread Function.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
RAII scoped guard for moving the HDU in a Fits object.
Lifetime-management for memory that goes into FITS memory files.
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
A thin wrapper around std::map to allow aperture corrections to be attached to Exposures.
std::shared_ptr< T > readComponent(afw::fits::Fits *fitsFile, std::string c)
Read an arbitrary component, if available.
std::map< std::string, std::shared_ptr< table::io::Persistable > > readExtraComponents(afw::fits::Fits *fitsFile)
Read the components that are stored using arbitrary-component support.
ArchiveReader(daf::base::PropertyList &metadata)
std::shared_ptr< T > readComponent(afw::fits::Fits *fitsFile, Component c)
Read a known component, if available.
A FITS reader class for Exposures and their components.
std::shared_ptr< TransmissionCurve > readTransmissionCurve()
Read the Exposure's transmission curve.
std::string readMaskDType() const
Read a string describing the pixel type of the on-disk image plane.
Exposure< ImagePixelT, MaskPixelT, VariancePixelT > read(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false, bool allowUnsafe=false)
Read the full Exposure.
std::shared_ptr< typehandling::Storable > readComponent(std::string const &componentName)
Read an arbitrary non-standard component by name.
std::shared_ptr< afw::geom::SkyWcs > readWcs()
Read the Exposure's world coordinate system.
MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > readMaskedImage(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false, bool allowUnsafe=false)
Read the MaskedImage.
std::map< std::string, std::shared_ptr< table::io::Persistable > > readExtraComponents()
Read the Exposure's non-standard components.
lsst::geom::Point2I readXY0(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT)
Read the image origin from the on-disk image or a subimage thereof.
ndarray::Array< VariancePixelT, 2, 2 > readVarianceArray(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the variance plane.
int readSerializationVersion()
Read the serialization version number from the header.
ExposureFitsReader(std::string const &fileName)
Construct a FITS reader object.
std::shared_ptr< detection::Psf > readPsf()
Read the Exposure's point-spread function.
std::shared_ptr< afw::geom::polygon::Polygon > readValidPolygon()
Read the polygon describing the region of validity for the Exposure.
Image< ImagePixelT > readImage(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the image plane.
std::string readVarianceDType() const
Read a string describing the pixel type of the on-disk image plane.
std::shared_ptr< FilterLabel > readFilter()
Read the Exposure's filter information.
ndarray::Array< ImagePixelT, 2, 2 > readImageArray(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the image plane.
lsst::geom::Box2I readBBox(ImageOrigin origin=PARENT)
Read the bounding box of the on-disk image.
Image< VariancePixelT > readVariance(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the variance plane.
std::shared_ptr< daf::base::PropertyList > readMetadata()
Read the flexible metadata associated with the Exposure.
std::shared_ptr< PhotoCalib > readPhotoCalib()
Read the Exposure's photometric calibration.
std::optional< table::RecordId > readExposureId()
Read the Exposure's exposure ID, if it exists.
std::shared_ptr< ApCorrMap > readApCorrMap()
Read the Exposure's aperture correction map.
~ExposureFitsReader() noexcept
ndarray::Array< MaskPixelT, 2, 2 > readMaskArray(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the mask plane.
std::string readImageDType() const
Read a string describing the pixel type of the on-disk image plane.
std::shared_ptr< CoaddInputs > readCoaddInputs()
Read the Exposure's coadd input catalogs.
std::shared_ptr< cameraGeom::Detector > readDetector()
Read the Exposure's detector.
std::shared_ptr< ExposureInfo > readExposureInfo()
Read the ExposureInfo containing all non-image components.
std::shared_ptr< VisitInfo > readVisitInfo()
Read the Exposure's visit metadata.
Mask< MaskPixelT > readMask(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false, bool allowUnsafe=false)
Read the mask plane.
A class to contain the data, WCS, and other information needed to describe an image of the sky.
static int getFitsSerializationVersion()
Get the version of FITS serialization that this ExposureInfo understands.
static std::string const & getFitsSerializationVersionName()
Get the version of FITS serialization version info name.
static typehandling::Key< std::string, std::shared_ptr< FilterLabel const > > const KEY_FILTER
Standard key for looking up filter information.
A group of labels for a filter in an exposure or coadd.
static FilterLabel fromBand(std::string const &band)
Construct a FilterLabel from specific inputs.
static FilterLabel fromBandPhysical(std::string const &band, std::string const &physical)
Construct a FilterLabel from specific inputs.
static FilterLabel fromPhysical(std::string const &physical)
Construct a FilterLabel from specific inputs.
A class to represent a 2-dimensional array of pixels.
Represent a 2-dimensional array of bitmask pixels.
std::string readMaskDType() const
Read a string describing the pixel type of the on-disk image plane.
std::shared_ptr< daf::base::PropertyList > readImageMetadata()
Read the FITS header of one of the HDUs.
std::shared_ptr< daf::base::PropertyList > readPrimaryMetadata()
Read the FITS header of one of the HDUs.
std::string readVarianceDType() const
Read a string describing the pixel type of the on-disk image plane.
ndarray::Array< MaskPixelT, 2, 2 > readMaskArray(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the mask plane.
std::string readImageDType() const
Read a string describing the pixel type of the on-disk image plane.
ndarray::Array< ImagePixelT, 2, 2 > readImageArray(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the image plane.
ndarray::Array< VariancePixelT, 2, 2 > readVarianceArray(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the variance plane.
Mask< MaskPixelT > readMask(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false, bool allowUnsafe=false)
Read the mask plane.
MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > read(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false, bool needAllHdus=false, bool allowUnsafe=false)
Read the full MaskedImage.
Image< ImagePixelT > readImage(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the image plane.
Image< VariancePixelT > readVariance(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the variance plane.
lsst::geom::Point2I readXY0(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT)
Read the image origin from the on-disk image or a subimage thereof.
A class to manipulate images, masks, and variance as a single object.
The photometric calibration of an exposure.
A spatially-varying transmission curve as a function of wavelength.
Interface supporting iteration over heterogenous containers.
Class for storing ordered metadata with comments.
T get(std::string const &name) const
Get the last value for a property name (possibly hierarchical).
virtual void remove(std::string const &name)
Remove all values for a property name (possibly hierarchical).
bool exists(std::string const &name) const
Determine if a name (possibly hierarchical) exists.
An integer coordinate rectangle.
CoordinateExpr< N > ne(Point< T, N > const &other) const noexcept
virtual char const * what(void) const noexcept
Return a character string summarizing this exception.
Reports attempts to access elements using an invalid key.
Reports errors from accepting an object of an unexpected or inappropriate type.
int stripVisitInfoKeywords(daf::base::PropertySet &metadata)
Remove VisitInfo-related keywords from the metadata.
std::shared_ptr< PhotoCalib > makePhotoCalibFromMetadata(daf::base::PropertySet &metadata, bool strip=false)
Construct a PhotoCalib from FITS FLUXMAG0/FLUXMAG0ERR keywords.
std::shared_ptr< FilterLabel > makeFilterLabel(std::string const &name)
Convert an old-style single Filter name to a FilterLabel, using available information.
std::shared_ptr< FilterLabel > makeFilterLabelDirect(std::string const &name)
Convert an old-style filter name to a FilterLabel without external information.