LSST Applications  21.0.0+75b29a8a7f,21.0.0+e70536a077,21.0.0-1-ga51b5d4+62c747d40b,21.0.0-10-gbfb87ad6+1472003707,21.0.0-12-g51f5968d7+47cba9fc36,21.0.0-2-g103fe59+b7c383bd9a,21.0.0-2-g1367e85+48b67f5d39,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g4bc9b9f+3fe6d1dcab,21.0.0-2-g5242d73+48b67f5d39,21.0.0-2-g54e2caa+df6b29423d,21.0.0-2-g7f82c8f+6775bdeedd,21.0.0-2-g8dde007+9e83774735,21.0.0-2-g8f08a60+9402881886,21.0.0-2-ga326454+6775bdeedd,21.0.0-2-ga63a54e+1ed2fee5f8,21.0.0-2-gde069b7+26c92b3210,21.0.0-2-gecfae73+adba745f5b,21.0.0-2-gfc62afb+48b67f5d39,21.0.0-23-ga70773b+149afabbf4,21.0.0-25-g85b8e57b+773e41f820,21.0.0-3-g357aad2+5f60c9c50d,21.0.0-3-g4be5c26+48b67f5d39,21.0.0-3-g65f322c+73694798db,21.0.0-3-g6d51c4a+ed84a54361,21.0.0-3-g7d9da8d+75b29a8a7f,21.0.0-3-gaa929c8+6a9f1b9ca4,21.0.0-3-ge02ed75+ed84a54361,21.0.0-4-g3300ddd+e70536a077,21.0.0-4-gc004bbf+542906830e,21.0.0-4-gccdca77+f94adcd104,21.0.0-4-gd1c1571+0451688df7,21.0.0-5-g7b47fff+ed84a54361,21.0.0-5-gb155db7+58d9d10622,21.0.0-5-gdf36809+637e4641ee,21.0.0-6-g722ad07+d350a29088,21.0.0-7-gfd72ab2+fa9972ccfc,21.0.0-8-gfbe0b4b+6a9f1b9ca4,w.2021.05
LSST Data Management Base Package
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Static Protected Member Functions | Related Functions | List of all members
lsst::afw::image::Filter Class Referencefinal

Holds an integer identifier for an LSST filter. More...

#include <Filter.h>

Inheritance diagram for lsst::afw::image::Filter:
lsst::afw::typehandling::Storable lsst::afw::table::io::Persistable

