28 namespace cameraGeom {
39 class AmpInfoBoxKey :
public table::FunctorKey<lsst::geom::Box2I> {
61 schema.join(name,
"min"),
67 schema.join(name,
"extent"),
75 AmpInfoBoxKey() noexcept = default;
85 AmpInfoBoxKey(table::SubSchema const& s) : _min(s["
min"]), _dimensions(s["extent"]) {}
87 AmpInfoBoxKey(AmpInfoBoxKey
const&) noexcept =
default;
88 AmpInfoBoxKey(AmpInfoBoxKey&&) noexcept = default;
89 AmpInfoBoxKey& operator=(AmpInfoBoxKey const&) noexcept = default;
90 AmpInfoBoxKey& operator=(AmpInfoBoxKey&&) noexcept = default;
91 ~AmpInfoBoxKey() noexcept override = default;
94 lsst::
geom::
Box2I get(table::BaseRecord const& record)
const override {
100 void set(table::BaseRecord& record,
lsst::geom::Box2I const& value)
const override {
101 record.set(_min, value.getMin());
106 bool isValid() const noexcept {
return _min.isValid() && _dimensions.isValid(); }
114 struct RecordSchemaHelper {
138 static RecordSchemaHelper
const & getMinimal() {
139 static RecordSchemaHelper
const instance;
143 RecordSchemaHelper(table::Schema
const & existing) :
145 name(schema[
"name"]),
146 bbox(schema[
"bbox"]),
147 gain(schema[
"gain"]),
167 }
catch (pex::exceptions::NotFoundError &) {}
175 setKeyIfPresent(linearityThreshold,
"linearityThreshold");
176 setKeyIfPresent(linearityMaximum,
"linearityMaximum");
177 setKeyIfPresent(linearityUnits,
"linearityUnits");
182 RecordSchemaHelper() :
184 name(schema.addField<
std::string>(
"name",
"name of amplifier location in camera",
"", 0)),
185 bbox(AmpInfoBoxKey::addFields(
186 schema,
"bbox",
"bbox of amplifier image data on assembled image",
"pixel")),
187 gain(schema.addField<
double>(
"gain",
"amplifier gain",
"electron adu^-1")),
190 "level above which pixels are considered saturated; use `nan` if no such level applies",
194 "level above which pixels are considered suspicious, meaning they may be affected by unknown " 195 "systematics; for example if non-linearity corrections above a certain level are unstable " 196 "then that would be a useful value for suspectLevel; use `nan` if no such level applies",
198 readNoise(schema.addField<
double>(
"readnoise",
"amplifier read noise",
"electron")),
200 schema.addField<
int>(
"readoutcorner",
"readout corner, in the frame of the assembled image")),
202 schema.addField<table::Array<double> >(
"linearity_coeffs",
203 "coefficients for linearity fit up to cubic",
"", 0)),
206 "hasrawinfo",
"is raw amplifier information available (e.g. untrimmed bounding boxes)?")),
207 rawBBox(AmpInfoBoxKey::addFields(schema,
"raw_bbox",
208 "entire amplifier bbox on raw image",
"pixel")),
209 rawDataBBox(AmpInfoBoxKey::addFields(schema,
"raw_databbox",
210 "image data bbox on raw image",
"pixel")),
211 rawFlipX(schema.addField<table::Flag>(
"raw_flip_x",
"flip row order to make assembled image?")),
212 rawFlipY(schema.addField<table::Flag>(
"raw_flip_y",
"flip column order to make an assembled image?")),
214 schema,
"raw_xyoffset",
215 "offset for assembling a raw CCD image: desired xy0 - raw xy0; 0,0 if raw data comes assembled",
218 AmpInfoBoxKey::addFields(schema,
"raw_horizontaloverscanbbox",
219 "usable horizontal overscan bbox on raw image",
"pixel")),
221 AmpInfoBoxKey::addFields(schema,
"raw_verticaloverscanbbox",
222 "usable vertical overscan region raw image",
"pixel")),
224 AmpInfoBoxKey::addFields(schema,
"raw_prescanbbox",
225 "usable (horizontal) prescan bbox on raw image",
"pixel")),
227 "Minimum ADU level to apply linearity.")),
229 "Maximum ADU level to apply linearity.")),
231 "Input units for linearity relation.",
"", 0))
239 class FrozenAmplifier final :
public Amplifier {
242 explicit FrozenAmplifier(Fields
const & fields) : _fields(fields) {}
247 FrozenAmplifier(FrozenAmplifier
const &) =
delete;
248 FrozenAmplifier(FrozenAmplifier &&) =
delete;
250 FrozenAmplifier & operator=(FrozenAmplifier
const &) =
delete;
251 FrozenAmplifier & operator=(FrozenAmplifier &&) =
delete;
253 ~FrozenAmplifier() noexcept
override =
default;
257 Fields
const & getFields()
const override {
return _fields; }
261 Fields
const _fields;
268 return RecordSchemaHelper::getMinimal().schema;
283 return std::make_shared<FrozenAmplifier>(_fields);
287 auto const helper = RecordSchemaHelper(record.
getSchema());
289 result.setName(record.
get(helper.name));
290 result.setBBox(record.
get(helper.bbox));
291 result.setGain(record.
get(helper.gain));
292 result.setReadNoise(record.
get(helper.readNoise));
293 result.setSaturation(record.
get(helper.saturation));
294 result.setSuspectLevel(record.
get(helper.suspectLevel));
295 result.setReadoutCorner(static_cast<ReadoutCorner>(record.
get(helper.readoutCorner)));
296 result.setLinearityCoeffs(ndarray::copy(record.
get(helper.linearityCoeffs)));
297 result.setLinearityType(record.
get(helper.linearityType));
298 result.setRawBBox(record.
get(helper.rawBBox));
299 result.setRawDataBBox(record.
get(helper.rawDataBBox));
300 result.setRawFlipX(record.
get(helper.rawFlipX));
301 result.setRawFlipY(record.
get(helper.rawFlipY));
303 result.setRawHorizontalOverscanBBox(record.
get(helper.rawHorizontalOverscanBBox));
304 result.setRawVerticalOverscanBBox(record.
get(helper.rawVerticalOverscanBBox));
305 result.setRawHorizontalOverscanBBox(record.
get(helper.rawHorizontalOverscanBBox));
306 result.setRawPrescanBBox(record.
get(helper.rawPrescanBBox));
311 auto setIfValid = [&record](
auto & member,
auto &
key) {
316 setIfValid(result._fields.linearityThreshold, helper.linearityThreshold);
317 setIfValid(result._fields.linearityMaximum, helper.linearityMaximum);
318 setIfValid(result._fields.linearityUnits, helper.linearityUnits);
323 auto const helper = RecordSchemaHelper(record.
getSchema());
325 record.
set(helper.name, fields.name);
326 record.
set(helper.bbox, fields.bbox);
327 record.
set(helper.gain, fields.gain);
328 record.
set(helper.readNoise, fields.readNoise);
329 record.
set(helper.saturation, fields.saturation);
330 record.
set(helper.suspectLevel, fields.suspectLevel);
331 record.
set(helper.readoutCorner, static_cast<int>(fields.readoutCorner));
332 ndarray::Array<double, 1, 1> coeffs = ndarray::copy(fields.linearityCoeffs);
333 record.
set(helper.linearityCoeffs, coeffs);
334 record.
set(helper.linearityType, fields.linearityType);
335 record.
set(helper.rawBBox, fields.rawBBox);
336 record.
set(helper.rawDataBBox, fields.rawDataBBox);
337 record.
set(helper.rawFlipX, fields.rawFlipX);
338 record.
set(helper.rawFlipY, fields.rawFlipY);
340 record.
set(helper.rawHorizontalOverscanBBox, fields.rawHorizontalOverscanBBox);
341 record.
set(helper.rawVerticalOverscanBBox, fields.rawVerticalOverscanBBox);
342 record.
set(helper.rawPrescanBBox, fields.rawPrescanBBox);
344 auto setIfValid = [
this, &record](
auto value,
auto &
key) {
349 setIfValid(fields.linearityThreshold, helper.linearityThreshold);
350 setIfValid(fields.linearityMaximum, helper.linearityMaximum);
351 setIfValid(fields.linearityUnits, helper.linearityUnits);
Defines the fields and offsets for a table.
table::Key< double > linearityMaximum
PointKey< int > Point2IKey
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.
ItemVariant const * other
table::Key< double > suspectLevel
void toRecord(table::BaseRecord &record) const
Copy the Amplifier's fields into the given record.
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
table::Key< std::string > linearityType
AmpInfoBoxKey rawDataBBox
Builder rebuild() const
Return a Builder object initialized with the fields of this.
A mutable Amplifier subclass class that can be used to incrementally construct or modify Amplifiers...
table::Key< std::string > linearityUnits
table::Key< double > saturation
Builder & operator=(Builder const &)=default
Standard copy assignment.
table::PointKey< int > rawXYOffset
A base class for image defects.
std::shared_ptr< Amplifier const > finish() const
Construct an immutable Amplifier with the same values as the Builder.
table::Key< double > gain
table::Key< double > readNoise
AmpInfoBoxKey rawVerticalOverscanBBox
Schema getSchema() const
Return the Schema that holds this record's fields and keys.
table::Key< table::Array< double > > linearityCoeffs
virtual Fields const & getFields() const =0
static Builder fromRecord(table::BaseRecord const &record)
Construct a new Builder object from the fields in the given record.
Extent< int, 2 > Extent2I
table::Key< table::Flag > hasRawInfo
Base class for all records.
table::Key< double > linearityThreshold
table::Key< std::string > name
Geometry and electronic information about raw amplifier images.
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
void swap(CameraSys &a, CameraSys &b)
table::Key< table::Flag > rawFlipX
An integer coordinate rectangle.
AmpInfoBoxKey rawPrescanBBox
AmpInfoBoxKey rawHorizontalOverscanBBox
table::Key< int > readoutCorner
table::Key< table::Flag > rawFlipY
Fields const & getFields() const override
static table::Schema getRecordSchema()
Return the schema used in the afw.table representation of amplifiers.
Builder()=default
Construct a Builder with default values for all fields.