lsst.afw  15.0-17-g0b88e3da8
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"
41 #include "lsst/pex/policy/Policy.h"
42 
43 namespace lsst {
44 namespace daf {
45 namespace base {
46 class PropertySet;
47 }
48 }
49 
50 namespace afw {
51 namespace image {
52 
57 public:
58  explicit FilterProperty(std::string const& name, double lambdaEff,
59  double lambdaMin=NAN, double lambdaMax=NAN, bool force = false)
60  : _name(name), _lambdaEff(lambdaEff), _lambdaMin(lambdaMin), _lambdaMax(lambdaMax) {
61  _insert(force);
62  }
68  explicit FilterProperty(std::string const& name,
70  bool force = false);
78  explicit FilterProperty(std::string const& name, lsst::pex::policy::Policy const& pol,
79  bool force = false);
80 
81  FilterProperty(FilterProperty const&) = default;
82  FilterProperty(FilterProperty&&) = default;
83  FilterProperty& operator=(FilterProperty const&) = default;
84  FilterProperty& operator=(FilterProperty&&) = default;
85  ~FilterProperty() = default;
86 
90  std::string const& getName() const { return _name; }
94  double getLambdaEff() const { return _lambdaEff; }
98  double getLambdaMin() const { return _lambdaMin; }
102  double getLambdaMax() const { return _lambdaMax; }
108  bool operator==(FilterProperty const& rhs) const;
112  bool operator!=(FilterProperty const& rhs
113  ) const {
114  return !(*this == rhs);
115  }
119  static void reset() { _initRegistry(); }
120 
126  static FilterProperty const& lookup(std::string const& name);
127 
128 private:
130 
134  static void _initRegistry();
140  void _insert(bool force = false);
141 
142  std::string _name; // name of filter
143  double _lambdaEff; // effective wavelength (nm)
144  double _lambdaMin; // minimum wavelength (nm)
145  double _lambdaMax; // maximum wavelength (nm)
146 
147  static PropertyMap* _propertyMap; // mapping from name -> FilterProperty
148 };
149 
153 class Filter {
154 public:
155  static int const AUTO;
156  static int const UNKNOWN;
157 
161  explicit Filter(std::string const& name,
162  bool const force = false
163  )
164  : _id(_lookup(name, force)), _name(name) {}
168  explicit Filter(int id = UNKNOWN
169  )
170  : _id(id), _name(_lookup(id)) {}
177  explicit Filter(std::shared_ptr<lsst::daf::base::PropertySet const> metadata, bool const force = false);
178 
179  Filter(Filter const&) = default;
180  Filter(Filter&&) = default;
181  Filter& operator=(Filter const&) = default;
182  Filter& operator=(Filter&&) = default;
183  ~Filter() = default;
184 
188  bool operator==(Filter const& rhs) const;
189  bool operator!=(Filter const& rhs) const { return !(*this == rhs); }
190 
194  int getId() const { return _id; }
198  std::string const& getName() const { return _name; }
204  std::string const& getCanonicalName() const { return _lookup(_id); }
210  std::vector<std::string> getAliases() const;
211 
215  FilterProperty const& getFilterProperty() const;
219  static void reset() { _initRegistry(); }
227  static int define(FilterProperty const& filterProperty, int id = AUTO, bool force = false);
235  static int defineAlias(std::string const& oldName, std::string const& newName, bool force = false);
236 
240  static std::vector<std::string> getNames();
241 
242 private:
246 
250  static void _initRegistry();
257  static int _lookup(std::string const& name, bool const force = false);
261  static std::string const& _lookup(int id);
262 
263  int _id;
265 
266  static int _id0; // next Id to use
267  static AliasMap* _aliasMap; // mapping from alias -> name
268  static IdMap* _idMap; // mapping from id -> name
269  static NameMap* _nameMap; // mapping from name -> id
270 };
271 
272 namespace detail {
280 }
281 }
282 }
283 } // lsst::afw::image
284 
285 #endif // LSST_AFW_IMAGE_FILTER_H
std::string const & getCanonicalName() const
Return a filter&#39;s canonical name.
Definition: Filter.h:204
static void reset()
Clear all definitions.
Definition: Filter.h:119
bool operator!=(Filter const &rhs) const
Definition: Filter.h:189
std::string const & _name
Definition: Mask.cc:576
int getId() const
Return a Filter&#39;s integral id.
Definition: Filter.h:194
static int const UNKNOWN
Definition: Filter.h:156
bool operator==(CoordKey const &lhs, CoordKey const &rhs)
Compare CoordKeys for equality using the constituent Keys.
int stripFilterKeywords(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Remove Filter-related keywords from the metadata.
Definition: Filter.cc:136
STL class.
double getLambdaMax() const
Return the filter&#39;s maximum wavelength (nm) where the transmission is above 1% of the maximum...
Definition: Filter.h:102
double getLambdaEff() const
Return the filter&#39;s effective wavelength (nm)
Definition: Filter.h:94
A base class for image defects.
int _id
Definition: Mask.cc:577
static int const AUTO
Definition: Filter.h:155
std::string const & getName() const
Return a filter&#39;s name.
Definition: Filter.h:90
double getLambdaMin() const
Return the filter&#39;s minimum wavelength (nm) where the transmission is above 1% of the maximum...
Definition: Filter.h:98
Holds an integer identifier for an LSST filter.
Definition: Filter.h:153
std::string const & getName() const
Return a Filter&#39;s name.
Definition: Filter.h:198
bool operator!=(FilterProperty const &rhs) const
Return true iff rhs != this.
Definition: Filter.h:112
Filter(int id=UNKNOWN)
Creates a Filter with the given identifier.
Definition: Filter.h:168
Filter(std::string const &name, bool const force=false)
Creates a Filter with the given name.
Definition: Filter.h:161
Describe the properties of a Filter (e.g.
Definition: Filter.h:56
FilterProperty(std::string const &name, double lambdaEff, double lambdaMin=NAN, double lambdaMax=NAN, bool force=false)
Definition: Filter.h:58
static void reset()
Clear all definitions.
Definition: Filter.h:219