36 int const EXPOSURE_TABLE_CURRENT_VERSION = 3;
37 std::string const EXPOSURE_TABLE_VERSION_KEY =
"EXPTABLE_VER";
45 std::string const VISIT_INFO_FIELD_NAME =
"visitInfo";
46 std::string const AP_CORR_MAP_FIELD_NAME =
"apCorrMap";
47 std::string const VALID_POLYGON_FIELD_NAME =
"validPolygon";
48 std::string const TRANSMISSION_CURVE_FIELD_NAME =
"transmissionCurve";
51 int getTableVersion(daf::base::PropertySet &metadata) {
52 return metadata.exists(EXPOSURE_TABLE_VERSION_KEY) ? metadata.get<
int>(EXPOSURE_TABLE_VERSION_KEY) : 1;
60 struct PersistenceHelper {
71 SchemaMapper makeWriteMapper(Schema
const &inputSchema)
const {
73 inSchemas.
push_back(PersistenceHelper().schema);
77 result.editOutputSchema().setAliasMap(inputSchema.getAliasMap());
82 SchemaMapper makeReadMapper(Schema
const &inputSchema)
const {
84 result.editOutputSchema().setAliasMap(inputSchema.getAliasMap());
89 template <
typename OutputArchiveIsh>
90 void writeRecord(ExposureRecord
const &input, BaseRecord &output, SchemaMapper
const &
mapper,
91 OutputArchiveIsh &archive,
bool permissive)
const {
92 output.assign(input, mapper);
93 output.set(psf, archive.put(input.getPsf(), permissive));
94 output.set(wcs, archive.put(input.getWcs(), permissive));
95 output.set(calib, archive.put(input.getCalib(), permissive));
96 output.set(apCorrMap, archive.put(input.getApCorrMap(), permissive));
97 output.set(validPolygon, archive.put(input.getValidPolygon(), permissive));
98 output.set(visitInfo, archive.put(input.getVisitInfo(), permissive));
99 output.set(transmissionCurve, archive.put(input.getTransmissionCurve(), permissive));
103 void readRecord(BaseRecord
const &input, ExposureRecord &output, SchemaMapper
const &mapper,
104 io::InputArchive
const &archive)
const {
105 output.assign(input, mapper);
107 output.setPsf(archive.get<detection::Psf>(input.get(psf)));
110 output.setWcs(archive.get<geom::SkyWcs>(input.get(wcs)));
112 if (calib.isValid()) {
113 output.setCalib(archive.get<
image::Calib>(input.get(calib)));
115 if (apCorrMap.isValid()) {
118 if (validPolygon.isValid()) {
119 output.setValidPolygon(archive.get<geom::polygon::Polygon>(input.get(validPolygon)));
121 if (visitInfo.isValid()) {
124 if (transmissionCurve.isValid()) {
130 PersistenceHelper(
const PersistenceHelper &) =
delete;
131 PersistenceHelper &operator=(
const PersistenceHelper &) =
delete;
134 PersistenceHelper(PersistenceHelper &&) =
delete;
135 PersistenceHelper &operator=(PersistenceHelper &&) =
delete;
140 wcs(schema.addField<
int>(WCS_FIELD_NAME,
"archive ID for Wcs object")),
141 psf(schema.addField<
int>(PSF_FIELD_NAME,
"archive ID for Psf object")),
142 calib(schema.addField<
int>(CALIB_FIELD_NAME,
"archive ID for Calib object")),
143 apCorrMap(schema.addField<
int>(AP_CORR_MAP_FIELD_NAME,
"archive ID for ApCorrMap object")),
144 validPolygon(schema.addField<
int>(VALID_POLYGON_FIELD_NAME,
"archive ID for Polygon object")),
145 visitInfo(schema.addField<
int>(VISIT_INFO_FIELD_NAME,
"archive ID for VisitInfo object")),
147 "archive ID for TransmissionCurve object")) {}
152 auto item = oldSchema.find<
int>(
name);
153 key = schema.addField(item.field);
154 }
catch (pex::exceptions::NotFoundError &) {
159 PersistenceHelper(Schema
const &oldSchema) {
160 addIfPresent(oldSchema, wcs, WCS_FIELD_NAME);
161 addIfPresent(oldSchema, psf, PSF_FIELD_NAME);
162 addIfPresent(oldSchema, calib, CALIB_FIELD_NAME);
163 addIfPresent(oldSchema, apCorrMap, AP_CORR_MAP_FIELD_NAME);
164 addIfPresent(oldSchema, validPolygon, VALID_POLYGON_FIELD_NAME);
165 addIfPresent(oldSchema, visitInfo, VISIT_INFO_FIELD_NAME);
166 addIfPresent(oldSchema, transmissionCurve, TRANSMISSION_CURVE_FIELD_NAME);
167 assert(oldSchema.contains(schema));
183 class ExposureFitsWriter :
public io::FitsWriter {
189 _archive.reset(
new io::OutputArchive());
196 virtual void _writeRecord(BaseRecord
const &r);
198 virtual void _finish() {
213 "Cannot use a ExposureFitsWriter on a non-Exposure table.");
218 _fits->writeKey(
"AFW_TYPE",
"EXPOSURE",
"Tells lsst::afw to load this as an Exposure table.");
219 _fits->writeKey(EXPOSURE_TABLE_VERSION_KEY, EXPOSURE_TABLE_CURRENT_VERSION,
"Exposure table version");
220 _record = outTable->makeRecord();
223 void ExposureFitsWriter::_writeRecord(BaseRecord
const &r) {
224 ExposureRecord
const &record =
static_cast<ExposureRecord
const &
>(r);
238 template <
typename T,
void (ExposureRecord::*Setter)(std::shared_ptr<T const>)>
242 auto item = mapper.
find(name);
275 int ioFlags,
bool stripMetadata)
const {
281 auto tableVersion = getTableVersion(*metadata);
288 "validPolygon", mapper);
289 if (tableVersion > 1) {
293 if (tableVersion > 2) {
299 table->setMetadata(metadata);
303 virtual bool usesArchive(
int ioFlags)
const {
return true; }
306 static ExposureFitsReader
const exposureFitsReader;
325 "ExposureRecord does not have a Wcs; cannot call contains()");
329 if (includeValidPolygon && !getValidPolygon()) {
330 includeValidPolygon =
false;
335 if (includeValidPolygon)
336 return (
geom::Box2D(getBBox()).contains(point) && getValidPolygon()->contains(point));
346 bool includeValidPolygon)
const {
347 return contains(wcs.
pixelToSky(point), includeValidPolygon);
360 _apCorrMap = s._apCorrMap;
361 _validPolygon = s._validPolygon;
362 _visitInfo = s._visitInfo;
363 _transmissionCurve = s._transmissionCurve;
369 if (!checkSchema(schema)) {
372 "Schema for Exposure must contain at least the keys defined by makeMinimalSchema().");
385 ExposureTable::MinimalSchema::MinimalSchema() {
388 schema.getCitizen().markPersistent();
391 ExposureTable::MinimalSchema &ExposureTable::getMinimalSchema() {
392 static MinimalSchema it;
403 return std::make_shared<ExposureFitsWriter>(fitsfile, archive, flags);
418 template <
typename RecordT>
420 PersistenceHelper helper{};
423 outputCat.
reserve(this->size());
425 helper.writeRecord(*i, *outputCat.
addNew(),
mapper, handle, permissive);
430 template <
typename RecordT>
435 PersistenceHelper helper{catalog.
getSchema()};
440 helper.readRecord(*i, *
result.addNew(),
mapper, archive);
445 template <
typename RecordT>
447 bool includeValidPolygon)
const {
450 if (i->contains(coord, includeValidPolygon)) {
457 template <
typename RecordT>
460 bool includeValidPolygon)
const {
463 if (i->contains(point, wcs, includeValidPolygon)) {
std::shared_ptr< BaseRecord > _record
Defines the fields and offsets for a table.
friend class ExposureTable
Point in an unspecified spherical coordinate system.
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.
A utility class for reading FITS binary tables.
bool contains(Point2D const &point) const
Return true if the box contains the point.
An object passed to Persistable::write to allow it to persist itself.
void setBBox(geom::Box2I const &bbox)
Table class used to store exposure metadata.
std::shared_ptr< BaseTable > _clone() const override
Clone implementation with noncovariant return types.
geom::Box2I getBBox() const
A thin wrapper around std::map to allow aperture corrections to be attached to Exposures.
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)
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).
Describe an exposure's calibration.
std::shared_ptr< io::OutputArchive > _archive
ExposureCatalogT subsetContaining(geom::SpherePoint const &coord, bool includeValidPolygon=false) const
Return a shallow subset of the catalog with only those records that contain the given point...
An integer coordinate rectangle.
static SchemaMapper removeMinimalSchema(Schema const &input, Schema const &minimal)
Create a mapper by removing fields from the front of a schema.
Key< int > transmissionCurve
void push_back(Record const &r)
Add a copy of the given record to the end of the catalog.
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.
bool contains(geom::SpherePoint const &coord, bool includeValidPolygon=false) const
Return true if the bounding box contains the given celestial coordinate point, taking into account th...
T dynamic_pointer_cast(T... args)
std::unique_ptr< SchemaItem< U > > result
virtual void _writeTable(std::shared_ptr< BaseTable const > const &table, std::size_t nRows)
Write a table and its schema.
virtual void _assign(BaseRecord const &other)
Called by assign() after transferring fields to allow subclass data members to be copied...
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,...)
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.
SpherePoint pixelToSky(Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
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, Calib, or ApCorrMap. No copies are made.
virtual void _writeRecord(BaseRecord const &source)
Write an individual record.
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.
A floating-point coordinate rectangle geometry.
iterator begin()
Iterator access.
PersistenceHelper _helper
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...
virtual void readCell(BaseRecord &record, std::size_t row, fits::Fits &fits, std::shared_ptr< io::InputArchive > const &archive) const
Base class for all tables.
ExposureRecord(ExposureRecord const &)=delete
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.