Public Member Functions

 Filter (std::string const &name, bool const force=false)
 Creates a Filter with the given name. More...
 
 Filter (int id=UNKNOWN)
 Creates a Filter with the given identifier. More...
 
 Filter (std::shared_ptr< lsst::daf::base::PropertySet const > metadata, bool const force=false)
 Create a Filter from a PropertySet (e.g. More...
 
 Filter (Filter const &)=default
 
 Filter (Filter &&) noexcept=default
 
Filteroperator= (Filter const &)=default
 
Filteroperator= (Filter &&) noexcept=default
 
 ~Filter () noexcept=default
 
bool operator== (Filter const &rhs) const noexcept
 Are two filters identical? More...
 
bool operator!= (Filter const &rhs) const noexcept
 
std::size_t hash_value () const noexcept override
 Return a hash of this object. More...
 
int getId () const noexcept
 Return a Filter's integral id. More...
 
std::string const & getName () const noexcept
 Return a Filter's name. More...
 
std::string const & getCanonicalName () const
 Return a filter's canonical name. More...
 
std::vector< std::stringgetAliases () const
 Return all aliases by which this filter is known. More...
 
FilterProperty const & getFilterProperty () const
 Return a Filter's FilterProperty. More...
 
std::shared_ptr< typehandling::StorablecloneStorable () const override
 Create a new Filter that is a copy of this one. More...
 
bool equals (typehandling::Storable const &other) const noexcept override
 Compare this object to another Storable. More...
 
bool isPersistable () const noexcept override
 Return true if this particular object can be persisted using afw::table::io. More...
 
virtual std::string toString () const
 Create a string representation of this object (optional operation). More...
 
void writeFits (std::string const &fileName, std::string const &mode="w") const
 Write the object to a regular FITS file. More...
 
void writeFits (fits::MemFileManager &manager, std::string const &mode="w") const
 Write the object to a FITS image in memory. More...
 
void writeFits (fits::Fits &fitsfile) const
 Write the object to an already-open FITS object. More...
 

Static Public Member Functions

static void reset ()
 Clear all definitions. More...
 
static int define (FilterProperty const &filterProperty, int id=AUTO, bool force=false)
 Define a filter name to have the specified id. More...
 
static int defineAlias (std::string const &oldName, std::string const &newName, bool force=false)
 Define an alias for a filter. More...
 
static std::vector< std::stringgetNames ()
 Return a list of known filters. More...
 

Static Public Attributes

static int const AUTO = -1
 
static int const UNKNOWN = -1
 

Protected Types

typedef io::OutputArchiveHandle OutputArchiveHandle
 

Protected Member Functions

std::string getPersistenceName () const override
 Return the unique name used to persist this object and look up its factory. More...
 
std::string getPythonModule () const override
 Return the fully-qualified Python module that should be imported to guarantee that its factory is registered. More...
 
void write (OutputArchiveHandle &handle) const override
 Write the object to one or more catalogs. More...
 

Static Protected Member Functions

template<class T >
static bool singleClassEquals (T const &lhs, Storable const &rhs)
 Test if a Storable is of a particular class and equal to another object. More...
 

Related Functions

(Note that these are not member functions.)

std::ostreamoperator<< (std::ostream &os, Storable const &storable)
 Output operator for Storable. More...
 

Detailed Description

Holds an integer identifier for an LSST filter.

Definition at line 141 of file Filter.h.

Member Typedef Documentation

◆ OutputArchiveHandle

typedef io::OutputArchiveHandle lsst::afw::table::io::Persistable::OutputArchiveHandle
protectedinherited

Definition at line 108 of file Persistable.h.

Constructor & Destructor Documentation

◆ Filter() [1/5]

lsst::afw::image::Filter::Filter ( std::string const &  name,
bool const  force = false 
)
inlineexplicit

Creates a Filter with the given name.

Parameters
nameName of filter
forceAllow us to construct an unknown Filter

Definition at line 149 of file Filter.h.

152  : _id(_lookup(name, force)), _name(name) {}

◆ Filter() [2/5]

lsst::afw::image::Filter::Filter ( int  id = UNKNOWN)
inlineexplicit

Creates a Filter with the given identifier.

Parameters
idId number of desired filter

Definition at line 156 of file Filter.h.

158  : _id(id), _name(_lookup(id)) {}

◆ Filter() [3/5]

lsst::afw::image::Filter::Filter ( std::shared_ptr< lsst::daf::base::PropertySet const >  metadata,
bool const  force = false 
)
explicit

Create a Filter from a PropertySet (e.g.

a FITS header)

Parameters
metadataMetadata to process (e.g. a IFITS header)
forceAllow us to construct an unknown Filter

Definition at line 122 of file Filter.cc.

122  {
123  std::string const key = "FILTER";
124  if (metadata->exists(key)) {
125  std::string filterName = boost::algorithm::trim_right_copy(metadata->getAsString(key));
126  _id = _lookup(filterName, force);
127  _name = filterName;
128  }
129 }
Key< U > key
Definition: Schema.cc:281

◆ Filter() [4/5]

lsst::afw::image::Filter::Filter ( Filter const &  )
default

◆ Filter() [5/5]

lsst::afw::image::Filter::Filter ( Filter &&  )
defaultnoexcept

◆ ~Filter()

lsst::afw::image::Filter::~Filter ( )
defaultnoexcept

Member Function Documentation

◆ cloneStorable()

std::shared_ptr< typehandling::Storable > lsst::afw::image::Filter::cloneStorable ( ) const
overridevirtual

Create a new Filter that is a copy of this one.

Reimplemented from lsst::afw::typehandling::Storable.

Definition at line 176 of file Filter.cc.

176  {
177  return std::make_unique<Filter>(*this);
178 }

◆ define()

int lsst::afw::image::Filter::define ( FilterProperty const &  filterProperty,
int  id = AUTO,
bool  force = false 
)
static

Define a filter name to have the specified id.

If id == Filter::AUTO a value will be chosen for you.

It is an error to attempt to change a name's id (unless you specify force)

Definition at line 256 of file Filter.cc.

256  {
257  if (!_nameMap) {
258  _initRegistry();
259  }
260 
261  std::string const& name = fp.getName();
262  NameMap::iterator keyVal = _nameMap->find(name);
263 
264  if (keyVal != _nameMap->end()) {
265  int oid = keyVal->second;
266 
267  if (id == oid || id == AUTO) {
268  return oid; // OK, same value as before
269  }
270 
271  if (!force) {
272  throw LSST_EXCEPT(pexEx::RuntimeError, "Filter " + name + " is already defined");
273  }
274  _nameMap->erase(keyVal);
275  _idMap->erase(oid);
276  }
277 
278  if (id == AUTO) {
279  id = _id0;
280  ++_id0;
281  }
282 
283  _nameMap->insert(std::make_pair(name, id));
284  _idMap->insert(std::make_pair(id, name));
285 
286  return id;
287 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
static int const AUTO
Definition: Filter.h:143
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104
T end(T... args)
T erase(T... args)
T find(T... args)
T insert(T... args)
T make_pair(T... args)
table::Key< int > id
Definition: Detector.cc:162
table::Key< std::string > name
Definition: Filter.cc:188

◆ defineAlias()

int lsst::afw::image::Filter::defineAlias ( std::string const &  oldName,
std::string const &  newName,
bool  force = false 
)
static

Define an alias for a filter.

Parameters
oldNameold name for Filter
newNamenew name for Filter
forceforce an alias even if newName is already in use

Definition at line 289 of file Filter.cc.

289  {
290  if (!_nameMap) {
291  _initRegistry();
292  }
293 
294  // Lookup oldName
295  NameMap::iterator keyVal = _nameMap->find(oldName);
296  if (keyVal == _nameMap->end()) {
297  throw LSST_EXCEPT(pexEx::NotFoundError, "Unable to find filter " + oldName);
298  }
299  int const id = keyVal->second;
300 
301  // Lookup oldName in aliasMap
302  AliasMap::iterator aliasKeyVal = _aliasMap->find(newName);
303  if (aliasKeyVal != _aliasMap->end()) {
304  if (aliasKeyVal->second == oldName) {
305  return id; // OK, same value as before
306  }
307 
308  if (!force) {
309  throw LSST_EXCEPT(pexEx::NotFoundError, "Filter " + newName + " is already defined");
310  }
311  _aliasMap->erase(aliasKeyVal);
312  }
313 
314  _aliasMap->insert(std::make_pair(newName, oldName));
315 
316  return id;
317 }
Reports attempts to access elements using an invalid key.
Definition: Runtime.h:151

◆ equals()

bool lsst::afw::image::Filter::equals ( typehandling::Storable const &  other) const
overridevirtualnoexcept

Compare this object to another Storable.

Returns
*this == other if other is a Filter; otherwise false.

Reimplemented from lsst::afw::typehandling::Storable.

Definition at line 180 of file Filter.cc.

180  {
181  return singleClassEquals(*this, other);
182 }
ItemVariant const * other
Definition: Schema.cc:56
static bool singleClassEquals(T const &lhs, Storable const &rhs)
Test if a Storable is of a particular class and equal to another object.
Definition: Storable.h:151

◆ getAliases()

std::vector< std::string > lsst::afw::image::Filter::getAliases ( ) const

Return all aliases by which this filter is known.

The list excludes the canonical name

Definition at line 146 of file Filter.cc.

146  {
147  std::vector<std::string> aliases;
148 
149  std::string const& canonicalName = getCanonicalName();
150  for (AliasMap::iterator ptr = _aliasMap->begin(), end = _aliasMap->end(); ptr != end; ++ptr) {
151  if (ptr->second == canonicalName) {
152  aliases.push_back(ptr->first);
153  }
154  }
155 
156  return aliases;
157 }
uint64_t * ptr
Definition: RangeSet.cc:88
T begin(T... args)
std::string const & getCanonicalName() const
Return a filter's canonical name.
Definition: Filter.h:195
T push_back(T... args)
int end

◆ getCanonicalName()

std::string const& lsst::afw::image::Filter::getCanonicalName ( ) const
inline

Return a filter's canonical name.

I.e. if this filter's an alias, return the name of the aliased Filter

Definition at line 195 of file Filter.h.

195 { return _lookup(_id); }

◆ getFilterProperty()

FilterProperty const & lsst::afw::image::Filter::getFilterProperty ( ) const

Return a Filter's FilterProperty.

Definition at line 355 of file Filter.cc.

355  {
356  //
357  // Map name to its ID and back to resolve aliases
358  //
359  int const id = _lookup(_name, true);
360  std::string const& name = (id == UNKNOWN) ? _name : _lookup(id);
361 
363 }
static int const UNKNOWN
Definition: Filter.h:144
static FilterProperty const & lookup(std::string const &name)
Lookup the properties of a filter "name".
Definition: Filter.cc:101

◆ getId()

int lsst::afw::image::Filter::getId ( ) const
inlinenoexcept

Return a Filter's integral id.

Definition at line 185 of file Filter.h.

185 { return _id; }

◆ getName()

std::string const& lsst::afw::image::Filter::getName ( ) const
inlinenoexcept

Return a Filter's name.

Definition at line 189 of file Filter.h.

189 { return _name; }

◆ getNames()

std::vector< std::string > lsst::afw::image::Filter::getNames ( )
static

Return a list of known filters.

Definition at line 159 of file Filter.cc.

159  {
160  if (!_nameMap) {
161  _initRegistry();
162  }
163 
165 
166  for (NameMap::const_iterator ptr = _nameMap->begin(), end = _nameMap->end(); ptr != end; ++ptr) {
167  if (ptr->first != unknownFilter) {
168  names.push_back(ptr->first);
169  }
170  }
171  std::sort(names.begin(), names.end());
172 
173  return names;
174 }
T sort(T... args)

◆ getPersistenceName()

std::string lsst::afw::image::Filter::getPersistenceName ( ) const
overrideprotectedvirtual

Return the unique name used to persist this object and look up its factory.

Must be less than ArchiveIndexSchema::MAX_NAME_LENGTH characters.

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 220 of file Filter.cc.

220 { return _getPersistenceName(); }

◆ getPythonModule()

std::string lsst::afw::image::Filter::getPythonModule ( ) const
overrideprotectedvirtual

Return the fully-qualified Python module that should be imported to guarantee that its factory is registered.

Must be less than ArchiveIndexSchema::MAX_MODULE_LENGTH characters.

Will be ignored if empty.

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 222 of file Filter.cc.

222 { return "lsst.afw.image"; };

◆ hash_value()

std::size_t lsst::afw::image::Filter::hash_value ( ) const
overridevirtualnoexcept

Return a hash of this object.

Reimplemented from lsst::afw::typehandling::Storable.

Definition at line 234 of file Filter.cc.

234 { return std::hash<int>()(_id); }

◆ isPersistable()

bool lsst::afw::image::Filter::isPersistable ( ) const
overridevirtualnoexcept

Return true if this particular object can be persisted using afw::table::io.

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 218 of file Filter.cc.

218 { return true; }

◆ operator!=()

bool lsst::afw::image::Filter::operator!= ( Filter const &  rhs) const
inlinenoexcept

Definition at line 177 of file Filter.h.

177 { return !(*this == rhs); }

◆ operator=() [1/2]

Filter& lsst::afw::image::Filter::operator= ( Filter &&  )
defaultnoexcept

◆ operator=() [2/2]

Filter& lsst::afw::image::Filter::operator= ( Filter const &  )
default

◆ operator==()

bool lsst::afw::image::Filter::operator== ( Filter const &  rhs) const
noexcept

Are two filters identical?

Definition at line 232 of file Filter.cc.

232 { return _id != UNKNOWN && _id == rhs._id; }

◆ reset()

static void lsst::afw::image::Filter::reset ( )
inlinestatic

Clear all definitions.

Definition at line 210 of file Filter.h.

210 { _initRegistry(); }

◆ singleClassEquals()

template<class T >
static bool lsst::afw::typehandling::Storable::singleClassEquals ( T const &  lhs,
Storable const &  rhs 
)
inlinestaticprotectedinherited

Test if a Storable is of a particular class and equal to another object.

This method template simplifies implementations of equals that delegate to operator== without supporting cross-class comparisons.

Template Parameters
TThe class expected of the two objects to be compared.
Parameters
lhs,rhsThe objects to compare. Note that rhs need not be a T, while lhs must be.
Returns
true if rhs is a T and lhs == rhs; false otherwise.
Exception Safety
Provides the same level of exception safety as operator==. Most implementations of operator== do not throw.
Note
This method template calls operator== with both arguments of compile-time type T const&. Its use is not recommended if there would be any ambiguity as to which operator== gets picked by overload resolution.

This method template is typically called from equals as:

bool MyType::equals(Storable const& other) const noexcept {
    return singleClassEquals(*this, other);
}

Definition at line 151 of file Storable.h.

151  {
152  auto typedRhs = dynamic_cast<T const*>(&rhs);
153  if (typedRhs != nullptr) {
154  return lhs == *typedRhs;
155  } else {
156  return false;
157  }
158  }

◆ toString()

std::string lsst::afw::typehandling::Storable::toString ( ) const
virtualinherited

Create a string representation of this object (optional operation).

Exceptions
UnsupportedOperationExceptionThrown if this object does not have a string representation.
Note
When called on Python classes, this method delegates to __repr__.

Reimplemented in lsst::afw::typehandling::StorableHelper< Base >, lsst::afw::image::VisitInfo, lsst::afw::image::PhotoCalib, lsst::afw::image::FilterLabel, lsst::afw::geom::SkyWcs, and lsst::afw::geom::polygon::Polygon.

Definition at line 40 of file Storable.cc.

40  {
41  throw LSST_EXCEPT(UnsupportedOperationException, "No string representation available.");
42 }

◆ write()

void lsst::afw::image::Filter::write ( OutputArchiveHandle handle) const
overrideprotectedvirtual

Write the object to one or more catalogs.

The handle object passed to this function provides an interface for adding new catalogs and adding nested objects to the same archive (while checking for duplicates). See OutputArchiveHandle for more information.

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 224 of file Filter.cc.

224  {
225  PersistenceHelper const& keys = PersistenceHelper::get();
226  table::BaseCatalog catalog = handle.makeCatalog(keys.schema);
227  std::shared_ptr<table::BaseRecord> record = catalog.addNew();
228  record->set(keys.name, getName());
229  handle.saveCatalog(catalog);
230 }
std::string const & getName() const noexcept
Return a Filter's name.
Definition: Filter.h:189
CatalogT< BaseRecord > BaseCatalog
Definition: fwd.h:71

◆ writeFits() [1/3]

void lsst::afw::table::io::Persistable::writeFits ( fits::Fits fitsfile) const
inherited

Write the object to an already-open FITS object.

Parameters
[in]fitsfileOpen FITS object to write to.

Definition at line 18 of file Persistable.cc.

18  {
19  OutputArchive archive;
20  archive.put(this);
21  archive.writeFits(fitsfile);
22 }

◆ writeFits() [2/3]

void lsst::afw::table::io::Persistable::writeFits ( fits::MemFileManager manager,
std::string const &  mode = "w" 
) const
inherited

Write the object to a FITS image in memory.

Parameters
[in]managerName of the file to write to.
[in]modeIf "w", any existing file with the given name will be overwritten. If "a", new HDUs will be appended to an existing file.

Definition at line 29 of file Persistable.cc.

29  {
30  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
31  writeFits(fitsfile);
32 }
void writeFits(std::string const &fileName, std::string const &mode="w") const
Write the object to a regular FITS file.
Definition: Persistable.cc:24

◆ writeFits() [3/3]

void lsst::afw::table::io::Persistable::writeFits ( std::string const &  fileName,
std::string const &  mode = "w" 
) const
inherited

Write the object to a regular FITS file.

Parameters
[in]fileNameName of the file to write to.
[in]modeIf "w", any existing file with the given name will be overwritten. If "a", new HDUs will be appended to an existing file.

Definition at line 24 of file Persistable.cc.

24  {
25  fits::Fits fitsfile(fileName, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
26  writeFits(fitsfile);
27 }

Friends And Related Function Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream os,
Storable const &  storable 
)
related

Output operator for Storable.

Parameters
osthe desired output stream
storablethe object to print
Returns
a reference to os
Exceptions
UnsupportedOperationExceptionThrown if storable does not have an implementation of Storable::toString.

Definition at line 174 of file Storable.h.

174  {
175  return os << storable.toString();
176 }
std::ostream * os
Definition: Schema.cc:746

Member Data Documentation

◆ AUTO

int const lsst::afw::image::Filter::AUTO = -1
static

Definition at line 143 of file Filter.h.

◆ UNKNOWN

int const lsst::afw::image::Filter::UNKNOWN = -1
static

Definition at line 144 of file Filter.h.


The documentation for this class was generated from the following files: