37 int const EXPOSURE_TABLE_CURRENT_VERSION = 5;
38 std::string const EXPOSURE_TABLE_VERSION_KEY =
"EXPTABLE_VER";
46 std::string const PHOTOCALIB_FIELD_NAME =
"photoCalib";
47 std::string const VISIT_INFO_FIELD_NAME =
"visitInfo";
48 std::string const AP_CORR_MAP_FIELD_NAME =
"apCorrMap";
49 std::string const VALID_POLYGON_FIELD_NAME =
"validPolygon";
50 std::string const TRANSMISSION_CURVE_FIELD_NAME =
"transmissionCurve";
53 int getTableVersion(daf::base::PropertySet &metadata) {
54 return metadata.exists(EXPOSURE_TABLE_VERSION_KEY) ? metadata.get<
int>(EXPOSURE_TABLE_VERSION_KEY) : 1;
62 struct PersistenceHelper {
75 SchemaMapper makeWriteMapper(Schema
const &inputSchema)
const {
77 inSchemas.
push_back(PersistenceHelper().schema);
81 result.editOutputSchema().setAliasMap(inputSchema.getAliasMap());
86 SchemaMapper makeReadMapper(Schema
const &inputSchema)
const {
88 result.editOutputSchema().setAliasMap(inputSchema.getAliasMap());
93 template <
typename OutputArchiveIsh>
94 void writeRecord(ExposureRecord
const &input, BaseRecord &output, SchemaMapper
const &
mapper,
95 OutputArchiveIsh &archive,
bool permissive)
const {
96 output.assign(input, mapper);
97 output.set(psf, archive.put(input.getPsf(), permissive));
98 output.set(wcs, archive.put(input.getWcs(), permissive));
99 output.set(photoCalib, archive.put(input.getPhotoCalib(), permissive));
100 output.set(apCorrMap, archive.put(input.getApCorrMap(), permissive));
101 output.set(validPolygon, archive.put(input.getValidPolygon(), permissive));
102 output.set(visitInfo, archive.put(input.getVisitInfo(), permissive));
103 output.set(transmissionCurve, archive.put(input.getTransmissionCurve(), permissive));
104 output.set(detector, archive.put(input.getDetector(), permissive));
108 void readRecord(BaseRecord
const &input, ExposureRecord &output, SchemaMapper
const &mapper,
109 io::InputArchive
const &archive)
const {
110 output.assign(input, mapper);
112 output.setPsf(archive.get<detection::Psf>(input.get(psf)));
115 output.setWcs(archive.get<geom::SkyWcs>(input.get(wcs)));
117 if (calib.isValid()) {
120 if (photoCalib.isValid()) {
123 if (apCorrMap.isValid()) {
126 if (validPolygon.isValid()) {
127 output.setValidPolygon(archive.get<geom::polygon::Polygon>(input.get(validPolygon)));
129 if (visitInfo.isValid()) {
132 if (transmissionCurve.isValid()) {
135 if (detector.isValid()) {
136 output.setDetector(archive.get<cameraGeom::Detector>(input.get(detector)));
141 PersistenceHelper(
const PersistenceHelper &) =
delete;
142 PersistenceHelper &operator=(
const PersistenceHelper &) =
delete;
145 PersistenceHelper(PersistenceHelper &&) =
delete;
146 PersistenceHelper &operator=(PersistenceHelper &&) =
delete;
151 wcs(schema.addField<
int>(WCS_FIELD_NAME,
"archive ID for Wcs object")),
152 psf(schema.addField<
int>(PSF_FIELD_NAME,
"archive ID for Psf object")),
153 photoCalib(schema.addField<
int>(PHOTOCALIB_FIELD_NAME,
"archive ID for PhotoCalib object")),
154 apCorrMap(schema.addField<
int>(AP_CORR_MAP_FIELD_NAME,
"archive ID for ApCorrMap object")),
155 validPolygon(schema.addField<
int>(VALID_POLYGON_FIELD_NAME,
"archive ID for Polygon object")),
156 visitInfo(schema.addField<
int>(VISIT_INFO_FIELD_NAME,
"archive ID for VisitInfo object")),
158 "archive ID for TransmissionCurve object")),
159 detector(schema.addField<
int>(DETECTOR_FIELD_NAME,
"archive ID for Detector object")) {}
164 auto item = oldSchema.find<
int>(
name);
165 key = schema.addField(item.field);
166 }
catch (pex::exceptions::NotFoundError &) {
171 PersistenceHelper(Schema
const &oldSchema) {
172 addIfPresent(oldSchema, wcs, WCS_FIELD_NAME);
173 addIfPresent(oldSchema, psf, PSF_FIELD_NAME);
174 addIfPresent(oldSchema, calib, CALIB_FIELD_NAME);
175 addIfPresent(oldSchema, photoCalib, PHOTOCALIB_FIELD_NAME);
176 addIfPresent(oldSchema, apCorrMap, AP_CORR_MAP_FIELD_NAME);
177 addIfPresent(oldSchema, validPolygon, VALID_POLYGON_FIELD_NAME);
178 addIfPresent(oldSchema, visitInfo, VISIT_INFO_FIELD_NAME);
179 addIfPresent(oldSchema, transmissionCurve, TRANSMISSION_CURVE_FIELD_NAME);
180 addIfPresent(oldSchema, detector, DETECTOR_FIELD_NAME);
181 assert(oldSchema.contains(schema));
197 class ExposureFitsWriter :
public io::FitsWriter {
203 _archive.reset(
new io::OutputArchive());
210 void _writeRecord(BaseRecord
const &r)
override;
212 void _finish()
override {
227 "Cannot use a ExposureFitsWriter on a non-Exposure table.");
232 _fits->writeKey(
"AFW_TYPE",
"EXPOSURE",
"Tells lsst::afw to load this as an Exposure table.");
233 _fits->writeKey(EXPOSURE_TABLE_VERSION_KEY, EXPOSURE_TABLE_CURRENT_VERSION,
"Exposure table version");
234 _record = outTable->makeRecord();
237 void ExposureFitsWriter::_writeRecord(BaseRecord
const &r) {
238 ExposureRecord
const &record =
static_cast<ExposureRecord
const &
>(r);
252 template <
typename T,
void (ExposureRecord::*Setter)(std::shared_ptr<T const>)>
256 auto item = mapper.
find(name);
289 bool stripMetadata)
const override {
295 auto tableVersion = getTableVersion(*metadata);
301 "validPolygon", mapper);
302 if (tableVersion > 1) {
306 if (tableVersion > 2) {
311 if (tableVersion > 3) {
316 if (tableVersion <= 4) {
321 "photoCalib", mapper);
326 table->setMetadata(metadata);
330 bool usesArchive(
int ioFlags)
const override {
return true; }
333 static ExposureFitsReader
const exposureFitsReader;
350 "ExposureRecord does not have a Wcs; cannot call contains()");
354 if (includeValidPolygon && !getValidPolygon()) {
355 includeValidPolygon =
false;
360 if (includeValidPolygon)
371 bool includeValidPolygon)
const {
372 return contains(wcs.pixelToSky(point), includeValidPolygon);
382 _photoCalib = s._photoCalib;
383 _apCorrMap = s._apCorrMap;
384 _validPolygon = s._validPolygon;
385 _visitInfo = s._visitInfo;
386 _transmissionCurve = s._transmissionCurve;
387 _detector = s._detector;
393 if (!checkSchema(schema)) {
396 "Schema for Exposure must contain at least the keys defined by makeMinimalSchema().");
409 ExposureTable::MinimalSchema::MinimalSchema() {
414 ExposureTable::MinimalSchema &ExposureTable::getMinimalSchema() {
415 static MinimalSchema it;
426 return std::make_shared<ExposureFitsWriter>(fitsfile, archive, flags);
434 return constructRecord<ExposureRecord>();
441 template <
typename RecordT>
443 PersistenceHelper helper{};
446 outputCat.
reserve(this->size());
448 helper.writeRecord(*i, *outputCat.
addNew(),
mapper, handle, permissive);
453 template <
typename RecordT>
458 PersistenceHelper helper{catalog.
getSchema()};
463 helper.readRecord(*i, *
result.addNew(),
mapper, archive);
468 template <
typename RecordT>
470 bool includeValidPolygon)
const {
473 if (i->contains(coord, includeValidPolygon)) {
480 template <
typename RecordT>
482 geom::SkyWcs
const &
wcs,
483 bool includeValidPolygon)
const {
486 if (i->contains(point, wcs, includeValidPolygon)) {
Defines the fields and offsets for a table.
A spatially-varying transmission curve as a function of wavelength.
~ExposureTable() override
A utility class for reading FITS binary tables.
A floating-point coordinate rectangle geometry.
An object passed to Persistable::write to allow it to persist itself.
The photometric calibration of an exposure.
Table class used to store exposure metadata.
std::shared_ptr< BaseTable > _clone() const override
Clone implementation with noncovariant return types.
ExposureCatalogT subsetContaining(lsst::geom::SpherePoint const &coord, bool includeValidPolygon=false) const
Return a shallow subset of the catalog with only those records that contain the given point...
A thin wrapper around std::map to allow aperture corrections to be attached to Exposures.
bool contains(lsst::geom::SpherePoint const &coord, bool includeValidPolygon=false) const
Return true if the bounding box contains the given celestial coordinate point, taking into account th...
A mapping between the keys of two Schemas, used to copy data between them.
Schema getSchema() const
Return the table's schema.
static void setup(std::string const &name, io::FitsSchemaInputMapper &mapper)
Information about a single exposure of an imaging camera.
static Box2IKey getBBoxKey()
Key for the full bbox.
Schema const getOutputSchema() const
Return the output schema (copy-on-write).
void readTableScalar(std::size_t row, int col, T &value)
Read an array scalar from a binary table.
ExposureTable(Schema const &schema)
std::shared_ptr< BaseRecord > _record
Reports arguments outside the domain of an operation.
Schema getSchema() const
Return the schema associated with the catalog's table.
ItemVariant const * other
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
std::shared_ptr< BaseRecord > _makeRecord() override
Default-construct an associated record (protected implementation).
void setBBox(lsst::geom::Box2I const &bbox)
static SchemaMapper removeMinimalSchema(Schema const &input, Schema const &minimal)
Create a mapper by removing fields from the front of a schema.
void push_back(Record const &r)
Add a copy of the given record to the end of the catalog.
PersistenceHelper _helper
static std::vector< SchemaMapper > join(std::vector< Schema > const &inputs, std::vector< std::string > const &prefixes=std::vector< std::string >())
Combine a sequence of schemas into one, creating a SchemaMapper for each.
A base class for image defects.
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
iterator end()
Iterator access.
Iterator class for CatalogT.
Key< int > transmissionCurve
~ExposureRecord() override
T dynamic_pointer_cast(T... args)
Reports errors in the logical structure of the program.
virtual void _writeTable(std::shared_ptr< BaseTable const > const &table, std::size_t nRows)
Write a table and its schema.
std::shared_ptr< io::OutputArchive > _archive
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
void reserve(size_type n)
Increase the capacity of the catalog to the given size.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
static std::shared_ptr< ExposureTable > make(Schema const &schema)
Construct a new table.
Base class for all records.
static std::shared_ptr< BaseTable > make(Schema const &schema)
Construct a new table.
Point in an unspecified spherical coordinate system.
static ExposureCatalogT readFromArchive(io::InputArchive const &archive, BaseCatalog const &catalog)
Convenience input function for Persistables that contain an ExposureCatalog.
Custom catalog class for ExposureRecord/Table.
void writeToArchive(io::OutputArchiveHandle &handle, bool ignoreUnpersistable=true) const
Convenience output function for Persistables that contain an ExposureCatalog.
void setTransmissionCurve(std::shared_ptr< image::TransmissionCurve const > transmissionCurve)
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
virtual void _writeRecord(BaseRecord const &source)
Write an individual record.
Reports invalid arguments.
Record class used to store exposure metadata.
size_type size() const
Return the number of elements in the catalog.
PersistableObjectColumnReader(int column)
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
Polymorphic reader interface used to read different kinds of objects from one or more FITS binary tab...
iterator begin()
Iterator access.
void _assign(BaseRecord const &other) override
Called by assign() after transferring fields to allow subclass data members to be copied...
An integer coordinate rectangle.
void readCell(BaseRecord &record, std::size_t row, fits::Fits &fits, std::shared_ptr< io::InputArchive > const &archive) const override
Read values from a single row.
lsst::geom::Box2I getBBox() const
Implementation of the Photometric Calibration class.
static BoxKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
Add _min_x, _min_y, _max_x, _max_y fields to a Schema, and return a BoxKey that points to them...
Base class for all tables.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.