LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
ExposureFitsReader.cc
Go to the documentation of this file.
1/*
2 * Developed for the LSST Data Management System.
3 * This product includes software developed by the LSST Project
4 * (https://www.lsst.org).
5 * See the COPYRIGHT file at the top-level directory of this distribution
6 * for details of code ownership.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <map>
23#include <optional>
24#include <regex>
25#include <set>
26
27#include "lsst/log/Log.h"
28
37
38namespace lsst {
39namespace afw {
40namespace image {
41
42namespace {
43
44LOG_LOGGER _log = LOG_GET("lsst.afw.image.fits.ExposureFitsReader");
45
46template <typename T, std::size_t N>
47bool _contains(std::array<T, N> const& array, T const& value) {
48 for (T const& element : array) {
49 if (element == value) {
50 return true;
51 }
52 }
53 return false;
54}
55
56// Map from compatibility "afw name" to correct filter label
57std::map<std::string, FilterLabel> const _AFW_NAMES = {
60 std::make_pair("SOLID", FilterLabel::fromPhysical("solid plate 0.0 0.0")),
61};
62
68bool _isBand(std::string const& name) {
69 static std::set<std::string> const BANDS = {"u", "g", "r", "i", "z", "y", "SH", "PH", "VR", "white"};
70 // Standard band
71 if (BANDS.count(name) > 0) {
72 return true;
73 }
74 // Looks like a narrow-band band
75 if (std::regex_match(name, std::regex("N\\d+"))) {
76 return true;
77 }
78 // Looks like an intermediate-band band; exclude "I2"
79 if (std::regex_match(name, std::regex("I\\d{2,}"))) {
80 return true;
81 }
82 return false;
83}
84
85} // namespace
86
96 static std::string const DEFAULT = "_unknown_";
97 // Avoid turning dummy filters into real FilterLabels.
98 if (name == DEFAULT) {
99 return nullptr;
100 }
101
102 // FilterLabel::from* returns a statically allocated object, so only way
103 // to get it into shared_ptr is to copy it.
104 if (_isBand(name)) {
105 return std::make_shared<FilterLabel>(FilterLabel::fromBand(name));
106 } else {
107 return std::make_shared<FilterLabel>(FilterLabel::fromPhysical(name));
108 }
109}
110
118 if (_AFW_NAMES.count(name) > 0) {
119 return std::make_shared<FilterLabel>(_AFW_NAMES.at(name));
120 }
121 // else name is either a band, a physical filter, or a deprecated alias
122
123 // Unknown filter, no extra info to be gained
125}
126
128public:
132 if (primaryMetadata->exists(versionName)) {
133 version = primaryMetadata->getAsInt(versionName);
134 primaryMetadata->remove(versionName);
135 } else {
136 version = 0; // unversioned files are implicitly version 0
137 }
140 str(boost::format("Cannot read Exposure FITS version > %i") %
142 }
143
144 // Try to read WCS from image metadata, and if found, strip the keywords used
145 try {
146 wcs = afw::geom::makeSkyWcs(*imageMetadata, true);
147 } catch (lsst::pex::exceptions::TypeError const&) {
148 LOGLS_DEBUG(_log, "No WCS found in FITS metadata");
149 }
150 if (wcs && any(xy0.ne(lsst::geom::Point2I(0, 0)))) {
151 wcs = wcs->copyAtShiftedPixelOrigin(lsst::geom::Extent2D(xy0));
152 }
153
154 // Strip LTV1, LTV2 from imageMetadata, because we don't use it internally
155 imageMetadata->remove("LTV1");
156 imageMetadata->remove("LTV2");
157
158 if (!imageMetadata->exists("INHERIT")) {
159 // New-style exposures put everything but the Wcs in the primary HDU, use
160 // INHERIT keyword in the others. For backwards compatibility, if we don't
161 // find the INHERIT keyword, we ignore the primary HDU metadata and expect
162 // everything to be in the image HDU metadata. Note that we can't merge them,
163 // because they're probably duplicates.
164 metadata = imageMetadata;
165 } else {
166 metadata = primaryMetadata;
167 }
168
169 // Earlier versions persisted Filter as header keyword, version 2 persists FilterLabel as a Storable
170 if (version < 2) {
171 std::string key = "FILTER";
172 if (metadata->exists(key)) {
173 // Original Filter code depended on Boost for string trimming.
174 // DIY to avoid making this module depend on Boost.
175 std::string name = metadata->getAsString(key);
176 size_t end = name.find_last_not_of(' ');
177 filterLabel = makeFilterLabel(name.substr(0, end + 1));
178 }
179 }
180
181 // EXPID keyword used in all versions, but was VisitInfo's responsibility before VisitInfo v3.
182 if (metadata->exists("EXPID")) {
183 exposureId = metadata->getAsInt64("EXPID");
184 }
185
186 visitInfo = std::make_shared<VisitInfo>(*metadata);
188
189 // This keyword is no longer handled by VisitInfo version >= 3.
190 metadata->remove("EXPID");
191
192 // Version 0 persisted Calib FLUXMAG0 in the metadata, >=1 persisted PhotoCalib as a binary table.
193 if (version == 0) {
195 }
196
197 // Strip MJD-OBS and DATE-OBS from metadata; those may be read by
198 // either SkyWcs or VisitInfo or both, so neither can strip them.
199 metadata->remove("MJD-OBS");
200 metadata->remove("DATE-OBS");
201
202 // Strip DETSER, DETNAME; these are added when writing an Exposure
203 // with a Detector
204 metadata->remove("DETNAME");
205 metadata->remove("DETSER");
206 }
207
209 std::optional<table::RecordId> exposureId;
215};
216
218public:
220 PSF = 0,
229 };
230
232 auto popInt = [&metadata](std::string const& name) {
233 // The default of zero will cause archive.get to return a
234 // null/empty pointer, just as if a null/empty pointer was
235 // originally written to the archive.
236 int r = 0;
237 if (metadata.exists(name)) {
238 r = metadata.get<int>(name);
239 // We remove metadata entries to maintaing our practice
240 // of stripped metadata entries that have been used to
241 // construct more structured components.
242 metadata.remove(name);
243 }
244 return r;
245 };
246 _hdu = popInt("AR_HDU");
247 if (_hdu == 0) {
248 _state = ArchiveState::MISSING;
249 } else {
250 --_hdu; // Switch from FITS 1-indexed convention to LSST 0-indexed convention.
251 _state = ArchiveState::PRESENT;
252 }
253 // Read in traditional components using old-style IDs, for backwards compatibility
254 _ids[PSF] = popInt("PSF_ID");
255 _ids[WCS] = popInt("SKYWCS_ID");
256 _ids[COADD_INPUTS] = popInt("COADD_INPUTS_ID");
257 _ids[AP_CORR_MAP] = popInt("AP_CORR_MAP_ID");
258 _ids[VALID_POLYGON] = popInt("VALID_POLYGON_ID");
259 _ids[TRANSMISSION_CURVE] = popInt("TRANSMISSION_CURVE_ID");
260 _ids[DETECTOR] = popInt("DETECTOR_ID");
261 _ids[PHOTOCALIB] = popInt("PHOTOCALIB_ID");
262
263 // "Extra" components use a different keyword convention to avoid collisions with non-persistence IDs
265 for (std::string const& headerKey : metadata) {
266 static std::string const PREFIX = "ARCHIVE_ID_";
267 if (headerKey.substr(0, PREFIX.size()) == PREFIX) {
268 std::string componentName = headerKey.substr(PREFIX.size());
269 int archiveId = metadata.get<int>(headerKey);
270 _genericIds.emplace(componentName, archiveId);
271 if (!_contains(_ids, archiveId)) {
272 _extraIds.emplace(componentName);
273 }
274 toStrip.push_back(headerKey);
275 toStrip.push_back(componentName + "_ID"); // strip corresponding old-style ID, if it exists
276 }
277 }
278 for (std::string const& key : toStrip) {
279 metadata.remove(key);
280 }
281 }
282
292 template <typename T>
294 if (!_ensureLoaded(fitsFile)) {
295 return nullptr;
296 }
297 return _archive.get<T>(_ids[c]);
298 }
299
316 // This method takes a string instead of a strongly typed Key because
317 // readExtraComponents() gets its keys from the FITS metadata.
318 // Using a Key would make the calling code more complicated.
319 template <typename T>
321 if (!_ensureLoaded(fitsFile)) {
322 return nullptr;
323 }
324
325 if (_genericIds.count(c) > 0) {
326 int archiveId = _genericIds.at(c);
327 return _archive.get<T>(archiveId);
328 } else {
329 return nullptr;
330 }
331 }
332
343 afw::fits::Fits* fitsFile) {
345
346 if (!_ensureLoaded(fitsFile)) {
347 return result;
348 }
349
350 // Not safe to call getAll if a component cannot be unpersisted
351 // Instead, look for the archives registered in the metadata
352 for (std::string const& componentName : _extraIds) {
353 try {
354 result.emplace(componentName, readComponent<table::io::Persistable>(fitsFile, componentName));
355 } catch (pex::exceptions::NotFoundError const& err) {
356 LOGLS_WARN(_log,
357 "Could not read component " << componentName << "; skipping: " << err.what());
358 }
359 }
360 return result;
361 }
362
363private:
364 bool _ensureLoaded(afw::fits::Fits* fitsFile) {
365 if (_state == ArchiveState::MISSING) {
366 return false;
367 }
368 if (_state == ArchiveState::PRESENT) {
369 afw::fits::HduMoveGuard guard(*fitsFile, _hdu);
370 _archive = table::io::InputArchive::readFits(*fitsFile);
371 _state = ArchiveState::LOADED;
372 }
373 assert(_state == ArchiveState::LOADED); // constructor body should guarantee it's not UNKNOWN
374 return true;
375 }
376
377 enum class ArchiveState { UNKNOWN, MISSING, PRESENT, LOADED };
378
379 int _hdu = 0;
380 ArchiveState _state = ArchiveState::UNKNOWN;
381 table::io::InputArchive _archive;
383 std::map<std::string, int> _genericIds;
384 std::set<std::string> _extraIds; // _genericIds not included in _ids
385};
386
387ExposureFitsReader::ExposureFitsReader(std::string const& fileName) : _maskedImageReader(fileName) {}
388
389ExposureFitsReader::ExposureFitsReader(fits::MemFileManager& manager) : _maskedImageReader(manager) {}
390
391ExposureFitsReader::ExposureFitsReader(fits::Fits* fitsFile) : _maskedImageReader(fitsFile) {}
392
393ExposureFitsReader::~ExposureFitsReader() noexcept = default;
394
396 return _maskedImageReader.readBBox(origin);
397}
398
400 return _maskedImageReader.readXY0(bbox, origin);
401}
402
404 _ensureReaders();
405 return _metadataReader->version;
406}
407
408std::string ExposureFitsReader::readImageDType() const { return _maskedImageReader.readImageDType(); }
409
410std::string ExposureFitsReader::readMaskDType() const { return _maskedImageReader.readMaskDType(); }
411
413
415 _ensureReaders();
416 return _metadataReader->metadata;
417}
418
419std::optional<table::RecordId> ExposureFitsReader::readExposureId() {
420 _ensureReaders();
421 return _metadataReader->exposureId;
422}
423
425 _ensureReaders();
426 auto r = _archiveReader->readComponent<afw::geom::SkyWcs>(_getFitsFile(), ArchiveReader::WCS);
427 if (!r) {
428 r = _metadataReader->wcs;
429 }
430 return r;
431}
432
434 return readFilter();
435}
436
438 _ensureReaders();
439 if (_metadataReader->version < 2) {
440 return _metadataReader->filterLabel;
441 } else {
442 return _archiveReader->readComponent<FilterLabel>(_getFitsFile(), ExposureInfo::KEY_FILTER.getId());
443 }
444}
445
447 _ensureReaders();
448 if (_metadataReader->version == 0) {
449 return _metadataReader->photoCalib;
450 } else {
451 return _archiveReader->readComponent<image::PhotoCalib>(_getFitsFile(), ArchiveReader::PHOTOCALIB);
452 }
453}
454
456 _ensureReaders();
457 return _archiveReader->readComponent<detection::Psf>(_getFitsFile(), ArchiveReader::PSF);
458}
459
461 _ensureReaders();
462 return _archiveReader->readComponent<afw::geom::polygon::Polygon>(_getFitsFile(),
464}
465
467 _ensureReaders();
468 return _archiveReader->readComponent<ApCorrMap>(_getFitsFile(), ArchiveReader::AP_CORR_MAP);
469}
470
472 _ensureReaders();
473 return _archiveReader->readComponent<CoaddInputs>(_getFitsFile(), ArchiveReader::COADD_INPUTS);
474}
475
477 _ensureReaders();
478 return _metadataReader->visitInfo;
479}
480
482 _ensureReaders();
483 return _archiveReader->readComponent<TransmissionCurve>(_getFitsFile(),
485}
486
488 _ensureReaders();
489 return _archiveReader->readComponent<cameraGeom::Detector>(_getFitsFile(), ArchiveReader::DETECTOR);
490}
491
493 _ensureReaders();
494 return _archiveReader->readComponent<typehandling::Storable>(_getFitsFile(), componentName);
495}
496
498 _ensureReaders();
499 return _archiveReader->readExtraComponents(_getFitsFile());
500}
501
503 auto result = std::make_shared<ExposureInfo>();
504 result->setMetadata(readMetadata());
505 result->setPhotoCalib(readPhotoCalib());
506 result->setVisitInfo(readVisitInfo());
507 // Override ID set in visitInfo, if necessary
508 std::optional<table::RecordId> exposureId = readExposureId();
509 if (exposureId) {
510 result->setId(*exposureId);
511 }
512 // When reading an ExposureInfo (as opposed to reading individual
513 // components), we warn and try to proceed when a component is present
514 // but can't be read due its serialization factory not being set up
515 // (that's what throws the NotFoundErrors caught below).
516 try {
517 result->setPsf(readPsf());
518 } catch (pex::exceptions::NotFoundError& err) {
519 LOGLS_WARN(_log, "Could not read PSF; setting to null: " << err.what());
520 }
521 try {
522 result->setCoaddInputs(readCoaddInputs());
523 } catch (pex::exceptions::NotFoundError& err) {
524 LOGLS_WARN(_log, "Could not read CoaddInputs; setting to null: " << err.what());
525 }
526 try {
527 result->setApCorrMap(readApCorrMap());
528 } catch (pex::exceptions::NotFoundError& err) {
529 LOGLS_WARN(_log, "Could not read ApCorrMap; setting to null: " << err.what());
530 }
531 try {
532 result->setValidPolygon(readValidPolygon());
533 } catch (pex::exceptions::NotFoundError& err) {
534 LOGLS_WARN(_log, "Could not read ValidPolygon; setting to null: " << err.what());
535 }
536 try {
537 result->setTransmissionCurve(readTransmissionCurve());
538 } catch (pex::exceptions::NotFoundError& err) {
539 LOGLS_WARN(_log, "Could not read TransmissionCurve; setting to null: " << err.what());
540 }
541 try {
542 result->setDetector(readDetector());
543 } catch (pex::exceptions::NotFoundError& err) {
544 LOGLS_WARN(_log, "Could not read Detector; setting to null: " << err.what());
545 }
546 // In the case of WCS, we fall back to the metadata WCS if the one from
547 // the archive can't be read.
548 _ensureReaders();
549 result->setWcs(_metadataReader->wcs);
550 try {
551 auto wcs = _archiveReader->readComponent<afw::geom::SkyWcs>(_getFitsFile(), ArchiveReader::WCS);
552 if (!wcs) {
553 LOGLS_DEBUG(_log, "No WCS found in binary table");
554 } else {
555 result->setWcs(wcs);
556 }
557 } catch (pex::exceptions::NotFoundError& err) {
558 auto msg = str(boost::format("Could not read WCS extension; setting to null: %s") % err.what());
559 if (result->hasWcs()) {
560 msg += " ; using WCS from FITS header";
561 }
562 LOGLS_WARN(_log, msg);
563 }
564 for (const auto& keyValue : readExtraComponents()) {
566 std::string key = keyValue.first;
567 StorablePtr object = std::dynamic_pointer_cast<StorablePtr::element_type>(keyValue.second);
568
569 if (object.use_count() > 0) { // Failed cast guarantees empty pointer, but not a null one
570 result->setComponent(typehandling::makeKey<StorablePtr>(key), object);
571 } else {
572 LOGLS_WARN(_log, "Data corruption: generic component " << key << " is not a Storable; skipping.");
573 }
574 }
575 // Convert old-style Filter to new-style FilterLabel
576 // In newer versions this is handled by readExtraComponents()
577 if (_metadataReader->version < 2 && !result->hasFilter()) {
578 result->setFilter(readFilter());
579 }
580 return result;
581} // namespace image
582
583template <typename ImagePixelT>
585 bool allowUnsafe) {
586 return _maskedImageReader.readImage<ImagePixelT>(bbox, origin, allowUnsafe);
587}
588
589template <typename ImagePixelT>
590ndarray::Array<ImagePixelT, 2, 2> ExposureFitsReader::readImageArray(lsst::geom::Box2I const& bbox,
591 ImageOrigin origin, bool allowUnsafe) {
592 return _maskedImageReader.readImageArray<ImagePixelT>(bbox, origin, allowUnsafe);
593}
594
595template <typename MaskPixelT>
597 bool conformMasks, bool allowUnsafe) {
598 return _maskedImageReader.readMask<MaskPixelT>(bbox, origin, conformMasks, allowUnsafe);
599}
600
601template <typename MaskPixelT>
602ndarray::Array<MaskPixelT, 2, 2> ExposureFitsReader::readMaskArray(lsst::geom::Box2I const& bbox,
603 ImageOrigin origin, bool allowUnsafe) {
604 return _maskedImageReader.readMaskArray<MaskPixelT>(bbox, origin, allowUnsafe);
605}
606
607template <typename VariancePixelT>
609 bool allowUnsafe) {
610 return _maskedImageReader.readVariance<VariancePixelT>(bbox, origin, allowUnsafe);
611}
612
613template <typename VariancePixelT>
614ndarray::Array<VariancePixelT, 2, 2> ExposureFitsReader::readVarianceArray(lsst::geom::Box2I const& bbox,
615 ImageOrigin origin,
616 bool allowUnsafe) {
617 return _maskedImageReader.readVarianceArray<VariancePixelT>(bbox, origin, allowUnsafe);
618}
619
620template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
622 lsst::geom::Box2I const& bbox, ImageOrigin origin, bool conformMasks, bool allowUnsafe) {
623 return _maskedImageReader.read<ImagePixelT, MaskPixelT, VariancePixelT>(bbox, origin, conformMasks,
624 /* needAllHdus= */ false,
625 allowUnsafe);
626}
627
628template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
630 ImageOrigin origin,
631 bool conformMasks,
632 bool allowUnsafe) {
633 auto mi =
634 readMaskedImage<ImagePixelT, MaskPixelT, VariancePixelT>(bbox, origin, conformMasks, allowUnsafe);
636}
637
638void ExposureFitsReader::_ensureReaders() {
639 if (!_metadataReader) {
640 auto metadataReader = std::make_unique<MetadataReader>(_maskedImageReader.readPrimaryMetadata(),
641 _maskedImageReader.readImageMetadata(),
642 _maskedImageReader.readXY0());
643 _archiveReader = std::make_unique<ArchiveReader>(*metadataReader->metadata);
644 _metadataReader = std::move(metadataReader); // deferred for exception safety
645 }
646 assert(_archiveReader); // should always be initialized with _metadataReader.
647}
648
649#define INSTANTIATE(ImagePixelT) \
650 template Exposure<ImagePixelT, MaskPixel, VariancePixel> ExposureFitsReader::read( \
651 lsst::geom::Box2I const&, ImageOrigin, bool, bool); \
652 template Image<ImagePixelT> ExposureFitsReader::readImage(lsst::geom::Box2I const&, ImageOrigin, bool); \
653 template ndarray::Array<ImagePixelT, 2, 2> ExposureFitsReader::readImageArray(lsst::geom::Box2I const&, \
654 ImageOrigin, bool); \
655 template MaskedImage<ImagePixelT, MaskPixel, VariancePixel> ExposureFitsReader::readMaskedImage( \
656 lsst::geom::Box2I const&, ImageOrigin, bool, bool)
657
659INSTANTIATE(int);
660INSTANTIATE(float);
661INSTANTIATE(double);
663
664template Mask<MaskPixel> ExposureFitsReader::readMask(lsst::geom::Box2I const&, ImageOrigin, bool, bool);
665template ndarray::Array<MaskPixel, 2, 2> ExposureFitsReader::readMaskArray(lsst::geom::Box2I const&,
666 ImageOrigin, bool);
667
668template Image<VariancePixel> ExposureFitsReader::readVariance(lsst::geom::Box2I const&, ImageOrigin, bool);
669template ndarray::Array<VariancePixel, 2, 2> ExposureFitsReader::readVarianceArray(lsst::geom::Box2I const&,
670 ImageOrigin, bool);
671
672} // namespace image
673} // namespace afw
674} // namespace lsst
py::object result
Definition: _schema.cc:429
table::Key< std::string > name
Definition: Amplifier.cc:116
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
double element[2]
Definition: BaseTable.cc:90
int end
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
#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.
Definition: Log.h:659
#define LOG_GET(logger)
Returns a Log object associated with logger.
Definition: Log.h:75
#define LOG_LOGGER
Definition: Log.h:714
#define LOGLS_DEBUG(logger, message)
Log a debug-level message using an iostream-based interface.
Definition: Log.h:619
Implementation of the Photometric Calibration class.
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:66
table::Key< table::RecordId > exposureId
Definition: VisitInfo.cc:199
T at(T... args)
A representation of a detector in a mosaic camera.
Definition: Detector.h:185
A polymorphic base class for representing an image's Point Spread Function.
Definition: Psf.h:76
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
RAII scoped guard for moving the HDU in a Fits object.
Definition: fits.h:737
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:121
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:117
Cartesian polygons.
Definition: Polygon.h:59
A thin wrapper around std::map to allow aperture corrections to be attached to Exposures.
Definition: ApCorrMap.h:45
A simple Persistable struct containing ExposureCatalogs that record the inputs to a coadd.
Definition: CoaddInputs.h:49
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.
std::shared_ptr< T > readComponent(afw::fits::Fits *fitsFile, Component c)
Read a known component, if available.
std::shared_ptr< daf::base::PropertyList > metadata
MetadataReader(std::shared_ptr< daf::base::PropertyList > primaryMetadata, std::shared_ptr< daf::base::PropertyList > imageMetadata, lsst::geom::Point2I const &xy0)
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.
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.
std::shared_ptr< FilterLabel > readFilter()
Read the Exposure's filter 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.
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.
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.
Definition: Exposure.h:72
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.
Definition: ExposureInfo.h:109
A group of labels for a filter in an exposure or coadd.
Definition: FilterLabel.h:58
static FilterLabel fromBand(std::string const &band)
Construct a FilterLabel from specific inputs.
Definition: FilterLabel.cc:72
static FilterLabel fromBandPhysical(std::string const &band, std::string const &physical)
Construct a FilterLabel from specific inputs.
Definition: FilterLabel.cc:68
static FilterLabel fromPhysical(std::string const &physical)
Construct a FilterLabel from specific inputs.
Definition: FilterLabel.cc:74
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:51
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:77
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.
Definition: MaskedImage.h:73
The photometric calibration of an exposure.
Definition: PhotoCalib.h:114
A spatially-varying transmission curve as a function of wavelength.
static InputArchive readFits(fits::Fits &fitsfile)
Read an object from an already open FITS object.
std::shared_ptr< Persistable > get(int id) const
Load the Persistable with the given ID and return it.
Interface supporting iteration over heterogenous containers.
Definition: Storable.h:58
Class for storing ordered metadata with comments.
Definition: PropertyList.h:68
T get(std::string const &name) const
Get the last value for a property name (possibly hierarchical).
Definition: PropertyList.cc:62
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.
Definition: Box.h:55
CoordinateExpr< N > ne(Point< T, N > const &other) const noexcept
Definition: Point.cc:83
virtual char const * what(void) const noexcept
Return a character string summarizing this exception.
Definition: Exception.cc:99
Reports attempts to access elements using an invalid key.
Definition: Runtime.h:151
Reports errors from accepting an object of an unexpected or inappropriate type.
Definition: Runtime.h:167
T count(T... args)
T emplace(T... args)
T make_pair(T... args)
T move(T... args)
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Definition: SkyWcs.cc:521
int stripVisitInfoKeywords(daf::base::PropertySet &metadata)
Remove VisitInfo-related keywords from the metadata.
Definition: VisitInfo.cc:346
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
std::shared_ptr< PhotoCalib > makePhotoCalibFromMetadata(daf::base::PropertySet &metadata, bool strip=false)
Construct a PhotoCalib from FITS FLUXMAG0/FLUXMAG0ERR keywords.
Definition: PhotoCalib.cc:595
std::shared_ptr< FilterLabel > makeFilterLabel(std::string const &name)
Convert an old-style single Filter name to a FilterLabel, using available information.
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)
Definition: history.py:174
A base class for image defects.
T push_back(T... args)
T regex_match(T... args)
T size(T... args)
T substr(T... args)