-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No python bindings because astropy handles this directly. Lifted out of afw PhotoCalib.
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// -*- LSST-C++ -*- | ||
/* | ||
* This file is part of utils. | ||
* | ||
* Developed for the LSST Data Management System. | ||
* This product includes software developed by the LSST Project | ||
* (https://www.lsst.org). | ||
* See the COPYRIGHT file at the top-level directory of this distribution | ||
* for details of code ownership. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* @brief Utilities for converting between flux and magnitude in C++. | ||
* | ||
* Use `astropy.units` `ABmag` and `nJy` for converstions in python: | ||
* @code{.python} | ||
* import astropy.units as u | ||
* # .value gives just the number | ||
* mag = (flux*u.nJy).to(u.ABmag).value | ||
* flux = (mag*u.ABmag).to(u.nJy).value | ||
* @endcode | ||
*/ | ||
|
||
#ifndef LSST_UTILS_MAGNITUDE_H | ||
#define LSST_UTILS_MAGNITUDE_H | ||
|
||
#include <cmath> | ||
|
||
namespace lsst { | ||
namespace utils { | ||
|
||
/// The Oke & Gunn (1983) AB magnitude reference flux, in nJy (often approximated as 3631.0). | ||
const double referenceFlux = 1e23 * pow(10, (48.6 / -2.5)) * 1e9; | ||
|
||
/// Convert a flux in nanojansky to AB magnitude. | ||
double nanojanskyToABMagnitude(double flux); | ||
|
||
/// Convert an AB magnitude to a flux in nanojansky. | ||
double ABMagnitudeToNanojansky(double magnitude); | ||
|
||
} // namespace utils | ||
} // namespace lsst | ||
|
||
#endif // LSST_UTILS_MAGNITUDE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// -*- LSST-C++ -*- | ||
/* | ||
* This file is part of utils. | ||
* | ||
* Developed for the LSST Data Management System. | ||
* This product includes software developed by the LSST Project | ||
* (https://www.lsst.org). | ||
* See the COPYRIGHT file at the top-level directory of this distribution | ||
* for details of code ownership. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "lsst/utils/Magnitude.h" | ||
|
||
namespace lsst { | ||
namespace utils { | ||
|
||
double nanojanskyToABMagnitude(double flux) { return -2.5 * log10(flux / referenceFlux); } | ||
|
||
double ABMagnitudeToNanojansky(double magnitude) { return pow(10, magnitude / -2.5) * referenceFlux; } | ||
|
||
} // namespace utils | ||
} // namespace lsst |