LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Filter.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 //
26 //##====---------------- ----------------====##/
27 //
28 // Class encapsulating an identifier for an LSST filter.
29 //
30 //##====---------------- ----------------====##/
31 
32 #ifndef LSST_AFW_IMAGE_FILTER_H
33 #define LSST_AFW_IMAGE_FILTER_H
34 
35 #include <cmath>
36 #include <string>
37 #include <unordered_map>
38 #include <vector>
39 #include <memory>
40 #include "lsst/base.h"
43 
44 namespace lsst {
45 namespace afw {
46 namespace image {
47 
51 class[
52  [deprecated("Removed with no replacement (but see lsst::afw::image::TransmissionCurve). Will be "
53  "removed after v22.")]] FilterProperty final {
54 public:
55  explicit FilterProperty(std::string const& name, double lambdaEff, double lambdaMin = NAN,
56  double lambdaMax = NAN, bool force = false)
57  : _name(name), _lambdaEff(lambdaEff), _lambdaMin(lambdaMin), _lambdaMax(lambdaMax) {
58  _insert(force);
59  }
65  explicit FilterProperty(std::string const& name,
67  bool force = false);
68 
69  FilterProperty(FilterProperty const&) = default;
70  FilterProperty(FilterProperty &&) noexcept = default;
71  FilterProperty& operator=(FilterProperty const&) = default;
72  FilterProperty& operator=(FilterProperty&&) noexcept = default;
73  ~FilterProperty() noexcept = default;
74 
78  std::string const& getName() const noexcept { return _name; }
82  double getLambdaEff() const noexcept { return _lambdaEff; }
86  double getLambdaMin() const noexcept { return _lambdaMin; }
90  double getLambdaMax() const noexcept { return _lambdaMax; }
96  bool operator==(FilterProperty const& rhs) const noexcept;
100  bool operator!=(FilterProperty const& rhs
101  ) const noexcept {
102  return !(*this == rhs);
103  }
105  std::size_t hash_value() const noexcept;
109  static void reset() { _initRegistry(); }
110 
116  static FilterProperty const& lookup(std::string const& name);
117 
118 private:
120 
124  static void _initRegistry();
130  void _insert(bool force = false);
131 
132  std::string _name; // name of filter
133  double _lambdaEff; // effective wavelength (nm)
134  double _lambdaMin; // minimum wavelength (nm)
135  double _lambdaMax; // maximum wavelength (nm)
136 
137  static PropertyMap* _propertyMap; // mapping from name -> FilterProperty
138 };
139 
143 class[[deprecated("Replaced with FilterLabel. Will be removed after v22.")]] Filter final
144  : public typehandling::Storable {
145 public:
146  static int const AUTO;
147  static int const UNKNOWN;
148 
152  explicit Filter(std::string const& name,
153  bool const force = false
154  )
155  : _id(_lookup(name, force)), _name(name) {}
159  explicit Filter(int id = UNKNOWN
160  )
161  : _id(id), _name(_lookup(id)) {}
168  explicit Filter(std::shared_ptr<lsst::daf::base::PropertySet const> metadata, bool const force = false);
169 
170  Filter(Filter const&) = default;
171  Filter(Filter &&) noexcept = default;
172  Filter& operator=(Filter const&) = default;
173  Filter& operator=(Filter&&) noexcept = default;
174  ~Filter() noexcept = default;
175 
179  bool operator==(Filter const& rhs) const noexcept;
180  bool operator!=(Filter const& rhs) const noexcept { return !(*this == rhs); }
181 
183  std::size_t hash_value() const noexcept override;
184 
188  int getId() const noexcept { return _id; }
192  std::string const& getName() const noexcept { return _name; }
198  std::string const& getCanonicalName() const { return _lookup(_id); }
204  std::vector<std::string> getAliases() const;
205 
209  FilterProperty const& getFilterProperty() const;
213  static void reset() { _initRegistry(); }
221  static int define(FilterProperty const& filterProperty, int id = AUTO, bool force = false);
229  static int defineAlias(std::string const& oldName, std::string const& newName, bool force = false);
230 
234  static std::vector<std::string> getNames();
235 
237  std::shared_ptr<typehandling::Storable> cloneStorable() const override;
238 
244  bool equals(typehandling::Storable const& other) const noexcept override;
245 
246  bool isPersistable() const noexcept override;
247 
248 protected:
249  std::string getPersistenceName() const override;
250  std::string getPythonModule() const override;
251  void write(OutputArchiveHandle & handle) const override;
252 
253 private:
254  using AliasMap = std::unordered_map<std::string, const std::string>;
255  using NameMap = std::unordered_map<std::string, const unsigned int>;
256  using IdMap = std::unordered_map<unsigned int, const std::string>;
257 
261  static void _initRegistry();
268  static int _lookup(std::string const& name, bool const force = false);
272  static std::string const& _lookup(int id);
273 
274  int _id;
275  std::string _name;
276 
277  static int _id0; // next Id to use
278  static AliasMap* _aliasMap; // mapping from alias -> name
279  static IdMap* _idMap; // mapping from id -> name
280  static NameMap* _nameMap; // mapping from name -> id
281 };
282 
283 namespace detail {
291 } // namespace detail
292 } // namespace image
293 } // namespace afw
294 } // namespace lsst
295 
296 namespace std {
297 template <>
301  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
302 };
303 
304 template <>
305 struct hash<lsst::afw::image::Filter> {
308  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
309 };
310 } // namespace std
311 
312 #endif // LSST_AFW_IMAGE_FILTER_H
table::Key< std::string > name
Definition: Amplifier.cc:116
table::Key< int > id
Definition: Detector.cc:162
Basic LSST definitions.
Class for storing generic metadata.
Definition: PropertySet.h:66
int stripFilterKeywords(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Remove Filter-related keywords from the metadata.
Definition: Filter.cc:130
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
bool operator==(FilterProperty const &rhs) const noexcept
Return true iff two FilterProperties are identical.
std::string getPythonModule() const override
class[[deprecated("Removed with no replacement (but see lsst::afw::image::TransmissionCurve). Will be " "removed after v22.")]] FilterProperty final
Describe the properties of a Filter (e.g.
Definition: Filter.h:53
std::string getPersistenceName() const override
void write(OutputArchiveHandle &handle) const override
std::size_t hash_value() const noexcept
Return a hash of this object.
double getLambdaMin() const noexcept
Return the filter's minimum wavelength (nm) where the transmission is above 1% of the maximum.
Definition: Filter.h:86
std::string const & getName() const noexcept
Return a filter's name.
Definition: Filter.h:78
double getLambdaEff() const noexcept
Return the filter's effective wavelength (nm)
Definition: Filter.h:82
double getLambdaMax() const noexcept
Return the filter's maximum wavelength (nm) where the transmission is above 1% of the maximum.
Definition: Filter.h:90
bool operator!=(FilterProperty const &rhs) const noexcept
Return true iff rhs != this.
Definition: Filter.h:100
FilterProperty(FilterProperty const &)=default
A base class for image defects.
STL namespace.
size_t operator()(argument_type const &obj) const noexcept
Definition: Filter.h:308
size_t operator()(argument_type const &obj) const noexcept
Definition: Filter.h:301