46 template <
typename T, std::
size_t N>
96 static Filter const DEFAULT;
98 if (
name == DEFAULT.getName()) {
123 static Filter const DEFAULT;
126 if (
filter.getId() == DEFAULT.getId() &&
filter.getName() == DEFAULT.getName()) {
132 if (
filter.getId() == Filter::UNKNOWN) {
141 canonical =
filter.getCanonicalName();
147 if (_AFW_NAMES.
count(canonical) > 0) {
148 return std::make_shared<FilterLabel>(_AFW_NAMES.
at(canonical));
149 }
else if (_isBand(canonical)) {
154 aliases =
filter.getAliases();
158 if (aliases.
size() == 1) {
180 return std::make_shared<FilterLabel>(_AFW_NAMES.
at(
name));
193 return std::make_shared<FilterLabel>(
214 for (
auto const& keyValue : _AFW_NAMES) {
217 if (label == afwFilter) {
235 if (primaryMetadata->exists(versionName)) {
236 version = primaryMetadata->getAsInt(versionName);
237 primaryMetadata->remove(versionName);
243 str(
boost::format(
"Cannot read Exposure FITS version > %i") %
251 LOGLS_DEBUG(_log,
"No WCS found in FITS metadata");
258 imageMetadata->remove(
"LTV1");
259 imageMetadata->remove(
"LTV2");
261 if (!imageMetadata->exists(
"INHERIT")) {
279 size_t end =
name.find_last_not_of(
' ');
349 _hdu = popInt(
"AR_HDU");
351 _state = ArchiveState::MISSING;
354 _state = ArchiveState::PRESENT;
357 _ids[
PSF] = popInt(
"PSF_ID");
358 _ids[
WCS] = popInt(
"SKYWCS_ID");
363 _ids[
DETECTOR] = popInt(
"DETECTOR_ID");
370 if (headerKey.substr(0, PREFIX.
size()) == PREFIX) {
372 int archiveId = metadata.
get<
int>(headerKey);
373 _genericIds.
emplace(componentName, archiveId);
374 if (!_contains(_ids, archiveId)) {
375 _extraIds.
emplace(componentName);
378 toStrip.
push_back(componentName +
"_ID");
395 template <
typename T>
397 if (!_ensureLoaded(fitsFile)) {
400 return _archive.
get<
T>(_ids[c]);
422 template <
typename T>
424 if (!_ensureLoaded(fitsFile)) {
428 if (_genericIds.
count(c) > 0) {
429 int archiveId = _genericIds.
at(c);
430 return _archive.
get<
T>(archiveId);
449 if (!_ensureLoaded(fitsFile)) {
455 for (
std::string const& componentName : _extraIds) {
457 result.emplace(componentName, readComponent<table::io::Persistable>(fitsFile, componentName));
460 "Could not read component " << componentName <<
"; skipping: " << err.
what());
468 if (_state == ArchiveState::MISSING) {
471 if (_state == ArchiveState::PRESENT) {
474 _state = ArchiveState::LOADED;
476 assert(_state == ArchiveState::LOADED);
480 enum class ArchiveState { UNKNOWN, MISSING, PRESENT, LOADED };
483 ArchiveState _state = ArchiveState::UNKNOWN;
484 table::io::InputArchive _archive;
499 return _maskedImageReader.
readBBox(origin);
508 return _metadataReader->version;
519 return _metadataReader->metadata;
524 return _metadataReader->exposureId;
531 r = _metadataReader->wcs;
548 if (_metadataReader->version < 2) {
549 return _metadataReader->filterLabel;
557 if (_metadataReader->version == 0) {
558 return _metadataReader->photoCalib;
587 return _metadataReader->visitInfo;
608 return _archiveReader->readExtraComponents(_getFitsFile());
612 auto result = std::make_shared<ExposureInfo>();
628 LOGLS_WARN(_log,
"Could not read PSF; setting to null: " << err.
what());
633 LOGLS_WARN(_log,
"Could not read CoaddInputs; setting to null: " << err.
what());
638 LOGLS_WARN(_log,
"Could not read ApCorrMap; setting to null: " << err.
what());
643 LOGLS_WARN(_log,
"Could not read ValidPolygon; setting to null: " << err.
what());
648 LOGLS_WARN(_log,
"Could not read TransmissionCurve; setting to null: " << err.
what());
653 LOGLS_WARN(_log,
"Could not read Detector; setting to null: " << err.
what());
658 result->setWcs(_metadataReader->wcs);
667 auto msg = str(
boost::format(
"Could not read WCS extension; setting to null: %s") % err.
what());
669 msg +=
" ; using WCS from FITS header";
676 StorablePtr
object = std::dynamic_pointer_cast<StorablePtr::element_type>(keyValue.second);
678 if (
object.use_count() > 0) {
679 result->setComponent(typehandling::makeKey<StorablePtr>(key),
object);
681 LOGLS_WARN(_log,
"Data corruption: generic component " << key <<
" is not a Storable; skipping.");
686 if (_metadataReader->version < 2 && !
result->hasFilterLabel()) {
692 template <
typename ImagePixelT>
695 return _maskedImageReader.
readImage<ImagePixelT>(
bbox, origin, allowUnsafe);
698 template <
typename ImagePixelT>
704 template <
typename MaskPixelT>
706 bool conformMasks,
bool allowUnsafe) {
707 return _maskedImageReader.
readMask<MaskPixelT>(
bbox, origin, conformMasks, allowUnsafe);
710 template <
typename MaskPixelT>
716 template <
typename VariancePixelT>
719 return _maskedImageReader.
readVariance<VariancePixelT>(
bbox, origin, allowUnsafe);
722 template <
typename VariancePixelT>
729 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
732 return _maskedImageReader.
read<ImagePixelT, MaskPixelT, VariancePixelT>(
bbox, origin, conformMasks,
737 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
743 readMaskedImage<ImagePixelT, MaskPixelT, VariancePixelT>(
bbox, origin, conformMasks, allowUnsafe);
747 void ExposureFitsReader::_ensureReaders() {
748 if (!_metadataReader) {
749 auto metadataReader = std::make_unique<MetadataReader>(_maskedImageReader.
readPrimaryMetadata(),
752 _archiveReader = std::make_unique<ArchiveReader>(*metadataReader->metadata);
753 _metadataReader =
std::move(metadataReader);
755 assert(_archiveReader);
758 #define INSTANTIATE(ImagePixelT) \
759 template Exposure<ImagePixelT, MaskPixel, VariancePixel> ExposureFitsReader::read( \
760 lsst::geom::Box2I const&, ImageOrigin, bool, bool); \
761 template Image<ImagePixelT> ExposureFitsReader::readImage(lsst::geom::Box2I const&, ImageOrigin, bool); \
762 template ndarray::Array<ImagePixelT, 2, 2> ExposureFitsReader::readImageArray(lsst::geom::Box2I const&, \
763 ImageOrigin, bool); \
764 template MaskedImage<ImagePixelT, MaskPixel, VariancePixel> ExposureFitsReader::readMaskedImage( \
765 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
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, 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::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.
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.