32 namespace lsst {
namespace afw {
namespace image {
36 LOG_LOGGER _log =
LOG_GET(
"afw.image.fits.ExposureFitsReader");
59 imageMetadata->remove(
"LTV1");
60 imageMetadata->remove(
"LTV2");
62 if (!imageMetadata->exists(
"INHERIT")) {
76 visitInfo = std::make_shared<VisitInfo>(*metadata);
84 metadata->remove(
"MJD-OBS");
85 metadata->remove(
"DATE-OBS");
124 _hdu = popInt(
"AR_HDU");
126 _state = ArchiveState::MISSING;
129 _state = ArchiveState::PRESENT;
131 _ids[PSF] = popInt(
"PSF_ID");
132 _ids[WCS] = popInt(
"SKYWCS_ID");
133 _ids[COADD_INPUTS] = popInt(
"COADD_INPUTS_ID");
134 _ids[AP_CORR_MAP] = popInt(
"AP_CORR_MAP_ID");
135 _ids[VALID_POLYGON] = popInt(
"VALID_POLYGON_ID");
136 _ids[TRANSMISSION_CURVE] = popInt(
"TRANSMISSION_CURVE_ID");
139 template <
typename T>
141 if (!_ensureLoaded(fitsFile)) {
150 if (_state == ArchiveState::MISSING) {
153 if (_state == ArchiveState::PRESENT) {
156 _state = ArchiveState::LOADED;
158 assert(_state == ArchiveState::LOADED);
172 _maskedImageReader(fileName)
176 _maskedImageReader(manager)
180 _maskedImageReader(fitsFile)
186 return _maskedImageReader.
readBBox(origin);
190 return _maskedImageReader.
readXY0(bbox, origin);
201 return _metadataReader->metadata;
208 r = _metadataReader->wcs;
215 return _metadataReader->filter;
220 return _metadataReader->calib;
246 return _metadataReader->visitInfo;
255 auto result = std::make_shared<ExposureInfo>();
267 LOGLS_WARN(_log,
"Could not read PSF; setting to null: " << err.
what());
272 LOGLS_WARN(_log,
"Could not read CoaddInputs; setting to null: " << err.
what());
277 LOGLS_WARN(_log,
"Could not read ApCorrMap; setting to null: " << err.
what());
282 LOGLS_WARN(_log,
"Could not read ValidPolygon; setting to null: " << err.
what());
287 LOGLS_WARN(_log,
"Could not read TransmissionCurve; setting to null: " << err.
what());
292 result->setWcs(_metadataReader->wcs);
301 auto msg = str(boost::format(
"Could not read WCS extension; setting to null: %s") % err.
what());
303 msg +=
" ; using WCS from FITS header";
310 template <
typename ImagePixelT>
313 return _maskedImageReader.
readImage<ImagePixelT>(
bbox, origin, allowUnsafe);
316 template <
typename ImagePixelT>
323 template <
typename MaskPixelT>
325 bool conformMasks,
bool allowUnsafe) {
326 return _maskedImageReader.
readMask<MaskPixelT>(
bbox, origin, conformMasks, allowUnsafe);
329 template <
typename MaskPixelT>
336 template <
typename VariancePixelT>
339 return _maskedImageReader.
readVariance<VariancePixelT>(
bbox, origin, allowUnsafe);
342 template <
typename VariancePixelT>
349 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
356 return _maskedImageReader.
read<ImagePixelT, MaskPixelT, VariancePixelT>(
bbox, origin, conformMasks,
361 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
368 auto mi = readMaskedImage<ImagePixelT, MaskPixelT, VariancePixelT>(
bbox, origin, conformMasks,
373 void ExposureFitsReader::_ensureReaders() {
374 if (!_metadataReader) {
375 auto metadataReader = std::make_unique<MetadataReader>(
380 _archiveReader = std::make_unique<ArchiveReader>(*metadataReader->metadata);
381 _metadataReader =
std::move(metadataReader);
383 assert(_archiveReader);
386 #define INSTANTIATE(ImagePixelT) \ 387 template Exposure<ImagePixelT, MaskPixel, VariancePixel> ExposureFitsReader::read( \ 388 lsst::geom::Box2I const &, \ 392 template Image<ImagePixelT> ExposureFitsReader::readImage( \ 393 lsst::geom::Box2I const &, \ 396 template ndarray::Array<ImagePixelT, 2, 2> ExposureFitsReader::readImageArray(\ 397 lsst::geom::Box2I const &, \ 401 template MaskedImage<ImagePixelT, MaskPixel, VariancePixel> ExposureFitsReader::readMaskedImage( \ 402 lsst::geom::Box2I const &, \ #define LOGLS_WARN(logger, message)
std::shared_ptr< T > readComponent(afw::fits::Fits *fitsFile, Component c)
lsst::geom::Box2I readBBox(ImageOrigin origin=PARENT)
Read the bounding box of the on-disk image.
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
A spatially-varying transmission curve as a function of wavelength.
std::shared_ptr< ExposureInfo > readExposureInfo()
Read the ExposureInfo containing all non-image components.
CoordinateExpr< N > ne(Point< int, N > const &other) const noexcept
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.
virtual char const * what(void) const noexcept
std::shared_ptr< Calib > readCalib()
Read the Exposure's photometric calibration.
A thin wrapper around std::map to allow aperture corrections to be attached to Exposures.
A class to contain the data, WCS, and other information needed to describe an image of the sky...
std::string readVarianceDType() 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.
ndarray::Array< MaskPixelT, 2, 2 > readMaskArray(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the mask plane.
Image< VariancePixelT > readVariance(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the variance plane.
int stripFilterKeywords(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Remove Filter-related keywords from the metadata.
ndarray::Array< VariancePixelT, 2, 2 > readVarianceArray(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the variance plane.
ArchiveReader(daf::base::PropertyList &metadata)
std::shared_ptr< VisitInfo > readVisitInfo()
Read the Exposure's visit metadata.
Image< ImagePixelT > readImage(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the image plane.
ExposureFitsReader(std::string const &fileName)
Construct a FITS reader object.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Rotation angle is unknown.
std::shared_ptr< io::OutputArchive > _archive
Image< ImagePixelT > readImage(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the image plane.
bool any(CoordinateExpr< N > const &expr) noexcept
std::string readImageDType() const
Read a string describing the pixel type of the on-disk image plane.
Filter readFilter()
Read the Exposure's filter.
virtual void remove(std::string const &name)
std::shared_ptr< afw::geom::polygon::Polygon > readValidPolygon()
Read the polygon describing the region of validity for the Exposure.
~ExposureFitsReader() noexcept
table::Key< table::Array< std::uint8_t > > wcs
#define LOGLS_DEBUG(logger, message)
A base class for image defects.
Represent a 2-dimensional array of bitmask pixels.
Lifetime-management for memory that goes into FITS memory files.
std::string readImageDType() const
Read a string describing the pixel type of the on-disk image plane.
A class to manipulate images, masks, and variance as a single object.
std::shared_ptr< daf::base::PropertyList > readPrimaryMetadata()
Read the FITS header of one of the HDUs.
bool exists(std::string const &name) const
int stripCalibKeywords(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Remove Calib-related keywords from the metadata.
std::string readMaskDType() const
Read a string describing the pixel type of the on-disk image plane.
Holds an integer identifier for an LSST filter.
std::unique_ptr< SchemaItem< U > > result
std::shared_ptr< afw::geom::SkyWcs > readWcs()
Read the Exposure's world coordinate system.
Mask< MaskPixelT > readMask(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool conformMasks=false, bool allowUnsafe=false)
Read the mask 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.
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.
std::shared_ptr< ApCorrMap > readApCorrMap()
Read the Exposure's aperture correction map.
std::string readMaskDType() const
Read a string describing the pixel type of the on-disk image plane.
T get(std::string const &name) const
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::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
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.
#define INSTANTIATE(ImagePixelT)
int stripVisitInfoKeywords(daf::base::PropertySet &metadata)
Remove VisitInfo-related keywords from the metadata.
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< MaskPixelT, 2, 2 > readMaskArray(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the mask 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< daf::base::PropertyList > readMetadata()
Read the flexible metadata associated with the Exposure.
std::shared_ptr< daf::base::PropertyList > readImageMetadata()
Read the FITS header of one of the HDUs.
std::shared_ptr< detection::Psf > readPsf()
Read the Exposure's point-spread function.
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 polymorphic base class for representing an image's Point Spread Function.
std::shared_ptr< TransmissionCurve > readTransmissionCurve()
Read the Exposure's transmission curve.
A class to represent a 2-dimensional array of pixels.
ndarray::Array< ImagePixelT, 2, 2 > readImageArray(lsst::geom::Box2I const &bbox=lsst::geom::Box2I(), ImageOrigin origin=PARENT, bool allowUnsafe=false)
Read the image plane.
RAII scoped guard for moving the HDU in a Fits object.
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.