LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
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