45 template <
typename T, std::
size_t N>
47 for (T
const&
element : array) {
95 static Filter const DEFAULT;
97 if (
name == DEFAULT.getName()) {
122 static Filter const DEFAULT;
125 if (
filter.getId() == DEFAULT.getId() &&
filter.getName() == DEFAULT.getName()) {
131 if (
filter.getId() == Filter::UNKNOWN) {
140 canonical =
filter.getCanonicalName();
146 if (_AFW_NAMES.
count(canonical) > 0) {
147 return std::make_shared<FilterLabel>(_AFW_NAMES.
at(canonical));
148 }
else if (_isBand(canonical)) {
153 aliases =
filter.getAliases();
157 if (aliases.
size() == 1) {
179 return std::make_shared<FilterLabel>(_AFW_NAMES.
at(
name));
192 return std::make_shared<FilterLabel>(
213 for (
auto const& keyValue : _AFW_NAMES) {
216 if (label == afwFilter) {
234 if (primaryMetadata->exists(versionName)) {
235 version = primaryMetadata->getAsInt(versionName);
236 primaryMetadata->remove(versionName);
242 str(
boost::format(
"Cannot read Exposure FITS version > %i") %
250 LOGLS_DEBUG(_log,
"No WCS found in FITS metadata");
257 imageMetadata->remove(
"LTV1");
258 imageMetadata->remove(
"LTV2");
260 if (!imageMetadata->exists(
"INHERIT")) {
278 size_t end =
name.find_last_not_of(
' ');
339 _hdu = popInt(
"AR_HDU");
341 _state = ArchiveState::MISSING;
344 _state = ArchiveState::PRESENT;
347 _ids[
PSF] = popInt(
"PSF_ID");
348 _ids[
WCS] = popInt(
"SKYWCS_ID");
353 _ids[
DETECTOR] = popInt(
"DETECTOR_ID");
360 if (headerKey.substr(0, PREFIX.
size()) == PREFIX) {
362 int archiveId = metadata.
get<
int>(headerKey);
363 _genericIds.
emplace(componentName, archiveId);
364 if (!_contains(_ids, archiveId)) {
365 _extraIds.
emplace(componentName);
368 toStrip.
push_back(componentName +
"_ID");
385 template <
typename T>
387 if (!_ensureLoaded(fitsFile)) {
390 return _archive.
get<T>(_ids[c]);
412 template <
typename T>
414 if (!_ensureLoaded(fitsFile)) {
418 if (_genericIds.
count(c) > 0) {
419 int archiveId = _genericIds.
at(c);
420 return _archive.
get<T>(archiveId);
439 if (!_ensureLoaded(fitsFile)) {
445 for (
std::string const& componentName : _extraIds) {
447 result.emplace(componentName, readComponent<table::io::Persistable>(fitsFile, componentName));
450 "Could not read component " << componentName <<
"; skipping: " << err.
what());
458 if (_state == ArchiveState::MISSING) {
461 if (_state == ArchiveState::PRESENT) {
464 _state = ArchiveState::LOADED;
466 assert(_state == ArchiveState::LOADED);
470 enum class ArchiveState { UNKNOWN, MISSING, PRESENT, LOADED };
473 ArchiveState _state = ArchiveState::UNKNOWN;
474 table::io::InputArchive _archive;
489 return _maskedImageReader.
readBBox(origin);
498 return _metadataReader->version;
509 return _metadataReader->metadata;
516 r = _metadataReader->wcs;
533 if (_metadataReader->version < 2) {
534 return _metadataReader->filterLabel;
542 if (_metadataReader->version == 0) {
543 return _metadataReader->photoCalib;
572 return _metadataReader->visitInfo;
593 return _archiveReader->readExtraComponents(_getFitsFile());
597 auto result = std::make_shared<ExposureInfo>();
608 LOGLS_WARN(_log,
"Could not read PSF; setting to null: " << err.
what());
613 LOGLS_WARN(_log,
"Could not read CoaddInputs; setting to null: " << err.
what());
618 LOGLS_WARN(_log,
"Could not read ApCorrMap; setting to null: " << err.
what());
623 LOGLS_WARN(_log,
"Could not read ValidPolygon; setting to null: " << err.
what());
628 LOGLS_WARN(_log,
"Could not read TransmissionCurve; setting to null: " << err.
what());
633 LOGLS_WARN(_log,
"Could not read Detector; setting to null: " << err.
what());
638 result->setWcs(_metadataReader->wcs);
647 auto msg = str(
boost::format(
"Could not read WCS extension; setting to null: %s") % err.
what());
649 msg +=
" ; using WCS from FITS header";
656 StorablePtr
object = std::dynamic_pointer_cast<StorablePtr::element_type>(keyValue.second);
658 if (
object.use_count() > 0) {
659 result->setComponent(typehandling::makeKey<StorablePtr>(
key),
object);
661 LOGLS_WARN(_log,
"Data corruption: generic component " <<
key <<
" is not a Storable; skipping.");
666 if (_metadataReader->version < 2 && !
result->hasFilterLabel()) {
672 template <
typename ImagePixelT>
675 return _maskedImageReader.
readImage<ImagePixelT>(
bbox, origin, allowUnsafe);
678 template <
typename ImagePixelT>
684 template <
typename MaskPixelT>
686 bool conformMasks,
bool allowUnsafe) {
687 return _maskedImageReader.
readMask<MaskPixelT>(
bbox, origin, conformMasks, allowUnsafe);
690 template <
typename MaskPixelT>
696 template <
typename VariancePixelT>
699 return _maskedImageReader.
readVariance<VariancePixelT>(
bbox, origin, allowUnsafe);
702 template <
typename VariancePixelT>
709 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
712 return _maskedImageReader.
read<ImagePixelT, MaskPixelT, VariancePixelT>(
bbox, origin, conformMasks,
717 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
723 readMaskedImage<ImagePixelT, MaskPixelT, VariancePixelT>(
bbox, origin, conformMasks, allowUnsafe);
727 void ExposureFitsReader::_ensureReaders() {
728 if (!_metadataReader) {
729 auto metadataReader = std::make_unique<MetadataReader>(_maskedImageReader.
readPrimaryMetadata(),
732 _archiveReader = std::make_unique<ArchiveReader>(*metadataReader->metadata);
733 _metadataReader =
std::move(metadataReader);
735 assert(_archiveReader);
738 #define INSTANTIATE(ImagePixelT) \
739 template Exposure<ImagePixelT, MaskPixel, VariancePixel> ExposureFitsReader::read( \
740 lsst::geom::Box2I const&, ImageOrigin, bool, bool); \
741 template Image<ImagePixelT> ExposureFitsReader::readImage(lsst::geom::Box2I const&, ImageOrigin, bool); \
742 template ndarray::Array<ImagePixelT, 2, 2> ExposureFitsReader::readImageArray(lsst::geom::Box2I const&, \
743 ImageOrigin, bool); \
744 template MaskedImage<ImagePixelT, MaskPixel, VariancePixel> ExposureFitsReader::readMaskedImage( \
745 lsst::geom::Box2I const&, ImageOrigin, bool, bool)
table::Key< std::string > name
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
#define INSTANTIATE(ImagePixelT)
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
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, Component c)
Read a known component, if available.
ArchiveReader(daf::base::PropertyList &metadata)
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.
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.
std::shared_ptr< FilterLabel > readFilterLabel()
Read the Exposure's filter information.
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.
Filter readFilter()
Read the Exposure's filter.
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.
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::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.
std::string getBandLabel() const
Return the band label.
bool hasBandLabel() const noexcept
Return whether the filter label names a band.
static FilterLabel fromBand(std::string const &band)
Construct a FilterLabel from specific inputs.
std::string getPhysicalLabel() const
Return the physical filter label.
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.
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
int stripVisitInfoKeywords(daf::base::PropertySet &metadata)
Remove VisitInfo-related keywords from the metadata.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Filter makeFilter(FilterLabel const &label)
Convert a FilterLabel back to an old-style Filter.
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(Filter const &filter)
Convert an old-style Filter to a FilterLabel.
std::shared_ptr< FilterLabel > makeFilterLabelDirect(std::string const &name)
Convert an old-style filter name to a FilterLabel without external information.
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
A base class for image defects.