lsst.afw  16.0-10-gd1b3a1c94
TransmissionCurve.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2017 LSST/AURA.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include <algorithm>
24 #include <memory>
25 
26 #include "ndarray.h"
27 
28 #include "gsl/gsl_interp.h"
29 #include "gsl/gsl_interp2d.h"
30 #include "gsl/gsl_errno.h"
31 
36 
37 using namespace std::string_literals;
38 
39 #define LSST_CHECK_GSL(type, status) \
40  if (status) throw LSST_EXCEPT(type, "GSL error: "s + ::gsl_strerror(status))
41 
42 namespace lsst {
43 namespace afw {
44 namespace image {
45 
46 namespace {
47 
48 /*
49  * The TransmissionCurve implementation returned by TransmissionCurve::makeIdentity.
50  *
51  * This is zero-state singleton whose throughput is always exactly 1.
52  */
53 class IdentityTransmissionCurve : public TransmissionCurve {
54 public:
55  static constexpr char const* NAME = "IdentityTransmissionCurve";
56 
58  static std::shared_ptr<IdentityTransmissionCurve> instance(new IdentityTransmissionCurve());
59  return instance;
60  }
61 
62  std::pair<double, double> getWavelengthBounds() const override {
63  constexpr double inf = std::numeric_limits<double>::infinity();
64  return std::make_pair(-inf, inf);
65  }
66 
67  std::pair<double, double> getThroughputAtBounds() const override { return std::make_pair(1.0, 1.0); }
68 
69  void sampleAt(lsst::geom::Point2D const&, ndarray::Array<double const, 1, 1> const& wavelengths,
70  ndarray::Array<double, 1, 1> const& out) const override {
71  out.deep() = 1.0;
72  }
73 
74  bool isPersistable() const override { return true; }
75 
76 protected:
77  // transforming an IdentityTransmissionCurve is a no-op
80  return shared_from_this();
81  }
82 
83  // multiplying an IdentityTransmissionCurve always yields the other operand
86  return other;
87  }
88 
89  std::string getPersistenceName() const override { return NAME; }
90 
91  void write(OutputArchiveHandle& handle) const override { handle.saveEmpty(); }
92 
93  class Factory : public table::io::PersistableFactory {
94  public:
95  std::shared_ptr<table::io::Persistable> read(InputArchive const& archive,
96  CatalogVector const& catalogs) const override {
97  LSST_ARCHIVE_ASSERT(catalogs.size() == 0u);
98  return get();
99  }
100 
101  Factory() : table::io::PersistableFactory(NAME) {}
102  };
103 
104  static Factory registration;
105 
106 private:
107  IdentityTransmissionCurve() = default;
108 };
109 
110 IdentityTransmissionCurve::Factory IdentityTransmissionCurve::registration;
111 
112 /*
113  * InterpolatedTransmissionCurve: implements makeSpatiallyConstant and makeRadial.
114  *
115  * InterpolatedTransmissionCurve is templated on an implementation class
116  * that does most of the work, letting it handle the boilerplate that is
117  * common to both spatially-constant and radially-varying curves.
118  *
119  * We use two tricks to avoid repetition that bear some explanation:
120  *
121  * - Even though the two implementations have different state, we can use
122  * the same PersistenceHelper template for both by using a std::vector
123  * to hold the keys for the arrays. Impl2d has one extra array to save,
124  * so its vector is one element longer.
125  *
126  * - The throughput array held by Impl2d is conceptually a 2-d array, but we
127  * actually store a flattened view into it. That's okay because both GSL
128  * and the persistence layer only care about the pointer and the size. That
129  * requires going through some hoops in makeRadial, but from then on it's
130  * clean sailing.
131  */
132 
133 template <typename T>
134 using GslPtr = std::unique_ptr<T, void (*)(T*)>;
135 
136 template <typename T>
137 GslPtr<T> makeGslPtr(T* p, void (*free)(T*)) {
138  if (p == nullptr) {
139  throw std::bad_alloc();
140  }
141  return GslPtr<T>(p, free);
142 }
143 
144 using ArrayKeyVector = std::vector<table::Key<table::Array<double>>>;
145 
146 /*
147  * Implementation object as a template parameter for the instantiation of
148  * InterpolatedTransmissionCurve used by makeSpatiallyConstant.
149  */
150 class Impl1d {
151 public:
152  static constexpr bool isSpatiallyConstant = true;
153  static constexpr char const* NAME = "SpatiallyConstantTransmissionCurve";
154 
155  // Initialize the GSL interpolator and take ownership of the given arrays.
156  // Array size consistency checks are done by makeSpatiallyConstant,
157  // so we don't need to worry about them here.
158  Impl1d(ndarray::Array<double, 1, 1> const& throughput, ndarray::Array<double, 1, 1> const& wavelengths)
159  : _throughput(throughput),
160  _wavelengths(wavelengths),
161  _interp(makeGslPtr(::gsl_interp_alloc(::gsl_interp_linear, _wavelengths.size()),
162  &::gsl_interp_free)) {
163  int status = ::gsl_interp_init(_interp.get(), _wavelengths.getData(), _throughput.getData(),
164  _wavelengths.size());
165  LSST_CHECK_GSL(pex::exceptions::LogicError, status);
166  }
167 
168  std::pair<double, double> getWavelengthBounds() const {
169  return std::make_pair(_wavelengths.front(), _wavelengths.back());
170  }
171 
172  static void setupPersistence(table::Schema& schema, ArrayKeyVector& keys) {
173  keys.push_back(schema.addField<table::Array<double>>("throughput", "array of known throughput values",
174  "", 0));
175  keys.push_back(schema.addField<table::Array<double>>(
176  "wavelengths", "array of known wavelength values", "angstrom", 0));
177  }
178 
179  void persist(table::BaseRecord& record, ArrayKeyVector const& keys) const {
180  record.set(keys[0], _throughput);
181  record.set(keys[1], _wavelengths);
182  }
183 
184  static Impl1d unpersist(table::BaseRecord& record, ArrayKeyVector const& keys) {
185  return Impl1d(record[keys[0]], record[keys[1]]);
186  }
187 
188  // A helper object constructed every time InterpolatedTransmissionCurve::sampleAt
189  // is called, and then invoked at every iteration of the loop therein.
190  struct Functor {
191  Functor(Impl1d const&, lsst::geom::Point2D const&)
192  : _accel(makeGslPtr(::gsl_interp_accel_alloc(), &gsl_interp_accel_free)) {}
193 
194  double operator()(Impl1d const& parent, double wavelength) {
195  double result = 0.0;
196  int status = ::gsl_interp_eval_e(parent._interp.get(), parent._wavelengths.getData(),
197  parent._throughput.getData(), wavelength, _accel.get(), &result);
198  LSST_CHECK_GSL(pex::exceptions::RuntimeError, status);
199  return result;
200  }
201 
202  private:
203  GslPtr<::gsl_interp_accel> _accel;
204  };
205 
206 private:
207  ndarray::Array<double, 1, 1> _throughput;
208  ndarray::Array<double, 1, 1> _wavelengths;
209  GslPtr<::gsl_interp> _interp;
210 };
211 
212 /*
213  * Implementation object as a template parameter for the instantiation of
214  * InterpolatedTransmissionCurve used by makeRadial.
215  */
216 class Impl2d {
217 public:
218  static constexpr bool isSpatiallyConstant = false;
219  static constexpr char const* NAME = "RadialTransmissionCurve";
220 
221  Impl2d(ndarray::Array<double, 1, 1> const& throughput, ndarray::Array<double, 1, 1> const& wavelengths,
222  ndarray::Array<double, 1, 1> const& radii)
223  : _throughput(throughput),
224  _wavelengths(wavelengths),
225  _radii(radii),
226  _interp(makeGslPtr(
227  ::gsl_interp2d_alloc(::gsl_interp2d_bilinear, _wavelengths.size(), _radii.size()),
228  &::gsl_interp2d_free)) {
229  int status = ::gsl_interp2d_init(_interp.get(), _wavelengths.getData(), _radii.getData(),
230  _throughput.getData(), _wavelengths.size(), _radii.size());
231  LSST_CHECK_GSL(pex::exceptions::LogicError, status);
232  }
233 
234  std::pair<double, double> getWavelengthBounds() const {
235  return std::make_pair(_wavelengths.front(), _wavelengths.back());
236  }
237 
238  static void setupPersistence(table::Schema& schema, ArrayKeyVector& keys) {
239  keys.push_back(schema.addField<table::Array<double>>(
240  "throughput",
241  "flattenned 2-d array of known throughput values, with radius dimension fastest", "", 0));
242  keys.push_back(schema.addField<table::Array<double>>(
243  "wavelengths", "array of known wavelength values", "angstrom", 0));
244  keys.push_back(schema.addField<table::Array<double>>("radii", "array of known radius values", "", 0));
245  }
246 
247  void persist(table::BaseRecord& record, ArrayKeyVector const& keys) const {
248  record.set(keys[0], _throughput);
249  record.set(keys[1], _wavelengths);
250  record.set(keys[2], _radii);
251  }
252 
253  static Impl2d unpersist(table::BaseRecord& record, ArrayKeyVector const& keys) {
254  return Impl2d(record[keys[0]], record[keys[1]], record[keys[2]]);
255  }
256 
257  // A helper object constructed every time InterpolatedTransmissionCurve::sampleAt
258  // is called, and then invoked at every iteration of the loop therein.
259  struct Functor {
260  Functor(Impl2d const& parent, lsst::geom::Point2D const& point)
261  : _radius(point.asEigen().norm()),
262  _radiusAccel(makeGslPtr(::gsl_interp_accel_alloc(), &gsl_interp_accel_free)),
263  _wavelengthAccel(makeGslPtr(::gsl_interp_accel_alloc(), &gsl_interp_accel_free)) {
264  _radius = std::max(_radius, parent._radii.front());
265  _radius = std::min(_radius, parent._radii.back());
266  }
267 
268  double operator()(Impl2d const& parent, double wavelength) {
269  double result = 0.0;
270  int status =
271  ::gsl_interp2d_eval_e(parent._interp.get(), parent._wavelengths.getData(),
272  parent._radii.getData(), parent._throughput.getData(), wavelength,
273  _radius, _radiusAccel.get(), _wavelengthAccel.get(), &result);
274  LSST_CHECK_GSL(pex::exceptions::RuntimeError, status);
275  return result;
276  }
277 
278  private:
279  double _radius;
280  GslPtr<::gsl_interp_accel> _radiusAccel;
281  GslPtr<::gsl_interp_accel> _wavelengthAccel;
282  };
283 
284 private:
285  ndarray::Array<double, 1, 1> _throughput;
286  ndarray::Array<double, 1, 1> _wavelengths;
287  ndarray::Array<double, 1, 1> _radii;
288  GslPtr<::gsl_interp2d> _interp;
289 };
290 
291 template <typename Impl>
292 class InterpolatedTransmissionCurve : public TransmissionCurve {
293 public:
294  InterpolatedTransmissionCurve(Impl impl, std::pair<double, double> throughputAtBounds)
295  : _atBounds(throughputAtBounds), _impl(std::move(impl)) {
296  if (!std::isfinite(_atBounds.first) || !std::isfinite(_atBounds.second)) {
297  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
298  "Throughput values at bounds must be finite");
299  }
300  }
301 
302  std::pair<double, double> getWavelengthBounds() const override { return _impl.getWavelengthBounds(); }
303 
304  std::pair<double, double> getThroughputAtBounds() const override { return _atBounds; }
305 
306  void sampleAt(lsst::geom::Point2D const& point, ndarray::Array<double const, 1, 1> const& wavelengths,
307  ndarray::Array<double, 1, 1> const& out) const override {
308  LSST_THROW_IF_NE(wavelengths.getSize<0>(), out.getSize<0>(), pex::exceptions::LengthError,
309  "Length of wavelength array (%d) does not match size of output array (%d)");
310  typename Impl::Functor functor(_impl, point);
311  auto bounds = _impl.getWavelengthBounds();
312  auto wlIter = wavelengths.begin();
313  for (auto outIter = out.begin(); outIter != out.end(); ++outIter, ++wlIter) {
314  double& y = *outIter;
315  if (*wlIter < bounds.first) {
316  y = _atBounds.first;
317  } else if (*wlIter > bounds.second) {
318  y = _atBounds.second;
319  } else {
320  y = functor(_impl, *wlIter);
321  }
322  }
323  }
324 
325  bool isPersistable() const override { return true; }
326 
327 protected:
328  std::shared_ptr<TransmissionCurve const> _transformedByImpl(
330  if (_impl.isSpatiallyConstant) {
331  return shared_from_this();
332  } else {
333  return TransmissionCurve::_transformedByImpl(transform);
334  }
335  }
336 
337  std::string getPersistenceName() const override { return Impl::NAME; }
338 
339  struct PersistenceHelper {
340  table::Schema schema;
341  table::Key<double> throughputAtMin;
342  table::Key<double> throughputAtMax;
343  ArrayKeyVector arrays;
344 
345  static PersistenceHelper const& get() {
346  static PersistenceHelper const instance;
347  return instance;
348  }
349 
350  private:
351  PersistenceHelper()
352  : schema(),
354  schema.addField<double>("throughputAtMin", "throughput below minimum wavelength")),
356  schema.addField<double>("throughputAtMax", "throughput above minimum wavelength")) {
357  Impl::setupPersistence(schema, arrays);
358  schema.getCitizen().markPersistent();
359  }
360  };
361 
362  void write(OutputArchiveHandle& handle) const override {
363  auto const& keys = PersistenceHelper::get();
364  auto catalog = handle.makeCatalog(keys.schema);
365  auto record = catalog.addNew();
366  record->set(keys.throughputAtMin, _atBounds.first);
367  record->set(keys.throughputAtMax, _atBounds.second);
368  _impl.persist(*record, keys.arrays);
369  handle.saveCatalog(catalog);
370  }
371 
372  class Factory : public table::io::PersistableFactory {
373  public:
374  std::shared_ptr<table::io::Persistable> read(InputArchive const& archive,
375  CatalogVector const& catalogs) const override {
376  auto const& keys = PersistenceHelper::get();
377  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
378  LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
379  auto& record = catalogs.front().front();
380  return std::make_shared<InterpolatedTransmissionCurve>(
381  Impl::unpersist(record, keys.arrays),
382  std::make_pair(record.get(keys.throughputAtMin), record.get(keys.throughputAtMax)));
383  }
384 
385  Factory() : table::io::PersistableFactory(Impl::NAME) {}
386  };
387 
388  static Factory registration;
389 
390 private:
391  std::pair<double, double> _atBounds;
392  Impl _impl;
393 };
394 
395 template <typename Impl>
396 typename InterpolatedTransmissionCurve<Impl>::Factory InterpolatedTransmissionCurve<Impl>::registration;
397 
398 template class InterpolatedTransmissionCurve<Impl1d>;
399 template class InterpolatedTransmissionCurve<Impl2d>;
400 
401 /*
402  * ProductTransmissionCurve: default for TransmissionCurve::multipliedBy().
403  *
404  * This is a straightforward lazy-evaluation object. Its only state is the
405  * two operands it delegates to.
406  */
407 class ProductTransmissionCurve : public TransmissionCurve {
408 public:
409  static constexpr char const* NAME = "ProductTransmissionCurve";
410 
411  ProductTransmissionCurve(std::shared_ptr<TransmissionCurve const> a,
413  : _a(std::move(a)), _b(std::move(b)) {}
414 
415  std::pair<double, double> getWavelengthBounds() const override {
416  auto aWavelengthBounds = _a->getWavelengthBounds();
417  auto bWavelengthBounds = _b->getWavelengthBounds();
418  auto aThroughputAtBounds = _a->getThroughputAtBounds();
419  auto bThroughputAtBounds = _b->getThroughputAtBounds();
420 
421  auto determineWavelengthBound = [](double aWavelength, double bWavelength, double aThroughput,
422  double bThroughput, auto isFirstOuter) -> double {
423  // Use the outermost wavelength bound only if its throughput
424  // values are not being multiplied by zeros from the operand with
425  // the innermost wavelength bound.
426  if (isFirstOuter(aWavelength, bWavelength)) {
427  return (bThroughput == 0.0) ? bWavelength : aWavelength;
428  } else {
429  return (aThroughput == 0.0) ? aWavelength : bWavelength;
430  }
431  };
432 
433  return std::make_pair(determineWavelengthBound(aWavelengthBounds.first, bWavelengthBounds.first,
434  aThroughputAtBounds.first, bThroughputAtBounds.first,
436  determineWavelengthBound(aWavelengthBounds.second, bWavelengthBounds.second,
437  aThroughputAtBounds.second, bThroughputAtBounds.second,
439  }
440 
441  std::pair<double, double> getThroughputAtBounds() const override {
442  auto aAtBounds = _a->getThroughputAtBounds();
443  auto bAtBounds = _b->getThroughputAtBounds();
444  return std::make_pair(aAtBounds.first * bAtBounds.first, aAtBounds.second * bAtBounds.second);
445  }
446 
447  void sampleAt(lsst::geom::Point2D const& position, ndarray::Array<double const, 1, 1> const& wavelengths,
448  ndarray::Array<double, 1, 1> const& out) const override {
449  _a->sampleAt(position, wavelengths, out);
450  ndarray::Array<double, 1, 1> tmp = ndarray::allocate(wavelengths.getSize<0>());
451  _b->sampleAt(position, wavelengths, tmp);
452  out.deep() *= tmp;
453  }
454 
455  bool isPersistable() const override { return _a->isPersistable() && _b->isPersistable(); }
456 
457 protected:
458  std::string getPersistenceName() const override { return NAME; }
459 
460  struct PersistenceHelper {
461  table::Schema schema;
462  table::Key<int> a;
463  table::Key<int> b;
464 
465  static PersistenceHelper const& get() {
466  static PersistenceHelper const instance;
467  return instance;
468  }
469 
470  private:
471  PersistenceHelper()
472  : schema(),
473  a(schema.addField<int>("a", "archive ID of first operand")),
474  b(schema.addField<int>("b", "archive ID of second operand")) {
475  schema.getCitizen().markPersistent();
476  }
477  };
478 
479  class Factory : public table::io::PersistableFactory {
480  public:
481  std::shared_ptr<table::io::Persistable> read(InputArchive const& archive,
482  CatalogVector const& catalogs) const override {
483  auto const& keys = PersistenceHelper::get();
484  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
485  LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
486  auto const& record = catalogs.front().front();
487  return std::make_shared<ProductTransmissionCurve>(
488  archive.get<TransmissionCurve>(record.get(keys.a)),
489  archive.get<TransmissionCurve>(record.get(keys.b)));
490  }
491 
492  Factory() : table::io::PersistableFactory(NAME) {}
493  };
494 
495  void write(OutputArchiveHandle& handle) const override {
496  auto const& keys = PersistenceHelper::get();
497  auto catalog = handle.makeCatalog(keys.schema);
498  auto record = catalog.addNew();
499  record->set(keys.a, handle.put(_a));
500  record->set(keys.b, handle.put(_b));
501  handle.saveCatalog(catalog);
502  }
503 
504  static Factory registration;
505 
506 private:
509 };
510 
511 ProductTransmissionCurve::Factory ProductTransmissionCurve::registration;
512 
513 /*
514  * TransformedTransmissionCurve: default for TransmissionCurve::transform.
515  *
516  * This is a another straightforward lazy-evaluation object. Its only state
517  * is the two operands it delegates to.
518  */
519 class TransformedTransmissionCurve : public TransmissionCurve {
520 public:
521  static constexpr char const* NAME = "TransformedTransmissionCurve";
522 
523  TransformedTransmissionCurve(std::shared_ptr<TransmissionCurve const> nested,
525  : _nested(std::move(nested)), _transform(std::move(transform)) {}
526 
527  std::pair<double, double> getWavelengthBounds() const override { return _nested->getWavelengthBounds(); }
528 
529  std::pair<double, double> getThroughputAtBounds() const override {
530  return _nested->getThroughputAtBounds();
531  }
532 
533  void sampleAt(lsst::geom::Point2D const& position, ndarray::Array<double const, 1, 1> const& wavelengths,
534  ndarray::Array<double, 1, 1> const& out) const override {
535  return _nested->sampleAt(_transform->applyInverse(position), wavelengths, out);
536  }
537 
538  bool isPersistable() const override { return _nested->isPersistable() && _transform->isPersistable(); }
539 
540 protected:
541  // transforming a TransformedTransmissionCurve composes the transforms
542  std::shared_ptr<TransmissionCurve const> _transformedByImpl(
543  std::shared_ptr<geom::TransformPoint2ToPoint2> transform) const override {
544  return std::make_shared<TransformedTransmissionCurve>(_nested, transform->then(*_transform));
545  }
546 
547  std::string getPersistenceName() const override { return NAME; }
548 
549  struct PersistenceHelper {
550  table::Schema schema;
551  table::Key<int> nested;
552  table::Key<int> transform;
553 
554  static PersistenceHelper const& get() {
555  static PersistenceHelper const instance;
556  return instance;
557  }
558 
559  private:
560  PersistenceHelper()
561  : schema(),
562  nested(schema.addField<int>("nested", "archive ID of the nested TransmissionCurve")),
563  transform(schema.addField<int>("transform", "archive ID of the coordinate transform")) {
564  schema.getCitizen().markPersistent();
565  }
566  };
567 
568  void write(OutputArchiveHandle& handle) const override {
569  auto const& keys = PersistenceHelper::get();
570  auto catalog = handle.makeCatalog(keys.schema);
571  auto record = catalog.addNew();
572  record->set(keys.nested, handle.put(_nested));
573  record->set(keys.transform, handle.put(_transform));
574  handle.saveCatalog(catalog);
575  }
576 
577  class Factory : public table::io::PersistableFactory {
578  public:
579  std::shared_ptr<table::io::Persistable> read(InputArchive const& archive,
580  CatalogVector const& catalogs) const override {
581  auto const& keys = PersistenceHelper::get();
582  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
583  LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
584  auto const& record = catalogs.front().front();
585  return std::make_shared<TransformedTransmissionCurve>(
586  archive.get<TransmissionCurve>(record.get(keys.nested)),
587  archive.get<geom::TransformPoint2ToPoint2>(record.get(keys.transform)));
588  }
589 
590  Factory() : table::io::PersistableFactory(NAME) {}
591  };
592 
593  static Factory registration;
594 
595 private:
598 };
599 
600 TransformedTransmissionCurve::Factory TransformedTransmissionCurve::registration;
601 
602 } // namespace
603 
604 /*
605  * TransmissionCurve itself
606  */
607 
608 std::shared_ptr<TransmissionCurve const> TransmissionCurve::makeIdentity() {
609  return IdentityTransmissionCurve::get();
610 }
611 
612 std::shared_ptr<TransmissionCurve const> TransmissionCurve::makeSpatiallyConstant(
613  ndarray::Array<double const, 1> const& throughput, ndarray::Array<double const, 1> const& wavelengths,
614  double throughputAtMin, double throughputAtMax) {
615  ::gsl_set_error_handler_off();
616  LSST_THROW_IF_NE(wavelengths.getSize<0>(), throughput.getSize<0>(), pex::exceptions::LengthError,
617  "Length of wavelength array (%d) does not match size of throughput array (%d)");
618  return std::make_shared<InterpolatedTransmissionCurve<Impl1d>>(
619  Impl1d(ndarray::copy(throughput), ndarray::copy(wavelengths)),
620  std::make_pair(throughputAtMin, throughputAtMax));
621 }
622 
623 std::shared_ptr<TransmissionCurve const> TransmissionCurve::makeRadial(
624  ndarray::Array<double const, 2> const& throughput, ndarray::Array<double const, 1> const& wavelengths,
625  ndarray::Array<double const, 1> const& radii, double throughputAtMin, double throughputAtMax) {
626  ::gsl_set_error_handler_off();
628  wavelengths.getSize<0>(), throughput.getSize<0>(), pex::exceptions::LengthError,
629  "Length of wavelength array (%d) does not match first dimension of of throughput array (%d)");
631  radii.getSize<0>(), throughput.getSize<1>(), pex::exceptions::LengthError,
632  "Length of radii array (%d) does not match second dimension of of throughput array (%d)");
633  // GSL wants a column major array (Array<T,2,-2>). But ndarray can only flatten row-major arrays
634  // (Array<T,2,2>). So we allocate a row-major array, assign the caller's throughput array to a
635  // transposed view of it, and then flatten the row-major array.
636  ndarray::Array<double, 2, 2> throughputTransposed = ndarray::allocate(throughput.getShape().reverse());
637  throughputTransposed.transpose() = throughput;
638  ndarray::Array<double, 1, 1> throughputFlat = ndarray::flatten<1>(throughputTransposed);
639  return std::make_shared<InterpolatedTransmissionCurve<Impl2d>>(
640  Impl2d(throughputFlat, ndarray::copy(wavelengths), ndarray::copy(radii)),
641  std::make_pair(throughputAtMin, throughputAtMax));
642 }
643 
644 std::shared_ptr<TransmissionCurve const> TransmissionCurve::multipliedBy(
645  TransmissionCurve const& other) const {
646  auto a = shared_from_this();
647  auto b = other.shared_from_this();
648  auto result = a->_multipliedByImpl(b);
649  if (result == nullptr) {
650  result = b->_multipliedByImpl(a);
651  }
652  if (result == nullptr) {
653  result = std::make_shared<ProductTransmissionCurve>(std::move(a), std::move(b));
654  }
655  return result;
656 }
657 
658 std::shared_ptr<TransmissionCurve const> TransmissionCurve::transformedBy(
660  return _transformedByImpl(std::move(transform));
661 }
662 
663 ndarray::Array<double, 1, 1> TransmissionCurve::sampleAt(
664  lsst::geom::Point2D const& position, ndarray::Array<double const, 1, 1> const& wavelengths) const {
665  ndarray::Array<double, 1, 1> out = ndarray::allocate(wavelengths.getSize<0>());
666  sampleAt(position, wavelengths, out);
667  return out;
668 }
669 
670 std::shared_ptr<TransmissionCurve const> TransmissionCurve::_transformedByImpl(
672  return std::make_shared<TransformedTransmissionCurve>(shared_from_this(), std::move(transform));
673 }
674 
675 std::shared_ptr<TransmissionCurve const> TransmissionCurve::_multipliedByImpl(
677  return nullptr;
678 }
679 
680 std::string TransmissionCurve::getPythonModule() const { return "lsst.afw.image"; }
681 
682 } // namespace image
683 } // namespace afw
684 } // namespace lsst
A spatially-varying transmission curve as a function of wavelength.
def keys(self)
#define LSST_THROW_IF_NE(N1, N2, EXC_CLASS, MSG)
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Definition: Persistable.h:48
table::Key< double > throughputAtMax
ItemVariant const * other
Definition: Schema.cc:55
T free(T... args)
table::Key< double > throughputAtMin
table::Key< int > nested
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:300
STL class.
T min(T... args)
A base class for image defects.
#define LSST_CHECK_GSL(type, status)
table::Key< int > b
T make_pair(T... args)
T isfinite(T... args)
T infinity(T... args)
T max(T... args)
T move(T... args)
std::unique_ptr< SchemaItem< U > > result
Definition: Schema.cc:194
#define LSST_EXCEPT(type,...)
STL class.
STL class.
STL class.
table::Key< int > a
table::Schema schema
T transform(T... args)
EigenVector const & asEigen() const
ArrayKeyVector arrays
int y
Definition: SpanSet.cc:44