lsst.afw  14.0-58-g91bfccb15
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/afw/geom/Box.h"
27 #include "lsst/afw/fitsDefaults.h"
34 
35 namespace lsst {
36 namespace afw {
37 
38 namespace image {
39 class Calib;
40 class ApCorrMap;
41 class VisitInfo;
42 class TransmissionCurve;
43 } // namespace image
44 
45 namespace detection {
46 class Psf;
47 } // namespace detection
48 
49 namespace geom {
50 class SkyWcs;
51 namespace polygon {
52 class Polygon;
53 }
54 }
55 
56 namespace table {
57 
58 class ExposureRecord;
59 class ExposureTable;
60 
61 template <typename RecordT>
63 
64 namespace io {
65 
66 class OutputArchiveHandle;
67 class InputArchive;
68 
69 } // namespace io
70 
74 class ExposureRecord : public BaseRecord {
75 public:
80 
82  return std::static_pointer_cast<ExposureTable const>(BaseRecord::getTable());
83  }
84 
85  RecordId getId() const;
86  void setId(RecordId id);
87 
88  geom::Box2I getBBox() const;
89  void setBBox(geom::Box2I const& bbox);
90 
101  bool contains(Coord const& coord, bool includeValidPolygon = false) const;
102 
113  bool contains(geom::Point2D const& point, geom::SkyWcs const& wcs, bool includeValidPolygon = false) const;
114 
116  std::shared_ptr<geom::SkyWcs const> getWcs() const { return _wcs; }
118  void setWcs(std::shared_ptr<geom::SkyWcs const> wcs) { _wcs = wcs; }
119 
122 
125 
127  void setApCorrMap(std::shared_ptr<image::ApCorrMap const> apCorrMap) { _apCorrMap = apCorrMap; }
128 
130  void setValidPolygon(std::shared_ptr<geom::polygon::Polygon const> polygon) { _validPolygon = polygon; }
131 
134 
137  _transmissionCurve = std::move(transmissionCurve);
138  }
140 
141  ExposureRecord(ExposureRecord const &) = delete;
142  ExposureRecord(ExposureRecord &&) = delete;
143  ExposureRecord & operator=(ExposureRecord const &) = delete;
144  ExposureRecord & operator=(ExposureRecord &&) = delete;
145  ~ExposureRecord();
146 
147 protected:
148  explicit ExposureRecord(std::shared_ptr<ExposureTable> const& table);
149 
150  virtual void _assign(BaseRecord const& other);
151 
152 private:
153  friend class ExposureTable;
154 
162 };
163 
169 class ExposureTable : public BaseTable {
170 public:
175 
181  static std::shared_ptr<ExposureTable> make(Schema const& schema);
182 
191  Schema r = getMinimalSchema().schema;
192  r.disconnectAliases();
193  return r;
194  }
195 
202  static bool checkSchema(Schema const& other) { return other.contains(getMinimalSchema().schema); }
203 
205 
210  static Key<RecordId> getIdKey() { return getMinimalSchema().id; }
213  static PointKey<int> getBBoxMinKey() { return getMinimalSchema().bbox.getMin(); }
215  static PointKey<int> getBBoxMaxKey() { return getMinimalSchema().bbox.getMax(); }
217  static Box2IKey getBBoxKey() { return getMinimalSchema().bbox; }
219 
222 
225  return std::static_pointer_cast<ExposureRecord>(_makeRecord());
226  }
227 
230  return std::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other));
231  }
232 
235  return std::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other, mapper));
236  }
237 
238  ExposureTable & operator=(ExposureTable const &) = delete;
239  ExposureTable & operator=(ExposureTable &&) = delete;
240  ~ExposureTable();
241 
242 protected:
243  explicit ExposureTable(Schema const& schema);
244 
245  ExposureTable(ExposureTable const& other);
246  ExposureTable(ExposureTable && other);
247 
248  std::shared_ptr<BaseTable> _clone() const override;
249 
250  std::shared_ptr<BaseRecord> _makeRecord() override;
251 
252 private:
253  // Struct that holds the minimal schema and the special keys we've added to it.
254  struct MinimalSchema {
255  Schema schema;
256  Key<RecordId> id;
257  Box2IKey bbox;
258 
259  MinimalSchema();
260  };
261 
262  // Return the singleton minimal schema.
263  static MinimalSchema& getMinimalSchema();
264 
265  friend class io::FitsWriter;
266 
267  template <typename RecordT>
268  friend class ExposureCatalogT;
269 
270  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
271  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const override;
272 
273  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile,
275  int flags) const;
276 };
277 
284 template <typename RecordT>
285 class ExposureCatalogT : public SortedCatalogT<RecordT> {
286  typedef SortedCatalogT<RecordT> Base;
287 
288 public:
289  typedef RecordT Record;
290  typedef typename Record::Table Table;
291 
292  typedef typename Base::iterator iterator;
294 
301  explicit ExposureCatalogT(std::shared_ptr<Table> const& table = std::shared_ptr<Table>()) : Base(table) {}
302 
304  explicit ExposureCatalogT(Schema const& schema) : Base(schema) {}
305 
316  template <typename InputIterator>
317  ExposureCatalogT(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last,
318  bool deep = false)
319  : Base(table, first, last, deep) {}
320 
327  template <typename OtherRecordT>
328  ExposureCatalogT(ExposureCatalogT<OtherRecordT> const& other) : Base(other) {}
329 
330  ExposureCatalogT(ExposureCatalogT const &) = default;
331  ExposureCatalogT(ExposureCatalogT &&) = default;
332  ExposureCatalogT & operator=(ExposureCatalogT const &) = default;
333  ExposureCatalogT & operator=(ExposureCatalogT &&) = default;
334  ~ExposureCatalogT() = default;
335 
336  using Base::writeFits;
337 
345  void writeFits(fits::Fits& fitsfile, std::shared_ptr<io::OutputArchive> archive, int flags = 0) const {
346  std::shared_ptr<io::FitsWriter> writer = this->getTable()->makeFitsWriter(&fitsfile, archive, flags);
347  writer->write(*this);
348  }
349 
360  static ExposureCatalogT readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU,
361  int flags = 0) {
362  return io::FitsReader::apply<ExposureCatalogT>(filename, hdu, flags);
363  }
364 
376  int flags = 0) {
377  return io::FitsReader::apply<ExposureCatalogT>(manager, hdu, flags);
378  }
379 
387  static ExposureCatalogT readFits(fits::Fits& fitsfile, int flags = 0) {
388  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags);
389  }
390 
398  int flags = 0) {
399  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags, archive);
400  }
401 
409  void writeToArchive(io::OutputArchiveHandle& handle, bool ignoreUnpersistable = true) const;
410 
417  static ExposureCatalogT readFromArchive(io::InputArchive const& archive, BaseCatalog const& catalog);
418 
424  ExposureCatalogT<RecordT> subset(ndarray::Array<bool const, 1> const& mask) const {
425  return ExposureCatalogT(Base::subset(mask));
426  }
427 
433  return ExposureCatalogT(Base::subset(startd, stopd, step));
434  }
435 
444  ExposureCatalogT subsetContaining(Coord const& coord, bool includeValidPolygon = false) const;
445 
454  ExposureCatalogT subsetContaining(geom::Point2D const& point, geom::SkyWcs const& wcs,
455  bool includeValidPolygon = false) const;
456 
457 protected:
458  explicit ExposureCatalogT(Base const& other) : Base(other) {}
459 };
460 
464 
465 inline RecordId ExposureRecord::getId() const { return get(ExposureTable::getIdKey()); }
466 inline void ExposureRecord::setId(RecordId id) { set(ExposureTable::getIdKey(), id); }
467 }
468 }
469 } // namespace lsst::afw::table
470 
471 #endif // !AFW_TABLE_Exposure_h_INCLUDED
std::shared_ptr< ExposureTable > clone() const
Return a polymorphic deep copy of the table.
Definition: Exposure.h:221
std::shared_ptr< ExposureTable const > getTable() const
Definition: Exposure.h:81
Defines the fields and offsets for a table.
Definition: Schema.h:47
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:130
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:424
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:114
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:126
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:172
ExposureCatalogT< ExposureRecord const > ConstExposureCatalog
Definition: Exposure.h:463
afw::table::Key< afw::table::Array< MaskPixelT > > mask
An object passed to Persistable::write to allow it to persist itself.
ExposureCatalogT(Base const &other)
Definition: Exposure.h:458
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:317
Table class used to store exposure metadata.
Definition: Exposure.h:169
A custom container class for records, based on std::vector.
Definition: Catalog.h:97
ColumnViewT< ExposureRecord > ExposureColumnView
Definition: Exposure.h:461
afw::table::Schema schema
Definition: GaussianPsf.cc:43
ExposureCatalogT(std::shared_ptr< Table > const &table=std::shared_ptr< Table >())
Construct a vector from a table (or nothing).
Definition: Exposure.h:301
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:217
ExposureCatalogT< Record const > ConstCatalog
Definition: Exposure.h:174
static Schema makeMinimalSchema()
Return a minimal schema for Exposure tables and records.
Definition: Exposure.h:190
void disconnectAliases()
Sever the connection between this schema and any others with which it shares aliases.
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:229
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:135
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:133
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:77
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:298
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:234
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:120
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:387
ExposureCatalogT(ExposureCatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition: Exposure.h:328
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:123
ExposureCatalogT< Record > Catalog
Definition: Exposure.h:173
An integer coordinate rectangle.
Definition: Box.h:55
int const step
Definition: BoundedField.cc:97
STL class.
ExposureCatalogT< ExposureRecord const > ConstCatalog
Definition: Exposure.h:79
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.
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:120
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:124
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:345
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:360
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:375
T static_pointer_cast(T... args)
static PointKey< int > getBBoxMinKey()
Key for the minimum point of the bbox.
Definition: Exposure.h:213
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:121
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:202
Base::const_iterator const_iterator
Definition: Exposure.h:293
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:118
Custom catalog class for ExposureRecord/Table.
Definition: Exposure.h:62
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:136
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:132
std::shared_ptr< ExposureRecord > makeRecord()
Default-construct an associated record.
Definition: Exposure.h:224
table::Box2IKey bbox
Record class used to store exposure metadata.
Definition: Exposure.h:74
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:129
ExposureCatalogT< ExposureRecord > ExposureCatalog
Definition: Exposure.h:462
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:31
ExposureCatalogT< ExposureRecord > Catalog
Definition: Exposure.h:78
This is the base class for spherical coordinates.
Definition: Coord.h:63
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:397
ExposureCatalogT(Schema const &schema)
Construct a vector from a schema, creating a table with Table::make(schema).
Definition: Exposure.h:304
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:432
Base class for all tables.
Definition: BaseTable.h:44
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:127
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:215