LSSTApplications  18.1.0
LSSTDataManagementBasePackage
AmpInfo.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 #include <typeinfo>
3 
7 
8 namespace lsst {
9 namespace afw {
10 namespace table {
11 
12 //-----------------------------------------------------------------------------------------------------------
13 //----- AmpInfoFitsWriter ---------------------------------------------------------------------------------
14 //-----------------------------------------------------------------------------------------------------------
15 
16 // A custom FitsWriter for AmpInfo - this just sets the AFW_TYPE key to AMPINFO, which should ensure
17 // we use AmpInfoFitsReader to read it.
18 
19 namespace {
20 
21 class AmpInfoFitsWriter : public io::FitsWriter {
22 public:
23  explicit AmpInfoFitsWriter(Fits *fits, int flags) : io::FitsWriter(fits, flags) {}
24 
25 protected:
26  void _writeTable(std::shared_ptr<BaseTable const> const &table, std::size_t nRows) override;
27 };
28 
29 void AmpInfoFitsWriter::_writeTable(std::shared_ptr<BaseTable const> const &t, std::size_t nRows) {
31  if (!table) {
33  "Cannot use a AmpInfoFitsWriter on a non-AmpInfo table.");
34  }
35  io::FitsWriter::_writeTable(table, nRows);
36  _fits->writeKey("AFW_TYPE", "AMPINFO", "Tells lsst::afw to load this as a AmpInfo table.");
37 }
38 
39 } // namespace
40 
41 //-----------------------------------------------------------------------------------------------------------
42 //----- AmpInfoFitsReader ---------------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------------------------------------
44 
45 // A custom FitsReader for AmpInfoTable/Record - this gets registered with name AMPINFO, so it should get used
46 // whenever we read a table with AFW_TYPE set to that value.
47 
48 namespace {
49 
50 class AmpInfoFitsReader : public io::FitsReader {
51 public:
52  AmpInfoFitsReader() : io::FitsReader("AMPINFO") {}
53 
54  std::shared_ptr<BaseTable> makeTable(io::FitsSchemaInputMapper &mapper,
55  std::shared_ptr<daf::base::PropertyList> metadata, int ioFlags,
56  bool stripMetadata) const override {
57  std::shared_ptr<AmpInfoTable> table = AmpInfoTable::make(mapper.finalize());
58  table->setMetadata(metadata);
59  return table;
60  }
61 };
62 
63 static AmpInfoFitsReader const ampInfoFitsReader;
64 
65 } // namespace
66 
67 //-----------------------------------------------------------------------------------------------------------
68 //----- AmpInfoTable/Record member function implementations -----------------------------------------------
69 //-----------------------------------------------------------------------------------------------------------
70 
72 
74  if (!checkSchema(schema)) {
75  throw LSST_EXCEPT(
77  "Schema for AmpInfo must contain at least the keys defined by makeMinimalSchema().");
78  }
79  return std::shared_ptr<AmpInfoTable>(new AmpInfoTable(schema));
80 }
81 
83 
85 // Delegate to copy-constructor for backwards compatibility
87 
88 AmpInfoTable::~AmpInfoTable() = default;
89 
90 AmpInfoTable::MinimalSchema::MinimalSchema() {
91  name = schema.addField<std::string>("name", "name of amplifier location in camera",
94  "bbox of amplifier image data on assembled image, min point", "pixel");
95  bboxExtent = PointKey<int>::addFields(schema, "bbox_extent",
96  "bbox of amplifier image data on assembled image, extent", "pixel");
97  gain = schema.addField<double>("gain", "amplifier gain", "electron adu^-1");
98  saturation = schema.addField<double>(
99  "saturation",
100  "level above which pixels are considered saturated; use `nan` if no such level applies", "adu");
101  suspectLevel = schema.addField<double>(
102  "suspectlevel",
103  "level above which pixels are considered suspicious, meaning they may be affected by unknown "
104  "systematics; for example if non-linearity corrections above a certain level are unstable "
105  "then that would be a useful value for suspectLevel; use `nan` if no such level applies",
106  "adu");
107  readNoise = schema.addField<double>("readnoise", "amplifier read noise", "electron");
108  readoutCorner =
109  schema.addField<int>("readoutcorner", "readout corner, in the frame of the assembled image");
110  linearityCoeffs =
111  schema.addField<Array<double> >("linearity_coeffs", "coefficients for linearity fit up to cubic",
113  linearityType = schema.addField<std::string>("linearity_type", "type of linearity model",
115 
116  // Raw data fields
117  hasRawInfo = schema.addField<Flag>(
118  "hasrawinfo", "is raw amplifier information available (e.g. untrimmed bounding boxes)?");
119  rawBBoxMin = PointKey<int>::addFields(schema, "raw_bbox_min",
120  "entire amplifier bbox on raw image, min point", "pixel");
121  rawBBoxExtent = PointKey<int>::addFields(schema, "raw_bbox_extent",
122  "entire amplifier bbox on raw image, extent", "pixel");
123  rawDataBBoxMin = PointKey<int>::addFields(schema, "raw_databbox_min",
124  "image data bbox on raw image, min point", "pixel");
125  rawDataBBoxExtent = PointKey<int>::addFields(schema, "raw_databbox_extent",
126  "image data bbox on raw image, extent", "pixel");
127  rawFlipX = schema.addField<Flag>("raw_flip_x", "flip row order to make assembled image?");
128  rawFlipY = schema.addField<Flag>("raw_flip_y", "flip column order to make an assembled image?");
129  rawXYOffset = PointKey<int>::addFields(
130  schema, "raw_xyoffset",
131  "offset for assembling a raw CCD image: desired xy0 - raw xy0; 0,0 if raw data comes assembled",
132  "pixel");
133  rawHorizontalOverscanBBoxMin =
134  PointKey<int>::addFields(schema, "raw_horizontaloverscanbbox_min",
135  "usable horizontal overscan bbox on raw image, min point", "pixel");
136  rawHorizontalOverscanBBoxExtent =
137  PointKey<int>::addFields(schema, "raw_horizontaloverscanbbox_extent",
138  "usable horizontal overscan bbox on raw image, extent", "pixel");
139  rawVerticalOverscanBBoxMin =
140  PointKey<int>::addFields(schema, "raw_verticaloverscanbbox_min",
141  "usable vertical overscan region raw image, min point", "pixel");
142  rawVerticalOverscanBBoxExtent =
143  PointKey<int>::addFields(schema, "raw_verticaloverscanbbox_extent",
144  "usable vertical overscan region raw image, extent", "pixel");
145  rawPrescanBBoxMin =
146  PointKey<int>::addFields(schema, "raw_prescanbbox_min",
147  "usable (horizontal) prescan bbox on raw image, min point", "pixel");
148  rawPrescanBBoxExtent =
149  PointKey<int>::addFields(schema, "raw_prescanbbox_extent",
150  "usable (horizontal) prescan bbox on raw image, extent", "pixel");
151  schema.getCitizen().markPersistent();
152 }
153 
154 AmpInfoTable::MinimalSchema &AmpInfoTable::getMinimalSchema() {
155  static MinimalSchema it;
156  return it;
157 }
158 
159 std::shared_ptr<io::FitsWriter> AmpInfoTable::makeFitsWriter(fits::Fits *fitsfile, int flags) const {
160  return std::make_shared<AmpInfoFitsWriter>(fitsfile, flags);
161 }
162 
164  return std::shared_ptr<AmpInfoTable>(new AmpInfoTable(*this));
165 }
166 
168  return constructRecord<AmpInfoRecord>();
169 }
170 
171 //-------------------------------------------------------------------------------------------------
172 // Getters and Setters
173 //-------------------------------------------------------------------------------------------------
176 
180 }
182  set(AmpInfoTable::getBBoxMinKey(), bbox.getMin());
184 }
185 
186 double AmpInfoRecord::getGain() const { return get(AmpInfoTable::getGainKey()); }
187 void AmpInfoRecord::setGain(double gain) { set(AmpInfoTable::getGainKey(), gain); }
188 
190 void AmpInfoRecord::setSaturation(double saturation) { set(AmpInfoTable::getSaturationKey(), saturation); }
191 
193 void AmpInfoRecord::setSuspectLevel(double suspectLevel) {
194  set(AmpInfoTable::getSuspectLevelKey(), suspectLevel);
195 }
196 
198 void AmpInfoRecord::setReadNoise(double readNoise) { set(AmpInfoTable::getReadNoiseKey(), readNoise); }
199 
201  return static_cast<ReadoutCorner>(get(AmpInfoTable::getReadoutCornerKey()));
202 }
204  set(AmpInfoTable::getReadoutCornerKey(), readoutCorner);
205 }
206 
209  return coeffKey.extractVector(*this);
210 }
213  coeffKey.assignVector(*this, linearityCoeffs);
214 }
215 
217 void AmpInfoRecord::setLinearityType(std::string const &linearityType) {
218  set(AmpInfoTable::getLinearityTypeKey(), linearityType);
219 }
220 
222 void AmpInfoRecord::setHasRawInfo(bool hasrawamplifier) {
223  set(AmpInfoTable::getHasRawInfoKey(), hasrawamplifier);
224 }
225 
229 }
231  set(AmpInfoTable::getRawBBoxMinKey(), bbox.getMin());
233 }
234 
238 }
242 }
243 
245 void AmpInfoRecord::setRawFlipX(bool rawFlipX) { set(AmpInfoTable::getRawFlipXKey(), rawFlipX); }
246 
248 void AmpInfoRecord::setRawFlipY(bool rawFlipY) { set(AmpInfoTable::getRawFlipYKey(), rawFlipY); }
249 
252 }
254  set(AmpInfoTable::getRawXYOffsetKey(), lsst::geom::Point2I(rawxyoffset.asPair()));
255 }
256 
258  return lsst::geom::Box2I(
261 }
265 }
266 
270 }
274 }
275 
279 }
283 }
284 
285 template class CatalogT<AmpInfoRecord>;
286 template class CatalogT<AmpInfoRecord const>;
287 } // namespace table
288 } // namespace afw
289 } // namespace lsst
std::vector< double > getLinearityCoeffs() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:207
Extent2I const getDimensions() const noexcept
Definition: Box.h:173
Defines the fields and offsets for a table.
Definition: Schema.h:50
static PointKey< int > getRawPrescanBBoxExtentKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:265
lsst::geom::Box2I getRawDataBBox() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:235
void setRawFlipY(bool rawFlipY)
flip column order to make an assembled image?
Definition: AmpInfo.cc:248
static int const MAX_NAME_LENGTH
Definition: AmpInfo.h:192
static Key< Flag > getRawFlipXKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:249
lsst::geom::Extent2I getRawXYOffset() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:250
double getReadNoise() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:197
void setReadNoise(double readNoise)
amplifier read noise, in e-
Definition: AmpInfo.cc:198
double getGain() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:186
void setLinearityCoeffs(std::vector< double > const &coeffs)
vector of linearity coefficients
Definition: AmpInfo.cc:211
static PointKey< int > getRawXYOffsetKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:251
static PointKey< int > getRawDataBBoxMinKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:247
static PointKey< int > getRawVerticalOverscanBBoxMinKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:258
void setRawFlipX(bool rawFlipX)
flip row order to make assembled image?
Definition: AmpInfo.cc:245
void setName(std::string const &name)
name of amplifier location in camera
Definition: AmpInfo.cc:175
static PointKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
Add a pair of _x, _y fields to a Schema, and return a PointKey that points to them.
Definition: aggregates.cc:36
lsst::geom::Box2I getRawBBox() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:226
static Key< std::string > getLinearityTypeKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:243
static PointKey< int > getRawBBoxMinKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:245
void setRawPrescanBBox(lsst::geom::Box2I const &bbox)
bounding box of usable (horizontal) prescan pixels on raw image
Definition: AmpInfo.cc:280
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
void setHasRawInfo(bool hasRawInfo)
does this table have raw amplifier information?
Definition: AmpInfo.cc:222
Fits * fits
Definition: FitsWriter.cc:90
STL class.
bool getRawFlipX() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:244
Point2I const getMin() const noexcept
Definition: Box.h:143
afw::table::PointKey< int > bboxMin
void setSuspectLevel(double suspectLevel)
level in ADU above which pixels are considered suspicious,
Definition: AmpInfo.cc:193
static PointKey< int > getRawHorizontalOverscanBBoxExtentKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:255
double getSuspectLevel() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:192
lsst::geom::Box2I getBBox() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:177
void setGain(double gain)
amplifier gain in e-/ADU
Definition: AmpInfo.cc:187
static Key< double > getSuspectLevelKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:240
A base class for image defects.
static PointKey< int > getBBoxMinKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:235
AmpInfoTable(Schema const &schema)
Definition: AmpInfo.cc:82
void setRawHorizontalOverscanBBox(lsst::geom::Box2I const &bbox)
bounding box of usable horizontal overscan pixels
Definition: AmpInfo.cc:262
static int const MAX_LINEARITY_COEFFS
Definition: AmpInfo.h:193
std::shared_ptr< BaseTable > _clone() const override
Clone implementation with noncovariant return types.
Definition: AmpInfo.cc:163
table::Schema schema
Definition: Camera.cc:161
Tag types used to declare specialized field types.
Definition: misc.h:32
T dynamic_pointer_cast(T... args)
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
table::Box2IKey bbox
Definition: Detector.cc:169
static PointKey< int > getRawBBoxExtentKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:246
ReadoutCorner getReadoutCorner() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:200
static Key< Flag > getRawFlipYKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:250
Point< int, 2 > Point2I
Definition: Point.h:321
virtual void _writeTable(std::shared_ptr< BaseTable const > const &table, std::size_t nRows)
Write a table and its schema.
Definition: FitsWriter.cc:103
void setBBox(lsst::geom::Box2I const &bbox)
bounding box of amplifier pixels in assembled image
Definition: AmpInfo.cc:181
static Key< Flag > getHasRawInfoKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:244
ReadoutCorner
Readout corner, in the frame of reference of the assembled image.
Definition: AmpInfo.h:39
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
Extent< int, 2 > Extent2I
Definition: Extent.h:397
bool getHasRawInfo() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:221
void setRawDataBBox(lsst::geom::Box2I const &bbox)
bounding box of amplifier image pixels on raw image
Definition: AmpInfo.cc:239
std::string getLinearityType() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:216
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
std::string getName() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:174
lsst::geom::Box2I getRawVerticalOverscanBBox() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:267
Reports invalid arguments.
Definition: Runtime.h:66
static PointKey< int > getRawVerticalOverscanBBoxExtentKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:261
static PointKey< int > getRawPrescanBBoxMinKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:264
lsst::geom::Box2I getRawPrescanBBox() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:276
ItemVariant const * other
Definition: Schema.cc:56
static Key< double > getReadNoiseKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:238
void setReadoutCorner(ReadoutCorner val)
set readout corner
Definition: AmpInfo.cc:203
static int const MAX_LINEARITY_TYPE_LENGTH
Definition: AmpInfo.h:194
bool getRawFlipY() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:247
static Key< int > getReadoutCornerKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:241
static PointKey< int > getRawDataBBoxExtentKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:248
void setSaturation(double saturation)
level in ADU above which pixels are considered saturated;
Definition: AmpInfo.cc:190
void setLinearityType(std::string const &type)
name of linearity parameterization
Definition: AmpInfo.cc:217
An integer coordinate rectangle.
Definition: Box.h:54
static Key< std::string > getNameKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:234
static PointKey< int > getBBoxExtentKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:236
Table of amplifier information (AmpInfoRecord records)
Definition: AmpInfo.h:186
static PointKey< int > getRawHorizontalOverscanBBoxMinKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:252
Base class for all tables.
Definition: BaseTable.h:61
static Key< double > getGainKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:237
void setRawVerticalOverscanBBox(lsst::geom::Box2I const &bbox)
bounding box of usable vertical overscan pixels
Definition: AmpInfo.cc:271
static Key< Array< double > > getLinearityCoeffsKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:242
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
lsst::geom::Box2I getRawHorizontalOverscanBBox() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:257
void setRawXYOffset(lsst::geom::Extent2I const &xy)
offset for assembling a raw CCD image: desired xy0 - raw xy0
Definition: AmpInfo.cc:253
double getSaturation() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:189
static std::shared_ptr< AmpInfoTable > make(Schema const &schema)
Construct a new table.
Definition: AmpInfo.cc:73
void setRawBBox(lsst::geom::Box2I const &bbox)
bounding box of all amplifier pixels on raw image
Definition: AmpInfo.cc:230
std::shared_ptr< BaseRecord > _makeRecord() override
Default-construct an associated record (protected implementation).
Definition: AmpInfo.cc:167
static Key< double > getSaturationKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:239