LSSTApplications  17.0+115,17.0+12,17.0+65,18.0.0+14,18.0.0+29,18.0.0+6,18.0.0+70,18.0.0-4-g68ffd23+1,18.1.0-1-g0001055+9,18.1.0-1-g03d53ef+2,18.1.0-1-g1349e88+44,18.1.0-1-g2505f39+35,18.1.0-1-g5315e5e+2,18.1.0-1-g5e4b7ea+11,18.1.0-1-g7e8fceb+2,18.1.0-1-g85f8cd4+38,18.1.0-1-gd55f500+25,18.1.0-13-gfe4edf0b,18.1.0-14-g259bd21+9,18.1.0-14-gd04256d+35,18.1.0-2-g4903023+12,18.1.0-2-g5f9922c+13,18.1.0-2-gd3b74e5+3,18.1.0-2-gfbf3545+22,18.1.0-2-gfefb8b5+34,18.1.0-22-g936f6a9b4,18.1.0-23-g364d03b8,18.1.0-23-g52ab674,18.1.0-3-g52aa583+17,18.1.0-3-g8f4a2b1+32,18.1.0-3-gb69f684+30,18.1.0-4-g1ee41a7+2,18.1.0-5-g6dbcb01+31,18.1.0-5-gc286bb7+4,18.1.0-6-g857e778+4,18.1.0-7-gae09a6d+18,18.1.0-8-g42b2ab3+10,18.1.0-8-gc69d46e+17,18.1.0-9-gee19f03+2,w.2019.44
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 }
152 
153 AmpInfoTable::MinimalSchema &AmpInfoTable::getMinimalSchema() {
154  static MinimalSchema it;
155  return it;
156 }
157 
158 std::shared_ptr<io::FitsWriter> AmpInfoTable::makeFitsWriter(fits::Fits *fitsfile, int flags) const {
159  return std::make_shared<AmpInfoFitsWriter>(fitsfile, flags);
160 }
161 
163  return std::shared_ptr<AmpInfoTable>(new AmpInfoTable(*this));
164 }
165 
167  return constructRecord<AmpInfoRecord>();
168 }
169 
170 //-------------------------------------------------------------------------------------------------
171 // Getters and Setters
172 //-------------------------------------------------------------------------------------------------
175 
179 }
181  set(AmpInfoTable::getBBoxMinKey(), bbox.getMin());
183 }
184 
185 double AmpInfoRecord::getGain() const { return get(AmpInfoTable::getGainKey()); }
186 void AmpInfoRecord::setGain(double gain) { set(AmpInfoTable::getGainKey(), gain); }
187 
189 void AmpInfoRecord::setSaturation(double saturation) { set(AmpInfoTable::getSaturationKey(), saturation); }
190 
192 void AmpInfoRecord::setSuspectLevel(double suspectLevel) {
193  set(AmpInfoTable::getSuspectLevelKey(), suspectLevel);
194 }
195 
197 void AmpInfoRecord::setReadNoise(double readNoise) { set(AmpInfoTable::getReadNoiseKey(), readNoise); }
198 
200  return static_cast<ReadoutCorner>(get(AmpInfoTable::getReadoutCornerKey()));
201 }
203  set(AmpInfoTable::getReadoutCornerKey(), readoutCorner);
204 }
205 
208  return coeffKey.extractVector(*this);
209 }
212  coeffKey.assignVector(*this, linearityCoeffs);
213 }
214 
216 void AmpInfoRecord::setLinearityType(std::string const &linearityType) {
217  set(AmpInfoTable::getLinearityTypeKey(), linearityType);
218 }
219 
221 void AmpInfoRecord::setHasRawInfo(bool hasrawamplifier) {
222  set(AmpInfoTable::getHasRawInfoKey(), hasrawamplifier);
223 }
224 
228 }
230  set(AmpInfoTable::getRawBBoxMinKey(), bbox.getMin());
232 }
233 
237 }
241 }
242 
244 void AmpInfoRecord::setRawFlipX(bool rawFlipX) { set(AmpInfoTable::getRawFlipXKey(), rawFlipX); }
245 
247 void AmpInfoRecord::setRawFlipY(bool rawFlipY) { set(AmpInfoTable::getRawFlipYKey(), rawFlipY); }
248 
251 }
253  set(AmpInfoTable::getRawXYOffsetKey(), lsst::geom::Point2I(rawxyoffset.asPair()));
254 }
255 
257  return lsst::geom::Box2I(
260 }
264 }
265 
269 }
273 }
274 
278 }
282 }
283 
284 template class CatalogT<AmpInfoRecord>;
285 template class CatalogT<AmpInfoRecord const>;
286 } // namespace table
287 } // namespace afw
288 } // namespace lsst
std::vector< double > getLinearityCoeffs() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:206
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:234
void setRawFlipY(bool rawFlipY)
flip column order to make an assembled image?
Definition: AmpInfo.cc:247
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:249
double getReadNoise() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:196
void setReadNoise(double readNoise)
amplifier read noise, in e-
Definition: AmpInfo.cc:197
double getGain() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:185
void setLinearityCoeffs(std::vector< double > const &coeffs)
vector of linearity coefficients
Definition: AmpInfo.cc:210
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:244
void setName(std::string const &name)
name of amplifier location in camera
Definition: AmpInfo.cc:174
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:225
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
ItemVariant const * other
Definition: Schema.cc:56
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
void setRawPrescanBBox(lsst::geom::Box2I const &bbox)
bounding box of usable (horizontal) prescan pixels on raw image
Definition: AmpInfo.cc:279
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:221
Fits * fits
Definition: FitsWriter.cc:90
STL class.
bool getRawFlipX() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:243
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:192
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:191
lsst::geom::Box2I getBBox() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:176
void setGain(double gain)
amplifier gain in e-/ADU
Definition: AmpInfo.cc:186
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:261
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:162
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:199
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:180
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:220
void setRawDataBBox(lsst::geom::Box2I const &bbox)
bounding box of amplifier image pixels on raw image
Definition: AmpInfo.cc:238
std::string getLinearityType() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:215
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:173
lsst::geom::Box2I getRawVerticalOverscanBBox() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:266
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:275
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:202
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:246
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:189
void setLinearityType(std::string const &type)
name of linearity parameterization
Definition: AmpInfo.cc:216
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:270
static Key< Array< double > > getLinearityCoeffsKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:242
lsst::geom::Box2I getRawHorizontalOverscanBBox() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:256
void setRawXYOffset(lsst::geom::Extent2I const &xy)
offset for assembling a raw CCD image: desired xy0 - raw xy0
Definition: AmpInfo.cc:252
double getSaturation() const
Convenience accessors for the keys in the minimal reference schema.
Definition: AmpInfo.cc:188
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:229
std::shared_ptr< BaseRecord > _makeRecord() override
Default-construct an associated record (protected implementation).
Definition: AmpInfo.cc:166
static Key< double > getSaturationKey()
Get keys for standard fields shared by all references.
Definition: AmpInfo.h:239