41 template <
typename T, std::
size_t N>
58 if (primaryMetadata->exists(versionName)) {
59 version = primaryMetadata->getAsInt(versionName);
60 primaryMetadata->remove(versionName);
66 str(
boost::format(
"Cannot read Exposure FITS version >= %i") %
81 imageMetadata->remove(
"LTV1");
82 imageMetadata->remove(
"LTV2");
84 if (!imageMetadata->exists(
"INHERIT")) {
98 visitInfo = std::make_shared<VisitInfo>(*metadata);
108 metadata->remove(
"MJD-OBS");
109 metadata->remove(
"DATE-OBS");
113 metadata->remove(
"DETNAME");
114 metadata->remove(
"DETSER");
154 _hdu = popInt(
"AR_HDU");
156 _state = ArchiveState::MISSING;
159 _state = ArchiveState::PRESENT;
162 _ids[PSF] = popInt(
"PSF_ID");
163 _ids[WCS] = popInt(
"SKYWCS_ID");
164 _ids[COADD_INPUTS] = popInt(
"COADD_INPUTS_ID");
165 _ids[AP_CORR_MAP] = popInt(
"AP_CORR_MAP_ID");
166 _ids[VALID_POLYGON] = popInt(
"VALID_POLYGON_ID");
167 _ids[TRANSMISSION_CURVE] = popInt(
"TRANSMISSION_CURVE_ID");
168 _ids[DETECTOR] = popInt(
"DETECTOR_ID");
169 _ids[PHOTOCALIB] = popInt(
"PHOTOCALIB_ID");
175 if (headerKey.substr(0, PREFIX.
size()) == PREFIX) {
177 int archiveId = metadata.get<
int>(headerKey);
178 if (!_contains(_ids, archiveId)) {
179 _extraIds.emplace(componentName, archiveId);
182 toStrip.
push_back(componentName +
"_ID");
186 metadata.remove(
key);
199 template <
typename T>
201 if (!_ensureLoaded(fitsFile)) {
220 if (!_ensureLoaded(fitsFile)) {
226 for (
auto const& keyValue : _extraIds) {
228 int archiveId = keyValue.second;
234 "Could not read component " << componentName <<
"; skipping: " << err.
what());
242 if (_state == ArchiveState::MISSING) {
245 if (_state == ArchiveState::PRESENT) {
248 _state = ArchiveState::LOADED;
250 assert(_state == ArchiveState::LOADED);
254 enum class ArchiveState {
UNKNOWN, MISSING, PRESENT, LOADED };
272 return _maskedImageReader.
readBBox(origin);
276 return _maskedImageReader.
readXY0(bbox, origin);
287 return _metadataReader->metadata;
294 r = _metadataReader->wcs;
301 return _metadataReader->filter;
306 if (_metadataReader->version == 0) {
307 return _metadataReader->photoCalib;
336 return _metadataReader->visitInfo;
352 return _archiveReader->readExtraComponents(_getFitsFile());
356 auto result = std::make_shared<ExposureInfo>();
368 LOGLS_WARN(_log,
"Could not read PSF; setting to null: " << err.
what());
373 LOGLS_WARN(_log,
"Could not read CoaddInputs; setting to null: " << err.
what());
378 LOGLS_WARN(_log,
"Could not read ApCorrMap; setting to null: " << err.
what());
383 LOGLS_WARN(_log,
"Could not read ValidPolygon; setting to null: " << err.
what());
388 LOGLS_WARN(_log,
"Could not read TransmissionCurve; setting to null: " << err.
what());
393 LOGLS_WARN(_log,
"Could not read Detector; setting to null: " << err.
what());
398 result->setWcs(_metadataReader->wcs);
407 auto msg = str(
boost::format(
"Could not read WCS extension; setting to null: %s") % err.
what());
409 msg +=
" ; using WCS from FITS header";
418 if (
object.use_count() > 0) {
419 result->setComponent(typehandling::makeKey<StorablePtr>(key),
object);
421 LOGLS_WARN(_log,
"Data corruption: generic component " << key <<
" is not a Storable; skipping.");
427 template <
typename ImagePixelT>
430 return _maskedImageReader.
readImage<ImagePixelT>(
bbox, origin, allowUnsafe);
433 template <
typename ImagePixelT>
439 template <
typename MaskPixelT>
441 bool conformMasks,
bool allowUnsafe) {
442 return _maskedImageReader.
readMask<MaskPixelT>(
bbox, origin, conformMasks, allowUnsafe);
445 template <
typename MaskPixelT>
451 template <
typename VariancePixelT>
454 return _maskedImageReader.
readVariance<VariancePixelT>(
bbox, origin, allowUnsafe);
457 template <
typename VariancePixelT>
464 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
467 return _maskedImageReader.
read<ImagePixelT, MaskPixelT, VariancePixelT>(
bbox, origin, conformMasks,
472 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
478 readMaskedImage<ImagePixelT, MaskPixelT, VariancePixelT>(
bbox, origin, conformMasks, allowUnsafe);
482 void ExposureFitsReader::_ensureReaders() {
483 if (!_metadataReader) {
484 auto metadataReader = std::make_unique<MetadataReader>(_maskedImageReader.
readPrimaryMetadata(),
487 _archiveReader = std::make_unique<ArchiveReader>(*metadataReader->metadata);
488 _metadataReader =
std::move(metadataReader);
490 assert(_archiveReader);
493 #define INSTANTIATE(ImagePixelT) \ 494 template Exposure<ImagePixelT, MaskPixel, VariancePixel> ExposureFitsReader::read( \ 495 lsst::geom::Box2I const&, ImageOrigin, bool, bool); \ 496 template Image<ImagePixelT> ExposureFitsReader::readImage(lsst::geom::Box2I const&, ImageOrigin, bool); \ 497 template ndarray::Array<ImagePixelT, 2, 2> ExposureFitsReader::readImageArray(lsst::geom::Box2I const&, \ 498 ImageOrigin, bool); \ 499 template MaskedImage<ImagePixelT, MaskPixel, VariancePixel> ExposureFitsReader::readMaskedImage( \ 500 lsst::geom::Box2I const&, ImageOrigin, bool, bool)
#define LOGLS_WARN(logger, message)
Log a warn-level message using an iostream-based interface.
static std::string const & getFitsSerializationVersionName()
Get the version of FITS serialization version info name.
std::shared_ptr< T > readComponent(afw::fits::Fits *fitsFile, Component c)
Read a known component, if available.
std::shared_ptr< PhotoCalib > makePhotoCalibFromMetadata(daf::base::PropertySet &metadata, bool strip=false)
Construct a PhotoCalib from FITS FLUXMAG0/FLUXMAG0ERR keywords.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
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< T, 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.
The photometric calibration of an exposure.
Class for storing ordered metadata with comments.
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.
static int getFitsSerializationVersion()
Get the version of FITS serialization that this ExposureInfo understands.
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...
std::shared_ptr< PhotoCalib > readPhotoCalib()
Read the Exposure's photometric calibration.
Rotation angle is unknown.
table::Key< table::Array< std::uint8_t > > wcs
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
Return true if any elements are true.
std::string readImageDType() const
Read a string describing the pixel type of the on-disk image plane.
LSST DM logging module built on log4cxx.
Filter readFilter()
Read the Exposure's filter.
virtual void remove(std::string const &name)
Remove all values for a property name (possibly hierarchical).
Reports attempts to access elements using an invalid key.
std::map< std::string, std::shared_ptr< table::io::Persistable > > readExtraComponents()
Read the Exposure's non-standard components.
virtual char const * what(void) const noexcept
Return a character string summarizing this exception.
std::shared_ptr< afw::geom::polygon::Polygon > readValidPolygon()
Read the polygon describing the region of validity for the Exposure.
~ExposureFitsReader() noexcept
#define LOGLS_DEBUG(logger, message)
Log a debug-level message using an iostream-based interface.
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
Determine if a name (possibly hierarchical) exists.
T dynamic_pointer_cast(T... args)
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::shared_ptr< afw::geom::SkyWcs > readWcs()
Read the Exposure's world coordinate system.
std::shared_ptr< io::OutputArchive > _archive
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::map< std::string, std::shared_ptr< table::io::Persistable > > readExtraComponents(afw::fits::Fits *fitsFile)
Read the components that are stored using arbitrary-component support.
std::string readMaskDType() const
Read a string describing the pixel type of the on-disk image plane.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
T get(std::string const &name) const
Get the last value for a property name (possibly hierarchical).
A representation of a detector in a mosaic camera.
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.
std::shared_ptr< cameraGeom::Detector > readDetector()
Read the Exposure's detector.
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.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
Reports errors from accepting an object of an unexpected or inappropriate type.
#define LOG_GET(logger)
Returns a Log object associated with logger.
A polymorphic base class for representing an image's Point Spread Function.
std::shared_ptr< TransmissionCurve > readTransmissionCurve()
Read the Exposure's transmission curve.
An integer coordinate rectangle.
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.
Implementation of the Photometric Calibration class.
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.