lsst.afw  14.0-32-gbc0f584f6
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 Wcs;
40 class Calib;
41 class ApCorrMap;
42 class VisitInfo;
43 } // namespace image
44 
45 namespace detection {
46 class Psf;
47 } // namespace detection
48 
49 namespace geom {
50 namespace polygon {
51 class Polygon;
52 }
53 }
54 
55 namespace table {
56 
57 class ExposureRecord;
58 class ExposureTable;
59 
60 template <typename RecordT>
62 
63 namespace io {
64 
65 class OutputArchiveHandle;
66 class InputArchive;
67 
68 } // namespace io
69 
73 class ExposureRecord : public BaseRecord {
74 public:
79 
81  return std::static_pointer_cast<ExposureTable const>(BaseRecord::getTable());
82  }
83 
84  RecordId getId() const;
85  void setId(RecordId id);
86 
87  geom::Box2I getBBox() const;
88  void setBBox(geom::Box2I const& bbox);
89 
100  bool contains(Coord const& coord, bool includeValidPolygon = false) const;
101 
112  bool contains(geom::Point2D const& point, image::Wcs const& wcs, bool includeValidPolygon = false) const;
113 
115  std::shared_ptr<image::Wcs const> getWcs() const { return _wcs; }
117  void setWcs(std::shared_ptr<image::Wcs const> wcs) { _wcs = wcs; }
118 
121 
124 
126  void setApCorrMap(std::shared_ptr<image::ApCorrMap const> apCorrMap) { _apCorrMap = apCorrMap; }
127 
129  void setValidPolygon(std::shared_ptr<geom::polygon::Polygon const> polygon) { _validPolygon = polygon; }
130 
134 
135 protected:
136  explicit ExposureRecord(std::shared_ptr<ExposureTable> const& table);
137 
138  virtual void _assign(BaseRecord const& other);
139 
140 private:
141  friend class ExposureTable;
142 
149 };
150 
156 class ExposureTable : public BaseTable {
157 public:
162 
168  static std::shared_ptr<ExposureTable> make(Schema const& schema);
169 
178  Schema r = getMinimalSchema().schema;
179  r.disconnectAliases();
180  return r;
181  }
182 
189  static bool checkSchema(Schema const& other) { return other.contains(getMinimalSchema().schema); }
190 
192 
197  static Key<RecordId> getIdKey() { return getMinimalSchema().id; }
200  static PointKey<int> getBBoxMinKey() { return getMinimalSchema().bboxMin; }
202  static PointKey<int> getBBoxMaxKey() { return getMinimalSchema().bboxMax; }
204 
207 
210  return std::static_pointer_cast<ExposureRecord>(_makeRecord());
211  }
212 
215  return std::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other));
216  }
217 
220  return std::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other, mapper));
221  }
222 
223 protected:
224  explicit ExposureTable(Schema const& schema);
225 
226  ExposureTable(ExposureTable const& other);
227 
228  std::shared_ptr<BaseTable> _clone() const override;
229 
230  std::shared_ptr<BaseRecord> _makeRecord() override;
231 
232 private:
233  // Struct that holds the minimal schema and the special keys we've added to it.
234  struct MinimalSchema {
235  Schema schema;
236  Key<RecordId> id;
239 
240  MinimalSchema();
241  };
242 
243  // Return the singleton minimal schema.
244  static MinimalSchema& getMinimalSchema();
245 
246  friend class io::FitsWriter;
247 
248  template <typename RecordT>
249  friend class ExposureCatalogT;
250 
251  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
252  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const override;
253 
254  std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile,
256  int flags) const;
257 };
258 
265 template <typename RecordT>
266 class ExposureCatalogT : public SortedCatalogT<RecordT> {
267  typedef SortedCatalogT<RecordT> Base;
268 
269 public:
270  typedef RecordT Record;
271  typedef typename Record::Table Table;
272 
273  typedef typename Base::iterator iterator;
275 
282  explicit ExposureCatalogT(std::shared_ptr<Table> const& table = std::shared_ptr<Table>()) : Base(table) {}
283 
285  explicit ExposureCatalogT(Schema const& schema) : Base(schema) {}
286 
297  template <typename InputIterator>
298  ExposureCatalogT(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last,
299  bool deep = false)
300  : Base(table, first, last, deep) {}
301 
308  template <typename OtherRecordT>
309  ExposureCatalogT(ExposureCatalogT<OtherRecordT> const& other) : Base(other) {}
310 
311  using Base::writeFits;
312 
320  void writeFits(fits::Fits& fitsfile, std::shared_ptr<io::OutputArchive> archive, int flags = 0) const {
321  std::shared_ptr<io::FitsWriter> writer = this->getTable()->makeFitsWriter(&fitsfile, archive, flags);
322  writer->write(*this);
323  }
324 
335  static ExposureCatalogT readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU,
336  int flags = 0) {
337  return io::FitsReader::apply<ExposureCatalogT>(filename, hdu, flags);
338  }
339 
351  int flags = 0) {
352  return io::FitsReader::apply<ExposureCatalogT>(manager, hdu, flags);
353  }
354 
362  static ExposureCatalogT readFits(fits::Fits& fitsfile, int flags = 0) {
363  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags);
364  }
365 
373  int flags = 0) {
374  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags, archive);
375  }
376 
384  void writeToArchive(io::OutputArchiveHandle& handle, bool ignoreUnpersistable = true) const;
385 
392  static ExposureCatalogT readFromArchive(io::InputArchive const& archive, BaseCatalog const& catalog);
393 
399  ExposureCatalogT<RecordT> subset(ndarray::Array<bool const, 1> const& mask) const {
400  return ExposureCatalogT(Base::subset(mask));
401  }
402 
408  return ExposureCatalogT(Base::subset(startd, stopd, step));
409  }
410 
419  ExposureCatalogT subsetContaining(Coord const& coord, bool includeValidPolygon = false) const;
420 
429  ExposureCatalogT subsetContaining(geom::Point2D const& point, image::Wcs const& wcs,
430  bool includeValidPolygon = false) const;
431 
432 protected:
433  explicit ExposureCatalogT(Base const& other) : Base(other) {}
434 };
435 
439 
440 inline RecordId ExposureRecord::getId() const { return get(ExposureTable::getIdKey()); }
441 inline void ExposureRecord::setId(RecordId id) { set(ExposureTable::getIdKey(), id); }
442 }
443 }
444 } // namespace lsst::afw::table
445 
446 #endif // !AFW_TABLE_Exposure_h_INCLUDED
std::shared_ptr< ExposureTable > clone() const
Return a polymorphic deep copy of the table.
Definition: Exposure.h:206
std::shared_ptr< ExposureTable const > getTable() const
Definition: Exposure.h:80
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:129
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:399
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:125
table::PointKey< int > bboxMax
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:159
ExposureCatalogT< ExposureRecord const > ConstExposureCatalog
Definition: Exposure.h:438
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:433
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:298
Table class used to store exposure metadata.
Definition: Exposure.h:156
A custom container class for records, based on std::vector.
Definition: Catalog.h:97
ColumnViewT< ExposureRecord > ExposureColumnView
Definition: Exposure.h:436
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:282
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:161
static Schema makeMinimalSchema()
Return a minimal schema for Exposure tables and records.
Definition: Exposure.h:177
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:214
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:132
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:76
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:280
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:219
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:119
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:362
ExposureCatalogT(ExposureCatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition: Exposure.h:309
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:122
ExposureCatalogT< Record > Catalog
Definition: Exposure.h:160
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:117
ExposureCatalogT< ExposureRecord const > ConstCatalog
Definition: Exposure.h:78
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:102
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:123
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:320
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:335
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:350
T static_pointer_cast(T... args)
static PointKey< int > getBBoxMinKey()
Key for the minimum point of the bbox.
Definition: Exposure.h:200
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:120
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:189
Base::const_iterator const_iterator
Definition: Exposure.h:274
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:61
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:131
std::shared_ptr< ExposureRecord > makeRecord()
Default-construct an associated record.
Definition: Exposure.h:209
Record class used to store exposure metadata.
Definition: Exposure.h:73
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:128
ExposureCatalogT< ExposureRecord > ExposureCatalog
Definition: Exposure.h:437
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:31
ExposureCatalogT< ExposureRecord > Catalog
Definition: Exposure.h:77
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:372
ExposureCatalogT(Schema const &schema)
Construct a vector from a schema, creating a table with Table::make(schema).
Definition: Exposure.h:285
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:407
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:126
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:202