lsst.afw
21.0.0-8-gd9c33f4a0+ec3713772a
|
Go to the documentation of this file.
43 LOG_LOGGER _log =
LOG_GET(
"afw.image.fits.ExposureFitsReader");
45 template <
typename T, std::
size_t N>
47 for (T
const&
element : array) {
95 static Filter const DEFAULT;
122 static Filter const DEFAULT;
146 if (_AFW_NAMES.
count(canonical) > 0) {
147 return std::make_shared<FilterLabel>(_AFW_NAMES.
at(canonical));
148 }
else if (_isBand(canonical)) {
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");
372 metadata.remove(
key);
385 template <
typename T>
387 if (!_ensureLoaded(fitsFile)) {
390 return _archive.
get<T>(_ids[c]);
408 template <
typename T>
410 if (!_ensureLoaded(fitsFile)) {
414 if (_extraIds.
count(c) > 0) {
415 int archiveId = _genericIds.
at(c);
416 return _archive.
get<T>(archiveId);
435 if (!_ensureLoaded(fitsFile)) {
441 for (
std::string const& componentName : _extraIds) {
443 result.emplace(componentName, readComponent<table::io::Persistable>(fitsFile, componentName));
446 "Could not read component " << componentName <<
"; skipping: " << err.
what());
454 if (_state == ArchiveState::MISSING) {
457 if (_state == ArchiveState::PRESENT) {
460 _state = ArchiveState::LOADED;
462 assert(_state == ArchiveState::LOADED);
466 enum class ArchiveState { UNKNOWN, MISSING,
PRESENT, LOADED };
469 ArchiveState _state = ArchiveState::UNKNOWN;
470 table::io::InputArchive _archive;
485 return _maskedImageReader.
readBBox(origin);
500 return _metadataReader->metadata;
507 r = _metadataReader->wcs;
524 if (_metadataReader->version < 2) {
525 return _metadataReader->filterLabel;
533 if (_metadataReader->version == 0) {
534 return _metadataReader->photoCalib;
563 return _metadataReader->visitInfo;
584 return _archiveReader->readExtraComponents(_getFitsFile());
588 auto result = std::make_shared<ExposureInfo>();
599 LOGLS_WARN(_log,
"Could not read PSF; setting to null: " << err.
what());
604 LOGLS_WARN(_log,
"Could not read CoaddInputs; setting to null: " << err.
what());
609 LOGLS_WARN(_log,
"Could not read ApCorrMap; setting to null: " << err.
what());
614 LOGLS_WARN(_log,
"Could not read ValidPolygon; setting to null: " << err.
what());
619 LOGLS_WARN(_log,
"Could not read TransmissionCurve; setting to null: " << err.
what());
624 LOGLS_WARN(_log,
"Could not read Detector; setting to null: " << err.
what());
629 result->setWcs(_metadataReader->wcs);
638 auto msg = str(boost::format(
"Could not read WCS extension; setting to null: %s") % err.
what());
640 msg +=
" ; using WCS from FITS header";
647 StorablePtr
object = std::dynamic_pointer_cast<StorablePtr::element_type>(keyValue.second);
649 if (
object.use_count() > 0) {
650 result->setComponent(typehandling::makeKey<StorablePtr>(
key),
object);
652 LOGLS_WARN(_log,
"Data corruption: generic component " <<
key <<
" is not a Storable; skipping.");
657 if (_metadataReader->version < 2 && !
result->hasFilterLabel()) {
663 template <
typename ImagePixelT>
666 return _maskedImageReader.
readImage<ImagePixelT>(
bbox, origin, allowUnsafe);
669 template <
typename ImagePixelT>
675 template <
typename MaskPixelT>
677 bool conformMasks,
bool allowUnsafe) {
678 return _maskedImageReader.
readMask<MaskPixelT>(
bbox, origin, conformMasks, allowUnsafe);
681 template <
typename MaskPixelT>
687 template <
typename VariancePixelT>
690 return _maskedImageReader.
readVariance<VariancePixelT>(
bbox, origin, allowUnsafe);
693 template <
typename VariancePixelT>
700 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
703 return _maskedImageReader.
read<ImagePixelT, MaskPixelT, VariancePixelT>(
bbox, origin, conformMasks,
708 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
714 readMaskedImage<ImagePixelT, MaskPixelT, VariancePixelT>(
bbox, origin, conformMasks, allowUnsafe);
718 void ExposureFitsReader::_ensureReaders() {
719 if (!_metadataReader) {
720 auto metadataReader = std::make_unique<MetadataReader>(_maskedImageReader.
readPrimaryMetadata(),
723 _archiveReader = std::make_unique<ArchiveReader>(*metadataReader->metadata);
724 _metadataReader =
std::move(metadataReader);
726 assert(_archiveReader);
729 #define INSTANTIATE(ImagePixelT) \
730 template Exposure<ImagePixelT, MaskPixel, VariancePixel> ExposureFitsReader::read( \
731 lsst::geom::Box2I const&, ImageOrigin, bool, bool); \
732 template Image<ImagePixelT> ExposureFitsReader::readImage(lsst::geom::Box2I const&, ImageOrigin, bool); \
733 template ndarray::Array<ImagePixelT, 2, 2> ExposureFitsReader::readImageArray(lsst::geom::Box2I const&, \
734 ImageOrigin, bool); \
735 template MaskedImage<ImagePixelT, MaskPixel, VariancePixel> ExposureFitsReader::readMaskedImage( \
736 lsst::geom::Box2I const&, ImageOrigin, bool, bool)
Image< ImagePixelT > readImage(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the image plane.
bool hasPhysicalLabel() const noexcept
Return whether the filter label names a physical filter.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
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.
int getId() const noexcept
Return a Filter's integral id.
static FilterLabel fromPhysical(std::string const &physical)
Construct a FilterLabel from specific inputs.
std::shared_ptr< T > readComponent(afw::fits::Fits *fitsFile, std::string c)
Read an arbitrary component, if available.
std::shared_ptr< daf::base::PropertyList > readPrimaryMetadata()
Read the FITS header of one of the HDUs.
ndarray::Array< VariancePixelT, 2, 2 > readVarianceArray(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the variance plane.
ExposureFitsReader(std::string const &fileName)
Construct a FITS reader object.
Represent a 2-dimensional array of bitmask pixels.
std::shared_ptr< PhotoCalib > makePhotoCalibFromMetadata(daf::base::PropertySet &metadata, bool strip=false)
Construct a PhotoCalib from FITS FLUXMAG0/FLUXMAG0ERR keywords.
ndarray::Array< MaskPixelT, 2, 2 > readMaskArray(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, 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.
Filter readFilter()
Read the Exposure's filter.
Image< VariancePixelT > readVariance(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the variance plane.
table::Key< table::Array< std::uint8_t > > wcs
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Holds an integer identifier for an LSST filter.
ndarray::Array< MaskPixelT, 2, 2 > readMaskArray(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the mask plane.
RAII scoped guard for moving the HDU in a Fits object.
lsst::geom::Box2I readBBox(ImageOrigin origin=PARENT)
Read the bounding box of the on-disk image.
ArchiveReader(daf::base::PropertyList &metadata)
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.
bool exists(std::string const &name) const
std::shared_ptr< FilterLabel > makeFilterLabel(Filter const &filter)
Convert an old-style Filter to a FilterLabel.
std::string getPhysicalLabel() const
Return the physical filter label.
std::map< std::string, std::shared_ptr< table::io::Persistable > > readExtraComponents()
Read the Exposure's non-standard components.
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Interface supporting iteration over heterogenous containers.
std::string readImageDType() const
Read a string describing the pixel type of the on-disk image plane.
Lifetime-management for memory that goes into FITS memory files.
std::shared_ptr< cameraGeom::Detector > readDetector()
Read the Exposure's detector.
std::string readVarianceDType() const
Read a string describing the pixel type of the on-disk image plane.
static int getFitsSerializationVersion()
Get the version of FITS serialization that this ExposureInfo understands.
T get(std::string const &name) const
std::string readVarianceDType() const
Read a string describing the pixel type of the on-disk image plane.
std::shared_ptr< ExposureInfo > readExposureInfo()
Read the ExposureInfo containing all non-image components.
#define LOGLS_WARN(logger, message)
std::unique_ptr< SchemaItem< U > > result
Image< VariancePixelT > readVariance(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the variance plane.
A class to manipulate images, masks, and variance as a single object.
std::shared_ptr< daf::base::PropertyList > readMetadata()
Read the flexible metadata associated with the Exposure.
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.
std::shared_ptr< CoaddInputs > readCoaddInputs()
Read the Exposure's coadd input catalogs.
Image< ImagePixelT > readImage(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the image plane.
std::string readMaskDType() const
Read a string describing the pixel type of the on-disk image plane.
bool any(CoordinateExpr< N > const &expr) noexcept
static std::string const & getFitsSerializationVersionName()
Get the version of FITS serialization version info name.
Mask< MaskPixelT > readMask(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false, bool allowUnsafe=false)
Read the mask plane.
The photometric calibration of an exposure.
bool hasBandLabel() const noexcept
Return whether the filter label names a band.
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 group of labels for a filter in an exposure or coadd.
std::shared_ptr< T > readComponent(afw::fits::Fits *fitsFile, Component c)
Read a known component, if available.
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.
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 base class for image defects.
#define LSST_EXCEPT(type,...)
virtual char const * what(void) const noexcept
#define LOGLS_DEBUG(logger, message)
std::shared_ptr< ApCorrMap > readApCorrMap()
Read the Exposure's aperture correction map.
A spatially-varying transmission curve as a function of wavelength.
static FilterLabel fromBandPhysical(std::string const &band, std::string const &physical)
Construct a FilterLabel from specific inputs.
std::string getBandLabel() const
Return the band label.
A FITS reader class for Exposures and their components.
std::shared_ptr< TransmissionCurve > readTransmissionCurve()
Read the Exposure's transmission curve.
ndarray::Array< ImagePixelT, 2, 2 > readImageArray(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the image plane.
Filter makeFilter(FilterLabel const &label)
Convert a FilterLabel back to an old-style Filter.
static typehandling::Key< std::string, std::shared_ptr< FilterLabel const > > const KEY_FILTER
Standard key for looking up filter information.
std::shared_ptr< daf::base::PropertyList > readImageMetadata()
Read the FITS header of one of the HDUs.
std::string readMaskDType() const
Read a string describing the pixel type of the on-disk image plane.
Implementation of the Photometric Calibration class.
std::shared_ptr< typehandling::Storable > readComponent(std::string const &componentName)
Read an arbitrary non-standard component by name.
std::string readImageDType() const
Read a string describing the pixel type of the on-disk image plane.
std::shared_ptr< VisitInfo > readVisitInfo()
Read the Exposure's visit metadata.
std::string const & getCanonicalName() const
Return a filter's canonical name.
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
std::shared_ptr< afw::geom::polygon::Polygon > readValidPolygon()
Read the polygon describing the region of validity for the Exposure.
Mask< MaskPixelT > readMask(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false, bool allowUnsafe=false)
Read the mask plane.
static FilterLabel fromBand(std::string const &band)
Construct a FilterLabel from specific inputs.
virtual void remove(std::string const &name)
A polymorphic base class for representing an image's Point Spread Function.
std::string const & getName() const noexcept
Return a Filter's name.
std::vector< std::string > getAliases() const
Return all aliases by which this filter is known.
std::shared_ptr< detection::Psf > readPsf()
Read the Exposure's point-spread function.
std::shared_ptr< PhotoCalib > readPhotoCalib()
Read the Exposure's photometric calibration.
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.
A thin wrapper around std::map to allow aperture corrections to be attached to Exposures.
#define INSTANTIATE(ImagePixelT)
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 stripVisitInfoKeywords(daf::base::PropertySet &metadata)
Remove VisitInfo-related keywords from the metadata.
std::shared_ptr< FilterLabel > makeFilterLabelDirect(std::string const &name)
Convert an old-style filter name to a FilterLabel without external 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.
~ExposureFitsReader() noexcept
A representation of a detector in a mosaic camera.