LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
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"
42 
43 
44 namespace lsst {
45 namespace afw {
46 namespace image {
47 
51 class FilterProperty final {
52 public:
53  explicit FilterProperty(std::string const& name, double lambdaEff, double lambdaMin = NAN,
54  double lambdaMax = NAN, bool force = false)
55  : _name(name), _lambdaEff(lambdaEff), _lambdaMin(lambdaMin), _lambdaMax(lambdaMax) {
56  _insert(force);
57  }
63  explicit FilterProperty(std::string const& name,
65  bool force = false);
66 
67  FilterProperty(FilterProperty const&) = default;
68  FilterProperty(FilterProperty&&) noexcept = default;
69  FilterProperty& operator=(FilterProperty const&) = default;
70  FilterProperty& operator=(FilterProperty&&) noexcept = default;
71  ~FilterProperty() noexcept = default;
72 
76  std::string const& getName() const noexcept { return _name; }
80  double getLambdaEff() const noexcept { return _lambdaEff; }
84  double getLambdaMin() const noexcept { return _lambdaMin; }
88  double getLambdaMax() const noexcept { return _lambdaMax; }
94  bool operator==(FilterProperty const& rhs) const noexcept;
98  bool operator!=(FilterProperty const& rhs
99  ) const noexcept {
100  return !(*this == rhs);
101  }
103  std::size_t hash_value() const noexcept;
107  static void reset() { _initRegistry(); }
108 
114  static FilterProperty const& lookup(std::string const& name);
115 
116 private:
118 
122  static void _initRegistry();
128  void _insert(bool force = false);
129 
130  std::string _name; // name of filter
131  double _lambdaEff; // effective wavelength (nm)
132  double _lambdaMin; // minimum wavelength (nm)
133  double _lambdaMax; // maximum wavelength (nm)
134 
135  static PropertyMap* _propertyMap; // mapping from name -> FilterProperty
136 };
137 
141 class Filter final {
142 public:
143  static int const AUTO;
144  static int const UNKNOWN;
145 
149  explicit Filter(std::string const& name,
150  bool const force = false
151  )
152  : _id(_lookup(name, force)), _name(name) {}
156  explicit Filter(int id = UNKNOWN
157  )
158  : _id(id), _name(_lookup(id)) {}
165  explicit Filter(std::shared_ptr<lsst::daf::base::PropertySet const> metadata, bool const force = false);
166 
167  Filter(Filter const&) = default;
168  Filter(Filter&&) noexcept = default;
169  Filter& operator=(Filter const&) = default;
170  Filter& operator=(Filter&&) noexcept = default;
171  ~Filter() noexcept = default;
172 
176  bool operator==(Filter const& rhs) const noexcept;
177  bool operator!=(Filter const& rhs) const noexcept { return !(*this == rhs); }
178 
180  std::size_t hash_value() const noexcept;
181 
185  int getId() const noexcept { return _id; }
189  std::string const& getName() const noexcept { return _name; }
195  std::string const& getCanonicalName() const { return _lookup(_id); }
201  std::vector<std::string> getAliases() const;
202 
206  FilterProperty const& getFilterProperty() const;
210  static void reset() { _initRegistry(); }
218  static int define(FilterProperty const& filterProperty, int id = AUTO, bool force = false);
226  static int defineAlias(std::string const& oldName, std::string const& newName, bool force = false);
227 
231  static std::vector<std::string> getNames();
232 
233 private:
237 
241  static void _initRegistry();
248  static int _lookup(std::string const& name, bool const force = false);
252  static std::string const& _lookup(int id);
253 
254  int _id;
255  std::string _name;
256 
257  static int _id0; // next Id to use
258  static AliasMap* _aliasMap; // mapping from alias -> name
259  static IdMap* _idMap; // mapping from id -> name
260  static NameMap* _nameMap; // mapping from name -> id
261 };
262 
263 namespace detail {
271 } // namespace detail
272 } // namespace image
273 } // namespace afw
274 } // namespace lsst
275 
276 namespace std {
277 template <>
278 struct hash<lsst::afw::image::FilterProperty> {
281  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
282 };
283 
284 template <>
285 struct hash<lsst::afw::image::Filter> {
288  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
289 };
290 } // namespace std
291 
292 #endif // LSST_AFW_IMAGE_FILTER_H
std::string const & getCanonicalName() const
Return a filter&#39;s canonical name.
Definition: Filter.h:195
static void reset()
Clear all definitions.
Definition: Filter.h:107
std::string const & getName() const noexcept
Return a filter&#39;s name.
Definition: Filter.h:76
static int const UNKNOWN
Definition: Filter.h:144
STL namespace.
int stripFilterKeywords(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Remove Filter-related keywords from the metadata.
Definition: Filter.cc:127
table::Key< int > id
Definition: Detector.cc:163
size_t operator()(argument_type const &obj) const noexcept
Definition: Filter.h:281
STL class.
static FilterProperty const & lookup(std::string const &name)
Lookup the properties of a filter "name".
Definition: Filter.cc:96
A base class for image defects.
int getId() const noexcept
Return a Filter&#39;s integral id.
Definition: Filter.h:185
bool operator==(FilterProperty const &rhs) const noexcept
Return true iff two FilterProperties are identical.
Definition: Filter.cc:82
static int const AUTO
Definition: Filter.h:143
FilterProperty & operator=(FilterProperty const &)=default
double getLambdaMax() const noexcept
Return the filter&#39;s maximum wavelength (nm) where the transmission is above 1% of the maximum...
Definition: Filter.h:88
Holds an integer identifier for an LSST filter.
Definition: Filter.h:141
~FilterProperty() noexcept=default
bool operator!=(FilterProperty const &rhs) const noexcept
Return true iff rhs != this.
Definition: Filter.h:98
Class for storing generic metadata.
Definition: PropertySet.h:68
size_t operator()(argument_type const &obj) const noexcept
Definition: Filter.h:288
double getLambdaEff() const noexcept
Return the filter&#39;s effective wavelength (nm)
Definition: Filter.h:80
Filter(int id=UNKNOWN)
Creates a Filter with the given identifier.
Definition: Filter.h:156
Filter(std::string const &name, bool const force=false)
Creates a Filter with the given name.
Definition: Filter.h:149
bool operator!=(Filter const &rhs) const noexcept
Definition: Filter.h:177
Describe the properties of a Filter (e.g.
Definition: Filter.h:51
FilterProperty(std::string const &name, double lambdaEff, double lambdaMin=NAN, double lambdaMax=NAN, bool force=false)
Definition: Filter.h:53
static void reset()
Clear all definitions.
Definition: Filter.h:210
std::string const & getName() const noexcept
Return a Filter&#39;s name.
Definition: Filter.h:189
double getLambdaMin() const noexcept
Return the filter&#39;s minimum wavelength (nm) where the transmission is above 1% of the maximum...
Definition: Filter.h:84
std::size_t hash_value() const noexcept
Return a hash of this object.
Definition: Filter.cc:86
Basic LSST definitions.