LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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 
76  if (!checkSchema(schema)) {
77  throw LSST_EXCEPT(
79  "Schema for AmpInfo must contain at least the keys defined by makeMinimalSchema().");
80  }
81  return std::shared_ptr<AmpInfoTable>(new AmpInfoTable(schema));
82 }
83 
85 
87 // Delegate to copy-constructor for backwards compatibility
89 
90 AmpInfoTable::~AmpInfoTable() = default;
91 
92 AmpInfoTable::MinimalSchema::MinimalSchema() {
93  name = schema.addField<std::string>("name", "name of amplifier location in camera",
96  "bbox of amplifier image data on assembled image, min point", "pixel");
97  bboxExtent = PointKey<int>::addFields(schema, "bbox_extent",
98  "bbox of amplifier image data on assembled image, extent", "pixel");
99  gain = schema.addField<double>("gain", "amplifier gain", "electron adu^-1");
100  saturation = schema.addField<double>(
101  "saturation",
102  "level above which pixels are considered saturated; use `nan` if no such level applies", "adu");
103  suspectLevel = schema.addField<double>(
104  "suspectlevel",
105  "level above which pixels are considered suspicious, meaning they may be affected by unknown "
106  "systematics; for example if non-linearity corrections above a certain level are unstable "
107  "then that would be a useful value for suspectLevel; use `nan` if no such level applies",
108  "adu");
109  readNoise = schema.addField<double>("readnoise", "amplifier read noise", "electron");
110  readoutCorner =
111  schema.addField<int>("readoutcorner", "readout corner, in the frame of the assembled image");
112  linearityCoeffs =
113  schema.addField<Array<double> >("linearity_coeffs", "coefficients for linearity fit up to cubic",
115  linearityType = schema.addField<std::string>("linearity_type", "type of linearity model",
117 
118  // Raw data fields
119  hasRawInfo = schema.addField<Flag>(
120  "hasrawinfo", "is raw amplifier information available (e.g. untrimmed bounding boxes)?");
121  rawBBoxMin = PointKey<int>::addFields(schema, "raw_bbox_min",
122  "entire amplifier bbox on raw image, min point", "pixel");
123  rawBBoxExtent = PointKey<int>::addFields(schema, "raw_bbox_extent",
124  "entire amplifier bbox on raw image, extent", "pixel");
125  rawDataBBoxMin = PointKey<int>::addFields(schema, "raw_databbox_min",
126  "image data bbox on raw image, min point", "pixel");
127  rawDataBBoxExtent = PointKey<int>::addFields(schema, "raw_databbox_extent",
128  "image data bbox on raw image, extent", "pixel");
129  rawFlipX = schema.addField<Flag>("raw_flip_x", "flip row order to make assembled image?");
130  rawFlipY = schema.addField<Flag>("raw_flip_y", "flip column order to make an assembled image?");
131  rawXYOffset = PointKey<int>::addFields(
132  schema, "raw_xyoffset",
133  "offset for assembling a raw CCD image: desired xy0 - raw xy0; 0,0 if raw data comes assembled",
134  "pixel");
135  rawHorizontalOverscanBBoxMin =
136  PointKey<int>::addFields(schema, "raw_horizontaloverscanbbox_min",
137  "usable horizontal overscan bbox on raw image, min point", "pixel");
138  rawHorizontalOverscanBBoxExtent =
139  PointKey<int>::addFields(schema, "raw_horizontaloverscanbbox_extent",
140  "usable horizontal overscan bbox on raw image, extent", "pixel");
141  rawVerticalOverscanBBoxMin =
142  PointKey<int>::addFields(schema, "raw_verticaloverscanbbox_min",
143  "usable vertical overscan region raw image, min point", "pixel");
144  rawVerticalOverscanBBoxExtent =
145  PointKey<int>::addFields(schema, "raw_verticaloverscanbbox_extent",
146  "usable vertical overscan region raw image, extent", "pixel");
147  rawPrescanBBoxMin =
148  PointKey<int>::addFields(schema, "raw_prescanbbox_min",
149  "usable (horizontal) prescan bbox on raw image, min point", "pixel");
150  rawPrescanBBoxExtent =
151  PointKey<int>::addFields(schema, "raw_prescanbbox_extent",
152  "usable (horizontal) prescan bbox on raw image, extent", "pixel");
153  schema.getCitizen().markPersistent();
154 }
155 
156 AmpInfoTable::MinimalSchema &AmpInfoTable::getMinimalSchema() {
157  static MinimalSchema it;
158  return it;
159 }
160 
161 std::shared_ptr<io::FitsWriter> AmpInfoTable::makeFitsWriter(fits::Fits *fitsfile, int flags) const {
162  return std::make_shared<AmpInfoFitsWriter>(fitsfile, flags);
163 }
164 
166  return std::shared_ptr<AmpInfoTable>(new AmpInfoTable(*this));
167 }
168 
170  return std::shared_ptr<AmpInfoRecord>(new AmpInfoRecord(getSelf<AmpInfoTable>()));
171 }
172 
173 //-------------------------------------------------------------------------------------------------
174 // Getters and Setters
175 //-------------------------------------------------------------------------------------------------
178 
182 }
184  set(AmpInfoTable::getBBoxMinKey(), bbox.getMin());
186 }
187 
188 double AmpInfoRecord::getGain() const { return get(AmpInfoTable::getGainKey()); }
189 void AmpInfoRecord::setGain(double gain) { set(AmpInfoTable::getGainKey(), gain); }
190 
192 void AmpInfoRecord::setSaturation(double saturation) { set(AmpInfoTable::getSaturationKey(), saturation); }
193 
195 void AmpInfoRecord::setSuspectLevel(double suspectLevel) {
196  set(AmpInfoTable::getSuspectLevelKey(), suspectLevel);
197 }
198 
200 void AmpInfoRecord::setReadNoise(double readNoise) { set(AmpInfoTable::getReadNoiseKey(), readNoise); }
201 
203  return static_cast<ReadoutCorner>(get(AmpInfoTable::getReadoutCornerKey()));
204 }
206  set(AmpInfoTable::getReadoutCornerKey(), readoutCorner);
207 }
208 
211  return coeffKey.extractVector(*this);
212 }
215  coeffKey.assignVector(*this, linearityCoeffs);
216 }
217 
219 void AmpInfoRecord::setLinearityType(std::string const &linearityType) {
220  set(AmpInfoTable::getLinearityTypeKey(), linearityType);
221 }
222 
224 void AmpInfoRecord::setHasRawInfo(bool hasrawamplifier) {
225  set(AmpInfoTable::getHasRawInfoKey(), hasrawamplifier);
226 }
227 
231 }
233  set(AmpInfoTable::getRawBBoxMinKey(), bbox.getMin());
235 }
236 
240 }
244 }
245 
247 void AmpInfoRecord::setRawFlipX(bool rawFlipX) { set(AmpInfoTable::getRawFlipXKey(), rawFlipX); }
248 
250 void AmpInfoRecord::setRawFlipY(bool rawFlipY) { set(AmpInfoTable::getRawFlipYKey(), rawFlipY); }
251 
254 }
256  set(AmpInfoTable::getRawXYOffsetKey(), lsst::geom::Point2I(rawxyoffset.asPair()));
257 }
258 
260  return lsst::geom::Box2I(
263 }
267 }
268 
272 }
276 }
277 
281 }
285 }
286 
287 template class CatalogT<AmpInfoRecord>;
288 template class CatalogT<AmpInfoRecord const>;
289 } // namespace table
290 } // namespace afw
291 } // namespace lsst
std::vector< double > getLinearityCoeffs() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:209
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:254
lsst::geom::Box2I getRawDataBBox() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:237
void setRawFlipY(bool rawFlipY)
flip column order to make an assembled image?
Definition: AmpInfo.cc:250
static int const MAX_NAME_LENGTH
Definition: AmpInfo.h:181
static Key< Flag > getRawFlipXKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:238
lsst::geom::Extent2I getRawXYOffset() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:252
Geometry and electronic information about raw amplifier images.
Definition: AmpInfo.h:79
double getReadNoise() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:199
void setReadNoise(double readNoise)
amplifier read noise, in e-
Definition: AmpInfo.cc:200
double getGain() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:188
void setLinearityCoeffs(std::vector< double > const &coeffs)
vector of linearity coefficients
Definition: AmpInfo.cc:213
static PointKey< int > getRawXYOffsetKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:240
static PointKey< int > getRawDataBBoxMinKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:236
static PointKey< int > getRawVerticalOverscanBBoxMinKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:247
void setRawFlipX(bool rawFlipX)
flip row order to make assembled image?
Definition: AmpInfo.cc:247
void setName(std::string const &name)
name of amplifier location in camera
Definition: AmpInfo.cc:177
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:228
static Key< std::string > getLinearityTypeKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:232
static PointKey< int > getRawBBoxMinKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:234
void setRawPrescanBBox(lsst::geom::Box2I const &bbox)
bounding box of usable (horizontal) prescan pixels on raw image
Definition: AmpInfo.cc:282
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:296
void setHasRawInfo(bool hasRawInfo)
does this table have raw amplifier information?
Definition: AmpInfo.cc:224
Fits * fits
Definition: FitsWriter.cc:90
STL class.
bool getRawFlipX() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:246
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:195
static PointKey< int > getRawHorizontalOverscanBBoxExtentKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:244
double getSuspectLevel() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:194
lsst::geom::Box2I getBBox() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:179
void setGain(double gain)
amplifier gain in e-/ADU
Definition: AmpInfo.cc:189
static Key< double > getSuspectLevelKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:229
A base class for image defects.
static PointKey< int > getBBoxMinKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:224
AmpInfoTable(Schema const &schema)
Definition: AmpInfo.cc:84
void setRawHorizontalOverscanBBox(lsst::geom::Box2I const &bbox)
bounding box of usable horizontal overscan pixels
Definition: AmpInfo.cc:264
static int const MAX_LINEARITY_COEFFS
Definition: AmpInfo.h:182
std::shared_ptr< BaseTable > _clone() const override
Clone implementation with noncovariant return types.
Definition: AmpInfo.cc:165
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:166
static PointKey< int > getRawBBoxExtentKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:235
ReadoutCorner getReadoutCorner() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:202
static Key< Flag > getRawFlipYKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:239
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:183
static Key< Flag > getHasRawInfoKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:233
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:223
void setRawDataBBox(lsst::geom::Box2I const &bbox)
bounding box of amplifier image pixels on raw image
Definition: AmpInfo.cc:241
Base class for all records.
Definition: BaseRecord.h:31
std::string getLinearityType() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:218
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:176
lsst::geom::Box2I getRawVerticalOverscanBBox() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:269
AmpInfoRecord(AmpInfoRecord const &)=delete
Reports invalid arguments.
Definition: Runtime.h:66
static PointKey< int > getRawVerticalOverscanBBoxExtentKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:250
static PointKey< int > getRawPrescanBBoxMinKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:253
lsst::geom::Box2I getRawPrescanBBox() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:278
ItemVariant const * other
Definition: Schema.cc:56
static Key< double > getReadNoiseKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:227
void setReadoutCorner(ReadoutCorner val)
set readout corner
Definition: AmpInfo.cc:205
static int const MAX_LINEARITY_TYPE_LENGTH
Definition: AmpInfo.h:183
bool getRawFlipY() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:249
static Key< int > getReadoutCornerKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:230
static PointKey< int > getRawDataBBoxExtentKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:237
void setSaturation(double saturation)
level in ADU above which pixels are considered saturated;
Definition: AmpInfo.cc:192
void setLinearityType(std::string const &type)
name of linearity parameterization
Definition: AmpInfo.cc:219
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:223
static PointKey< int > getBBoxExtentKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:225
Table of amplifier information (AmpInfoRecord records)
Definition: AmpInfo.h:175
static PointKey< int > getRawHorizontalOverscanBBoxMinKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:241
Base class for all tables.
Definition: BaseTable.h:44
static Key< double > getGainKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:226
void setRawVerticalOverscanBBox(lsst::geom::Box2I const &bbox)
bounding box of usable vertical overscan pixels
Definition: AmpInfo.cc:273
static Key< Array< double > > getLinearityCoeffsKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:231
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
lsst::geom::Box2I getRawHorizontalOverscanBBox() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:259
void setRawXYOffset(lsst::geom::Extent2I const &xy)
offset for assembling a raw CCD image: desired xy0 - raw xy0
Definition: AmpInfo.cc:255
double getSaturation() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:191
static std::shared_ptr< AmpInfoTable > make(Schema const &schema)
Construct a new table.
Definition: AmpInfo.cc:75
void setRawBBox(lsst::geom::Box2I const &bbox)
bounding box of all amplifier pixels on raw image
Definition: AmpInfo.cc:232
std::shared_ptr< BaseRecord > _makeRecord() override
Default-construct an associated record (protected implementation).
Definition: AmpInfo.cc:169
static Key< double > getSaturationKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:228