LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
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, "dn");
42  result._fluxSigma = schema.addField<FluxErrElement>(schema.join(name, "fluxSigma"),
43  "1-sigma flux uncertainty", "dn");
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
double getMagnitude(double const flux) const
Definition: Calib.cc:391
Defines the fields and offsets for a table.
Definition: Schema.h:46
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:94
void checkCatalogSize(afw::table::BaseCatalog const &cat1, afw::table::BaseCatalog const &cat2) const
Ensure that catalogs have the same size.
Definition: Transform.h:101
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:19
double MagErrElement
Definition: constants.h:52
A FunctorKey for MagResult.
A reusable result struct for magnitudes.
static void setThrowOnNegativeFlux(bool raiseException)
Definition: Calib.cc:138
tbl::Key< int > wcs
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
afw::table::Key< Mag > _magKey
static FluxResultKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc)
FluxResult()
Default constructor; initializes everything to NaN.
afw::table::Key< MagErrElement > _magErrKey
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
Definition: BaseRecord.h:123
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
Schema getSchema() const
Return the schema associated with the catalog&#39;s table.
Definition: Catalog.h:114
afw::table::Key< Flux > _flux
Iterator class for CatalogT.
Definition: Catalog.h:34
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
tbl::Schema schema
A FunctorKey for FluxResult.
Definition: FluxUtilities.h:56
static MagResultKey addFields(afw::table::Schema &schema, std::string const &name)
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a new field to the Schema, and return the associated Key.
FluxTransform(std::string const &name, afw::table::SchemaMapper &mapper)
Base class for all records.
Definition: BaseRecord.h:27
std::string join(std::string const &a, std::string const &b) const
Join strings using the field delimiter appropriate for this Schema.
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.
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:136
FluxErrElement fluxSigma
1-Sigma error (sqrt of variance) on flux in DN.
Definition: FluxUtilities.h:39
static bool getThrowOnNegativeFlux()
Definition: Calib.cc:148
afw::table::Key< FluxErrElement > _fluxSigma
A reusable result struct for flux measurements.
Definition: FluxUtilities.h:37