LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
LSSTDataManagementBasePackage
Exposure.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008, 2009, 2010, 2011 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 #ifndef AFW_TABLE_Exposure_h_INCLUDED
24 #define AFW_TABLE_Exposure_h_INCLUDED
25 
26 #include "lsst/geom/Box.h"
27 #include "lsst/geom/SpherePoint.h"
28 #include "lsst/afw/fitsDefaults.h"
35 
36 namespace lsst {
37 namespace afw {
38 
39 namespace image {
40 class PhotoCalib;
41 class ApCorrMap;
42 class VisitInfo;
43 class TransmissionCurve;
44 } // namespace image
45 
46 namespace detection {
47 class Psf;
48 } // namespace detection
49 
50 namespace geom {
51 class SkyWcs;
52 namespace polygon {
53 class Polygon;
54 }
55 } // namespace geom
56 
57 namespace cameraGeom {
58 class Detector;
59 } // namespace cameraGeom
60 
61 namespace table {
62 
63 class ExposureRecord;
64 class ExposureTable;
65 
66 template <typename RecordT>
68 
69 namespace io {
70 
71 class OutputArchiveHandle;
72 class InputArchive;
73 
74 } // namespace io
75 
79 class ExposureRecord : public BaseRecord {
80 public:
85 
96  BaseRecord(token, std::move(data))
97  {}
98 
100  return std::static_pointer_cast<ExposureTable const>(BaseRecord::getTable());
101  }
102 
103  RecordId getId() const;
104  void setId(RecordId id);
105 
106  lsst::geom::Box2I getBBox() const;
107  void setBBox(lsst::geom::Box2I const& bbox);
108 
119  bool contains(lsst::geom::SpherePoint const& coord, bool includeValidPolygon = false) const;
120 
131  bool contains(lsst::geom::Point2D const& point, geom::SkyWcs const& wcs,
132  bool includeValidPolygon = false) const;
133 
135  std::shared_ptr<geom::SkyWcs const> getWcs() const { return _wcs; }
138 
141 
144 
145  [[deprecated("Replaced with getPhotoCalib (will be removed in 18.0)")]] std::shared_ptr<
146  image::PhotoCalib const>
147  getCalib() const {
148  return _photoCalib;
149  }
150  [[deprecated("Replaced with setPhotoCalib (will be removed in 18.0)")]] void setCalib(
152  _photoCalib = photoCalib;
153  }
154 
157 
159  void setValidPolygon(std::shared_ptr<geom::polygon::Polygon const> polygon) { _validPolygon = polygon; }
160 
163 
165  return _transmissionCurve;
166  }
168  _transmissionCurve = std::move(transmissionCurve);
169  }
170 
173  _detector = std::move(detector);
174  }
176 
177  ExposureRecord(ExposureRecord const&) = delete;
178  ExposureRecord(ExposureRecord&&) = delete;
179  ExposureRecord& operator=(ExposureRecord const&) = delete;
180  ExposureRecord& operator=(ExposureRecord&&) = delete;
181  ~ExposureRecord() override;
182 
183 protected:
184 
185  void _assign(BaseRecord const& other) override;
186 
187 private:
188  friend class ExposureTable;
189 
198 };
199 
205 class ExposureTable : public BaseTable {
206 public:
211 
217  static std::shared_ptr<ExposureTable> make(Schema const& schema);
218 
227  Schema r = getMinimalSchema().schema;
228  r.disconnectAliases();
229  return r;
230  }
231 
238  static bool checkSchema(Schema const& other) { return other.contains(getMinimalSchema().schema); }
239 
241 
246  static Key<RecordId> getIdKey() { return getMinimalSchema().id; }
249  static PointKey<int> getBBoxMinKey() { return getMinimalSchema().bbox.getMin(); }
251  static PointKey<int> getBBoxMaxKey() { return getMinimalSchema().bbox.getMax(); }
253  static Box2IKey getBBoxKey() { return getMinimalSchema().bbox; }
255 
258 
261  return std::static_pointer_cast<ExposureRecord>(_makeRecord());
262  }
263 
266  return std::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other));
267  }
268 
271  return std::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other, mapper));
272  }
273 
274  ExposureTable& operator=(ExposureTable const&) = delete;
275  ExposureTable& operator=(ExposureTable&&) = delete;
276  ~ExposureTable() override;
277 
278 protected:
279  explicit ExposureTable(Schema const& schema);
280 
282  ExposureTable(ExposureTable&& other);
283 
284  std::shared_ptr<BaseTable> _clone() const override;
285 
286  std::shared_ptr<BaseRecord> _makeRecord() override;
287 
288 private:
289  // Struct that holds the minimal schema and the special keys we've added to it.
290  struct MinimalSchema {
291  Schema schema;
293  Box2IKey bbox;
294 
295  MinimalSchema();
296  };
297 
298  // Return the singleton minimal schema.
299  static MinimalSchema& getMinimalSchema();
300 
301  friend class io::FitsWriter;
302 
303  template <typename RecordT>
304  friend class ExposureCatalogT;
305 
306  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
307  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const override;
308 
309  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile,
311  int flags) const;
312 };
313 
320 template <typename RecordT>
321 class ExposureCatalogT : public SortedCatalogT<RecordT> {
322  typedef SortedCatalogT<RecordT> Base;
323 
324 public:
325  typedef RecordT Record;
326  typedef typename Record::Table Table;
327 
328  typedef typename Base::iterator iterator;
330 
337  explicit ExposureCatalogT(std::shared_ptr<Table> const& table = std::shared_ptr<Table>()) : Base(table) {}
338 
340  explicit ExposureCatalogT(Schema const& schema) : Base(schema) {}
341 
352  template <typename InputIterator>
353  ExposureCatalogT(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last,
354  bool deep = false)
355  : Base(table, first, last, deep) {}
356 
363  template <typename OtherRecordT>
365 
366  ExposureCatalogT(ExposureCatalogT const&) = default;
367  ExposureCatalogT(ExposureCatalogT&&) = default;
368  ExposureCatalogT& operator=(ExposureCatalogT const&) = default;
369  ExposureCatalogT& operator=(ExposureCatalogT&&) = default;
370  ~ExposureCatalogT() = default;
371 
372  using Base::writeFits;
373 
381  void writeFits(fits::Fits& fitsfile, std::shared_ptr<io::OutputArchive> archive, int flags = 0) const {
382  std::shared_ptr<io::FitsWriter> writer = this->getTable()->makeFitsWriter(&fitsfile, archive, flags);
383  writer->write(*this);
384  }
385 
396  static ExposureCatalogT readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU,
397  int flags = 0) {
398  return io::FitsReader::apply<ExposureCatalogT>(filename, hdu, flags);
399  }
400 
412  int flags = 0) {
413  return io::FitsReader::apply<ExposureCatalogT>(manager, hdu, flags);
414  }
415 
423  static ExposureCatalogT readFits(fits::Fits& fitsfile, int flags = 0) {
424  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags);
425  }
426 
434  int flags = 0) {
435  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags, archive);
436  }
437 
445  void writeToArchive(io::OutputArchiveHandle& handle, bool ignoreUnpersistable = true) const;
446 
453  static ExposureCatalogT readFromArchive(io::InputArchive const& archive, BaseCatalog const& catalog);
454 
460  ExposureCatalogT<RecordT> subset(ndarray::Array<bool const, 1> const& mask) const {
461  return ExposureCatalogT(Base::subset(mask));
462  }
463 
469  return ExposureCatalogT(Base::subset(startd, stopd, step));
470  }
471 
480  ExposureCatalogT subsetContaining(lsst::geom::SpherePoint const& coord,
481  bool includeValidPolygon = false) const;
482 
491  ExposureCatalogT subsetContaining(lsst::geom::Point2D const& point, geom::SkyWcs const& wcs,
492  bool includeValidPolygon = false) const;
493 
494 protected:
495  explicit ExposureCatalogT(Base const& other) : Base(other) {}
496 };
497 
501 
502 inline RecordId ExposureRecord::getId() const { return get(ExposureTable::getIdKey()); }
503 inline void ExposureRecord::setId(RecordId id) { set(ExposureTable::getIdKey(), id); }
504 } // namespace table
505 } // namespace afw
506 } // namespace lsst
507 
508 #endif // !AFW_TABLE_Exposure_h_INCLUDED
std::shared_ptr< ExposureTable > clone() const
Return a polymorphic deep copy of the table.
Definition: Exposure.h:257
std::shared_ptr< ExposureTable const > getTable() const
Definition: Exposure.h:99
Defines the fields and offsets for a table.
Definition: Schema.h:50
void setValidPolygon(std::shared_ptr< geom::polygon::Polygon const > polygon)
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:159
ExposureCatalogT< RecordT > subset(ndarray::Array< bool const, 1 > const &mask) const
Return the subset of a catalog corresponding to the True values of the given mask array...
Definition: Exposure.h:460
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:117
Writer object for FITS binary tables.
Definition: FitsWriter.h:25
std::shared_ptr< image::ApCorrMap const > getApCorrMap() const
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:155
Key< int > visitInfo
Definition: Exposure.cc:70
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:208
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
ExposureCatalogT< ExposureRecord const > ConstExposureCatalog
Definition: Exposure.h:500
std::shared_ptr< image::PhotoCalib const > getCalib() const
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:147
Helper struct that contains the information passed from BaseTable to BaseRecord at construction...
Definition: BaseTable.h:32
An object passed to Persistable::write to allow it to persist itself.
The photometric calibration of an exposure.
Definition: PhotoCalib.h:116
ExposureCatalogT(Base const &other)
Definition: Exposure.h:495
ExposureCatalogT(std::shared_ptr< Table > const &table, InputIterator first, InputIterator last, bool deep=false)
Construct a vector from a table and an iterator range.
Definition: Exposure.h:353
Table class used to store exposure metadata.
Definition: Exposure.h:205
ColumnViewT< ExposureRecord > ExposureColumnView
Definition: Exposure.h:498
ExposureCatalogT(std::shared_ptr< Table > const &table=std::shared_ptr< Table >())
Construct a vector from a table (or nothing).
Definition: Exposure.h:337
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
static Box2IKey getBBoxKey()
Key for the full bbox.
Definition: Exposure.h:253
ExposureCatalogT< Record const > ConstCatalog
Definition: Exposure.h:210
static Schema makeMinimalSchema()
Return a minimal schema for Exposure tables and records.
Definition: Exposure.h:226
void disconnectAliases()
Sever the connection between this schema and any others with which it shares aliases.
Definition: Schema.cc:729
STL namespace.
void setDetector(std::shared_ptr< cameraGeom::Detector const > detector)
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:172
std::shared_ptr< ExposureRecord > copyRecord(BaseRecord const &other)
Deep-copy a record, requiring that it have the same schema as this table.
Definition: Exposure.h:265
Key< int > photoCalib
Definition: Exposure.cc:67
std::shared_ptr< image::TransmissionCurve const > getTransmissionCurve() const
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:164
table::Key< int > id
Definition: Detector.cc:166
void setVisitInfo(std::shared_ptr< image::VisitInfo const > visitInfo)
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:162
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:82
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
std::shared_ptr< ExposureRecord > copyRecord(BaseRecord const &other, SchemaMapper const &mapper)
Deep-copy a record, requiring that it have the same schema as this table.
Definition: Exposure.h:270
std::shared_ptr< detection::Psf const > getPsf() const
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:139
static ExposureCatalogT readFits(fits::Fits &fitsfile, int flags=0)
Read a FITS binary table from a file object already at the correct extension.
Definition: Exposure.h:423
void setPhotoCalib(std::shared_ptr< image::PhotoCalib const > photoCalib)
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:143
ExposureCatalogT(ExposureCatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition: Exposure.h:364
ExposureCatalogT< Record > Catalog
Definition: Exposure.h:209
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:71
STL class.
ExposureCatalogT< ExposureRecord const > ConstCatalog
Definition: Exposure.h:84
ExposureRecord(ConstructionToken const &token, detail::RecordData &&data)
Constructor used by ExposureTable.
Definition: Exposure.h:95
A base class for image defects.
char * data
Definition: BaseRecord.cc:62
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
Definition: fwd.h:63
int contains(Schema const &other, int flags=EQUAL_KEYS) const
Test whether the given schema is a subset of this.
Definition: Schema.cc:679
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:121
int const step
std::shared_ptr< image::PhotoCalib const > getPhotoCalib() const
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:142
Iterator class for CatalogT.
Definition: Catalog.h:38
void writeFits(fits::Fits &fitsfile, std::shared_ptr< io::OutputArchive > archive, int flags=0) const
Write a FITS binary table to an open file object.
Definition: Exposure.h:381
static ExposureCatalogT readFits(std::string const &filename, int hdu=fits::DEFAULT_HDU, int flags=0)
Read a FITS binary table from a regular file.
Definition: Exposure.h:396
table::Schema schema
Definition: Camera.cc:161
static ExposureCatalogT readFits(fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU, int flags=0)
Read a FITS binary table from a RAM file.
Definition: Exposure.h:411
table::Key< int > detector
T static_pointer_cast(T... args)
static PointKey< int > getBBoxMinKey()
Key for the minimum point of the bbox.
Definition: Exposure.h:249
table::Box2IKey bbox
Definition: Detector.cc:169
T move(T... args)
void setPsf(std::shared_ptr< detection::Psf const > psf)
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:140
Key< int > apCorrMap
Definition: Exposure.cc:68
afw::table::Key< afw::table::Array< MaskPixelT > > mask
Base class for all records.
Definition: BaseRecord.h:31
static bool checkSchema(Schema const &other)
Return true if the given schema is a valid ExposureTable schema.
Definition: Exposure.h:238
Base::const_iterator const_iterator
Definition: Exposure.h:329
Point in an unspecified spherical coordinate system.
Definition: SpherePoint.h:57
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
void setWcs(std::shared_ptr< geom::SkyWcs const > wcs)
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:137
Custom catalog class for ExposureRecord/Table.
Definition: Exposure.h:67
void setTransmissionCurve(std::shared_ptr< image::TransmissionCurve const > transmissionCurve)
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:167
std::shared_ptr< image::VisitInfo const > getVisitInfo() const
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:161
std::shared_ptr< ExposureRecord > makeRecord()
Default-construct an associated record.
Definition: Exposure.h:260
std::shared_ptr< cameraGeom::Detector const > getDetector() const
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:171
Record class used to store exposure metadata.
Definition: Exposure.h:79
ItemVariant const * other
Definition: Schema.cc:56
std::shared_ptr< geom::polygon::Polygon const > getValidPolygon() const
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:158
ExposureCatalogT< ExposureRecord > ExposureCatalog
Definition: Exposure.h:499
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:31
ExposureCatalogT< ExposureRecord > Catalog
Definition: Exposure.h:83
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
static ExposureCatalogT readFits(fits::Fits &fitsfile, std::shared_ptr< io::InputArchive > archive, int flags=0)
Read a FITS binary table from a file object already at the correct extension.
Definition: Exposure.h:433
ExposureCatalogT(Schema const &schema)
Construct a vector from a schema, creating a table with Table::make(schema).
Definition: Exposure.h:340
Key< int > psf
Definition: Exposure.cc:65
An integer coordinate rectangle.
Definition: Box.h:54
ExposureCatalogT subset(std::ptrdiff_t startd, std::ptrdiff_t stopd, std::ptrdiff_t step) const
Shallow copy a subset of another ExposureCatalog.
Definition: Exposure.h:468
Base class for all tables.
Definition: BaseTable.h:61
void setCalib(std::shared_ptr< image::PhotoCalib const > photoCalib)
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:150
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
void setApCorrMap(std::shared_ptr< image::ApCorrMap const > apCorrMap)
Get/Set the the attached Wcs, Psf, PhotoCalib, or ApCorrMap. No copies are made.
Definition: Exposure.h:156
const int DEFAULT_HDU
Specify that the default HDU should be read.
Definition: fitsDefaults.h:18
static PointKey< int > getBBoxMaxKey()
Key for the maximum point of the bbox.
Definition: Exposure.h:251