lsst.afw  15.0-21-g91b8abf62
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 override {
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 std::bad_alloc();
156  }
157  return GslPtr<T>(p, free);
158 }
159 
160 using ArrayKeyVector = std::vector<table::Key<table::Array<double>>>;
161 
162 /*
163  * Implementation object as a template parameter for the instantiation of
164  * InterpolatedTransmissionCurve used by makeSpatiallyConstant.
165  */
166 class Impl1d {
167 public:
168 
169  static constexpr bool isSpatiallyConstant = true;
170  static constexpr char const * NAME = "SpatiallyConstantTransmissionCurve";
171 
172  // Initialize the GSL interpolator and take ownership of the given arrays.
173  // Array size consistency checks are done by makeSpatiallyConstant,
174  // so we don't need to worry about them here.
175  Impl1d(ndarray::Array<double,1,1> const & throughput,
176  ndarray::Array<double,1,1> const & wavelengths) :
177  _throughput(throughput),
178  _wavelengths(wavelengths),
179  _interp(makeGslPtr(::gsl_interp_alloc(::gsl_interp_linear, _wavelengths.size()),
180  &::gsl_interp_free))
181  {
182  int status = ::gsl_interp_init(_interp.get(), _wavelengths.getData(), _throughput.getData(),
183  _wavelengths.size());
184  LSST_CHECK_GSL(pex::exceptions::LogicError, status);
185  }
186 
187  std::pair<double, double> getWavelengthBounds() const {
188  return std::make_pair(_wavelengths.front(), _wavelengths.back());
189  }
190 
191  static void setupPersistence(table::Schema & schema, ArrayKeyVector & keys) {
192  keys.push_back(
193  schema.addField<table::Array<double>>(
194  "throughput", "array of known throughput values", "", 0
195  )
196  );
197  keys.push_back(
198  schema.addField<table::Array<double>>(
199  "wavelengths", "array of known wavelength values", "angstrom", 0
200  )
201  );
202  }
203 
204  void persist(table::BaseRecord & record, ArrayKeyVector const & keys) const {
205  record.set(keys[0], _throughput);
206  record.set(keys[1], _wavelengths);
207  }
208 
209  static Impl1d unpersist(table::BaseRecord & record, ArrayKeyVector const & keys) {
210  return Impl1d(record[keys[0]], record[keys[1]]);
211  }
212 
213  // A helper object constructed every time InterpolatedTransmissionCurve::sampleAt
214  // is called, and then invoked at every iteration of the loop therein.
215  struct Functor {
216 
217  Functor(Impl1d const &, geom::Point2D const &) :
218  _accel(makeGslPtr(::gsl_interp_accel_alloc(), &gsl_interp_accel_free))
219  {}
220 
221  double operator()(Impl1d const & parent, double wavelength) {
222  double result = 0.0;
223  int status = ::gsl_interp_eval_e(parent._interp.get(), parent._wavelengths.getData(),
224  parent._throughput.getData(),
225  wavelength, _accel.get(), &result);
226  LSST_CHECK_GSL(pex::exceptions::RuntimeError, status);
227  return result;
228  }
229 
230  private:
231  GslPtr<::gsl_interp_accel> _accel;
232  };
233 
234 private:
235  ndarray::Array<double,1,1> _throughput;
236  ndarray::Array<double,1,1> _wavelengths;
237  GslPtr<::gsl_interp> _interp;
238 };
239 
240 /*
241  * Implementation object as a template parameter for the instantiation of
242  * InterpolatedTransmissionCurve used by makeRadial.
243  */
244 class Impl2d {
245 public:
246 
247  static constexpr bool isSpatiallyConstant = false;
248  static constexpr char const * NAME = "RadialTransmissionCurve";
249 
250  Impl2d(ndarray::Array<double,1,1> const & throughput,
251  ndarray::Array<double,1,1> const & wavelengths,
252  ndarray::Array<double,1,1> const & radii) :
253  _throughput(throughput),
254  _wavelengths(wavelengths),
255  _radii(radii),
256  _interp(makeGslPtr(::gsl_interp2d_alloc(::gsl_interp2d_bilinear, _wavelengths.size(),
257  _radii.size()),
258  &::gsl_interp2d_free))
259  {
260  int status = ::gsl_interp2d_init(_interp.get(), _wavelengths.getData(), _radii.getData(),
261  _throughput.getData(), _wavelengths.size(), _radii.size());
262  LSST_CHECK_GSL(pex::exceptions::LogicError, status);
263  }
264 
265  std::pair<double, double> getWavelengthBounds() const {
266  return std::make_pair(_wavelengths.front(), _wavelengths.back());
267  }
268 
269  static void setupPersistence(table::Schema & schema, ArrayKeyVector & keys) {
270  keys.push_back(
271  schema.addField<table::Array<double>>(
272  "throughput",
273  "flattenned 2-d array of known throughput values, with radius dimension fastest", "", 0
274  )
275  );
276  keys.push_back(
277  schema.addField<table::Array<double>>(
278  "wavelengths", "array of known wavelength values", "angstrom", 0
279  )
280  );
281  keys.push_back(
282  schema.addField<table::Array<double>>(
283  "radii", "array of known radius values", "", 0
284  )
285  );
286  }
287 
288  void persist(table::BaseRecord & record, ArrayKeyVector const & keys) const {
289  record.set(keys[0], _throughput);
290  record.set(keys[1], _wavelengths);
291  record.set(keys[2], _radii);
292  }
293 
294  static Impl2d unpersist(table::BaseRecord & record, ArrayKeyVector const & keys) {
295  return Impl2d(record[keys[0]], record[keys[1]], record[keys[2]]);
296  }
297 
298  // A helper object constructed every time InterpolatedTransmissionCurve::sampleAt
299  // is called, and then invoked at every iteration of the loop therein.
300  struct Functor {
301 
302  Functor(Impl2d const & parent, geom::Point2D const & point) :
303  _radius(point.asEigen().norm()),
304  _radiusAccel(makeGslPtr(::gsl_interp_accel_alloc(), &gsl_interp_accel_free)),
305  _wavelengthAccel(makeGslPtr(::gsl_interp_accel_alloc(), &gsl_interp_accel_free))
306  {
307  _radius = std::max(_radius, parent._radii.front());
308  _radius = std::min(_radius, parent._radii.back());
309  }
310 
311  double operator()(Impl2d const & parent, double wavelength) {
312  double result = 0.0;
313  int status = ::gsl_interp2d_eval_e(parent._interp.get(), parent._wavelengths.getData(),
314  parent._radii.getData(), parent._throughput.getData(),
315  wavelength, _radius,
316  _radiusAccel.get(), _wavelengthAccel.get(),
317  &result);
318  LSST_CHECK_GSL(pex::exceptions::RuntimeError, status);
319  return result;
320  }
321 
322  private:
323  double _radius;
324  GslPtr<::gsl_interp_accel> _radiusAccel;
325  GslPtr<::gsl_interp_accel> _wavelengthAccel;
326  };
327 
328 private:
329  ndarray::Array<double,1,1> _throughput;
330  ndarray::Array<double,1,1> _wavelengths;
331  ndarray::Array<double,1,1> _radii;
332  GslPtr<::gsl_interp2d> _interp;
333 };
334 
335 
336 template <typename Impl>
337 class InterpolatedTransmissionCurve : public TransmissionCurve {
338 public:
339 
340  InterpolatedTransmissionCurve(Impl impl, std::pair<double, double> throughputAtBounds) :
341  _atBounds(throughputAtBounds),
342  _impl(std::move(impl))
343  {
344  if (!std::isfinite(_atBounds.first) || !std::isfinite(_atBounds.second)) {
345  throw LSST_EXCEPT(
346  pex::exceptions::InvalidParameterError,
347  "Throughput values at bounds must be finite"
348  );
349  }
350  }
351 
352  std::pair<double,double> getWavelengthBounds() const override {
353  return _impl.getWavelengthBounds();
354  }
355 
356  std::pair<double,double> getThroughputAtBounds() const override {
357  return _atBounds;
358  }
359 
360  void sampleAt(
361  geom::Point2D const & point,
362  ndarray::Array<double const,1,1> const & wavelengths,
363  ndarray::Array<double,1,1> const & out
364  ) const override {
366  wavelengths.getSize<0>(), out.getSize<0>(),
367  pex::exceptions::LengthError,
368  "Length of wavelength array (%d) does not match size of output array (%d)"
369  );
370  typename Impl::Functor functor(_impl, point);
371  auto bounds = _impl.getWavelengthBounds();
372  auto wlIter = wavelengths.begin();
373  for (auto outIter = out.begin(); outIter != out.end(); ++outIter, ++wlIter) {
374  double & y = *outIter;
375  if (*wlIter < bounds.first) {
376  y = _atBounds.first;
377  } else if (*wlIter > bounds.second) {
378  y = _atBounds.second;
379  } else {
380  y = functor(_impl, *wlIter);
381  }
382  }
383  }
384 
385  bool isPersistable() const override { return true; }
386 
387 protected:
388 
389  std::shared_ptr<TransmissionCurve const> _transformedByImpl(
391  ) const override {
392  if (_impl.isSpatiallyConstant) {
393  return shared_from_this();
394  } else {
395  return TransmissionCurve::_transformedByImpl(transform);
396  }
397  }
398 
399  std::string getPersistenceName() const override { return Impl::NAME; }
400 
401  struct PersistenceHelper {
402  table::Schema schema;
403  table::Key<double> throughputAtMin;
404  table::Key<double> throughputAtMax;
405  ArrayKeyVector arrays;
406 
407  static PersistenceHelper const & get() {
408  static PersistenceHelper const instance;
409  return instance;
410  }
411 
412  private:
413 
414  PersistenceHelper() :
415  schema(),
416  throughputAtMin(schema.addField<double>(
417  "throughputAtMin", "throughput below minimum wavelength")),
418  throughputAtMax(schema.addField<double>(
419  "throughputAtMax", "throughput above minimum wavelength"))
420  {
421  Impl::setupPersistence(schema, arrays);
422  schema.getCitizen().markPersistent();
423  }
424 
425  };
426 
427  void write(OutputArchiveHandle& handle) const override {
428  auto const & keys = PersistenceHelper::get();
429  auto catalog = handle.makeCatalog(keys.schema);
430  auto record = catalog.addNew();
431  record->set(keys.throughputAtMin, _atBounds.first);
432  record->set(keys.throughputAtMax, _atBounds.second);
433  _impl.persist(*record, keys.arrays);
434  handle.saveCatalog(catalog);
435  }
436 
437  class Factory : public table::io::PersistableFactory {
438  public:
439 
441  InputArchive const& archive,
442  CatalogVector const& catalogs
443  ) const override {
444  auto const& keys = PersistenceHelper::get();
445  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
446  LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
447  auto & record = catalogs.front().front();
448  return std::make_shared<InterpolatedTransmissionCurve>(
449  Impl::unpersist(record, keys.arrays),
450  std::make_pair(record.get(keys.throughputAtMin), record.get(keys.throughputAtMax))
451  );
452  }
453 
454  Factory() : table::io::PersistableFactory(Impl::NAME) {}
455  };
456 
457  static Factory registration;
458 
459 private:
460  std::pair<double,double> _atBounds;
461  Impl _impl;
462 };
463 
464 template <typename Impl>
465 typename InterpolatedTransmissionCurve<Impl>::Factory InterpolatedTransmissionCurve<Impl>::registration;
466 
467 template class InterpolatedTransmissionCurve<Impl1d>;
468 template class InterpolatedTransmissionCurve<Impl2d>;
469 
470 
471 /*
472  * ProductTransmissionCurve: default for TransmissionCurve::multipliedBy().
473  *
474  * This is a straightforward lazy-evaluation object. Its only state is the
475  * two operands it delegates to.
476  */
477 class ProductTransmissionCurve : public TransmissionCurve {
478 public:
479 
480  static constexpr char const * NAME = "ProductTransmissionCurve";
481 
482  ProductTransmissionCurve(
485  ) : _a(std::move(a)), _b(std::move(b)) {}
486 
487  std::pair<double, double> getWavelengthBounds() const override {
488  auto aWavelengthBounds = _a->getWavelengthBounds();
489  auto bWavelengthBounds = _b->getWavelengthBounds();
490  auto aThroughputAtBounds = _a->getThroughputAtBounds();
491  auto bThroughputAtBounds = _b->getThroughputAtBounds();
492 
493  auto determineWavelengthBound = [](
494  double aWavelength, double bWavelength,
495  double aThroughput, double bThroughput,
496  auto isFirstOuter
497  ) -> double {
498  // Use the outermost wavelength bound only if its throughput
499  // values are not being multiplied by zeros from the operand with
500  // the innermost wavelength bound.
501  if (isFirstOuter(aWavelength, bWavelength)) {
502  return (bThroughput == 0.0) ? bWavelength : aWavelength;
503  } else {
504  return (aThroughput == 0.0) ? aWavelength : bWavelength;
505  }
506  };
507 
508  return std::make_pair(
509  determineWavelengthBound(aWavelengthBounds.first, bWavelengthBounds.first,
510  aThroughputAtBounds.first, bThroughputAtBounds.first,
512  determineWavelengthBound(aWavelengthBounds.second, bWavelengthBounds.second,
513  aThroughputAtBounds.second, bThroughputAtBounds.second,
515  );
516  }
517 
518  std::pair<double,double> getThroughputAtBounds() const override {
519  auto aAtBounds = _a->getThroughputAtBounds();
520  auto bAtBounds = _b->getThroughputAtBounds();
521  return std::make_pair(aAtBounds.first * bAtBounds.first,
522  aAtBounds.second * bAtBounds.second);
523  }
524 
525  void sampleAt(
526  geom::Point2D const & position,
527  ndarray::Array<double const,1,1> const & wavelengths,
528  ndarray::Array<double,1,1> const & out
529  ) const override {
530  _a->sampleAt(position, wavelengths, out);
531  ndarray::Array<double,1,1> tmp = ndarray::allocate(wavelengths.getSize<0>());
532  _b->sampleAt(position, wavelengths, tmp);
533  out.deep() *= tmp;
534  }
535 
536  bool isPersistable() const override { return _a->isPersistable() && _b->isPersistable(); }
537 
538 protected:
539 
540  std::string getPersistenceName() const override { return NAME; }
541 
542  struct PersistenceHelper {
543  table::Schema schema;
544  table::Key<int> a;
545  table::Key<int> b;
546 
547  static PersistenceHelper const & get() {
548  static PersistenceHelper const instance;
549  return instance;
550  }
551 
552  private:
553 
554  PersistenceHelper() :
555  schema(),
556  a(schema.addField<int>("a", "archive ID of first operand")),
557  b(schema.addField<int>("b", "archive ID of second operand"))
558  {
559  schema.getCitizen().markPersistent();
560  }
561 
562  };
563 
564  class Factory : public table::io::PersistableFactory {
565  public:
566 
568  InputArchive const& archive,
569  CatalogVector const& catalogs
570  ) const override {
571  auto const& keys = PersistenceHelper::get();
572  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
573  LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
574  auto const & record = catalogs.front().front();
575  return std::make_shared<ProductTransmissionCurve>(
576  archive.get<TransmissionCurve>(record.get(keys.a)),
577  archive.get<TransmissionCurve>(record.get(keys.b))
578  );
579  }
580 
581  Factory() : table::io::PersistableFactory(NAME) {}
582  };
583 
584  void write(OutputArchiveHandle & handle) const override {
585  auto const & keys = PersistenceHelper::get();
586  auto catalog = handle.makeCatalog(keys.schema);
587  auto record = catalog.addNew();
588  record->set(keys.a, handle.put(_a));
589  record->set(keys.b, handle.put(_b));
590  handle.saveCatalog(catalog);
591  }
592 
593  static Factory registration;
594 
595 private:
598 };
599 
600 ProductTransmissionCurve::Factory ProductTransmissionCurve::registration;
601 
602 
603 /*
604  * TransformedTransmissionCurve: default for TransmissionCurve::transform.
605  *
606  * This is a another straightforward lazy-evaluation object. Its only state
607  * is the two operands it delegates to.
608  */
609 class TransformedTransmissionCurve : public TransmissionCurve {
610 public:
611 
612  static constexpr char const * NAME = "TransformedTransmissionCurve";
613 
614  TransformedTransmissionCurve(
617  ) : _nested(std::move(nested)), _transform(std::move(transform)) {}
618 
619  std::pair<double,double> getWavelengthBounds() const override {
620  return _nested->getWavelengthBounds();
621  }
622 
623  std::pair<double,double> getThroughputAtBounds() const override {
624  return _nested->getThroughputAtBounds();
625  }
626 
627  void sampleAt(
628  geom::Point2D const & position,
629  ndarray::Array<double const,1,1> const & wavelengths,
630  ndarray::Array<double,1,1> const & out
631  ) const override {
632  return _nested->sampleAt(_transform->applyInverse(position), wavelengths, out);
633  }
634 
635  bool isPersistable() const override { return _nested->isPersistable() && _transform->isPersistable(); }
636 
637 protected:
638 
639  // transforming a TransformedTransmissionCurve composes the transforms
640  std::shared_ptr<TransmissionCurve const> _transformedByImpl(
642  ) const override {
643  return std::make_shared<TransformedTransmissionCurve>(
644  _nested,
645  transform->then(*_transform)
646  );
647  }
648 
649  std::string getPersistenceName() const override { return NAME; }
650 
651  struct PersistenceHelper {
652  table::Schema schema;
653  table::Key<int> nested;
654  table::Key<int> transform;
655 
656  static PersistenceHelper const & get() {
657  static PersistenceHelper const instance;
658  return instance;
659  }
660 
661  private:
662 
663  PersistenceHelper() :
664  schema(),
665  nested(schema.addField<int>("nested", "archive ID of the nested TransmissionCurve")),
666  transform(schema.addField<int>("transform", "archive ID of the coordinate transform"))
667  {
668  schema.getCitizen().markPersistent();
669  }
670 
671  };
672 
673  void write(OutputArchiveHandle & handle) const override {
674  auto const & keys = PersistenceHelper::get();
675  auto catalog = handle.makeCatalog(keys.schema);
676  auto record = catalog.addNew();
677  record->set(keys.nested, handle.put(_nested));
678  record->set(keys.transform, handle.put(_transform));
679  handle.saveCatalog(catalog);
680  }
681 
682  class Factory : public table::io::PersistableFactory {
683  public:
684 
686  InputArchive const& archive,
687  CatalogVector const& catalogs
688  ) const override {
689  auto const& keys = PersistenceHelper::get();
690  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
691  LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
692  auto const & record = catalogs.front().front();
693  return std::make_shared<TransformedTransmissionCurve>(
694  archive.get<TransmissionCurve>(record.get(keys.nested)),
695  archive.get<geom::TransformPoint2ToPoint2>(record.get(keys.transform))
696  );
697  }
698 
699  Factory() : table::io::PersistableFactory(NAME) {}
700  };
701 
702  static Factory registration;
703 
704 private:
707 };
708 
709 TransformedTransmissionCurve::Factory TransformedTransmissionCurve::registration;
710 
711 } // anonymous
712 
713 
714 
715 /*
716  * TransmissionCurve itself
717  */
718 
719 std::shared_ptr<TransmissionCurve const> TransmissionCurve::makeIdentity() {
720  return IdentityTransmissionCurve::get();
721 }
722 
723 std::shared_ptr<TransmissionCurve const> TransmissionCurve::makeSpatiallyConstant(
724  ndarray::Array<double const,1> const & throughput,
725  ndarray::Array<double const,1> const & wavelengths,
726  double throughputAtMin, double throughputAtMax
727 ) {
728  ::gsl_set_error_handler_off();
730  wavelengths.getSize<0>(), throughput.getSize<0>(),
732  "Length of wavelength array (%d) does not match size of throughput array (%d)"
733  );
734  return std::make_shared<InterpolatedTransmissionCurve<Impl1d>>(
735  Impl1d(ndarray::copy(throughput), ndarray::copy(wavelengths)),
736  std::make_pair(throughputAtMin, throughputAtMax)
737  );
738 }
739 
740 std::shared_ptr<TransmissionCurve const> TransmissionCurve::makeRadial(
741  ndarray::Array<double const,2> const & throughput,
742  ndarray::Array<double const,1> const & wavelengths,
743  ndarray::Array<double const,1> const & radii,
744  double throughputAtMin, double throughputAtMax
745 ) {
746  ::gsl_set_error_handler_off();
748  wavelengths.getSize<0>(), throughput.getSize<0>(),
750  "Length of wavelength array (%d) does not match first dimension of of throughput array (%d)"
751  );
753  radii.getSize<0>(), throughput.getSize<1>(),
755  "Length of radii array (%d) does not match second dimension of of throughput array (%d)"
756  );
757  // GSL wants a column major array (Array<T,2,-2>). But ndarray can only flatten row-major arrays
758  // (Array<T,2,2>). So we allocate a row-major array, assign the caller's throughput array to a
759  // transposed view of it, and then flatten the row-major array.
760  ndarray::Array<double,2,2> throughputTransposed = ndarray::allocate(throughput.getShape().reverse());
761  throughputTransposed.transpose() = throughput;
762  ndarray::Array<double,1,1> throughputFlat = ndarray::flatten<1>(throughputTransposed);
763  return std::make_shared<InterpolatedTransmissionCurve<Impl2d>>(
764  Impl2d(throughputFlat, ndarray::copy(wavelengths), ndarray::copy(radii)),
765  std::make_pair(throughputAtMin, throughputAtMax)
766  );
767 }
768 
769 std::shared_ptr<TransmissionCurve const> TransmissionCurve::multipliedBy(
770  TransmissionCurve const & other
771 ) const {
772  auto a = shared_from_this();
773  auto b = other.shared_from_this();
774  auto result = a->_multipliedByImpl(b);
775  if (result == nullptr) {
776  result = b->_multipliedByImpl(a);
777  }
778  if (result == nullptr) {
779  result = std::make_shared<ProductTransmissionCurve>(std::move(a), std::move(b));
780  }
781  return result;
782 }
783 
784 std::shared_ptr<TransmissionCurve const> TransmissionCurve::transformedBy(
786 ) const {
787  return _transformedByImpl(std::move(transform));
788 }
789 
790 ndarray::Array<double,1,1> TransmissionCurve::sampleAt(
791  geom::Point2D const & position,
792  ndarray::Array<double const,1,1> const & wavelengths
793 ) const {
794  ndarray::Array<double,1,1> out = ndarray::allocate(wavelengths.getSize<0>());
795  sampleAt(position, wavelengths, out);
796  return out;
797 }
798 
799 std::shared_ptr<TransmissionCurve const> TransmissionCurve::_transformedByImpl(
801 ) const {
802  return std::make_shared<TransformedTransmissionCurve>(shared_from_this(), std::move(transform));
803 }
804 
805 std::shared_ptr<TransmissionCurve const> TransmissionCurve::_multipliedByImpl(
807 ) const {
808  return nullptr;
809 }
810 
811 std::string TransmissionCurve::getPythonModule() const {
812  return "lsst.afw.image";
813 }
814 
815 }}} // lsst::afw::image
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:302
STL class.
T min(T... args)
A base class for image defects.
Point< double, 2 > Point2D
Definition: Point.h:304
#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)
ArrayKeyVector arrays
int y
Definition: SpanSet.cc:44