lsst.afw g5c39d4753b+b7a74ad830
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
44namespace lsst {
45namespace afw {
46namespace image {
47
51class[
52 [deprecated("Removed with no replacement (but see lsst::afw::image::TransmissionCurve). Will be "
53 "removed after v22.")]] FilterProperty final {
54public:
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
118private:
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
143class[[deprecated("Replaced with FilterLabel. Will be removed after v22.")]] Filter final
144 : public typehandling::Storable {
145public:
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
248protected:
249 std::string getPersistenceName() const override;
250 std::string getPythonModule() const override;
251 void write(OutputArchiveHandle & handle) const override;
252
253private:
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
283namespace detail {
291} // namespace detail
292} // namespace image
293} // namespace afw
294} // namespace lsst
295
296namespace std {
297template <>
301 size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
302};
303
304template <>
305struct 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
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