LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
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 
59 class OutputArchiveHandle;
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
static Key< RecordId > getIdKey()
Key for the unique ID.
Definition: Exposure.h:187
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
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
boost::shared_ptr< image::Wcs const > _wcs
Definition: Exposure.h:130
Writer object for FITS binary tables.
Definition: FitsWriter.h:22
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
void setBBox(geom::Box2I const &bbox)
boost::shared_ptr< detection::Psf const > _psf
Definition: Exposure.h:131
#define PTR(...)
Definition: base.h:41
void setId(RecordId id)
Definition: Exposure.h:419
ExposureCatalogT< ExposureRecord const > ConstExposureCatalog
Definition: Exposure.h:416
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
An object passed to Persistable::write to allow it to persist itself.
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
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
static PointKey< int > getBBoxMinKey()
Key for the minimum point of the bbox.
Definition: Exposure.h:189
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
boost::shared_ptr< BaseTable const > getTable() const
Return the table this record is associated with.
Definition: BaseRecord.h:51
#define CONST_PTR(...)
Definition: base.h:47
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
ExposureCatalogT(Base const &other)
Definition: Exposure.h:411
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
ExposureCatalogT< ExposureRecord const > ConstCatalog
Definition: Exposure.h:73
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
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
tbl::Key< int > wcs
Record::Table Table
Definition: Catalog.h:99
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
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
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:194
ExposureCatalogT< Record > Catalog
Definition: Exposure.h:147
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
Base::const_iterator const_iterator
Definition: Exposure.h:259
ExposureCatalogT< Record const > ConstCatalog
Definition: Exposure.h:148
virtual void _assign(BaseRecord const &other)
Called by assign() after transferring fields to allow subclass data members to be copied...
int contains(Schema const &other, int flags=EQUAL_KEYS) const
Test whether the given schema is a subset of this.
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
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
static PointKey< int > getBBoxMaxKey()
Key for the maximum point of the bbox.
Definition: Exposure.h:191
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:106
ExposureRecord(boost::shared_ptr< ExposureTable > const &table)
Iterator class for CatalogT.
Definition: Catalog.h:34
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
ExposureCatalogT(Schema const &schema)
Construct a vector from a schema, creating a table with Table::make(schema).
Definition: Exposure.h:270
boost::shared_ptr< ExposureTable const > getTable() const
Definition: Exposure.h:75
RecordId getId() const
Definition: Exposure.h:418
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
tbl::Schema schema
geom::Box2I getBBox() const
boost::shared_ptr< BaseRecord > copyRecord(BaseRecord const &input)
Deep-copy a record, requiring that it have the same schema as this table.
boost::shared_ptr< geom::polygon::Polygon const > _validPolygon
Definition: Exposure.h:134
A multidimensional strided array.
Definition: Array.h:47
Base class for all records.
Definition: BaseRecord.h:27
void disconnectAliases()
Sever the connection between this schema and any others with which it shares aliases.
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(std::string const &filename, int hdu=0, int flags=0)
Read a FITS binary table from a regular file.
Definition: Exposure.h:319
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
Custom catalog class for ExposureRecord/Table.
Definition: Exposure.h:55
ExposureCatalogT(ExposureCatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition: Exposure.h:294
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
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:146
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:136
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
ExposureCatalogT< ExposureRecord > Catalog
Definition: Exposure.h:72
static bool checkSchema(Schema const &other)
Return true if the given schema is a valid ExposureTable schema.
Definition: Exposure.h:176
Record class used to store exposure metadata.
Definition: Exposure.h:67
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...
ExposureCatalogT< ExposureRecord > ExposureCatalog
Definition: Exposure.h:415
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:28
SortedCatalogT< RecordT > Base
Definition: Exposure.h:252
A polymorphic base class for representing an image&#39;s Point Spread Function.
Definition: Psf.h:68
boost::shared_ptr< image::Calib const > _calib
Definition: Exposure.h:132
boost::int64_t RecordId
Type used for unique IDs for records.
Definition: misc.h:21
ExposureCatalogT(boost::shared_ptr< Table > const &table=boost::shared_ptr< Table >())
Construct a vector from a table (or nothing).
Definition: Exposure.h:267
Base class for all tables.
Definition: BaseTable.h:44
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:71
boost::shared_ptr< image::ApCorrMap const > _apCorrMap
Definition: Exposure.h:133