lsst.afw  14.0-25-g0e8fc950e+6
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"
33 
34 namespace lsst {
35 namespace afw {
36 
37 namespace image {
38 class Wcs;
39 class Calib;
40 class ApCorrMap;
41 class VisitInfo;
42 } // namespace image
43 
44 namespace detection {
45 class Psf;
46 } // namespace detection
47 
48 namespace geom {
49 namespace polygon {
50 class Polygon;
51 }
52 }
53 
54 namespace table {
55 
56 class ExposureRecord;
57 class ExposureTable;
58 
59 template <typename RecordT>
61 
62 namespace io {
63 
64 class OutputArchiveHandle;
65 class InputArchive;
66 
67 } // namespace io
68 
72 class ExposureRecord : public BaseRecord {
73 public:
78 
80  return std::static_pointer_cast<ExposureTable const>(BaseRecord::getTable());
81  }
82 
83  RecordId getId() const;
84  void setId(RecordId id);
85 
86  geom::Box2I getBBox() const;
87  void setBBox(geom::Box2I const& bbox);
88 
99  bool contains(Coord const& coord, bool includeValidPolygon = false) const;
100 
111  bool contains(geom::Point2D const& point, image::Wcs const& wcs, bool includeValidPolygon = false) const;
112 
114  std::shared_ptr<image::Wcs const> getWcs() const { return _wcs; }
116  void setWcs(std::shared_ptr<image::Wcs const> wcs) { _wcs = wcs; }
117 
120 
123 
125  void setApCorrMap(std::shared_ptr<image::ApCorrMap const> apCorrMap) { _apCorrMap = apCorrMap; }
126 
128  void setValidPolygon(std::shared_ptr<geom::polygon::Polygon const> polygon) { _validPolygon = polygon; }
129 
133 
134 protected:
135  explicit ExposureRecord(std::shared_ptr<ExposureTable> const& table);
136 
137  virtual void _assign(BaseRecord const& other);
138 
139 private:
140  friend class ExposureTable;
141 
148 };
149 
155 class ExposureTable : public BaseTable {
156 public:
161 
167  static std::shared_ptr<ExposureTable> make(Schema const& schema);
168 
177  Schema r = getMinimalSchema().schema;
178  r.disconnectAliases();
179  return r;
180  }
181 
188  static bool checkSchema(Schema const& other) { return other.contains(getMinimalSchema().schema); }
189 
191 
196  static Key<RecordId> getIdKey() { return getMinimalSchema().id; }
199  static PointKey<int> getBBoxMinKey() { return getMinimalSchema().bboxMin; }
201  static PointKey<int> getBBoxMaxKey() { return getMinimalSchema().bboxMax; }
203 
206 
209  return std::static_pointer_cast<ExposureRecord>(_makeRecord());
210  }
211 
214  return std::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other));
215  }
216 
219  return std::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other, mapper));
220  }
221 
222 protected:
223  explicit ExposureTable(Schema const& schema);
224 
225  ExposureTable(ExposureTable const& other);
226 
227  std::shared_ptr<BaseTable> _clone() const override;
228 
229  std::shared_ptr<BaseRecord> _makeRecord() override;
230 
231 private:
232  // Struct that holds the minimal schema and the special keys we've added to it.
233  struct MinimalSchema {
234  Schema schema;
235  Key<RecordId> id;
238 
239  MinimalSchema();
240  };
241 
242  // Return the singleton minimal schema.
243  static MinimalSchema& getMinimalSchema();
244 
245  friend class io::FitsWriter;
246 
247  template <typename RecordT>
248  friend class ExposureCatalogT;
249 
250  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
251  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const override;
252 
253  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile,
255  int flags) const;
256 };
257 
264 template <typename RecordT>
265 class ExposureCatalogT : public SortedCatalogT<RecordT> {
266  typedef SortedCatalogT<RecordT> Base;
267 
268 public:
269  typedef RecordT Record;
270  typedef typename Record::Table Table;
271 
272  typedef typename Base::iterator iterator;
274 
281  explicit ExposureCatalogT(std::shared_ptr<Table> const& table = std::shared_ptr<Table>()) : Base(table) {}
282 
284  explicit ExposureCatalogT(Schema const& schema) : Base(schema) {}
285 
296  template <typename InputIterator>
297  ExposureCatalogT(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last,
298  bool deep = false)
299  : Base(table, first, last, deep) {}
300 
307  template <typename OtherRecordT>
308  ExposureCatalogT(ExposureCatalogT<OtherRecordT> const& other) : Base(other) {}
309 
310  using Base::writeFits;
311 
319  void writeFits(fits::Fits& fitsfile, std::shared_ptr<io::OutputArchive> archive, int flags = 0) const {
320  std::shared_ptr<io::FitsWriter> writer = this->getTable()->makeFitsWriter(&fitsfile, archive, flags);
321  writer->write(*this);
322  }
323 
333  static ExposureCatalogT readFits(std::string const& filename, int hdu = INT_MIN, int flags = 0) {
334  return io::FitsReader::apply<ExposureCatalogT>(filename, hdu, flags);
335  }
336 
346  static ExposureCatalogT readFits(fits::MemFileManager& manager, int hdu = INT_MIN, int flags = 0) {
347  return io::FitsReader::apply<ExposureCatalogT>(manager, hdu, flags);
348  }
349 
357  static ExposureCatalogT readFits(fits::Fits& fitsfile, int flags = 0) {
358  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags);
359  }
360 
368  int flags = 0) {
369  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags, archive);
370  }
371 
379  void writeToArchive(io::OutputArchiveHandle& handle, bool ignoreUnpersistable = true) const;
380 
387  static ExposureCatalogT readFromArchive(io::InputArchive const& archive, BaseCatalog const& catalog);
388 
394  ExposureCatalogT<RecordT> subset(ndarray::Array<bool const, 1> const& mask) const {
395  return ExposureCatalogT(Base::subset(mask));
396  }
397 
403  return ExposureCatalogT(Base::subset(startd, stopd, step));
404  }
405 
414  ExposureCatalogT subsetContaining(Coord const& coord, bool includeValidPolygon = false) const;
415 
424  ExposureCatalogT subsetContaining(geom::Point2D const& point, image::Wcs const& wcs,
425  bool includeValidPolygon = false) const;
426 
427 protected:
428  explicit ExposureCatalogT(Base const& other) : Base(other) {}
429 };
430 
434 
435 inline RecordId ExposureRecord::getId() const { return get(ExposureTable::getIdKey()); }
436 inline void ExposureRecord::setId(RecordId id) { set(ExposureTable::getIdKey(), id); }
437 }
438 }
439 } // namespace lsst::afw::table
440 
441 #endif // !AFW_TABLE_Exposure_h_INCLUDED
std::shared_ptr< ExposureTable > clone() const
Return a polymorphic deep copy of the table.
Definition: Exposure.h:205
std::shared_ptr< ExposureTable const > getTable() const
Definition: Exposure.h:79
Defines the fields and offsets for a table.
Definition: Schema.h:46
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:128
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:394
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:124
table::PointKey< int > bboxMax
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:158
ExposureCatalogT< ExposureRecord const > ConstExposureCatalog
Definition: Exposure.h:433
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:428
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:297
Table class used to store exposure metadata.
Definition: Exposure.h:155
A custom container class for records, based on std::vector.
Definition: Catalog.h:96
ColumnViewT< ExposureRecord > ExposureColumnView
Definition: Exposure.h:431
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:281
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
ExposureCatalogT< Record const > ConstCatalog
Definition: Exposure.h:160
static Schema makeMinimalSchema()
Return a minimal schema for Exposure tables and records.
Definition: Exposure.h:176
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:213
static ExposureCatalogT readFits(std::string const &filename, int hdu=INT_MIN, int flags=0)
Read a FITS binary table from a regular file.
Definition: Exposure.h:333
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:104
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:131
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:75
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:279
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:218
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:118
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:357
ExposureCatalogT(ExposureCatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition: Exposure.h:308
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:121
ExposureCatalogT< Record > Catalog
Definition: Exposure.h:159
static ExposureCatalogT readFits(fits::MemFileManager &manager, int hdu=INT_MIN, int flags=0)
Read a FITS binary table from a RAM file.
Definition: Exposure.h:346
An integer coordinate rectangle.
Definition: Box.h:55
int const step
Definition: BoundedField.cc:97
STL class.
void setWcs(std::shared_ptr< image::Wcs const > wcs)
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:116
ExposureCatalogT< ExposureRecord const > ConstCatalog
Definition: Exposure.h:77
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:101
Iterator class for CatalogT.
Definition: Catalog.h:37
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:122
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:319
T static_pointer_cast(T... args)
static PointKey< int > getBBoxMinKey()
Key for the minimum point of the bbox.
Definition: Exposure.h:199
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:119
table::PointKey< int > bboxMin
Base class for all records.
Definition: BaseRecord.h:29
static bool checkSchema(Schema const &other)
Return true if the given schema is a valid ExposureTable schema.
Definition: Exposure.h:188
Base::const_iterator const_iterator
Definition: Exposure.h:273
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
Custom catalog class for ExposureRecord/Table.
Definition: Exposure.h:60
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:130
std::shared_ptr< ExposureRecord > makeRecord()
Default-construct an associated record.
Definition: Exposure.h:208
Record class used to store exposure metadata.
Definition: Exposure.h:72
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:127
ExposureCatalogT< ExposureRecord > ExposureCatalog
Definition: Exposure.h:432
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:31
ExposureCatalogT< ExposureRecord > Catalog
Definition: Exposure.h:76
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:367
ExposureCatalogT(Schema const &schema)
Construct a vector from a schema, creating a table with Table::make(schema).
Definition: Exposure.h:284
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:402
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:125
static PointKey< int > getBBoxMaxKey()
Key for the maximum point of the bbox.
Definition: Exposure.h:201