LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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/afw/geom/Box.h"
33 
34 namespace lsst { namespace afw {
35 
36 namespace image {
37 class Wcs;
38 class Calib;
39 class ApCorrMap;
40 } // namespace image
41 
42 namespace detection {
43 class Psf;
44 } // namespace detection
45 
46 namespace geom { namespace polygon {
47 class Polygon;
48 }}
49 
50 namespace table {
51 
52 class ExposureRecord;
53 class ExposureTable;
54 
55 template <typename RecordT> class ExposureCatalogT;
56 
57 namespace io {
58 
60 class InputArchive;
61 
62 } // namespace io
63 
67 class ExposureRecord : public BaseRecord {
68 public:
69 
74 
76  return boost::static_pointer_cast<ExposureTable const>(BaseRecord::getTable());
77  }
78 
79  RecordId getId() const;
80  void setId(RecordId id);
81 
82  geom::Box2I getBBox() const;
83  void setBBox(geom::Box2I const & bbox);
84 
93  bool contains(Coord const & coord, bool includeValidPolygon=false) const;
94 
103  bool contains(geom::Point2D const & point, image::Wcs const & wcs, bool includeValidPolygon=false) const;
104 
106  CONST_PTR(image::Wcs) getWcs() const { return _wcs; }
109 
110  CONST_PTR(detection::Psf) getPsf() const { return _psf; }
111  void setPsf(CONST_PTR(detection::Psf) psf) { _psf = psf; }
112 
113  CONST_PTR(image::Calib) getCalib() const { return _calib; }
114  void setCalib(CONST_PTR(image::Calib) calib) { _calib = calib; }
115 
117  void setApCorrMap(CONST_PTR(image::ApCorrMap) apCorrMap) { _apCorrMap = apCorrMap; }
118 
122 
123 protected:
124 
126 
127  virtual void _assign(BaseRecord const & other);
128 
129 private:
131  CONST_PTR(detection::Psf) _psf;
134  CONST_PTR(geom::polygon::Polygon) _validPolygon;
135 };
136 
142 class ExposureTable : public BaseTable {
143 public:
144 
149 
155  static PTR(ExposureTable) make(Schema const & schema);
156 
164  static Schema makeMinimalSchema() {
165  Schema r = getMinimalSchema().schema;
166  r.disconnectAliases();
167  return r;
168  }
169 
176  static bool checkSchema(Schema const & other) {
177  return other.contains(getMinimalSchema().schema);
178  }
179 
181 
186  static Key<RecordId> getIdKey() { return getMinimalSchema().id; }
189  static PointKey<int> getBBoxMinKey() { return getMinimalSchema().bboxMin; }
191  static PointKey<int> getBBoxMaxKey() { return getMinimalSchema().bboxMax; }
193 
195  PTR(ExposureTable) clone() const { return boost::static_pointer_cast<ExposureTable>(_clone()); }
196 
198  PTR(ExposureRecord) makeRecord() { return boost::static_pointer_cast<ExposureRecord>(_makeRecord()); }
199 
201  PTR(ExposureRecord) copyRecord(BaseRecord const & other) {
202  return boost::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other));
203  }
204 
206  PTR(ExposureRecord) copyRecord(BaseRecord const & other, SchemaMapper const & mapper) {
207  return boost::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other, mapper));
208  }
209 
210 protected:
211 
212  ExposureTable(Schema const & schema);
213 
214  ExposureTable(ExposureTable const & other);
215 
216 private:
217 
218  // Struct that holds the minimal schema and the special keys we've added to it.
219  struct MinimalSchema {
224 
225  MinimalSchema();
226  };
227 
228  // Return the singleton minimal schema.
229  static MinimalSchema & getMinimalSchema();
230 
231  friend class io::FitsWriter;
232 
233  template <typename RecordT> friend class ExposureCatalogT;
234 
235  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
236  virtual PTR(io::FitsWriter) makeFitsWriter(fits::Fits * fitsfile, int flags) const;
237  PTR(io::FitsWriter) makeFitsWriter(
238  fits::Fits * fitsfile, PTR(io::OutputArchive) archive, int flags
239  ) const;
240 };
241 
242 #ifndef SWIG
243 
250 template <typename RecordT>
251 class ExposureCatalogT : public SortedCatalogT<RecordT> {
253 public:
254 
255  typedef RecordT Record;
256  typedef typename Record::Table Table;
257 
258  typedef typename Base::iterator iterator;
260 
267  explicit ExposureCatalogT(PTR(Table) const & table = PTR(Table)()) : Base(table) {}
268 
270  explicit ExposureCatalogT(Schema const & schema) : Base(schema) {}
271 
282  template <typename InputIterator>
283  ExposureCatalogT(PTR(Table) const & table, InputIterator first, InputIterator last, bool deep=false) :
284  Base(table, first, last, deep)
285  {}
286 
293  template <typename OtherRecordT>
295 
296  using Base::writeFits;
297 
305  void writeFits(fits::Fits & fitsfile, PTR(io::OutputArchive) archive, int flags=0) const {
306  PTR(io::FitsWriter) writer = this->getTable()->makeFitsWriter(&fitsfile, archive, flags);
307  writer->write(*this);
308  }
309 
319  static ExposureCatalogT readFits(std::string const & filename, int hdu=0, int flags=0) {
320  return io::FitsReader::apply<ExposureCatalogT>(filename, hdu, flags);
321  }
322 
332  static ExposureCatalogT readFits(fits::MemFileManager & manager, int hdu=0, int flags=0) {
333  return io::FitsReader::apply<ExposureCatalogT>(manager, hdu, flags);
334  }
335 
343  static ExposureCatalogT readFits(fits::Fits & fitsfile, int flags=0) {
344  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags);
345  }
346 
353  static ExposureCatalogT readFits(fits::Fits & fitsfile, PTR(io::InputArchive) archive, int flags=0) {
354  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags, archive);
355  }
356 
364  void writeToArchive(io::OutputArchiveHandle & handle, bool ignoreUnpersistable=true) const;
365 
372  static ExposureCatalogT readFromArchive(io::InputArchive const & archive, BaseCatalog const & catalog);
373 
380  return ExposureCatalogT(Base::subset(mask));
381  }
382 
387  ExposureCatalogT subset(std::ptrdiff_t startd, std::ptrdiff_t stopd, std::ptrdiff_t step) const {
388  return ExposureCatalogT(Base::subset(startd, stopd, step));
389  }
390 
398  ExposureCatalogT subsetContaining(Coord const & coord, bool includeValidPolygon=false) const;
399 
407  ExposureCatalogT subsetContaining(geom::Point2D const & point, image::Wcs const & wcs,
408  bool includeValidPolygon=false) const;
409 
410 protected:
411  explicit ExposureCatalogT(Base const & other) : Base(other) {}
412 };
413 
417 
418 inline RecordId ExposureRecord::getId() const { return get(ExposureTable::getIdKey()); }
420 
421 #endif // !SWIG
422 
423 }}} // namespace lsst::afw::table
424 
425 #endif // !AFW_TABLE_Exposure_h_INCLUDED
Defines the fields and offsets for a table.
Definition: Schema.h:46
boost::shared_ptr< BaseRecord > copyRecord(BaseRecord const &input)
Deep-copy a record, requiring that it have the same schema as this table.
ExposureRecord(boost::shared_ptr< ExposureTable > const &table)
void writeFits(fits::Fits &fitsfile, boost::shared_ptr< io::OutputArchive > archive, int flags=0) const
Write a FITS binary table to an open file object.
Definition: Exposure.h:305
Writer object for FITS binary tables.
Definition: FitsWriter.h:22
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:146
ExposureCatalogT< ExposureRecord const > ConstExposureCatalog
Definition: Exposure.h:416
SortedCatalogT< RecordT > Base
Definition: Exposure.h:252
An object passed to Persistable::write to allow it to persist itself.
ExposureCatalogT(Base const &other)
Definition: Exposure.h:411
static ExposureCatalogT readFits(std::string const &filename, int hdu=0, int flags=0)
Read a FITS binary table from a regular file.
Definition: Exposure.h:319
void setBBox(geom::Box2I const &bbox)
Table class used to store exposure metadata.
Definition: Exposure.h:142
A custom container class for records, based on std::vector.
Definition: Catalog.h:94
ColumnViewT< ExposureRecord > ExposureColumnView
Definition: Exposure.h:414
afw::table::Schema schema
Definition: GaussianPsf.cc:41
A thin wrapper around std::map to allow aperture corrections to be attached to Exposures.
Definition: ApCorrMap.h:42
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:19
ExposureCatalogT(boost::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:283
boost::shared_ptr< ExposureTable const > getTable() const
Definition: Exposure.h:75
ExposureCatalogT< Record const > ConstCatalog
Definition: Exposure.h:148
void disconnectAliases()
Sever the connection between this schema and any others with which it shares aliases.
#define PTR(...)
Definition: base.h:41
boost::shared_ptr< detection::Psf const > getPsf() const
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:110
tbl::Key< int > wcs
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:71
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:194
void setApCorrMap(boost::shared_ptr< image::ApCorrMap const > apCorrMap)
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:117
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:343
ExposureCatalogT(ExposureCatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition: Exposure.h:294
ExposureCatalogT< Record > Catalog
Definition: Exposure.h:147
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:379
An integer coordinate rectangle.
Definition: Box.h:53
std::map< Citizen const *, CitizenInfo > table
Definition: Citizen.h:93
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
A multi-catalog archive object used to save table::io::Persistable objects.
Definition: OutputArchive.h:33
ExposureCatalogT< ExposureRecord const > ConstCatalog
Definition: Exposure.h:73
bool contains(Coord const &coord, bool includeValidPolygon=false) const
Return true if the bounding box contains the given celestial coordinate point, taking into account th...
geom::Box2I getBBox() const
boost::shared_ptr< BaseTable const > getTable() const
Return the table this record is associated with.
Definition: BaseRecord.h:51
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:55
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:106
ExposureCatalogT(boost::shared_ptr< Table > const &table=boost::shared_ptr< Table >())
Construct a vector from a table (or nothing).
Definition: Exposure.h:267
Iterator class for CatalogT.
Definition: Catalog.h:34
void setWcs(boost::shared_ptr< image::Wcs const > wcs)
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:108
static PointKey< int > getBBoxMinKey()
Key for the minimum point of the bbox.
Definition: Exposure.h:189
static Key< RecordId > getIdKey()
Key for the unique ID.
Definition: Exposure.h:187
static ExposureCatalogT readFits(fits::Fits &fitsfile, boost::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:353
boost::shared_ptr< image::Wcs const > _wcs
Definition: Exposure.h:130
boost::shared_ptr< image::Wcs const > getWcs() const
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:107
A multidimensional strided array.
Definition: Array.h:47
Base class for all records.
Definition: BaseRecord.h:27
static bool checkSchema(Schema const &other)
Return true if the given schema is a valid ExposureTable schema.
Definition: Exposure.h:176
Base::const_iterator const_iterator
Definition: Exposure.h:259
ExposureCatalogT subset(std::ptrdiff_t startd, std::ptrdiff_t stopd, std::ptrdiff_t step) const
Shallow copy a subset of another ExposureCatalog. Mostly here for use from python.
Definition: Exposure.h:387
Record::Table Table
Definition: Catalog.h:99
int contains(Schema const &other, int flags=EQUAL_KEYS) const
Test whether the given schema is a subset of this.
boost::shared_ptr< image::Calib const > getCalib() const
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:113
Custom catalog class for ExposureRecord/Table.
Definition: Exposure.h:55
boost::shared_ptr< image::ApCorrMap const > getApCorrMap() const
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:116
void setValidPolygon(boost::shared_ptr< geom::polygon::Polygon const > polygon)
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:120
#define CONST_PTR(...)
Definition: base.h:47
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:136
Record class used to store exposure metadata.
Definition: Exposure.h:67
void setCalib(boost::shared_ptr< image::Calib const > calib)
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:114
ExposureCatalogT< ExposureRecord > ExposureCatalog
Definition: Exposure.h:415
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:28
ExposureCatalogT< ExposureRecord > Catalog
Definition: Exposure.h:72
boost::shared_ptr< image::ApCorrMap const > _apCorrMap
Definition: Exposure.h:133
static ExposureCatalogT readFits(fits::MemFileManager &manager, int hdu=0, int flags=0)
Read a FITS binary table from a RAM file.
Definition: Exposure.h:332
A polymorphic base class for representing an image&#39;s Point Spread Function.
Definition: Psf.h:68
void setPsf(boost::shared_ptr< detection::Psf const > psf)
Get/Set the the attached Wcs, Psf, Calib, or ApCorrMap. No copies are made.
Definition: Exposure.h:111
ExposureCatalogT(Schema const &schema)
Construct a vector from a schema, creating a table with Table::make(schema).
Definition: Exposure.h:270
boost::shared_ptr< geom::polygon::Polygon const > _validPolygon
Definition: Exposure.h:134
boost::int64_t RecordId
Type used for unique IDs for records.
Definition: misc.h:21
boost::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:119
Base class for all tables.
Definition: BaseTable.h:44
virtual void _assign(BaseRecord const &other)
Called by assign() after transferring fields to allow subclass data members to be copied...
boost::shared_ptr< detection::Psf const > _psf
Definition: Exposure.h:131
boost::shared_ptr< image::Calib const > _calib
Definition: Exposure.h:132
static PointKey< int > getBBoxMaxKey()
Key for the maximum point of the bbox.
Definition: Exposure.h:191