LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
FluxUtilities.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2015 AURA/LSST.
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 
27 
28 namespace lsst { namespace meas { namespace base {
29 
31  flux(std::numeric_limits<Flux>::quiet_NaN()),
32  fluxSigma(std::numeric_limits<FluxErrElement>::quiet_NaN())
33 {}
34 
37  std::string const & name,
38  std::string const & doc
39 ) {
40  FluxResultKey result;
41  result._flux = schema.addField<Flux>(schema.join(name, "flux"), doc, "count");
42  result._fluxSigma = schema.addField<FluxErrElement>(schema.join(name, "fluxSigma"),
43  "1-sigma flux uncertainty", "count");
44  return result;
45 }
46 
48  FluxResult r;
49  r.flux = record.get(_flux);
50  r.fluxSigma = record.get(_fluxSigma);
51  return r;
52 }
53 
54 void FluxResultKey::set(afw::table::BaseRecord & record, FluxResult const & value) const {
55  record.set(_flux, value.flux);
56  record.set(_fluxSigma, value.fluxSigma);
57 }
58 
61  std::string const & name
62 ) {
63  MagResultKey result;
64  result._magKey = schema.addField<Mag>(schema.join(name, "mag"), "Magnitude");
65  result._magErrKey = schema.addField<MagErrElement>(schema.join(name, "magErr"), "Error on magnitude");
66  return result;
67 }
68 
70  MagResult result = {record.get(_magKey), record.get(_magErrKey)};
71  return result;
72 }
73 
74 void MagResultKey::set(afw::table::BaseRecord & record, MagResult const & magResult) const {
75  record.set(_magKey, magResult.mag);
76  record.set(_magErrKey, magResult.magErr);
77 }
78 
79 void MagResultKey::set(afw::table::BaseRecord & record, std::pair<double,double> const & magResult) const {
80  record.set(_magKey, magResult.first);
81  record.set(_magErrKey, magResult.second);
82 }
83 
85  std::string const & name,
87 ) :
88  BaseTransform{name}
89 {
90  // Map the flag through to the output
91  mapper.addMapping(mapper.getInputSchema().find<afw::table::Flag>(name + "_flag").key);
92 
93  // Add keys for the magnitude and associated error
94  _magKey = MagResultKey::addFields(mapper.editOutputSchema(), name);
95 }
96 
98  afw::table::SourceCatalog const & inputCatalog,
99  afw::table::BaseCatalog & outputCatalog,
100  afw::image::Wcs const & wcs,
101  afw::image::Calib const & calib
102 ) const {
103  checkCatalogSize(inputCatalog, outputCatalog);
104  FluxResultKey fluxKey(inputCatalog.getSchema()[_name]);
105  afw::table::SourceCatalog::const_iterator inSrc = inputCatalog.begin();
106  afw::table::BaseCatalog::iterator outSrc = outputCatalog.begin();
107  {
108  // While noThrow is in scope, converting a negative flux to a magnitude
109  // returns NaN rather than throwing.
111  for (; inSrc != inputCatalog.end() && outSrc != outputCatalog.end(); ++inSrc, ++outSrc) {
112  FluxResult fluxResult = fluxKey.get(*inSrc);
113  _magKey.set(*outSrc, calib.getMagnitude(fluxResult.flux, fluxResult.fluxSigma));
114  }
115  }
116 }
117 
121 }
122 
125 }
126 
127 }}} // namespace lsst::meas::base
Defines the fields and offsets for a table.
Definition: Schema.h:44
double FluxErrElement
Definition: constants.h:50
virtual void operator()(afw::table::SourceCatalog const &inputCatalog, afw::table::BaseCatalog &outputCatalog, afw::image::Wcs const &wcs, afw::image::Calib const &calib) const
table::Key< std::string > name
Definition: ApCorrMap.cc:71
virtual void set(afw::table::BaseRecord &record, FluxResult const &other) const
Set a FluxResult in the given record.
A custom container class for records, based on std::vector.
Definition: Catalog.h:95
void checkCatalogSize(afw::table::BaseCatalog const &cat1, afw::table::BaseCatalog const &cat2) const
Ensure that catalogs have the same size.
Definition: Transform.h:101
afw::table::Schema schema
Definition: GaussianPsf.cc:41
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:19
double MagErrElement
Definition: constants.h:52
This defines the base of measurement transformations.
A FunctorKey for MagResult.
Temporarily replace negative fluxes with NaNs.
A reusable result struct for magnitudes.
tbl::Key< int > wcs
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
afw::table::Key< Mag > _magKey
std::string join(std::string const &a, std::string const &b) const
Join strings using the field delimiter appropriate for this Schema.
static FluxResultKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc)
Add a pair of _flux, _fluxSigma fields to a Schema, and return a FluxResultKey that points to them...
FluxResult()
Default constructor; initializes everything to NaN.
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:145
Describe an exposure&#39;s calibration.
Definition: Calib.h:82
afw::table::Key< MagErrElement > _magErrKey
iterator begin()
Iterator access.
Definition: Catalog.h:392
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
Definition: fwd.h:55
afw::table::Key< Flux > _flux
static void setThrowOnNegativeFlux(bool raiseException)
Set whether Calib should throw an exception when asked to convert a flux to a magnitude.
Definition: Calib.cc:115
Iterator class for CatalogT.
Definition: Catalog.h:35
virtual FluxResult get(afw::table::BaseRecord const &record) const
Get a FluxResult from the given record.
Flux flux
Measured flux in DN.
Definition: FluxUtilities.h:38
Schema getSchema() const
Return the schema associated with the catalog&#39;s table.
Definition: Catalog.h:115
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
Definition: BaseRecord.h:132
A FunctorKey for FluxResult.
Definition: FluxUtilities.h:56
static MagResultKey addFields(afw::table::Schema &schema, std::string const &name)
Add a pair of _mag, _magErr fields to a Schema, and return a MagResultKey that points to them...
FluxTransform(std::string const &name, afw::table::SchemaMapper &mapper)
Base class for all records.
Definition: BaseRecord.h:27
virtual MagResult get(afw::table::BaseRecord const &record) const
Get a MagResult from the given record.
virtual void set(afw::table::BaseRecord &record, MagResult const &magResult) const
Set a MagResult in the given record.
iterator end()
Iterator access.
Definition: Catalog.h:393
Abstract base class for all C++ measurement transformations.
Definition: Transform.h:82
static bool getThrowOnNegativeFlux()
Tell me whether Calib will throw an exception if asked to convert a flux to a magnitude.
Definition: Calib.cc:125
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a new field to the Schema, and return the associated Key.
FluxErrElement fluxSigma
1-Sigma error (sqrt of variance) on flux in DN.
Definition: FluxUtilities.h:39
afw::table::Key< FluxErrElement > _fluxSigma
A reusable result struct for flux measurements.
Definition: FluxUtilities.h:37
double getMagnitude(double const flux) const
Return a magnitude given a flux.
Definition: Calib.cc:306