39class AmpInfoBoxKey :
public table::FunctorKey<lsst::geom::Box2I> {
56 static AmpInfoBoxKey addFields(table::Schema& schema, std::string
const& name, std::string
const& doc,
57 std::string
const& unit) {
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 {
95 return lsst::geom::Box2I(record.get(_min),
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(); }
114struct RecordSchemaHelper {
115 table::Schema schema;
116 table::Key<std::string> name;
118 table::Key<double> gain;
119 table::Key<double> saturation;
120 table::Key<double> suspectLevel;
121 table::Key<double> readNoise;
122 table::Key<int> readoutCorner;
123 table::Key<table::Array<double> > linearityCoeffs;
124 table::Key<std::string> linearityType;
125 table::Key<table::Flag> hasRawInfo;
126 AmpInfoBoxKey rawBBox;
127 AmpInfoBoxKey rawDataBBox;
128 table::Key<table::Flag> rawFlipX;
129 table::Key<table::Flag> rawFlipY;
130 table::PointKey<int> rawXYOffset;
131 AmpInfoBoxKey rawHorizontalOverscanBBox;
132 AmpInfoBoxKey rawVerticalOverscanBBox;
133 AmpInfoBoxKey rawPrescanBBox;
134 table::Key<double> linearityThreshold;
135 table::Key<double> linearityMaximum;
136 table::Key<std::string> linearityUnits;
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"]),
148 saturation(schema[
"saturation"]),
149 suspectLevel(schema[
"suspectlevel"]),
150 readNoise(schema[
"readnoise"]),
151 readoutCorner(schema[
"readoutcorner"]),
152 linearityCoeffs(schema[
"linearity_coeffs"]),
153 linearityType(schema[
"linearity_type"]),
154 hasRawInfo(schema[
"hasrawinfo"]),
155 rawBBox(schema[
"raw_bbox"]),
156 rawDataBBox(schema[
"raw_databbox"]),
157 rawFlipX(schema[
"raw_flip_x"]),
158 rawFlipY(schema[
"raw_flip_y"]),
159 rawXYOffset(schema[
"raw_xyoffset"]),
160 rawHorizontalOverscanBBox(schema[
"raw_horizontaloverscanbbox"]),
161 rawVerticalOverscanBBox(schema[
"raw_verticaloverscanbbox"]),
162 rawPrescanBBox(schema[
"raw_prescanbbox"])
164 auto setKeyIfPresent = [
this](
auto & key, std::string
const & name) {
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")),
188 saturation(schema.addField<double>(
190 "level above which pixels are considered saturated; use `nan` if no such level applies",
192 suspectLevel(schema.addField<double>(
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)),
204 linearityType(schema.addField<std::string>(
"linearity_type",
"type of linearity model",
"", 0)),
205 hasRawInfo(schema.addField<table::Flag>(
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",
217 rawHorizontalOverscanBBox(
218 AmpInfoBoxKey::addFields(schema,
"raw_horizontaloverscanbbox",
219 "usable horizontal overscan bbox on raw image",
"pixel")),
220 rawVerticalOverscanBBox(
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")),
226 linearityThreshold(schema.addField<double>(
"linearityThreshold",
227 "Minimum ADU level to apply linearity.")),
228 linearityMaximum(schema.addField<double>(
"linearityMaximum",
229 "Maximum ADU level to apply linearity.")),
230 linearityUnits(schema.addField<std::string>(
"linearityUnits",
231 "Input units for linearity relation.",
"", 0))
239class 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;
287 auto const helper = RecordSchemaHelper(record.
getSchema());
311 auto setIfValid = [&record](
auto & member,
auto & key) {
313 member = record.
get(key);
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 = [&record](
auto value,
auto & key) {
346 record.
set(key, value);
349 setIfValid(fields.linearityThreshold, helper.linearityThreshold);
350 setIfValid(fields.linearityMaximum, helper.linearityMaximum);
351 setIfValid(fields.linearityUnits, helper.linearityUnits);
A mutable Amplifier subclass class that can be used to incrementally construct or modify Amplifiers.
void setSaturation(double saturation)
Level in ADU above which pixels are considered saturated; use nan if no such level applies.
void setBBox(lsst::geom::Box2I const &bbox)
Bounding box of amplifier pixels in the trimmed, assembled image.
Builder & operator=(Builder const &)=default
Standard copy assignment.
void setRawFlipY(bool rawFlipY)
Is this amplifier (and the image to which it is attached) flipped in the Y direction,...
Builder()=default
Construct a Builder with default values for all fields.
void setReadNoise(double readNoise)
Amplifier read noise, in e-.
void setLinearityCoeffs(ndarray::Array< double const, 1, 1 > const &coeffs)
Vector of linearity coefficients.
static Builder fromRecord(table::BaseRecord const &record)
Construct a new Builder object from the fields in the given record.
void setRawHorizontalOverscanBBox(lsst::geom::Box2I const &bbox)
The bounding box of horizontal overscan pixels in the image to which it is attached,...
void setRawFlipX(bool rawFlipX)
Is this amplifier (and the image to which it is attached) flipped in the X direction,...
Fields const & getFields() const override
void setGain(double gain)
Amplifier gain in e-/ADU.
void setReadoutCorner(ReadoutCorner readoutCorner)
Readout corner in the trimmed, assembled image.
void setRawDataBBox(lsst::geom::Box2I const &bbox)
Bounding box of amplifier data pixels in the image to which it is attached, which is assumed to be un...
std::shared_ptr< Amplifier const > finish() const
Construct an immutable Amplifier with the same values as the Builder.
void setSuspectLevel(double suspectLevel)
Level in ADU above which pixels are considered suspicious, meaning they may be affected by unknown sy...
void setLinearityType(std::string const &type)
Name of linearity parameterization.
void setRawVerticalOverscanBBox(lsst::geom::Box2I const &bbox)
The bounding box of vertical overscan pixels in the image to which it is attached,...
void setRawXYOffset(lsst::geom::Extent2I const &xy)
Offset in transformation from this amplifier (and the image to which it is attached) to trimmed,...
void setRawPrescanBBox(lsst::geom::Box2I const &bbox)
The bounding box of (horizontal) prescan pixels in the image to which it is attached,...
void setName(std::string const &name)
Name of the amplifier.
void setRawBBox(lsst::geom::Box2I const &bbox)
Bounding box of the untrimmed amplifier in the image to which it is attached, which is assumed to be ...
Geometry and electronic information about raw amplifier images.
Builder rebuild() const
Return a Builder object initialized with the fields of this.
virtual Fields const & getFields() const =0
void toRecord(table::BaseRecord &record) const
Copy the Amplifier's fields into the given record.
static table::Schema getRecordSchema()
Return the schema used in the afw.table representation of amplifiers.
Base class for all records.
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
Schema getSchema() const
Return the Schema that holds this record's fields and keys.
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
static PointKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
Defines the fields and offsets for a table.
Point2I const getMin() const noexcept
Extent2I const getDimensions() const noexcept
ReadoutCorner
Readout corner, in the frame of reference of the assembled image.
void swap(CameraSys &a, CameraSys &b)
PointKey< int > Point2IKey
Extent< int, 2 > Extent2I
double linearityThreshold
std::string linearityUnits