28 namespace cameraGeom {
39 class AmpInfoBoxKey :
public table::FunctorKey<lsst::geom::Box2I> {
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 {
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) :
167 }
catch (pex::exceptions::NotFoundError &) {}
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)?")),
208 "entire amplifier bbox on raw image",
"pixel")),
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?")),
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());
292 result.setReadNoise(record.
get(helper.readNoise));
293 result.setSaturation(record.
get(helper.saturation));
294 result.setSuspectLevel(record.
get(helper.suspectLevel));
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);