lsst.afw  16.0-43-gaa65a4573+2
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 table {
58 
59 class ExposureRecord;
60 class ExposureTable;
61 
62 template <typename RecordT>
64 
65 namespace io {
66 
67 class OutputArchiveHandle;
68 class InputArchive;
69 
70 } // namespace io
71 
75 class ExposureRecord : public BaseRecord {
76 public:
81 
83  return std::static_pointer_cast<ExposureTable const>(BaseRecord::getTable());
84  }
85 
86  RecordId getId() const;
87  void setId(RecordId id);
88 
89  lsst::geom::Box2I getBBox() const;
90  void setBBox(lsst::geom::Box2I const& bbox);
91 
102  bool contains(lsst::geom::SpherePoint const& coord, bool includeValidPolygon = false) const;
103 
114  bool contains(lsst::geom::Point2D const& point, geom::SkyWcs const& wcs,
115  bool includeValidPolygon = false) const;
116 
118  std::shared_ptr<geom::SkyWcs const> getWcs() const { return _wcs; }
121 
124 
127 
130 
132  void setValidPolygon(std::shared_ptr<geom::polygon::Polygon const> polygon) { _validPolygon = polygon; }
133 
136 
138  return _transmissionCurve;
139  }
141  _transmissionCurve = std::move(transmissionCurve);
142  }
144 
145  ExposureRecord(ExposureRecord const&) = delete;
146  ExposureRecord(ExposureRecord&&) = delete;
147  ExposureRecord& operator=(ExposureRecord const&) = delete;
148  ExposureRecord& operator=(ExposureRecord&&) = delete;
149  ~ExposureRecord() override;
150 
151 protected:
152  explicit ExposureRecord(std::shared_ptr<ExposureTable> const& table);
153 
154  void _assign(BaseRecord const& other) override;
155 
156 private:
157  friend class ExposureTable;
158 
166 };
167 
173 class ExposureTable : public BaseTable {
174 public:
179 
185  static std::shared_ptr<ExposureTable> make(Schema const& schema);
186 
195  Schema r = getMinimalSchema().schema;
196  r.disconnectAliases();
197  return r;
198  }
199 
206  static bool checkSchema(Schema const& other) { return other.contains(getMinimalSchema().schema); }
207 
209 
214  static Key<RecordId> getIdKey() { return getMinimalSchema().id; }
217  static PointKey<int> getBBoxMinKey() { return getMinimalSchema().bbox.getMin(); }
219  static PointKey<int> getBBoxMaxKey() { return getMinimalSchema().bbox.getMax(); }
221  static Box2IKey getBBoxKey() { return getMinimalSchema().bbox; }
223 
226 
229  return std::static_pointer_cast<ExposureRecord>(_makeRecord());
230  }
231 
234  return std::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other));
235  }
236 
239  return std::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other, mapper));
240  }
241 
242  ExposureTable& operator=(ExposureTable const&) = delete;
243  ExposureTable& operator=(ExposureTable&&) = delete;
244  ~ExposureTable() override;
245 
246 protected:
247  explicit ExposureTable(Schema const& schema);
248 
250  ExposureTable(ExposureTable&& other);
251 
252  std::shared_ptr<BaseTable> _clone() const override;
253 
254  std::shared_ptr<BaseRecord> _makeRecord() override;
255 
256 private:
257  // Struct that holds the minimal schema and the special keys we've added to it.
258  struct MinimalSchema {
259  Schema schema;
260  Key<RecordId> id;
261  Box2IKey bbox;
262 
263  MinimalSchema();
264  };
265 
266  // Return the singleton minimal schema.
267  static MinimalSchema& getMinimalSchema();
268 
269  friend class io::FitsWriter;
270 
271  template <typename RecordT>
272  friend class ExposureCatalogT;
273 
274  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
275  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const override;
276 
277  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile,
279  int flags) const;
280 };
281 
288 template <typename RecordT>
289 class ExposureCatalogT : public SortedCatalogT<RecordT> {
290  typedef SortedCatalogT<RecordT> Base;
291 
292 public:
293  typedef RecordT Record;
294  typedef typename Record::Table Table;
295 
296  typedef typename Base::iterator iterator;
298 
305  explicit ExposureCatalogT(std::shared_ptr<Table> const& table = std::shared_ptr<Table>()) : Base(table) {}
306 
308  explicit ExposureCatalogT(Schema const& schema) : Base(schema) {}
309 
320  template <typename InputIterator>
321  ExposureCatalogT(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last,
322  bool deep = false)
323  : Base(table, first, last, deep) {}
324 
331  template <typename OtherRecordT>
333 
334  ExposureCatalogT(ExposureCatalogT const&) = default;
335  ExposureCatalogT(ExposureCatalogT&&) = default;
336  ExposureCatalogT& operator=(ExposureCatalogT const&) = default;
337  ExposureCatalogT& operator=(ExposureCatalogT&&) = default;
338  ~ExposureCatalogT() = default;
339 
340  using Base::writeFits;
341 
349  void writeFits(fits::Fits& fitsfile, std::shared_ptr<io::OutputArchive> archive, int flags = 0) const {
350  std::shared_ptr<io::FitsWriter> writer = this->getTable()->makeFitsWriter(&fitsfile, archive, flags);
351  writer->write(*this);
352  }
353 
364  static ExposureCatalogT readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU,
365  int flags = 0) {
366  return io::FitsReader::apply<ExposureCatalogT>(filename, hdu, flags);
367  }
368 
380  int flags = 0) {
381  return io::FitsReader::apply<ExposureCatalogT>(manager, hdu, flags);
382  }
383 
391  static ExposureCatalogT readFits(fits::Fits& fitsfile, int flags = 0) {
392  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags);
393  }
394 
402  int flags = 0) {
403  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags, archive);
404  }
405 
413  void writeToArchive(io::OutputArchiveHandle& handle, bool ignoreUnpersistable = true) const;
414 
421  static ExposureCatalogT readFromArchive(io::InputArchive const& archive, BaseCatalog const& catalog);
422 
428  ExposureCatalogT<RecordT> subset(ndarray::Array<bool const, 1> const& mask) const {
429  return ExposureCatalogT(Base::subset(mask));
430  }
431 
437  return ExposureCatalogT(Base::subset(startd, stopd, step));
438  }
439 
448  ExposureCatalogT subsetContaining(lsst::geom::SpherePoint const& coord,
449  bool includeValidPolygon = false) const;
450 
459  ExposureCatalogT subsetContaining(lsst::geom::Point2D const& point, geom::SkyWcs const& wcs,
460  bool includeValidPolygon = false) const;
461 
462 protected:
463  explicit ExposureCatalogT(Base const& other) : Base(other) {}
464 };
465 
469 
470 inline RecordId ExposureRecord::getId() const { return get(ExposureTable::getIdKey()); }
471 inline void ExposureRecord::setId(RecordId id) { set(ExposureTable::getIdKey(), id); }
472 } // namespace table
473 } // namespace afw
474 } // namespace lsst
475 
476 #endif // !AFW_TABLE_Exposure_h_INCLUDED
std::shared_ptr< ExposureTable > clone() const
Return a polymorphic deep copy of the table.
Definition: Exposure.h:225
std::shared_ptr< ExposureTable const > getTable() const
Definition: Exposure.h:82
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:132
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:428
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:128
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:176
ExposureCatalogT< ExposureRecord const > ConstExposureCatalog
Definition: Exposure.h:468
Key< int > calib
Definition: Exposure.cc:63
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:463
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:321
Table class used to store exposure metadata.
Definition: Exposure.h:173
ColumnViewT< ExposureRecord > ExposureColumnView
Definition: Exposure.h:466
afw::table::Schema schema
Definition: GaussianPsf.cc:48
ExposureCatalogT(std::shared_ptr< Table > const &table=std::shared_ptr< Table >())
Construct a vector from a table (or nothing).
Definition: Exposure.h:305
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:221
ExposureCatalogT< Record const > ConstCatalog
Definition: Exposure.h:178
static Schema makeMinimalSchema()
Return a minimal schema for Exposure tables and records.
Definition: Exposure.h:194
void disconnectAliases()
Sever the connection between this schema and any others with which it shares aliases.
Definition: Schema.cc:720
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:233
Key< int > apCorrMap
Definition: Exposure.cc:64
Key< int > psf
Definition: Exposure.cc:62
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:137
ItemVariant const * other
Definition: Schema.cc:55
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
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:135
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:78
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:238
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:122
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:391
ExposureCatalogT(ExposureCatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition: Exposure.h:332
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:125
ExposureCatalogT< Record > Catalog
Definition: Exposure.h:177
int const step
STL class.
ExposureCatalogT< ExposureRecord const > ConstCatalog
Definition: Exposure.h:80
table::Key< table::Array< std::uint8_t > > wcs
Definition: SkyWcs.cc:71
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:678
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:126
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:349
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:364
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:379
T static_pointer_cast(T... args)
static PointKey< int > getBBoxMinKey()
Key for the minimum point of the bbox.
Definition: Exposure.h:217
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:123
Key< int > visitInfo
Definition: Exposure.cc:66
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:206
Base::const_iterator const_iterator
Definition: Exposure.h:297
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:120
Custom catalog class for ExposureRecord/Table.
Definition: Exposure.h:63
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:140
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:134
std::shared_ptr< ExposureRecord > makeRecord()
Default-construct an associated record.
Definition: Exposure.h:228
table::Box2IKey bbox
Record class used to store exposure metadata.
Definition: Exposure.h:75
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:131
ExposureCatalogT< ExposureRecord > ExposureCatalog
Definition: Exposure.h:467
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:31
ExposureCatalogT< ExposureRecord > Catalog
Definition: Exposure.h:79
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:401
ExposureCatalogT(Schema const &schema)
Construct a vector from a schema, creating a table with Table::make(schema).
Definition: Exposure.h:308
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:436
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:129
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:219