LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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 Calib;
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 
87  return std::static_pointer_cast<ExposureTable const>(BaseRecord::getTable());
88  }
89 
90  RecordId getId() const;
91  void setId(RecordId id);
92 
93  lsst::geom::Box2I getBBox() const;
94  void setBBox(lsst::geom::Box2I const& bbox);
95 
106  bool contains(lsst::geom::SpherePoint const& coord, bool includeValidPolygon = false) const;
107 
118  bool contains(lsst::geom::Point2D const& point, geom::SkyWcs const& wcs,
119  bool includeValidPolygon = false) const;
120 
122  std::shared_ptr<geom::SkyWcs const> getWcs() const { return _wcs; }
125 
128 
131 
134 
136  void setValidPolygon(std::shared_ptr<geom::polygon::Polygon const> polygon) { _validPolygon = polygon; }
137 
140 
142  return _transmissionCurve;
143  }
145  _transmissionCurve = std::move(transmissionCurve);
146  }
147 
149  return _detector;
150  }
152  _detector = std::move(detector);
153  }
155 
156  ExposureRecord(ExposureRecord const&) = delete;
157  ExposureRecord(ExposureRecord&&) = delete;
158  ExposureRecord& operator=(ExposureRecord const&) = delete;
159  ExposureRecord& operator=(ExposureRecord&&) = delete;
160  ~ExposureRecord() override;
161 
162 protected:
164 
165  void _assign(BaseRecord const& other) override;
166 
167 private:
168  friend class ExposureTable;
169 
178 };
179 
185 class ExposureTable : public BaseTable {
186 public:
191 
197  static std::shared_ptr<ExposureTable> make(Schema const& schema);
198 
207  Schema r = getMinimalSchema().schema;
208  r.disconnectAliases();
209  return r;
210  }
211 
218  static bool checkSchema(Schema const& other) { return other.contains(getMinimalSchema().schema); }
219 
221 
226  static Key<RecordId> getIdKey() { return getMinimalSchema().id; }
229  static PointKey<int> getBBoxMinKey() { return getMinimalSchema().bbox.getMin(); }
231  static PointKey<int> getBBoxMaxKey() { return getMinimalSchema().bbox.getMax(); }
233  static Box2IKey getBBoxKey() { return getMinimalSchema().bbox; }
235 
238 
241  return std::static_pointer_cast<ExposureRecord>(_makeRecord());
242  }
243 
246  return std::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other));
247  }
248 
251  return std::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other, mapper));
252  }
253 
254  ExposureTable& operator=(ExposureTable const&) = delete;
255  ExposureTable& operator=(ExposureTable&&) = delete;
256  ~ExposureTable() override;
257 
258 protected:
259  explicit ExposureTable(Schema const& schema);
260 
262  ExposureTable(ExposureTable&& other);
263 
264  std::shared_ptr<BaseTable> _clone() const override;
265 
266  std::shared_ptr<BaseRecord> _makeRecord() override;
267 
268 private:
269  // Struct that holds the minimal schema and the special keys we've added to it.
270  struct MinimalSchema {
271  Schema schema;
273  Box2IKey bbox;
274 
275  MinimalSchema();
276  };
277 
278  // Return the singleton minimal schema.
279  static MinimalSchema& getMinimalSchema();
280 
281  friend class io::FitsWriter;
282 
283  template <typename RecordT>
284  friend class ExposureCatalogT;
285 
286  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
287  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const override;
288 
289  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile,
291  int flags) const;
292 };
293 
300 template <typename RecordT>
301 class ExposureCatalogT : public SortedCatalogT<RecordT> {
302  typedef SortedCatalogT<RecordT> Base;
303 
304 public:
305  typedef RecordT Record;
306  typedef typename Record::Table Table;
307 
308  typedef typename Base::iterator iterator;
310 
317  explicit ExposureCatalogT(std::shared_ptr<Table> const& table = std::shared_ptr<Table>()) : Base(table) {}
318 
320  explicit ExposureCatalogT(Schema const& schema) : Base(schema) {}
321 
332  template <typename InputIterator>
333  ExposureCatalogT(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last,
334  bool deep = false)
335  : Base(table, first, last, deep) {}
336 
343  template <typename OtherRecordT>
345 
346  ExposureCatalogT(ExposureCatalogT const&) = default;
347  ExposureCatalogT(ExposureCatalogT&&) = default;
348  ExposureCatalogT& operator=(ExposureCatalogT const&) = default;
349  ExposureCatalogT& operator=(ExposureCatalogT&&) = default;
350  ~ExposureCatalogT() = default;
351 
352  using Base::writeFits;
353 
361  void writeFits(fits::Fits& fitsfile, std::shared_ptr<io::OutputArchive> archive, int flags = 0) const {
362  std::shared_ptr<io::FitsWriter> writer = this->getTable()->makeFitsWriter(&fitsfile, archive, flags);
363  writer->write(*this);
364  }
365 
376  static ExposureCatalogT readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU,
377  int flags = 0) {
378  return io::FitsReader::apply<ExposureCatalogT>(filename, hdu, flags);
379  }
380 
392  int flags = 0) {
393  return io::FitsReader::apply<ExposureCatalogT>(manager, hdu, flags);
394  }
395 
403  static ExposureCatalogT readFits(fits::Fits& fitsfile, int flags = 0) {
404  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags);
405  }
406 
414  int flags = 0) {
415  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags, archive);
416  }
417 
425  void writeToArchive(io::OutputArchiveHandle& handle, bool ignoreUnpersistable = true) const;
426 
433  static ExposureCatalogT readFromArchive(io::InputArchive const& archive, BaseCatalog const& catalog);
434 
440  ExposureCatalogT<RecordT> subset(ndarray::Array<bool const, 1> const& mask) const {
441  return ExposureCatalogT(Base::subset(mask));
442  }
443 
449  return ExposureCatalogT(Base::subset(startd, stopd, step));
450  }
451 
460  ExposureCatalogT subsetContaining(lsst::geom::SpherePoint const& coord,
461  bool includeValidPolygon = false) const;
462 
471  ExposureCatalogT subsetContaining(lsst::geom::Point2D const& point, geom::SkyWcs const& wcs,
472  bool includeValidPolygon = false) const;
473 
474 protected:
475  explicit ExposureCatalogT(Base const& other) : Base(other) {}
476 };
477 
481 
482 inline RecordId ExposureRecord::getId() const { return get(ExposureTable::getIdKey()); }
483 inline void ExposureRecord::setId(RecordId id) { set(ExposureTable::getIdKey(), id); }
484 } // namespace table
485 } // namespace afw
486 } // namespace lsst
487 
488 #endif // !AFW_TABLE_Exposure_h_INCLUDED
std::shared_ptr< ExposureTable > clone() const
Return a polymorphic deep copy of the table.
Definition: Exposure.h:237
std::shared_ptr< ExposureTable const > getTable() const
Definition: Exposure.h:86
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, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:136
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:440
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:115
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, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:132
Key< int > visitInfo
Definition: Exposure.cc:68
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:188
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
ExposureCatalogT< ExposureRecord const > ConstExposureCatalog
Definition: Exposure.h:480
An object passed to Persistable::write to allow it to persist itself.
ExposureCatalogT(Base const &other)
Definition: Exposure.h:475
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:333
Table class used to store exposure metadata.
Definition: Exposure.h:185
ColumnViewT< ExposureRecord > ExposureColumnView
Definition: Exposure.h:478
ExposureCatalogT(std::shared_ptr< Table > const &table=std::shared_ptr< Table >())
Construct a vector from a table (or nothing).
Definition: Exposure.h:317
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:233
ExposureCatalogT< Record const > ConstCatalog
Definition: Exposure.h:190
static Schema makeMinimalSchema()
Return a minimal schema for Exposure tables and records.
Definition: Exposure.h:206
void disconnectAliases()
Sever the connection between this schema and any others with which it shares aliases.
Definition: Schema.cc:729
void setDetector(std::shared_ptr< cameraGeom::Detector const > detector)
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:151
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:245
std::shared_ptr< image::TransmissionCurve const > getTransmissionCurve() const
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:141
table::Key< int > id
Definition: Detector.cc:163
void setVisitInfo(std::shared_ptr< image::VisitInfo const > visitInfo)
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:139
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:296
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:250
std::shared_ptr< detection::Psf const > getPsf() const
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:126
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:403
STL class.
ExposureCatalogT(ExposureCatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition: Exposure.h:344
std::shared_ptr< image::Calib const > getCalib() const
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:129
ExposureCatalogT< Record > Catalog
Definition: Exposure.h:189
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:71
STL class.
ExposureCatalogT< ExposureRecord const > ConstCatalog
Definition: Exposure.h:84
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.
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:120
int const step
Iterator class for CatalogT.
Definition: Catalog.h:38
void setCalib(std::shared_ptr< image::Calib const > calib)
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:130
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:361
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:376
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:391
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:229
table::Box2IKey bbox
Definition: Detector.cc:166
T move(T... args)
void setPsf(std::shared_ptr< detection::Psf const > psf)
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:127
Key< int > calib
Definition: Exposure.cc:65
Key< int > apCorrMap
Definition: Exposure.cc:66
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:218
Base::const_iterator const_iterator
Definition: Exposure.h:309
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, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:124
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, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:144
std::shared_ptr< image::VisitInfo const > getVisitInfo() const
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:138
std::shared_ptr< ExposureRecord > makeRecord()
Default-construct an associated record.
Definition: Exposure.h:240
std::shared_ptr< cameraGeom::Detector const > getDetector() const
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:148
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, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:135
ExposureCatalogT< ExposureRecord > ExposureCatalog
Definition: Exposure.h:479
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:31
ExposureCatalogT< ExposureRecord > Catalog
Definition: Exposure.h:83
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:413
ExposureCatalogT(Schema const &schema)
Construct a vector from a schema, creating a table with Table::make(schema).
Definition: Exposure.h:320
Key< int > psf
Definition: Exposure.cc:64
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:448
Base class for all tables.
Definition: BaseTable.h:44
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
void setApCorrMap(std::shared_ptr< image::ApCorrMap const > apCorrMap)
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:133
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:231