LSSTApplications  21.0.0+1b62c9342b,21.0.0+45a059f35e,21.0.0-1-ga51b5d4+ceb9cf20a3,21.0.0-2-g103fe59+4d13aff7ba,21.0.0-2-g1367e85+571a348718,21.0.0-2-g2909d54+45a059f35e,21.0.0-2-g45278ab+1b62c9342b,21.0.0-2-g4bc9b9f+ebfe466dad,21.0.0-2-g5242d73+571a348718,21.0.0-2-g54e2caa+07cebfb09d,21.0.0-2-g66bcc37+0b2c5d3971,21.0.0-2-g7f82c8f+08f1f55c36,21.0.0-2-g8dde007+5d1b9cb3f5,21.0.0-2-g8f08a60+73884b2cf5,21.0.0-2-ga326454+08f1f55c36,21.0.0-2-ga63a54e+458e82fbcd,21.0.0-2-gc738bc1+8c4731df06,21.0.0-2-gde069b7+5a8f2956b8,21.0.0-2-ge17e5af+571a348718,21.0.0-2-ge712728+cfa36ee5f9,21.0.0-2-gecfae73+e597808034,21.0.0-2-gfc62afb+571a348718,21.0.0-20-g4449a12+6d1341e0f3,21.0.0-22-gf0532904+1cd928f0c5,21.0.0-3-g4c5b185+c3794955c6,21.0.0-3-g6d51c4a+0b2c5d3971,21.0.0-3-g8076721+5adeb471db,21.0.0-3-gaa929c8+01f4b7cfca,21.0.0-3-gd222c45+afc8332dbe,21.0.0-4-g1383c07+0b2c5d3971,21.0.0-4-g3300ddd+1b62c9342b,21.0.0-4-g5873dc9+9a92674037,21.0.0-4-g8a80011+bd904b6426,21.0.0-5-gcff38f6+844b7f7b93,21.0.0-6-g463d161+18af5fb57b,21.0.0-6-gd3283ba+01f4b7cfca,21.0.0-8-g19111d86+8234efb485,21.0.0-9-g7bed000b9+c7d3cce47e,w.2021.04
LSSTDataManagementBasePackage
ApCorrMap.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2014 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 #include <memory>
25 
31 
32 namespace lsst {
33 namespace afw {
34 
37 
38 namespace image {
39 
40 // Even though this static const member is set in the header, it needs to be declared here if we need
41 // to take its address (and Swig might).
42 std::size_t const ApCorrMap::MAX_NAME_LENGTH;
43 
44 std::shared_ptr<math::BoundedField> const ApCorrMap::operator[](std::string const& name) const {
45  Iterator i = _internal.find(name);
46  if (i == _internal.end()) {
48  (boost::format("Aperture correction with name '%s' not found") % name).str());
49  }
50  return i->second;
51 }
52 
53 std::shared_ptr<math::BoundedField> const ApCorrMap::get(std::string const& name) const {
54  Iterator i = _internal.find(name);
55  if (i == _internal.end()) {
57  }
58  return i->second;
59 }
60 
62  if (name.size() > MAX_NAME_LENGTH) {
63  throw LSST_EXCEPT(
65  (boost::format("Aperture correction name '%s' exceeds size limit of %d characters") % name %
66  MAX_NAME_LENGTH)
67  .str());
68  }
69  _internal.insert(std::make_pair(name, field));
70 }
71 
72 namespace {
73 
74 struct PersistenceHelper {
75  table::Schema schema;
76  table::Key<std::string> name;
77  table::Key<int> field;
78 
79  static PersistenceHelper const& get() {
80  static PersistenceHelper const instance;
81  return instance;
82  }
83 
84 private:
85  PersistenceHelper()
86  : schema(),
87  name(schema.addField<std::string>("name", "name of the aperture correction",
88  ApCorrMap::MAX_NAME_LENGTH)),
89  field(schema.addField<int>("field", "archive ID of the BoundedField object")) {}
90 };
91 
92 class ApCorrMapFactory : public table::io::PersistableFactory {
93 public:
94  std::shared_ptr<table::io::Persistable> read(InputArchive const& archive,
95  CatalogVector const& catalogs) const override {
96  PersistenceHelper const& keys = PersistenceHelper::get();
97  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
98  LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
99  std::shared_ptr<ApCorrMap> result = std::make_shared<ApCorrMap>();
100  for (table::BaseCatalog::const_iterator i = catalogs.front().begin(); i != catalogs.front().end();
101  ++i) {
102  result->set(i->get(keys.name), archive.get<math::BoundedField>(i->get(keys.field)));
103  }
104  return result;
105  }
106 
107  ApCorrMapFactory(std::string const& name) : afw::table::io::PersistableFactory(name) {}
108 };
109 
110 std::string getApCorrMapPersistenceName() { return "ApCorrMap"; }
111 
112 ApCorrMapFactory registration(getApCorrMapPersistenceName());
113 
114 } // namespace
115 
116 bool ApCorrMap::isPersistable() const noexcept {
117  for (Iterator i = begin(); i != end(); ++i) {
118  if (!i->second->isPersistable()) return false;
119  }
120  return true;
121 }
122 
123 std::string ApCorrMap::getPersistenceName() const { return getApCorrMapPersistenceName(); }
124 
125 std::string ApCorrMap::getPythonModule() const { return "lsst.afw.image"; }
126 
127 void ApCorrMap::write(OutputArchiveHandle& handle) const {
128  PersistenceHelper const& keys = PersistenceHelper::get();
129  table::BaseCatalog catalog = handle.makeCatalog(keys.schema);
130  for (Iterator i = begin(); i != end(); ++i) {
131  std::shared_ptr<table::BaseRecord> record = catalog.addNew();
132  record->set(keys.name, i->first);
133  record->set(keys.field, handle.put(i->second));
134  }
135  handle.saveCatalog(catalog);
136 }
137 
139  Internal replacement;
140  for (Iterator i = begin(); i != end(); ++i) {
141  replacement[i->first] = (*i->second) * scale;
142  }
143  _internal = replacement;
144  return *this;
145 }
146 
147 std::shared_ptr<typehandling::Storable> ApCorrMap::cloneStorable() const {
148  return std::make_unique<ApCorrMap>(*this);
149 }
150 
151 } // namespace image
152 } // namespace afw
153 } // namespace lsst
lsst::afw::table::CatalogT< BaseRecord >::const_iterator
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:111
lsst::afw::image
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Definition: imageAlgorithm.dox:1
std::string
STL class.
std::shared_ptr
STL class.
lsst.pex::exceptions::NotFoundError
Reports attempts to access elements using an invalid key.
Definition: Runtime.h:151
lsst::afw
Definition: imageAlgorithm.dox:1
astshim.keyMap.keyMapContinued.keys
def keys(self)
Definition: keyMapContinued.py:6
CatalogVector.h
lsst.pex.config.history.format
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
end
int end
Definition: BoundedField.cc:105
lsst::afw::image::operator*=
Image< LhsPixelT > & operator*=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Multiply lhs by Image rhs (i.e. pixel-by-pixel multiplication) where types are different.
Definition: Image.cc:677
lsst.pipe.tasks.mergeDetections.write
def write(self, patchRef, catalog)
Write the output.
Definition: mergeDetections.py:389
lsst::afw::image::ApCorrMap::Iterator
Internal::const_iterator Iterator
Iterator type returned by begin() and end().
Definition: ApCorrMap.h:54
name
table::Key< std::string > name
Definition: ApCorrMap.cc:76
schema
table::Schema schema
Definition: ApCorrMap.cc:75
lsst.pex::exceptions::LengthError
Reports attempts to exceed implementation-defined length limits for some classes.
Definition: Runtime.h:76
field
table::Key< int > field
Definition: ApCorrMap.cc:77
lsst::jointcal::Iterator
FastFinder::Iterator Iterator
Definition: FastFinder.cc:178
lsst.pipe.tasks.cli.cmd.commands.str
str
Definition: commands.py:50
std::map< std::string, std::shared_ptr< math::BoundedField > >
result
py::object result
Definition: _schema.cc:429
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
LSST_ARCHIVE_ASSERT
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Definition: Persistable.h:48
lsst::afw::table::io::PersistableFacade::dynamicCast
static std::shared_ptr< T > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
Definition: Persistable.cc:18
std
STL namespace.
lsst::afw.display.ds9.scale
def scale(algorithm, min, max=None, frame=None)
Definition: ds9.py:109
ApCorrMap.h
InputArchive.h
std::size_t
std::make_pair
T make_pair(T... args)
lsst::afw::table::CatalogT::addNew
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
Definition: Catalog.h:485
lsst::afw::table::BaseRecord::set
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:164
lsst::afw::image::ApCorrMap
A thin wrapper around std::map to allow aperture corrections to be attached to Exposures.
Definition: ApCorrMap.h:45
lsst::afw::table::CatalogT< BaseRecord >
set
daf::base::PropertySet * set
Definition: fits.cc:912
OutputArchive.h
Persistable.cc