LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
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"
32 
33 namespace lsst { namespace afw {
34 
35 namespace image {
36 class Wcs;
37 class Calib;
38 } // namespace image
39 
40 namespace detection {
41 class Psf;
42 } // namespace detection
43 
44 namespace table {
45 
46 class ExposureRecord;
47 class ExposureTable;
48 
49 template <typename RecordT> class ExposureCatalogT;
50 
51 namespace io {
52 
53 class OutputArchiveHandle;
54 class InputArchive;
55 
56 } // namespace io
57 
61 class ExposureRecord : public BaseRecord {
62 public:
63 
68 
70  return boost::static_pointer_cast<ExposureTable const>(BaseRecord::getTable());
71  }
72 
73  RecordId getId() const;
74  void setId(RecordId id);
75 
76  geom::Box2I getBBox() const;
77  void setBBox(geom::Box2I const & bbox);
78 
85  bool contains(Coord const & coord) const;
86 
93  bool contains(geom::Point2D const & point, image::Wcs const & wcs) const;
94 
96  CONST_PTR(image::Wcs) getWcs() const { return _wcs; }
98  void setWcs(CONST_PTR(image::Wcs) wcs) { _wcs = wcs; }
99 
100  CONST_PTR(detection::Psf) getPsf() const { return _psf; }
101  void setPsf(CONST_PTR(detection::Psf) psf) { _psf = psf; }
102 
103  CONST_PTR(image::Calib) getCalib() const { return _calib; }
104  void setCalib(CONST_PTR(image::Calib) calib) { _calib = calib; }
106 
107 protected:
108 
110 
111  virtual void _assign(BaseRecord const & other);
112 
113 private:
115  CONST_PTR(detection::Psf) _psf;
117 };
118 
124 class ExposureTable : public BaseTable {
125 public:
126 
131 
137  static PTR(ExposureTable) make(Schema const & schema);
138 
146  static Schema makeMinimalSchema() {
147  Schema r = getMinimalSchema().schema;
148  r.disconnectAliases();
149  return r;
150  }
151 
158  static bool checkSchema(Schema const & other) {
159  return other.contains(getMinimalSchema().schema);
160  }
161 
163 
168  static Key<RecordId> getIdKey() { return getMinimalSchema().id; }
171  static Key< Point<int> > getBBoxMinKey() { return getMinimalSchema().bboxMin; }
173  static Key< Point<int> > getBBoxMaxKey() { return getMinimalSchema().bboxMax; }
175 
177  PTR(ExposureTable) clone() const { return boost::static_pointer_cast<ExposureTable>(_clone()); }
178 
180  PTR(ExposureRecord) makeRecord() { return boost::static_pointer_cast<ExposureRecord>(_makeRecord()); }
181 
183  PTR(ExposureRecord) copyRecord(BaseRecord const & other) {
184  return boost::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other));
185  }
186 
188  PTR(ExposureRecord) copyRecord(BaseRecord const & other, SchemaMapper const & mapper) {
189  return boost::static_pointer_cast<ExposureRecord>(BaseTable::copyRecord(other, mapper));
190  }
191 
192 protected:
193 
194  ExposureTable(Schema const & schema);
195 
196  ExposureTable(ExposureTable const & other);
197 
198 private:
199 
200  // Struct that holds the minimal schema and the special keys we've added to it.
201  struct MinimalSchema {
206 
207  MinimalSchema();
208  };
209 
210  // Return the singleton minimal schema.
211  static MinimalSchema & getMinimalSchema();
212 
213  friend class io::FitsWriter;
214 
215  template <typename RecordT> friend class ExposureCatalogT;
216 
217  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
218  virtual PTR(io::FitsWriter) makeFitsWriter(fits::Fits * fitsfile, int flags) const;
219  PTR(io::FitsWriter) makeFitsWriter(
220  fits::Fits * fitsfile, PTR(io::OutputArchive) archive, int flags
221  ) const;
222 };
223 
224 #ifndef SWIG
225 
232 template <typename RecordT>
233 class ExposureCatalogT : public SortedCatalogT<RecordT> {
235 public:
236 
237  typedef RecordT Record;
238  typedef typename Record::Table Table;
239 
240  typedef typename Base::iterator iterator;
242 
249  explicit ExposureCatalogT(PTR(Table) const & table = PTR(Table)()) : Base(table) {}
250 
252  explicit ExposureCatalogT(Schema const & schema) : Base(schema) {}
253 
264  template <typename InputIterator>
265  ExposureCatalogT(PTR(Table) const & table, InputIterator first, InputIterator last, bool deep=false) :
266  Base(table, first, last, deep)
267  {}
268 
275  template <typename OtherRecordT>
277 
278  using Base::writeFits;
279 
287  void writeFits(fits::Fits & fitsfile, PTR(io::OutputArchive) archive, int flags=0) const {
288  PTR(io::FitsWriter) writer = this->getTable()->makeFitsWriter(&fitsfile, archive, flags);
289  writer->write(*this);
290  }
291 
301  static ExposureCatalogT readFits(std::string const & filename, int hdu=0, int flags=0) {
302  return io::FitsReader::apply<ExposureCatalogT>(filename, hdu, flags);
303  }
304 
314  static ExposureCatalogT readFits(fits::MemFileManager & manager, int hdu=0, int flags=0) {
315  return io::FitsReader::apply<ExposureCatalogT>(manager, hdu, flags);
316  }
317 
325  static ExposureCatalogT readFits(fits::Fits & fitsfile, int flags=0) {
326  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, flags);
327  }
328 
335  static ExposureCatalogT readFits(fits::Fits & fitsfile, PTR(io::InputArchive) archive, int flags=0) {
336  return io::FitsReader::apply<ExposureCatalogT>(fitsfile, archive, flags);
337  }
338 
346  void writeToArchive(io::OutputArchiveHandle & handle, bool ignoreUnpersistable=true) const;
347 
354  static ExposureCatalogT readFromArchive(io::InputArchive const & archive, BaseCatalog const & catalog);
355 
362  return ExposureCatalogT(Base::subset(mask));
363  }
364 
369  ExposureCatalogT subset(std::ptrdiff_t startd, std::ptrdiff_t stopd, std::ptrdiff_t step) const {
370  return ExposureCatalogT(Base::subset(startd, stopd, step));
371  }
372 
379  ExposureCatalogT subsetContaining(Coord const & coord) const;
380 
387  ExposureCatalogT subsetContaining(geom::Point2D const & point, image::Wcs const & wcs) const;
388 
389 protected:
390  explicit ExposureCatalogT(Base const & other) : Base(other) {}
391 };
392 
396 
397 inline RecordId ExposureRecord::getId() const { return get(ExposureTable::getIdKey()); }
399 
400 #endif // !SWIG
401 
402 }}} // namespace lsst::afw::table
403 
404 #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:169
void setPsf(boost::shared_ptr< detection::Psf const > psf)
Get/Set the the attached Wcs, Psf, or Calib. No copies are made.
Definition: Exposure.h:101
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:287
boost::shared_ptr< image::Wcs const > _wcs
Definition: Exposure.h:114
#define CONST_PTR(...)
Definition: base.h:47
Writer subclass for FITS binary tables.
Definition: FitsWriter.h:20
boost::shared_ptr< image::Calib const > getCalib() const
Get/Set the the attached Wcs, Psf, or Calib. No copies are made.
Definition: Exposure.h:103
void setBBox(geom::Box2I const &bbox)
boost::shared_ptr< detection::Psf const > _psf
Definition: Exposure.h:115
void setId(RecordId id)
Definition: Exposure.h:398
ExposureCatalogT< ExposureRecord const > ConstExposureCatalog
Definition: Exposure.h:395
void setWcs(boost::shared_ptr< image::Wcs const > wcs)
Get/Set the the attached Wcs, Psf, or Calib. No copies are made.
Definition: Exposure.h:98
An object passed to Persistable::write to allow it to persist itself.
static Key< Point< int > > getBBoxMaxKey()
Key for the maximum point of the bbox.
Definition: Exposure.h:173
Table class used to store exposure metadata.
Definition: Exposure.h:124
A custom container class for records, based on std::vector.
Definition: Catalog.h:94
ColumnViewT< ExposureRecord > ExposureColumnView
Definition: Exposure.h:393
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:19
static Key< Point< int > > getBBoxMinKey()
Key for the minimum point of the bbox.
Definition: Exposure.h:171
boost::shared_ptr< detection::Psf const > getPsf() const
Get/Set the the attached Wcs, Psf, or Calib. No copies are made.
Definition: Exposure.h:100
boost::shared_ptr< BaseTable const > getTable() const
Return the table this record is associated with.
Definition: BaseRecord.h:51
bool contains(Coord const &coord) const
Return true if the bounding box contains the given celestial coordinate point, taking into account th...
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:361
ExposureCatalogT(Base const &other)
Definition: Exposure.h:390
ExposureCatalogT< ExposureRecord const > ConstCatalog
Definition: Exposure.h:67
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:335
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:325
#define PTR(...)
Definition: base.h:41
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:129
An integer coordinate rectangle.
Definition: Box.h:53
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:241
ExposureCatalogT< Record const > ConstCatalog
Definition: Exposure.h:130
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.
tbl::Schema schema
Definition: CoaddPsf.cc:324
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
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, or Calib. No copies are made.
Definition: Exposure.h:97
ExposureCatalogT(Schema const &schema)
Construct a vector from a schema, creating a table with Table::make(schema).
Definition: Exposure.h:252
boost::shared_ptr< ExposureTable const > getTable() const
Definition: Exposure.h:69
RecordId getId() const
Definition: Exposure.h:397
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:369
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.
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.
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:301
static ExposureCatalogT readFits(fits::MemFileManager &manager, int hdu=0, int flags=0)
Read a FITS binary table from a RAM file.
Definition: Exposure.h:314
Custom catalog class for ExposureRecord/Table.
Definition: Exposure.h:49
ExposureCatalogT(ExposureCatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition: Exposure.h:276
void setCalib(boost::shared_ptr< image::Calib const > calib)
Get/Set the the attached Wcs, Psf, or Calib. No copies are made.
Definition: Exposure.h:104
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:128
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:265
ExposureCatalogT< ExposureRecord > Catalog
Definition: Exposure.h:66
static bool checkSchema(Schema const &other)
Return true if the given schema is a valid ExposureTable schema.
Definition: Exposure.h:158
Record class used to store exposure metadata.
Definition: Exposure.h:61
ExposureCatalogT< ExposureRecord > ExposureCatalog
Definition: Exposure.h:394
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:28
SortedCatalogT< RecordT > Base
Definition: Exposure.h:234
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:116
boost::int64_t RecordId
Type used for unique IDs for records.
Definition: misc.h:21
std::map< Citizen const *, CitizenInfo > table
Definition: Citizen.h:93
ExposureCatalogT(boost::shared_ptr< Table > const &table=boost::shared_ptr< Table >())
Construct a vector from a table (or nothing).
Definition: Exposure.h:249
Base class for all tables.
Definition: BaseTable.h:44
ColumnViewT< ExposureRecord > ColumnView
Definition: Exposure.h:65