lsst.afw  21.0.0-10-g68cce58c5+c7d3cce47e
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 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 : public typehandling::Storable {
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 override;
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); }
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 
232 
235 
241  bool equals(typehandling::Storable const& other) const noexcept override;
242 
243  bool isPersistable() const noexcept override;
244 
245 protected:
246  std::string getPersistenceName() const override;
247  std::string getPythonModule() const override;
248  void write(OutputArchiveHandle& handle) const override;
249 
250 private:
251  typedef std::unordered_map<std::string, std::string const> AliasMap;
252  typedef std::unordered_map<std::string, unsigned int const> NameMap;
253  typedef std::unordered_map<unsigned int, std::string const> IdMap;
254 
258  static void _initRegistry();
265  static int _lookup(std::string const& name, bool const force = false);
269  static std::string const& _lookup(int id);
270 
271  int _id;
272  std::string _name;
273 
274  static int _id0; // next Id to use
275  static AliasMap* _aliasMap; // mapping from alias -> name
276  static IdMap* _idMap; // mapping from id -> name
277  static NameMap* _nameMap; // mapping from name -> id
278 };
279 
280 namespace detail {
288 } // namespace detail
289 } // namespace image
290 } // namespace afw
291 } // namespace lsst
292 
293 namespace std {
294 template <>
295 struct hash<lsst::afw::image::FilterProperty> {
298  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
299 };
300 
301 template <>
302 struct hash<lsst::afw::image::Filter> {
305  size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
306 };
307 } // namespace std
308 
309 #endif // LSST_AFW_IMAGE_FILTER_H
lsst::afw::image
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Definition: imageAlgorithm.dox:1
lsst::afw::image::Filter::getId
int getId() const noexcept
Return a Filter's integral id.
Definition: Filter.h:185
lsst::afw::image::Filter::Filter
Filter(std::string const &name, bool const force=false)
Creates a Filter with the given name.
Definition: Filter.h:149
std::string
STL class.
std::shared_ptr
STL class.
lsst::afw::image::detail::stripFilterKeywords
int stripFilterKeywords(std::shared_ptr< lsst::daf::base::PropertySet > metadata)
Remove Filter-related keywords from the metadata.
Definition: Filter.cc:132
lsst::afw::image::Filter::define
static int define(FilterProperty const &filterProperty, int id=AUTO, bool force=false)
Define a filter name to have the specified id.
Definition: Filter.cc:256
lsst::afw::image::Filter::write
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition: Filter.cc:224
std::vector< std::string >
lsst::afw::image::Filter
Holds an integer identifier for an LSST filter.
Definition: Filter.h:141
lsst::afw::image::FilterProperty
Describe the properties of a Filter (e.g.
Definition: Filter.h:51
lsst::afw::image::Filter::getPythonModule
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition: Filter.cc:222
lsst::afw::image::FilterProperty::getLambdaMax
double getLambdaMax() const noexcept
Return the filter's maximum wavelength (nm) where the transmission is above 1% of the maximum.
Definition: Filter.h:88
lsst::afw::image::FilterProperty::operator!=
bool operator!=(FilterProperty const &rhs) const noexcept
Return true iff rhs != this.
Definition: Filter.h:98
lsst::afw::typehandling::Storable
Interface supporting iteration over heterogenous containers.
Definition: Storable.h:58
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
lsst::afw::image::FilterProperty::FilterProperty
FilterProperty(FilterProperty const &)=default
base.h
lsst::afw::image::FilterProperty::FilterProperty
FilterProperty(std::string const &name, double lambdaEff, double lambdaMin=NAN, double lambdaMax=NAN, bool force=false)
Definition: Filter.h:53
lsst::afw::image::Filter::defineAlias
static int defineAlias(std::string const &oldName, std::string const &newName, bool force=false)
Define an alias for a filter.
Definition: Filter.cc:289
lsst::afw::image::FilterProperty::getLambdaEff
double getLambdaEff() const noexcept
Return the filter's effective wavelength (nm)
Definition: Filter.h:80
lsst::afw::image::Filter::isPersistable
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition: Filter.cc:218
lsst::afw::image::FilterProperty::reset
static void reset()
Clear all definitions.
Definition: Filter.h:107
lsst::afw::image::Filter::AUTO
static int const AUTO
Definition: Filter.h:143
lsst::afw::image::FilterProperty::getLambdaMin
double getLambdaMin() const noexcept
Return the filter's minimum wavelength (nm) where the transmission is above 1% of the maximum.
Definition: Filter.h:84
lsst::afw::image::FilterProperty::FilterProperty
FilterProperty(FilterProperty &&) noexcept=default
lsst::afw::image::FilterProperty::hash_value
std::size_t hash_value() const noexcept
Return a hash of this object.
Definition: Filter.cc:91
id
table::Key< int > id
Definition: Detector.cc:162
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::afw::image::Filter::getNames
static std::vector< std::string > getNames()
Return a list of known filters.
Definition: Filter.cc:159
lsst::afw::image::Filter::getFilterProperty
FilterProperty const & getFilterProperty() const
Return a Filter's FilterProperty.
Definition: Filter.cc:355
lsst::afw::image::Filter::hash_value
std::size_t hash_value() const noexcept override
Return a hash of this object.
Definition: Filter.cc:234
PropertySet.h
Storable.h
lsst::afw::image::FilterProperty::getName
std::string const & getName() const noexcept
Return a filter's name.
Definition: Filter.h:76
std::hash< lsst::afw::image::Filter >::operator()
size_t operator()(argument_type const &obj) const noexcept
Definition: Filter.h:305
lsst
A base class for image defects.
lsst::afw::image::Filter::equals
bool equals(typehandling::Storable const &other) const noexcept override
Compare this object to another Storable.
Definition: Filter.cc:180
lsst::afw::image::Filter::reset
static void reset()
Clear all definitions.
Definition: Filter.h:210
lsst::afw::image::Filter::Filter
Filter(int id=UNKNOWN)
Creates a Filter with the given identifier.
Definition: Filter.h:156
std
STL namespace.
lsst::afw::image::Filter::UNKNOWN
static int const UNKNOWN
Definition: Filter.h:144
lsst::daf::base::PropertySet
lsst::afw::image::Filter::getCanonicalName
std::string const & getCanonicalName() const
Return a filter's canonical name.
Definition: Filter.h:195
std::size_t
lsst::afw::image::Filter::getName
std::string const & getName() const noexcept
Return a Filter's name.
Definition: Filter.h:189
lsst::afw::image::Filter::getAliases
std::vector< std::string > getAliases() const
Return all aliases by which this filter is known.
Definition: Filter.cc:146
lsst::afw::image::Filter::Filter
Filter(Filter &&) noexcept=default
lsst::afw::image::FilterProperty::lookup
static FilterProperty const & lookup(std::string const &name)
Lookup the properties of a filter "name".
Definition: Filter.cc:101
lsst::afw::table::io::Persistable::OutputArchiveHandle
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:108
std::unordered_map
STL class.
lsst::afw::image::Filter::cloneStorable
std::shared_ptr< typehandling::Storable > cloneStorable() const override
Create a new Filter that is a copy of this one.
Definition: Filter.cc:176
lsst::afw::image::Filter::Filter
Filter(Filter const &)=default
std::hash< lsst::afw::image::FilterProperty >::operator()
size_t operator()(argument_type const &obj) const noexcept
Definition: Filter.h:298
lsst::afw::image::Filter::getPersistenceName
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition: Filter.cc:220
std::hash
lsst::afw::image::FilterProperty::operator==
bool operator==(FilterProperty const &rhs) const noexcept
Return true iff two FilterProperties are identical.
Definition: Filter.cc:87