Skip to content

Commit

Permalink
Replace assert with exception for invalid argument
Browse files Browse the repository at this point in the history
The methods `setNumIter` and `setNumSigmaClip` must throw an exception
if the input parameters are invalid instead of asserting that they are
valid.
  • Loading branch information
arunkannawadi committed May 6, 2021
1 parent 2bc2b1e commit c4355d6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
10 changes: 8 additions & 2 deletions include/lsst/afw/math/Statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,17 @@ class StatisticsControl {
bool getCalcErrorFromInputVariance() const noexcept { return _calcErrorFromInputVariance; }

void setNumSigmaClip(double numSigmaClip) {
assert(numSigmaClip > 0);
if !(numSigmaClip > 0) {
throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
"numSigmaClip has to be positive.");
}
_numSigmaClip = numSigmaClip;
}
void setNumIter(int numIter) {
assert(numIter > 0);
if !(numIter > 0) {
throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
"numIter has to be positive.");
}
_numIter = numIter;
}
void setAndMask(int andMask) { _andMask = andMask; }
Expand Down
16 changes: 14 additions & 2 deletions python/lsst/afw/math/_statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,20 @@ void declareStatistics(lsst::utils::python::WrapperCollection &wrappers) {
cls.def("getWeighted", &StatisticsControl::getWeighted);
cls.def("getWeightedIsSet", &StatisticsControl::getWeightedIsSet);
cls.def("getCalcErrorFromInputVariance", &StatisticsControl::getCalcErrorFromInputVariance);
cls.def("setNumSigmaClip", &StatisticsControl::setNumSigmaClip);
cls.def("setNumIter", &StatisticsControl::setNumIter);
cls.def("setNumSigmaClip", [](StatisticsControl& sctrl, double numSigmaClip) {
if (numSigmaClip <= 0) {
throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
"numSigmaClip has to be positive");
}
sctrl.setNumSigmaClip(numSigmaClip);
});
cls.def("setNumIter", [](StatisticsControl& sctrl, int numIter) {
if (numIter <= 0) {
throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
"numIter has to be positive");
}
sctrl.setNumIter(numIter);
});
cls.def("setAndMask", &StatisticsControl::setAndMask);
cls.def("setNoGoodPixelsMask", &StatisticsControl::setNoGoodPixelsMask);
cls.def("setNanSafe", &StatisticsControl::setNanSafe);
Expand Down

0 comments on commit c4355d6

Please sign in to comment.