lsst.afw  14.0-38-g278b05818
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 
43 namespace lsst {
44 namespace afw {
45 namespace image {
46 
47 namespace {
48 
49 /*
50  * The TransmissionCurve implementation returned by TransmissionCurve::makeIdentity.
51  *
52  * This is zero-state singleton whose throughput is always exactly 1.
53  */
54 class IdentityTransmissionCurve : public TransmissionCurve {
55 public:
56 
57  static constexpr char const * NAME = "IdentityTransmissionCurve";
58 
60  static std::shared_ptr<IdentityTransmissionCurve> instance(new IdentityTransmissionCurve());
61  return instance;
62  }
63 
64  std::pair<double,double> getWavelengthBounds() const override {
65  constexpr double inf = std::numeric_limits<double>::infinity();
66  return std::make_pair(-inf, inf);
67  }
68 
69  std::pair<double,double> getThroughputAtBounds() const override {
70  return std::make_pair(1.0, 1.0);
71  }
72 
73  void sampleAt(
74  geom::Point2D const &,
75  ndarray::Array<double const,1,1> const & wavelengths,
76  ndarray::Array<double,1,1> const & out
77  ) const override {
78  out.deep() = 1.0;
79  }
80 
81  bool isPersistable() const override { return true; }
82 
83 protected:
84 
85  // transforming an IdentityTransmissionCurve is a no-op
88  ) const override {
89  return shared_from_this();
90  }
91 
92  // multiplying an IdentityTransmissionCurve always yields the other operand
95  ) const {
96  return other;
97  }
98 
99  std::string getPersistenceName() const override { return NAME; }
100 
101  void write(OutputArchiveHandle& handle) const override {
102  handle.saveEmpty();
103  }
104 
105  class Factory : public table::io::PersistableFactory {
106  public:
107 
109  InputArchive const& archive,
110  CatalogVector const& catalogs
111  ) const override {
112  LSST_ARCHIVE_ASSERT(catalogs.size() == 0u);
113  return get();
114  }
115 
116  Factory() : table::io::PersistableFactory(NAME) {}
117  };
118 
119  static Factory registration;
120 
121 private:
122  IdentityTransmissionCurve() = default;
123 };
124 
125 IdentityTransmissionCurve::Factory IdentityTransmissionCurve::registration;
126 
127 
128 /*
129  * InterpolatedTransmissionCurve: implements makeSpatiallyConstant and makeRadial.
130  *
131  * InterpolatedTransmissionCurve is templated on an implementation class
132  * that does most of the work, letting it handle the boilerplate that is
133  * common to both spatially-constant and radially-varying curves.
134  *
135  * We use two tricks to avoid repetition that bear some explanation:
136  *
137  * - Even though the two implementations have different state, we can use
138  * the same PersistenceHelper template for both by using a std::vector
139  * to hold the keys for the arrays. Impl2d has one extra array to save,
140  * so its vector is one element longer.
141  *
142  * - The throughput array held by Impl2d is conceptually a 2-d array, but we
143  * actually store a flattened view into it. That's okay because both GSL
144  * and the persistence layer only care about the pointer and the size. That
145  * requires going through some hoops in makeRadial, but from then on it's
146  * clean sailing.
147  */
148 
149 template <typename T>
150 using GslPtr = std::unique_ptr<T, void (*)(T*)>;
151 
152 template <typename T>
153 GslPtr<T> makeGslPtr(T* p, void (*free)(T*)) {
154  if (p == nullptr) {
155  throw LSST_EXCEPT(
156  pex::exceptions::MemoryError,
157  "Could not allocate GSL object."
158  );
159  }
160  return GslPtr<T>(p, free);
161 }
162 
163 using ArrayKeyVector = std::vector<table::Key<table::Array<double>>>;
164 
165 /*
166  * Implementation object as a template parameter for the instantiation of
167  * InterpolatedTransmissionCurve used by makeSpatiallyConstant.
168  */
169 class Impl1d {
170 public:
171 
172  static constexpr bool isSpatiallyConstant = true;
173  static constexpr char const * NAME = "SpatiallyConstantTransmissionCurve";
174 
175  // Initialize the GSL interpolator and take ownership of the given arrays.
176  // Array size consistency checks are done by makeSpatiallyConstant,
177  // so we don't need to worry about them here.
178  Impl1d(ndarray::Array<double,1,1> const & throughput,
179  ndarray::Array<double,1,1> const & wavelengths) :
180  _throughput(throughput),
181  _wavelengths(wavelengths),
182  _interp(makeGslPtr(::gsl_interp_alloc(::gsl_interp_linear, _wavelengths.size()),
183  &::gsl_interp_free))
184  {
185  int status = ::gsl_interp_init(_interp.get(), _wavelengths.getData(), _throughput.getData(),
186  _wavelengths.size());
187  LSST_CHECK_GSL(pex::exceptions::LogicError, status);
188  }
189 
190  std::pair<double, double> getWavelengthBounds() const {
191  return std::make_pair(_wavelengths.front(), _wavelengths.back());
192  }
193 
194  static void setupPersistence(table::Schema & schema, ArrayKeyVector & keys) {
195  keys.push_back(
196  schema.addField<table::Array<double>>(
197  "throughput", "array of known throughput values", "", 0
198  )
199  );
200  keys.push_back(
201  schema.addField<table::Array<double>>(
202  "wavelengths", "array of known wavelength values", "angstrom", 0
203  )
204  );
205  }
206 
207  void persist(table::BaseRecord & record, ArrayKeyVector const & keys) const {
208  record.set(keys[0], _throughput);
209  record.set(keys[1], _wavelengths);
210  }
211 
212  static Impl1d unpersist(table::BaseRecord & record, ArrayKeyVector const & keys) {
213  return Impl1d(record[keys[0]], record[keys[1]]);
214  }
215 
216  // A helper object constructed every time InterpolatedTransmissionCurve::sampleAt
217  // is called, and then invoked at every iteration of the loop therein.
218  struct Functor {
219 
220  Functor(Impl1d const &, geom::Point2D const &) :
221  _accel(makeGslPtr(::gsl_interp_accel_alloc(), &gsl_interp_accel_free))
222  {}
223 
224  double operator()(Impl1d const & parent, double wavelength) {
225  double result = 0.0;
226  int status = ::gsl_interp_eval_e(parent._interp.get(), parent._wavelengths.getData(),
227  parent._throughput.getData(),
228  wavelength, _accel.get(), &result);
229  LSST_CHECK_GSL(pex::exceptions::RuntimeError, status);
230  return result;
231  }
232 
233  private:
234  GslPtr<::gsl_interp_accel> _accel;
235  };
236 
237 private:
238  ndarray::Array<double,1,1> _throughput;
239  ndarray::Array<double,1,1> _wavelengths;
240  GslPtr<::gsl_interp> _interp;
241 };
242 
243 /*
244  * Implementation object as a template parameter for the instantiation of
245  * InterpolatedTransmissionCurve used by makeRadial.
246  */
247 class Impl2d {
248 public:
249 
250  static constexpr bool isSpatiallyConstant = false;
251  static constexpr char const * NAME = "RadialTransmissionCurve";
252 
253  Impl2d(ndarray::Array<double,1,1> const & throughput,
254  ndarray::Array<double,1,1> const & wavelengths,
255  ndarray::Array<double,1,1> const & radii) :
256  _throughput(throughput),
257  _wavelengths(wavelengths),
258  _radii(radii),
259  _interp(makeGslPtr(::gsl_interp2d_alloc(::gsl_interp2d_bilinear, _wavelengths.size(),
260  _radii.size()),
261  &::gsl_interp2d_free))
262  {
263  int status = ::gsl_interp2d_init(_interp.get(), _wavelengths.getData(), _radii.getData(),
264  _throughput.getData(), _wavelengths.size(), _radii.size());
265  LSST_CHECK_GSL(pex::exceptions::LogicError, status);
266  }
267 
268  std::pair<double, double> getWavelengthBounds() const {
269  return std::make_pair(_wavelengths.front(), _wavelengths.back());
270  }
271 
272  static void setupPersistence(table::Schema & schema, ArrayKeyVector & keys) {
273  keys.push_back(
274  schema.addField<table::Array<double>>(
275  "throughput",
276  "flattenned 2-d array of known throughput values, with radius dimension fastest", "", 0
277  )
278  );
279  keys.push_back(
280  schema.addField<table::Array<double>>(
281  "wavelengths", "array of known wavelength values", "angstrom", 0
282  )
283  );
284  keys.push_back(
285  schema.addField<table::Array<double>>(
286  "radii", "array of known radius values", "", 0
287  )
288  );
289  }
290 
291  void persist(table::BaseRecord & record, ArrayKeyVector const & keys) const {
292  record.set(keys[0], _throughput);
293  record.set(keys[1], _wavelengths);
294  record.set(keys[2], _radii);
295  }
296 
297  static Impl2d unpersist(table::BaseRecord & record, ArrayKeyVector const & keys) {
298  return Impl2d(record[keys[0]], record[keys[1]], record[keys[2]]);
299  }
300 
301  // A helper object constructed every time InterpolatedTransmissionCurve::sampleAt
302  // is called, and then invoked at every iteration of the loop therein.
303  struct Functor {
304 
305  Functor(Impl2d const & parent, geom::Point2D const & point) :
306  _radius(point.asEigen().norm()),
307  _radiusAccel(makeGslPtr(::gsl_interp_accel_alloc(), &gsl_interp_accel_free)),
308  _wavelengthAccel(makeGslPtr(::gsl_interp_accel_alloc(), &gsl_interp_accel_free))
309  {
310  _radius = std::max(_radius, parent._radii.front());
311  _radius = std::min(_radius, parent._radii.back());
312  }
313 
314  double operator()(Impl2d const & parent, double wavelength) {
315  double result = 0.0;
316  int status = ::gsl_interp2d_eval_e(parent._interp.get(), parent._wavelengths.getData(),
317  parent._radii.getData(), parent._throughput.getData(),
318  wavelength, _radius,
319  _radiusAccel.get(), _wavelengthAccel.get(),
320  &result);
321  LSST_CHECK_GSL(pex::exceptions::RuntimeError, status);
322  return result;
323  }
324 
325  private:
326  double _radius;
327  GslPtr<::gsl_interp_accel> _radiusAccel;
328  GslPtr<::gsl_interp_accel> _wavelengthAccel;
329  };
330 
331 private:
332  ndarray::Array<double,1,1> _throughput;
333  ndarray::Array<double,1,1> _wavelengths;
334  ndarray::Array<double,1,1> _radii;
335  GslPtr<::gsl_interp2d> _interp;
336 };
337 
338 
339 template <typename Impl>
340 class InterpolatedTransmissionCurve : public TransmissionCurve {
341 public:
342 
343  InterpolatedTransmissionCurve(Impl impl, std::pair<double, double> throughputAtBounds) :
344  _atBounds(throughputAtBounds),
345  _impl(std::move(impl))
346  {
347  if (!std::isfinite(_atBounds.first) || !std::isfinite(_atBounds.second)) {
348  throw LSST_EXCEPT(
349  pex::exceptions::InvalidParameterError,
350  "Throughput values at bounds must be finite"
351  );
352  }
353  }
354 
355  std::pair<double,double> getWavelengthBounds() const override {
356  return _impl.getWavelengthBounds();
357  }
358 
359  std::pair<double,double> getThroughputAtBounds() const override {
360  return _atBounds;
361  }
362 
363  void sampleAt(
364  geom::Point2D const & point,
365  ndarray::Array<double const,1,1> const & wavelengths,
366  ndarray::Array<double,1,1> const & out
367  ) const override {
369  wavelengths.getSize<0>(), out.getSize<0>(),
370  pex::exceptions::LengthError,
371  "Length of wavelength array (%d) does not match size of output array (%d)"
372  );
373  typename Impl::Functor functor(_impl, point);
374  auto bounds = _impl.getWavelengthBounds();
375  auto wlIter = wavelengths.begin();
376  for (auto outIter = out.begin(); outIter != out.end(); ++outIter, ++wlIter) {
377  double & y = *outIter;
378  if (*wlIter < bounds.first) {
379  y = _atBounds.first;
380  } else if (*wlIter > bounds.second) {
381  y = _atBounds.second;
382  } else {
383  y = functor(_impl, *wlIter);
384  }
385  }
386  }
387 
388  bool isPersistable() const override { return true; }
389 
390 protected:
391 
392  std::shared_ptr<TransmissionCurve const> _transformedByImpl(
394  ) const override {
395  if (_impl.isSpatiallyConstant) {
396  return shared_from_this();
397  } else {
398  return TransmissionCurve::_transformedByImpl(transform);
399  }
400  }
401 
402  std::string getPersistenceName() const override { return Impl::NAME; }
403 
404  struct PersistenceHelper {
405  table::Schema schema;
406  table::Key<double> throughputAtMin;
407  table::Key<double> throughputAtMax;
408  ArrayKeyVector arrays;
409 
410  static PersistenceHelper const & get() {
411  static PersistenceHelper const instance;
412  return instance;
413  }
414 
415  private:
416 
417  PersistenceHelper() :
418  schema(),
419  throughputAtMin(schema.addField<double>(
420  "throughputAtMin", "throughput below minimum wavelength")),
421  throughputAtMax(schema.addField<double>(
422  "throughputAtMax", "throughput above minimum wavelength"))
423  {
424  Impl::setupPersistence(schema, arrays);
425  schema.getCitizen().markPersistent();
426  }
427 
428  };
429 
430  void write(OutputArchiveHandle& handle) const override {
431  auto const & keys = PersistenceHelper::get();
432  auto catalog = handle.makeCatalog(keys.schema);
433  auto record = catalog.addNew();
434  record->set(keys.throughputAtMin, _atBounds.first);
435  record->set(keys.throughputAtMax, _atBounds.second);
436  _impl.persist(*record, keys.arrays);
437  handle.saveCatalog(catalog);
438  }
439 
440  class Factory : public table::io::PersistableFactory {
441  public:
442 
444  InputArchive const& archive,
445  CatalogVector const& catalogs
446  ) const override {
447  auto const& keys = PersistenceHelper::get();
448  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
449  LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
450  auto & record = catalogs.front().front();
451  return std::make_shared<InterpolatedTransmissionCurve>(
452  Impl::unpersist(record, keys.arrays),
453  std::make_pair(record.get(keys.throughputAtMin), record.get(keys.throughputAtMax))
454  );
455  }
456 
457  Factory() : table::io::PersistableFactory(Impl::NAME) {}
458  };
459 
460  static Factory registration;
461 
462 private:
463  std::pair<double,double> _atBounds;
464  Impl _impl;
465 };
466 
467 template <typename Impl>
468 typename InterpolatedTransmissionCurve<Impl>::Factory InterpolatedTransmissionCurve<Impl>::registration;
469 
470 template class InterpolatedTransmissionCurve<Impl1d>;
471 template class InterpolatedTransmissionCurve<Impl2d>;
472 
473 
474 /*
475  * ProductTransmissionCurve: default for TransmissionCurve::multipliedBy().
476  *
477  * This is a straightforward lazy-evaluation object. Its only state is the
478  * two operands it delegates to.
479  */
480 class ProductTransmissionCurve : public TransmissionCurve {
481 public:
482 
483  static constexpr char const * NAME = "ProductTransmissionCurve";
484 
485  ProductTransmissionCurve(
488  ) : _a(std::move(a)), _b(std::move(b)) {}
489 
490  std::pair<double, double> getWavelengthBounds() const override {
491  auto aWavelengthBounds = _a->getWavelengthBounds();
492  auto bWavelengthBounds = _b->getWavelengthBounds();
493  auto aThroughputAtBounds = _a->getThroughputAtBounds();
494  auto bThroughputAtBounds = _b->getThroughputAtBounds();
495 
496  auto determineWavelengthBound = [](
497  double aWavelength, double bWavelength,
498  double aThroughput, double bThroughput,
499  auto isFirstOuter
500  ) -> double {
501  // Use the outermost wavelength bound only if its throughput
502  // values are not being multiplied by zeros from the operand with
503  // the innermost wavelength bound.
504  if (isFirstOuter(aWavelength, bWavelength)) {
505  return (bThroughput == 0.0) ? bWavelength : aWavelength;
506  } else {
507  return (aThroughput == 0.0) ? aWavelength : bWavelength;
508  }
509  };
510 
511  return std::make_pair(
512  determineWavelengthBound(aWavelengthBounds.first, bWavelengthBounds.first,
513  aThroughputAtBounds.first, bThroughputAtBounds.first,
515  determineWavelengthBound(aWavelengthBounds.second, bWavelengthBounds.second,
516  aThroughputAtBounds.second, bThroughputAtBounds.second,
518  );
519  }
520 
521  std::pair<double,double> getThroughputAtBounds() const override {
522  auto aAtBounds = _a->getThroughputAtBounds();
523  auto bAtBounds = _b->getThroughputAtBounds();
524  return std::make_pair(aAtBounds.first * bAtBounds.first,
525  aAtBounds.second * bAtBounds.second);
526  }
527 
528  void sampleAt(
529  geom::Point2D const & position,
530  ndarray::Array<double const,1,1> const & wavelengths,
531  ndarray::Array<double,1,1> const & out
532  ) const override {
533  _a->sampleAt(position, wavelengths, out);
534  ndarray::Array<double,1,1> tmp = ndarray::allocate(wavelengths.getSize<0>());
535  _b->sampleAt(position, wavelengths, tmp);
536  out.deep() *= tmp;
537  }
538 
539  bool isPersistable() const override { return _a->isPersistable() && _b->isPersistable(); }
540 
541 protected:
542 
543  std::string getPersistenceName() const override { return NAME; }
544 
545  struct PersistenceHelper {
546  table::Schema schema;
547  table::Key<int> a;
548  table::Key<int> b;
549 
550  static PersistenceHelper const & get() {
551  static PersistenceHelper const instance;
552  return instance;
553  }
554 
555  private:
556 
557  PersistenceHelper() :
558  schema(),
559  a(schema.addField<int>("a", "archive ID of first operand")),
560  b(schema.addField<int>("b", "archive ID of second operand"))
561  {
562  schema.getCitizen().markPersistent();
563  }
564 
565  };
566 
567  class Factory : public table::io::PersistableFactory {
568  public:
569 
571  InputArchive const& archive,
572  CatalogVector const& catalogs
573  ) const override {
574  auto const& keys = PersistenceHelper::get();
575  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
576  LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
577  auto const & record = catalogs.front().front();
578  return std::make_shared<ProductTransmissionCurve>(
579  archive.get<TransmissionCurve>(record.get(keys.a)),
580  archive.get<TransmissionCurve>(record.get(keys.b))
581  );
582  }
583 
584  Factory() : table::io::PersistableFactory(NAME) {}
585  };
586 
587  void write(OutputArchiveHandle & handle) const {
588  auto const & keys = PersistenceHelper::get();
589  auto catalog = handle.makeCatalog(keys.schema);
590  auto record = catalog.addNew();
591  record->set(keys.a, handle.put(_a));
592  record->set(keys.b, handle.put(_b));
593  handle.saveCatalog(catalog);
594  }
595 
596  static Factory registration;
597 
598 private:
601 };
602 
603 ProductTransmissionCurve::Factory ProductTransmissionCurve::registration;
604 
605 
606 /*
607  * TransformedTransmissionCurve: default for TransmissionCurve::transform.
608  *
609  * This is a another straightforward lazy-evaluation object. Its only state
610  * is the two operands it delegates to.
611  */
612 class TransformedTransmissionCurve : public TransmissionCurve {
613 public:
614 
615  static constexpr char const * NAME = "TransformedTransmissionCurve";
616 
617  TransformedTransmissionCurve(
620  ) : _nested(std::move(nested)), _transform(std::move(transform)) {}
621 
622  std::pair<double,double> getWavelengthBounds() const override {
623  return _nested->getWavelengthBounds();
624  }
625 
626  std::pair<double,double> getThroughputAtBounds() const override {
627  return _nested->getThroughputAtBounds();
628  }
629 
630  void sampleAt(
631  geom::Point2D const & position,
632  ndarray::Array<double const,1,1> const & wavelengths,
633  ndarray::Array<double,1,1> const & out
634  ) const override {
635  return _nested->sampleAt(_transform->applyInverse(position), wavelengths, out);
636  }
637 
638  bool isPersistable() const override { return _nested->isPersistable() && _transform->isPersistable(); }
639 
640 protected:
641 
642  // transforming a TransformedTransmissionCurve composes the transforms
643  std::shared_ptr<TransmissionCurve const> _transformedByImpl(
645  ) const override {
646  return std::make_shared<TransformedTransmissionCurve>(
647  _nested,
648  transform->then(*_transform)
649  );
650  }
651 
652  std::string getPersistenceName() const override { return NAME; }
653 
654  struct PersistenceHelper {
655  table::Schema schema;
656  table::Key<int> nested;
657  table::Key<int> transform;
658 
659  static PersistenceHelper const & get() {
660  static PersistenceHelper const instance;
661  return instance;
662  }
663 
664  private:
665 
666  PersistenceHelper() :
667  schema(),
668  nested(schema.addField<int>("nested", "archive ID of the nested TransmissionCurve")),
669  transform(schema.addField<int>("transform", "archive ID of the coordinate transform"))
670  {
671  schema.getCitizen().markPersistent();
672  }
673 
674  };
675 
676  void write(OutputArchiveHandle & handle) const {
677  auto const & keys = PersistenceHelper::get();
678  auto catalog = handle.makeCatalog(keys.schema);
679  auto record = catalog.addNew();
680  record->set(keys.nested, handle.put(_nested));
681  record->set(keys.transform, handle.put(_transform));
682  handle.saveCatalog(catalog);
683  }
684 
685  class Factory : public table::io::PersistableFactory {
686  public:
687 
689  InputArchive const& archive,
690  CatalogVector const& catalogs
691  ) const override {
692  auto const& keys = PersistenceHelper::get();
693  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
694  LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
695  auto const & record = catalogs.front().front();
696  return std::make_shared<TransformedTransmissionCurve>(
697  archive.get<TransmissionCurve>(record.get(keys.nested)),
698  archive.get<geom::TransformPoint2ToPoint2>(record.get(keys.transform))
699  );
700  }
701 
702  Factory() : table::io::PersistableFactory(NAME) {}
703  };
704 
705  static Factory registration;
706 
707 private:
710 };
711 
712 TransformedTransmissionCurve::Factory TransformedTransmissionCurve::registration;
713 
714 } // anonymous
715 
716 
717 
718 /*
719  * TransmissionCurve itself
720  */
721 
722 std::shared_ptr<TransmissionCurve const> TransmissionCurve::makeIdentity() {
723  return IdentityTransmissionCurve::get();
724 }
725 
726 std::shared_ptr<TransmissionCurve const> TransmissionCurve::makeSpatiallyConstant(
727  ndarray::Array<double const,1> const & throughput,
728  ndarray::Array<double const,1> const & wavelengths,
729  double throughputAtMin, double throughputAtMax
730 ) {
731  ::gsl_set_error_handler_off();
733  wavelengths.getSize<0>(), throughput.getSize<0>(),
735  "Length of wavelength array (%d) does not match size of throughput array (%d)"
736  );
737  return std::make_shared<InterpolatedTransmissionCurve<Impl1d>>(
738  Impl1d(ndarray::copy(throughput), ndarray::copy(wavelengths)),
739  std::make_pair(throughputAtMin, throughputAtMax)
740  );
741 }
742 
743 std::shared_ptr<TransmissionCurve const> TransmissionCurve::makeRadial(
744  ndarray::Array<double const,2> const & throughput,
745  ndarray::Array<double const,1> const & wavelengths,
746  ndarray::Array<double const,1> const & radii,
747  double throughputAtMin, double throughputAtMax
748 ) {
749  ::gsl_set_error_handler_off();
751  wavelengths.getSize<0>(), throughput.getSize<0>(),
753  "Length of wavelength array (%d) does not match first dimension of of throughput array (%d)"
754  );
756  radii.getSize<0>(), throughput.getSize<1>(),
758  "Length of radii array (%d) does not match second dimension of of throughput array (%d)"
759  );
760  // GSL wants a column major array (Array<T,2,-2>). But ndarray can only flatten row-major arrays
761  // (Array<T,2,2>). So we allocate a row-major array, assign the caller's throughput array to a
762  // transposed view of it, and then flatten the row-major array.
763  ndarray::Array<double,2,2> throughputTransposed = ndarray::allocate(throughput.getShape().reverse());
764  throughputTransposed.transpose() = throughput;
765  ndarray::Array<double,1,1> throughputFlat = ndarray::flatten<1>(throughputTransposed);
766  return std::make_shared<InterpolatedTransmissionCurve<Impl2d>>(
767  Impl2d(throughputFlat, ndarray::copy(wavelengths), ndarray::copy(radii)),
768  std::make_pair(throughputAtMin, throughputAtMax)
769  );
770 }
771 
772 std::shared_ptr<TransmissionCurve const> TransmissionCurve::multipliedBy(
773  TransmissionCurve const & other
774 ) const {
775  auto a = shared_from_this();
776  auto b = other.shared_from_this();
777  auto result = a->_multipliedByImpl(b);
778  if (result == nullptr) {
779  result = b->_multipliedByImpl(a);
780  }
781  if (result == nullptr) {
782  result = std::make_shared<ProductTransmissionCurve>(std::move(a), std::move(b));
783  }
784  return result;
785 }
786 
787 std::shared_ptr<TransmissionCurve const> TransmissionCurve::transformedBy(
789 ) const {
790  return _transformedByImpl(std::move(transform));
791 }
792 
793 ndarray::Array<double,1,1> TransmissionCurve::sampleAt(
794  geom::Point2D const & position,
795  ndarray::Array<double const,1,1> const & wavelengths
796 ) const {
797  ndarray::Array<double,1,1> out = ndarray::allocate(wavelengths.getSize<0>());
798  sampleAt(position, wavelengths, out);
799  return out;
800 }
801 
802 std::shared_ptr<TransmissionCurve const> TransmissionCurve::_transformedByImpl(
804 ) const {
805  return std::make_shared<TransformedTransmissionCurve>(shared_from_this(), std::move(transform));
806 }
807 
808 std::shared_ptr<TransmissionCurve const> TransmissionCurve::_multipliedByImpl(
810 ) const {
811  return nullptr;
812 }
813 
814 std::string TransmissionCurve::getPythonModule() const {
815  return "lsst.afw.image";
816 }
817 
818 }}} // lsst::afw::image
A spatially-varying transmission curve as a function of wavelength.
#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
T free(T... args)
table::Key< double > throughputAtMin
table::Key< int > nested
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:310
STL class.
T min(T... args)
A base class for image defects.
Point< double, 2 > Point2D
Definition: Point.h:273
#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)
#define LSST_EXCEPT(type,...)
STL class.
STL class.
table::Key< int > a
table::Schema schema
T transform(T... args)
ArrayKeyVector arrays