|
19 | 19 | # You should have received a copy of the GNU General Public License |
20 | 20 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
21 | 21 |
|
22 | | -__all__ = ["PhotoCalTask", "PhotoCalConfig"] |
| 22 | +__all__ = ["PhotoCalTask", "PhotoCalConfig", "PhotoCalInputFluxError"] |
23 | 23 |
|
24 | 24 | import math |
25 | 25 | import sys |
|
38 | 38 | from .colorterms import ColortermLibrary |
39 | 39 |
|
40 | 40 |
|
| 41 | +class PhotoCalInputFluxError(pipeBase.AlgorithmError): |
| 42 | + """Raised if photoCal fails in a non-recoverable way. |
| 43 | +
|
| 44 | + Parameters |
| 45 | + ---------- |
| 46 | + nMatches : `int` |
| 47 | + Number of nMatches available to the fitter at the point of failure. |
| 48 | + nFiniteInstFluxes : `int` |
| 49 | + Number of calibration instFluxes that are are finite (non-NaN). |
| 50 | + nFiniteInstFluxes : `int` |
| 51 | + Number of calibration instFluxErrs that are are finite (non-NaN). |
| 52 | + """ |
| 53 | + def __init__(self, *, nMatches, nFiniteInstFluxes, nFiniteInstFluxErrs): |
| 54 | + msg = (f"No finite calibration instFluxes ({nFiniteInstFluxes}) or " |
| 55 | + f"instFluxErrs ({nFiniteInstFluxErrs}) for {nMatches} matches.") |
| 56 | + super().__init__(msg) |
| 57 | + self.nMatches = nMatches |
| 58 | + self.nFiniteInstFluxes = nFiniteInstFluxes |
| 59 | + self.nFiniteInstFluxErrs = nFiniteInstFluxErrs |
| 60 | + |
| 61 | + @property |
| 62 | + def metadata(self): |
| 63 | + metadata = {"nMatches": self.nMatches, |
| 64 | + "nFiniteInstFluxes": self.nFiniteInstFluxes, |
| 65 | + "nFiniteInstFluxErrs": self.nFiniteInstFluxErrs, |
| 66 | + } |
| 67 | + return metadata |
| 68 | + |
| 69 | + |
41 | 70 | class PhotoCalConfig(pexConf.Config): |
42 | 71 | """Config for PhotoCal.""" |
43 | 72 |
|
@@ -238,10 +267,13 @@ def extractMagArrays(self, matches, filterLabel, sourceKeys): |
238 | 267 | """ |
239 | 268 | srcInstFluxArr = np.array([m.second.get(sourceKeys.instFlux) for m in matches]) |
240 | 269 | srcInstFluxErrArr = np.array([m.second.get(sourceKeys.instFluxErr) for m in matches]) |
241 | | - if not np.all(np.isfinite(srcInstFluxErrArr)): |
242 | | - # this is an unpleasant hack; see DM-2308 requesting a better solution |
243 | | - self.log.warning("Source catalog does not have flux uncertainties; using sqrt(flux).") |
244 | | - srcInstFluxErrArr = np.sqrt(srcInstFluxArr) |
| 270 | + |
| 271 | + nFiniteInstFluxes = np.isfinite(srcInstFluxArr).sum() |
| 272 | + nFiniteInstFluxErrs = np.isfinite(srcInstFluxErrArr).sum() |
| 273 | + |
| 274 | + if not nFiniteInstFluxes or not nFiniteInstFluxErrs: |
| 275 | + raise PhotoCalInputFluxError(nMatches=len(matches), nFiniteInstFluxes=nFiniteInstFluxes, |
| 276 | + nFiniteInstFluxErrs=nFiniteInstFluxErrs) |
245 | 277 |
|
246 | 278 | # convert source instFlux from DN to an estimate of nJy |
247 | 279 | referenceFlux = (0*u.ABmag).to_value(u.nJy) |
|
0 commit comments