LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
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 
147 
149  void setValidPolygon(std::shared_ptr<geom::polygon::Polygon const> polygon) { _validPolygon = polygon; }
150 
153 
155  return _transmissionCurve;
156  }
158  _transmissionCurve = std::move(transmissionCurve);
159  }
160 
163  _detector = std::move(detector);
164  }
166 
167  ExposureRecord(ExposureRecord const&) = delete;
168  ExposureRecord(ExposureRecord&&) = delete;
169  ExposureRecord& operator=(ExposureRecord const&) = delete;
170  ExposureRecord& operator=(ExposureRecord&&) = delete;
171  ~ExposureRecord() override;
172 
173 protected:
174 
175  void _assign(BaseRecord const& other) override;
176 
177 private:
178  friend class ExposureTable;
179 
188 };
189 
195 class ExposureTable : public BaseTable {
196 public:
201 
207  static std::shared_ptr<ExposureTable> make(Schema const& schema);
208 
217  Schema r = getMinimalSchema().schema;
218  r.disconnectAliases();
219  return r;
220  }
221 
228  static bool checkSchema(Schema const& other) { return other.contains(getMinimalSchema().schema); }
229 
231 
236  static Key<RecordId> getIdKey() { return getMinimalSchema().id; }
239  static PointKey<int> getBBoxMinKey() { return getMinimalSchema().bbox.getMin(); }
241  static PointKey<int> getBBoxMaxKey() { return getMinimalSchema().bbox.getMax(); }
243  static Box2IKey getBBoxKey() { return getMinimalSchema().bbox; }
245 
248 
251  return std::static_pointer_cast<ExposureRecord>(_makeRecord());
252  }
253 
256  return std::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other));
257  }
258 
261  return std::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other, mapper));
262  }
263 
264  ExposureTable& operator=(ExposureTable const&) = delete;
265  ExposureTable& operator=(ExposureTable&&) = delete;
266  ~ExposureTable() override;
267 
268 protected:
269  explicit ExposureTable(Schema const& schema);
270 
272  ExposureTable(ExposureTable&& other);
273 
274  std::shared_ptr<BaseTable> _clone() const override;
275 
276  std::shared_ptr<BaseRecord> _makeRecord() override;
277 
278 private:
279  // Struct that holds the minimal schema and the special keys we've added to it.
280  struct MinimalSchema {
281  Schema schema;
283  Box2IKey bbox;
284 
285  MinimalSchema();
286  };
287 
288  // Return the singleton minimal schema.
289  static MinimalSchema& getMinimalSchema();
290 
291  friend class io::FitsWriter;
292 
293  template <typename RecordT>
294  friend class ExposureCatalogT;
295 
296  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
297  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const override;
298 
299  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile,
301  int flags) const;
302 };
303 
310 template <typename RecordT>
311 class ExposureCatalogT : public SortedCatalogT<RecordT> {
312  typedef SortedCatalogT<RecordT> Base;
313 
314 public:
315  typedef RecordT Record;
316  typedef typename Record::Table Table;
317 
318  typedef typename Base::iterator iterator;
320 
327  explicit ExposureCatalogT(std::shared_ptr<Table> const& table = std::shared_ptr<Table>()) : Base(table) {}
328 
330  explicit ExposureCatalogT(Schema const& schema) : Base(schema) {}
331 
342  template <typename InputIterator>
343  ExposureCatalogT(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last,
344  bool deep = false)
345  : Base(table, first, last, deep) {}
346 
353  template <typename OtherRecordT>
355 
356  ExposureCatalogT(ExposureCatalogT const&) = default;
357  ExposureCatalogT(ExposureCatalogT&&) = default;
358  ExposureCatalogT& operator=(ExposureCatalogT const&) = default;
359  ExposureCatalogT& operator=(ExposureCatalogT&&) = default;
360  ~ExposureCatalogT() = default;
361 
362  using Base::writeFits;
363 
371  void writeFits(fits::Fits& fitsfile, std::shared_ptr<io::OutputArchive> archive, int flags = 0) const {
372  std::shared_ptr<io::FitsWriter> writer = this->getTable()->makeFitsWriter(&fitsfile, archive, flags);
373  writer->write(*this);
374  }
375 
386  static ExposureCatalogT readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU,
387  int flags = 0) {
388  return io::FitsReader::apply<ExposureCatalogT>(filename, hdu, flags);
389  }
390 
402  int flags = 0) {
403  return io::FitsReader::apply<ExposureCatalogT>(manager, hdu, flags);
404  }
405 
413  static ExposureCatalogT readFits(fits::Fits& fitsfile, int flags = 0) {
414  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags);
415  }
416 
424  int flags = 0) {
425  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags, archive);
426  }
427 
435  void writeToArchive(io::OutputArchiveHandle& handle, bool ignoreUnpersistable = true) const;
436 
443  static ExposureCatalogT readFromArchive(io::InputArchive const& archive, BaseCatalog const& catalog);
444 
450  ExposureCatalogT<RecordT> subset(ndarray::Array<bool const, 1> const& mask) const {
451  return ExposureCatalogT(Base::subset(mask));
452  }
453 
459  return ExposureCatalogT(Base::subset(startd, stopd, step));
460  }
461 
470  ExposureCatalogT subsetContaining(lsst::geom::SpherePoint const& coord,
471  bool includeValidPolygon = false) const;
472 
481  ExposureCatalogT subsetContaining(lsst::geom::Point2D const& point, geom::SkyWcs const& wcs,
482  bool includeValidPolygon = false) const;
483 
484 protected:
485  explicit ExposureCatalogT(Base const& other) : Base(other) {}
486 };
487 
491 
492 inline RecordId ExposureRecord::getId() const { return get(ExposureTable::getIdKey()); }
493 inline void ExposureRecord::setId(RecordId id) { set(ExposureTable::getIdKey(), id); }
494 } // namespace table
495 } // namespace afw
496 } // namespace lsst
497 
498 #endif // !AFW_TABLE_Exposure_h_INCLUDED
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
std::shared_ptr< ExposureTable > clone() const
Return a polymorphic deep copy of the table.
Definition: Exposure.h:247
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:149
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:450
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:145
Key< int > visitInfo
Definition: Exposure.cc:70
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:198
ExposureCatalogT< ExposureRecord const > ConstExposureCatalog
Definition: Exposure.h:490
afw::table::Key< afw::table::Array< MaskPixelT > > mask
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.
ExposureCatalogT(Base const &other)
Definition: Exposure.h:485
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:343
Table class used to store exposure metadata.
Definition: Exposure.h:195
ColumnViewT< ExposureRecord > ExposureColumnView
Definition: Exposure.h:488
ExposureCatalogT(std::shared_ptr< Table > const &table=std::shared_ptr< Table >())
Construct a vector from a table (or nothing).
Definition: Exposure.h:327
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:243
ExposureCatalogT< Record const > ConstCatalog
Definition: Exposure.h:200
static Schema makeMinimalSchema()
Return a minimal schema for Exposure tables and records.
Definition: Exposure.h:216
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:162
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:255
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:154
table::Key< int > id
Definition: Detector.cc:162
ItemVariant const * other
Definition: Schema.cc:56
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
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:152
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:260
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:413
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:354
ExposureCatalogT< Record > Catalog
Definition: Exposure.h:199
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
table::Schema schema
Definition: Amplifier.cc:115
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:371
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:386
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:401
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:239
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
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:228
Base::const_iterator const_iterator
Definition: Exposure.h:319
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:157
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:151
std::shared_ptr< ExposureRecord > makeRecord()
Default-construct an associated record.
Definition: Exposure.h:250
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:161
Record class used to store exposure metadata.
Definition: Exposure.h:79
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:148
ExposureCatalogT< ExposureRecord > ExposureCatalog
Definition: Exposure.h:489
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:423
ExposureCatalogT(Schema const &schema)
Construct a vector from a schema, creating a table with Table::make(schema).
Definition: Exposure.h:330
Key< int > psf
Definition: Exposure.cc:65
An integer coordinate rectangle.
Definition: Box.h:55
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:458
Base class for all tables.
Definition: BaseTable.h:61
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:146
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:241